Ignore:
Timestamp:
Apr 30, 2019, 4:37:27 PM (6 years ago)
Author:
[email protected]
Message:

CodeBlock::m_instructionCount is wrong
https://bugs.webkit.org/show_bug.cgi?id=197304

Reviewed by Yusuke Suzuki.

What we were calling instructionCount() was wrong, as evidenced by
us using it incorrectly both in the sampling profiler and when we
dumped bytecode for a given CodeBlock. Prior to the bytecode rewrite,
instructionCount() was probably valid to do bounds checks against.
However, this is no longer the case. This patch renames what we called
instructionCount() to bytecodeCost(). It is now only used to make decisions
about inlining and tier up heuristics. I've also named options related to
this appropriately.

This patch also introduces instructionsSize(). The result of this method
is valid to do bounds checks against.

  • bytecode/CodeBlock.cpp:

(JSC::CodeBlock::dumpAssumingJITType const):
(JSC::CodeBlock::CodeBlock):
(JSC::CodeBlock::finishCreation):
(JSC::CodeBlock::optimizationThresholdScalingFactor):
(JSC::CodeBlock::predictedMachineCodeSize):

  • bytecode/CodeBlock.h:

(JSC::CodeBlock::instructionsSize const):
(JSC::CodeBlock::bytecodeCost const):
(JSC::CodeBlock::instructionCount const): Deleted.

  • dfg/DFGByteCodeParser.cpp:

(JSC::DFG::ByteCodeParser::inliningCost):
(JSC::DFG::ByteCodeParser::getInliningBalance):

  • dfg/DFGCapabilities.cpp:

(JSC::DFG::mightCompileEval):
(JSC::DFG::mightCompileProgram):
(JSC::DFG::mightCompileFunctionForCall):
(JSC::DFG::mightCompileFunctionForConstruct):
(JSC::DFG::mightInlineFunctionForCall):
(JSC::DFG::mightInlineFunctionForClosureCall):
(JSC::DFG::mightInlineFunctionForConstruct):

  • dfg/DFGCapabilities.h:

(JSC::DFG::isSmallEnoughToInlineCodeInto):

  • dfg/DFGDisassembler.cpp:

(JSC::DFG::Disassembler::dumpHeader):

  • dfg/DFGDriver.cpp:

(JSC::DFG::compileImpl):

  • dfg/DFGPlan.cpp:

(JSC::DFG::Plan::compileInThread):

  • dfg/DFGTierUpCheckInjectionPhase.cpp:

(JSC::DFG::TierUpCheckInjectionPhase::run):

  • ftl/FTLCapabilities.cpp:

(JSC::FTL::canCompile):

  • ftl/FTLCompile.cpp:

(JSC::FTL::compile):

  • ftl/FTLLink.cpp:

(JSC::FTL::link):

  • jit/JIT.cpp:

(JSC::JIT::link):

  • jit/JITDisassembler.cpp:

(JSC::JITDisassembler::dumpHeader):

  • llint/LLIntSlowPaths.cpp:

(JSC::LLInt::shouldJIT):

  • profiler/ProfilerBytecodes.cpp:

(JSC::Profiler::Bytecodes::Bytecodes):

  • runtime/Options.h:
  • runtime/SamplingProfiler.cpp:

(JSC::tryGetBytecodeIndex):
(JSC::SamplingProfiler::processUnverifiedStackTraces):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/bytecode/CodeBlock.cpp

    r244764 r244811  
    191191    if (codeType() == FunctionCode)
    192192        out.print(specializationKind());
    193     out.print(", ", instructionCount());
     193    out.print(", ", instructionsSize());
    194194    if (this->jitType() == JITType::BaselineJIT && m_shouldAlwaysBeInlined)
    195195        out.print(" (ShouldAlwaysBeInlined)");
     
    299299    , m_steppingMode(SteppingModeDisabled)
    300300    , m_numBreakpoints(0)
    301     , m_instructionCount(other.m_instructionCount)
     301    , m_bytecodeCost(other.m_bytecodeCost)
    302302    , m_scopeRegister(other.m_scopeRegister)
    303303    , m_hash(other.m_hash)
     
    525525    for (const auto& instruction : instructionStream) {
    526526        OpcodeID opcodeID = instruction->opcodeID();
    527         m_instructionCount += opcodeLengths[opcodeID];
     527        m_bytecodeCost += opcodeLengths[opcodeID];
    528528        switch (opcodeID) {
    529529        LINK(OpHasIndexedProperty, arrayProfile)
     
    23362336    const double d = 0.825914;
    23372337   
    2338     double instructionCount = this->instructionCount();
    2339    
    2340     ASSERT(instructionCount); // Make sure this is called only after we have an instruction stream; otherwise it'll just return the value of d, which makes no sense.
    2341    
    2342     double result = d + a * sqrt(instructionCount + b) + c * instructionCount;
     2338    double bytecodeCost = this->bytecodeCost();
     2339   
     2340    ASSERT(bytecodeCost); // Make sure this is called only after we have an instruction stream; otherwise it'll just return the value of d, which makes no sense.
     2341   
     2342    double result = d + a * sqrt(bytecodeCost + b) + c * bytecodeCost;
    23432343   
    23442344    result *= codeTypeThresholdMultiplier();
     
    23462346    if (Options::verboseOSR()) {
    23472347        dataLog(
    2348             *this, ": instruction count is ", instructionCount,
     2348            *this, ": bytecode cost is ", bytecodeCost,
    23492349            ", scaling execution counter by ", result, " * ", codeTypeThresholdMultiplier(),
    23502350            "\n");
     
    28712871        return 0;
    28722872   
    2873     double doubleResult = multiplier * instructionCount();
     2873    double doubleResult = multiplier * bytecodeCost();
    28742874   
    28752875    // Be even more paranoid: silently reject values that won't fit into a size_t. If
Note: See TracChangeset for help on using the changeset viewer.