Ignore:
Timestamp:
Apr 4, 2022, 9:10:35 PM (3 years ago)
Author:
[email protected]
Message:

[JSC] Store CodeBlock in caller side
https://bugs.webkit.org/show_bug.cgi?id=238535

Reviewed by Saam Barati.

This patch changes the calling convention of JS functions. Now, we need to store CodeBlock to the stack in the caller side instead.
This helps LLInt, unlinked Baseline, and DFG since we no longer need to load CodeBlock from callee via costly dependent loads: unlinked
ones cannot embed CodeBlock raw pointer into the machine code itself. So we needed to load it from callee. But now, caller puts the
right CodeBlock pointer into the stack so we do not need that code. And in most cases, caller already knows CodeBlock since it is tied
to actually used machine code pointer.
OSR entry also materializes CodeBlock in the stack in the OSR entry side instead of doing it in the callee side.

This contributes to 0.3% progression in Speedometer2.

  • assembler/CPU.h:

(JSC::prologueStackPointerDelta):

  • bytecode/CallLinkInfo.cpp:

(JSC::CallLinkInfo::setMonomorphicCallee):
(JSC::CallLinkInfo::clearCallee):
(JSC::CallLinkInfo::revertCallToStub):
(JSC::CallLinkInfo::emitFastPathImpl):
(JSC::CallLinkInfo::setStub):
(JSC::OptimizingCallLinkInfo::emitDirectFastPath):
(JSC::OptimizingCallLinkInfo::emitDirectTailCallFastPath):
(JSC::OptimizingCallLinkInfo::initializeDirectCall):
(JSC::OptimizingCallLinkInfo::setDirectCallTarget):

  • bytecode/CallLinkInfo.h:

(JSC::CallLinkInfo::offsetOfCodeBlock):

  • bytecode/Repatch.cpp:

(JSC::linkMonomorphicCall):
(JSC::linkDirectCall):
(JSC::linkPolymorphicCall):

  • bytecode/RepatchInlines.h:

(JSC::virtualForWithFunction):

  • dfg/DFGJITCompiler.cpp:

(JSC::DFG::JITCompiler::compileEntry):

  • dfg/DFGOSREntry.cpp:

(JSC::DFG::prepareOSREntry):
(JSC::DFG::prepareCatchOSREntry):

  • dfg/DFGSpeculativeJIT.cpp:

(JSC::DFG::SpeculativeJIT::compileCurrentBlock):

  • dfg/DFGThunks.cpp:

(JSC::DFG::osrEntryThunkGenerator):

  • ftl/FTLAbstractHeapRepository.h:
  • ftl/FTLLink.cpp:

(JSC::FTL::link):

  • ftl/FTLLowerDFGToB3.cpp:

(JSC::FTL::DFG::LowerDFGToB3::lower):

  • interpreter/CallFrame.h:
  • jit/AssemblyHelpers.h:

(JSC::AssemblyHelpers::calleeFrameCodeBlockBeforeCall):
(JSC::AssemblyHelpers::calleeFrameCodeBlockBeforeTailCall):
(JSC::AssemblyHelpers::prologueStackPointerDelta): Deleted.

  • jit/CCallHelpers.h:

(JSC::CCallHelpers::prepareForTailCallSlow):

  • jit/JIT.cpp:

(JSC::JIT::compileAndLinkWithoutFinalizing):
(JSC::JIT::emitPutCodeBlockToFrameInPrologue): Deleted.

  • jit/JIT.h:
  • jit/JITOperations.cpp:

(JSC::JSC_DEFINE_JIT_OPERATION):

  • jit/JITOperations.h:
  • jit/ThunkGenerators.cpp:

(JSC::virtualThunkFor):
(JSC::boundFunctionCallGenerator):
(JSC::remoteFunctionCallGenerator):

  • llint/LowLevelInterpreter.asm:
  • llint/LowLevelInterpreter32_64.asm:
  • llint/LowLevelInterpreter64.asm:
  • llint/WebAssembly.asm:
  • runtime/FunctionExecutable.h:
  • runtime/JSCast.h:
  • runtime/VM.cpp:

(JSC::VM::getRemoteFunction):

  • wasm/WasmOperations.cpp:

(JSC::Wasm::doOSREntry):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/jit/JIT.cpp

    r292191 r292372  
    202202    JITSlowPathCall slowPathCall(this, stub);
    203203    slowPathCall.call();
    204 }
    205 
    206 void JIT::emitPutCodeBlockToFrameInPrologue(GPRReg result)
    207 {
    208     RELEASE_ASSERT(m_unlinkedCodeBlock->codeType() == FunctionCode);
    209     emitGetFromCallFrameHeaderPtr(CallFrameSlot::callee, result);
    210     loadPtr(Address(result, JSFunction::offsetOfExecutableOrRareData()), result);
    211     auto hasExecutable = branchTestPtr(Zero, result, CCallHelpers::TrustedImm32(JSFunction::rareDataTag));
    212     loadPtr(Address(result, FunctionRareData::offsetOfExecutable() - JSFunction::rareDataTag), result);
    213     hasExecutable.link(this);
    214     if (m_unlinkedCodeBlock->isConstructor())
    215         loadPtr(Address(result, FunctionExecutable::offsetOfCodeBlockForConstruct()), result);
    216     else
    217         loadPtr(Address(result, FunctionExecutable::offsetOfCodeBlockForCall()), result);
    218     emitPutToCallFrameHeader(result, CallFrameSlot::codeBlock);
    219 
    220 #if ASSERT_ENABLED
    221     probeDebug([=] (Probe::Context& ctx) {
    222         CodeBlock* codeBlock = ctx.fp<CallFrame*>()->codeBlock();
    223         RELEASE_ASSERT(codeBlock->jitType() == JITType::BaselineJIT);
    224     });
    225 #endif
    226204}
    227205
     
    752730
    753731    std::optional<JITSizeStatistics::Marker> sizeMarker;
    754     if (UNLIKELY(Options::dumpBaselineJITSizeStatistics())) {
    755         String id = makeString("Baseline_prologue");
    756         sizeMarker = m_vm->jitSizeStatistics->markStart(id, *this);
    757     }
     732    if (UNLIKELY(Options::dumpBaselineJITSizeStatistics()))
     733        sizeMarker = m_vm->jitSizeStatistics->markStart("Baseline_prologue"_s, *this);
    758734
    759735    Label entryLabel(this);
     
    766742
    767743    emitFunctionPrologue();
    768     if (m_unlinkedCodeBlock->codeType() == FunctionCode)
    769         emitPutCodeBlockToFrameInPrologue();
     744#if ASSERT_ENABLED
     745    probeDebug([=](Probe::Context& ctx) {
     746        CodeBlock* codeBlock = ctx.fp<CallFrame*>()->codeBlock();
     747        if (codeBlock->jitType() != JITType::BaselineJIT) {
     748            dataLogLn("FP ", RawPointer(ctx.fp<CallFrame*>()));
     749            RELEASE_ASSERT_NOT_REACHED();
     750        }
     751    });
     752#endif
    770753
    771754    Label beginLabel(this);
     
    830813
    831814        emitFunctionPrologue();
    832         emitPutCodeBlockToFrameInPrologue(regT0);
     815        RELEASE_ASSERT(m_unlinkedCodeBlock->codeType() == FunctionCode);
     816#if ASSERT_ENABLED
     817        probeDebug([=](Probe::Context& ctx) {
     818            CodeBlock* codeBlock = ctx.fp<CallFrame*>()->codeBlock();
     819            if (codeBlock->jitType() != JITType::BaselineJIT) {
     820                dataLogLn("FP ", RawPointer(ctx.fp<CallFrame*>()));
     821                RELEASE_ASSERT_NOT_REACHED();
     822            }
     823        });
     824#endif
     825        emitGetFromCallFrameHeaderPtr(CallFrameSlot::codeBlock, regT0);
    833826        store8(TrustedImm32(0), Address(regT0, CodeBlock::offsetOfShouldAlwaysBeInlined()));
    834827
Note: See TracChangeset for help on using the changeset viewer.