Ignore:
Timestamp:
May 25, 2021, 11:16:47 AM (4 years ago)
Author:
[email protected]
Message:

Finalize DFG/FTL code refs on the compiler threads
https://bugs.webkit.org/show_bug.cgi?id=226096

Reviewed by Mark Lam.

Previously, link tasks that ran via the addLinkTask API were guaranteed to be
called on the main thread. This is no longer the case. Most link tasks are
happy running on a background thread, since all they're really doing is
linking branches/calls or grabbing labels. However, a few users of addLinkTask were
relying on it running on the main thread. For those users, there is a new
addMainThreadFinalizationTask API, which is now used instead.

  • assembler/LinkBuffer.cpp:

(JSC::LinkBuffer::~LinkBuffer):
(JSC::LinkBuffer::runMainThreadFinalizationTasks):

  • assembler/LinkBuffer.h:

(JSC::LinkBuffer::cancel):
(JSC::LinkBuffer::addMainThreadFinalizationTask):
(JSC::LinkBuffer::~LinkBuffer): Deleted.

  • dfg/DFGFailedFinalizer.cpp:

(JSC::DFG::FailedFinalizer::finalizeFunction): Deleted.

  • dfg/DFGFailedFinalizer.h:
  • dfg/DFGFinalizer.h:

(JSC::DFG::Finalizer::cancel):

  • dfg/DFGJITCompiler.cpp:

(JSC::DFG::JITCompiler::compile):
(JSC::DFG::JITCompiler::compileFunction):

  • dfg/DFGJITFinalizer.cpp:

(JSC::DFG::JITFinalizer::cancel):
(JSC::DFG::JITFinalizer::finalize):
(JSC::DFG::JITFinalizer::finalizeFunction): Deleted.
(JSC::DFG::JITFinalizer::finalizeCommon): Deleted.

  • dfg/DFGJITFinalizer.h:
  • dfg/DFGLazyJSValue.cpp:

(JSC::DFG::LazyJSValue::emit const):

  • dfg/DFGPlan.cpp:

(JSC::DFG::Plan::finalizeWithoutNotifyingCallback):
(JSC::DFG::Plan::cancel):

  • ftl/FTLJITFinalizer.cpp:

(JSC::FTL::JITFinalizer::finalize):
(JSC::FTL::JITFinalizer::cancel):
(JSC::FTL::JITFinalizer::finalizeFunction): Deleted.
(JSC::FTL::JITFinalizer::finalizeCommon): Deleted.

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

(JSC::FTL::link):

  • ftl/FTLPatchpointExceptionHandle.cpp:

(JSC::FTL::PatchpointExceptionHandle::scheduleExitCreationForUnwind):

  • ftl/FTLThunks.h:

(JSC::FTL::Thunks::getSlowPathCallThunk):
Add a lock to FTLThunks since we now may be calling into it from more than
one thread at a time.

  • jit/AssemblyHelpers.cpp:

(JSC::AssemblyHelpers::emitVirtualCall):
(JSC::AssemblyHelpers::emitUnlinkedVirtualCall): Deleted.

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

(JSC::JIT::finalizeOnMainThread):

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

(JSC::JIT::compileCallEvalSlowCase):

  • jit/JITCall32_64.cpp:

(JSC::JIT::compileCallEvalSlowCase):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/dfg/DFGJITFinalizer.cpp

    r261895 r278030  
    5656bool JITFinalizer::finalize()
    5757{
    58     MacroAssemblerCodeRef<JSEntryPtrTag> codeRef = FINALIZE_DFG_CODE(*m_linkBuffer, JSEntryPtrTag, "DFG JIT code for %s", toCString(CodeBlockWithJITType(m_plan.codeBlock(), JITType::DFGJIT)).data());
    59     m_jitCode->initializeCodeRefForDFG(codeRef, codeRef.code());
     58    VM& vm = *m_plan.vm();
    6059
    61     m_plan.codeBlock()->setJITCode(m_jitCode.copyRef());
     60    WTF::crossModifyingCodeFence();
    6261
    63     finalizeCommon();
    64    
    65     return true;
    66 }
     62    m_linkBuffer->runMainThreadFinalizationTasks();
    6763
    68 bool JITFinalizer::finalizeFunction()
    69 {
    70     RELEASE_ASSERT(!m_withArityCheck.isEmptyValue());
    71     m_jitCode->initializeCodeRefForDFG(
    72         FINALIZE_DFG_CODE(*m_linkBuffer, JSEntryPtrTag, "DFG JIT code for %s", toCString(CodeBlockWithJITType(m_plan.codeBlock(), JITType::DFGJIT)).data()),
    73         m_withArityCheck);
    74     m_plan.codeBlock()->setJITCode(m_jitCode.copyRef());
     64    CodeBlock* codeBlock = m_plan.codeBlock();
    7565
    76     finalizeCommon();
    77    
    78     return true;
    79 }
    80 
    81 void JITFinalizer::finalizeCommon()
    82 {
    83     CodeBlock* codeBlock = m_plan.codeBlock();
     66    codeBlock->setJITCode(m_jitCode.copyRef());
    8467
    8568#if ENABLE(FTL_JIT)
     
    8871
    8972    if (UNLIKELY(m_plan.compilation()))
    90         m_plan.vm()->m_perBytecodeProfiler->addCompilation(codeBlock, *m_plan.compilation());
     73        vm.m_perBytecodeProfiler->addCompilation(codeBlock, *m_plan.compilation());
    9174
    9275    if (!m_plan.willTryToTierUp())
     
    9578    // The codeBlock is now responsible for keeping many things alive (e.g. frozen values)
    9679    // that were previously kept alive by the plan.
    97     m_plan.vm()->heap.writeBarrier(codeBlock);
     80    vm.heap.writeBarrier(codeBlock);
     81
     82    return true;
    9883}
    9984
Note: See TracChangeset for help on using the changeset viewer.