⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 284668 in webkit


Ignore:
Timestamp:
Oct 22, 2021, 12:19:52 AM (5 years ago)
Author:
mark.lam@apple.com
Message:

Remove unneeded Heap::m_vm.
https://bugs.webkit.org/show_bug.cgi?id=232132

Reviewed by Yusuke Suzuki.

Heap::vm() already computes the associated VM& using offset math. This entails
subtracting a constant from Heap's this pointer, which is faster than loading from
a field.

  • heap/Heap.cpp:

(JSC::Heap::Heap):
(JSC::Heap::lastChanceToFinalize):
(JSC::Heap::releaseDelayedReleasedObjects):
(JSC::Heap::protect):
(JSC::Heap::unprotect):
(JSC::Heap::finalizeUnconditionalFinalizers):
(JSC::Heap::completeAllJITPlans):
(JSC::Heap::iterateExecutingAndCompilingCodeBlocks):
(JSC::Heap::gatherJSStackRoots):
(JSC::Heap::gatherScratchBufferRoots):
(JSC::Heap::removeDeadCompilerWorklistEntries):
(JSC::Heap::gatherExtraHeapData):
(JSC::Heap::deleteAllCodeBlocks):
(JSC::Heap::deleteAllUnlinkedCodeBlocks):
(JSC::Heap::finishChangingPhase):
(JSC::Heap::collectInMutatorThread):
(JSC::Heap::finishRelinquishingConn):
(JSC::Heap::deleteSourceProviderCaches):
(JSC::Heap::didFinishCollection):
(JSC::Heap::isValidAllocation):
(JSC::Heap::addCoreConstraints):

  • heap/Heap.h:
Location:
trunk/Source/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r284664 r284668  
     12021-10-22  Mark Lam  <mark.lam@apple.com>
     2
     3        Remove unneeded Heap::m_vm.
     4        https://bugs.webkit.org/show_bug.cgi?id=232132
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        Heap::vm() already computes the associated VM& using offset math.  This entails
     9        subtracting a constant from Heap's this pointer, which is faster than loading from
     10        a field.
     11
     12        * heap/Heap.cpp:
     13        (JSC::Heap::Heap):
     14        (JSC::Heap::lastChanceToFinalize):
     15        (JSC::Heap::releaseDelayedReleasedObjects):
     16        (JSC::Heap::protect):
     17        (JSC::Heap::unprotect):
     18        (JSC::Heap::finalizeUnconditionalFinalizers):
     19        (JSC::Heap::completeAllJITPlans):
     20        (JSC::Heap::iterateExecutingAndCompilingCodeBlocks):
     21        (JSC::Heap::gatherJSStackRoots):
     22        (JSC::Heap::gatherScratchBufferRoots):
     23        (JSC::Heap::removeDeadCompilerWorklistEntries):
     24        (JSC::Heap::gatherExtraHeapData):
     25        (JSC::Heap::deleteAllCodeBlocks):
     26        (JSC::Heap::deleteAllUnlinkedCodeBlocks):
     27        (JSC::Heap::finishChangingPhase):
     28        (JSC::Heap::collectInMutatorThread):
     29        (JSC::Heap::finishRelinquishingConn):
     30        (JSC::Heap::deleteSourceProviderCaches):
     31        (JSC::Heap::didFinishCollection):
     32        (JSC::Heap::isValidAllocation):
     33        (JSC::Heap::addCoreConstraints):
     34        * heap/Heap.h:
     35
    1362021-10-21  Saam Barati  <sbarati@apple.com>
    237
  • trunk/Source/JavaScriptCore/heap/Heap.cpp

    r282707 r284668  
    292292    , m_codeBlocks(makeUnique<CodeBlockSet>())
    293293    , m_jitStubRoutines(makeUnique<JITStubRoutineSet>())
    294     , m_vm(vm)
    295     // We seed with 10ms so that GCActivityCallback::didAllocate doesn't continuously
     294    // We seed with 10ms so that GCActivityCallback::didAllocate doesn't continuously
    296295    // schedule the timer if we've never done a collection.
    297296    , m_fullActivityCallback(GCActivityCallback::tryCreateFullTimer(this))
     
    396395    m_isShuttingDown = true;
    397396   
    398     RELEASE_ASSERT(!m_vm.entryScope);
     397    RELEASE_ASSERT(!vm().entryScope);
    399398    RELEASE_ASSERT(m_mutatorState == MutatorState::Running);
    400399   
     
    484483    if (!m_delayedReleaseRecursionCount++) {
    485484        while (!m_delayedReleaseObjects.isEmpty()) {
    486             ASSERT(m_vm.currentThreadIsHoldingAPILock());
     485            ASSERT(vm().currentThreadIsHoldingAPILock());
    487486
    488487            auto objectsToRelease = WTFMove(m_delayedReleaseObjects);
     
    490489            {
    491490                // We need to drop locks before calling out to arbitrary code.
    492                 JSLock::DropAllLocks dropAllLocks(m_vm);
     491                JSLock::DropAllLocks dropAllLocks(vm());
    493492
    494493#if USE(FOUNDATION)
     
    557556{
    558557    ASSERT(k);
    559     ASSERT(m_vm.currentThreadIsHoldingAPILock());
     558    ASSERT(vm().currentThreadIsHoldingAPILock());
    560559
    561560    if (!k.isCell())
     
    568567{
    569568    ASSERT(k);
    570     ASSERT(m_vm.currentThreadIsHoldingAPILock());
     569    ASSERT(vm().currentThreadIsHoldingAPILock());
    571570
    572571    if (!k.isCell())
     
    595594void Heap::finalizeUnconditionalFinalizers()
    596595{
    597     vm().builtinExecutables()->finalizeUnconditionally();
    598     finalizeMarkedUnconditionalFinalizers<FunctionExecutable>(vm().functionExecutableSpace.space);
    599     finalizeMarkedUnconditionalFinalizers<SymbolTable>(vm().symbolTableSpace);
    600     finalizeMarkedUnconditionalFinalizers<ExecutableToCodeBlockEdge>(vm().executableToCodeBlockEdgesWithFinalizers); // We run this before CodeBlock's unconditional finalizer since CodeBlock looks at the owner executable's installed CodeBlock in its finalizeUnconditionally.
    601     vm().forEachCodeBlockSpace(
     596    VM& vm = this->vm();
     597    vm.builtinExecutables()->finalizeUnconditionally();
     598    finalizeMarkedUnconditionalFinalizers<FunctionExecutable>(vm.functionExecutableSpace.space);
     599    finalizeMarkedUnconditionalFinalizers<SymbolTable>(vm.symbolTableSpace);
     600    finalizeMarkedUnconditionalFinalizers<ExecutableToCodeBlockEdge>(vm.executableToCodeBlockEdgesWithFinalizers); // We run this before CodeBlock's unconditional finalizer since CodeBlock looks at the owner executable's installed CodeBlock in its finalizeUnconditionally.
     601    vm.forEachCodeBlockSpace(
    602602        [&] (auto& space) {
    603603            this->finalizeMarkedUnconditionalFinalizers<CodeBlock>(space.set);
    604604        });
    605     finalizeMarkedUnconditionalFinalizers<StructureRareData>(vm().structureRareDataSpace);
    606     finalizeMarkedUnconditionalFinalizers<UnlinkedFunctionExecutable>(vm().unlinkedFunctionExecutableSpace.set);
    607     if (vm().m_weakSetSpace)
    608         finalizeMarkedUnconditionalFinalizers<JSWeakSet>(*vm().m_weakSetSpace);
    609     if (vm().m_weakMapSpace)
    610         finalizeMarkedUnconditionalFinalizers<JSWeakMap>(*vm().m_weakMapSpace);
    611     if (vm().m_weakObjectRefSpace)
    612         finalizeMarkedUnconditionalFinalizers<JSWeakObjectRef>(*vm().m_weakObjectRefSpace);
    613     if (vm().m_errorInstanceSpace)
    614         finalizeMarkedUnconditionalFinalizers<ErrorInstance>(*vm().m_errorInstanceSpace);
     605    finalizeMarkedUnconditionalFinalizers<StructureRareData>(vm.structureRareDataSpace);
     606    finalizeMarkedUnconditionalFinalizers<UnlinkedFunctionExecutable>(vm.unlinkedFunctionExecutableSpace.set);
     607    if (vm.m_weakSetSpace)
     608        finalizeMarkedUnconditionalFinalizers<JSWeakSet>(*vm.m_weakSetSpace);
     609    if (vm.m_weakMapSpace)
     610        finalizeMarkedUnconditionalFinalizers<JSWeakMap>(*vm.m_weakMapSpace);
     611    if (vm.m_weakObjectRefSpace)
     612        finalizeMarkedUnconditionalFinalizers<JSWeakObjectRef>(*vm.m_weakObjectRefSpace);
     613    if (vm.m_errorInstanceSpace)
     614        finalizeMarkedUnconditionalFinalizers<ErrorInstance>(*vm.m_errorInstanceSpace);
    615615
    616616    // FinalizationRegistries currently rely on serial finalization because they can post tasks to the deferredWorkTimer, which normally expects tasks to only be posted by the API lock holder.
    617     if (vm().m_finalizationRegistrySpace)
    618         finalizeMarkedUnconditionalFinalizers<JSFinalizationRegistry>(*vm().m_finalizationRegistrySpace);
     617    if (vm.m_finalizationRegistrySpace)
     618        finalizeMarkedUnconditionalFinalizers<JSFinalizationRegistry>(*vm.m_finalizationRegistrySpace);
    619619
    620620#if ENABLE(WEBASSEMBLY)
    621     if (vm().m_webAssemblyCodeBlockSpace)
    622         finalizeMarkedUnconditionalFinalizers<JSWebAssemblyCodeBlock>(*vm().m_webAssemblyCodeBlockSpace);
     621    if (vm.m_webAssemblyCodeBlockSpace)
     622        finalizeMarkedUnconditionalFinalizers<JSWebAssemblyCodeBlock>(*vm.m_webAssemblyCodeBlockSpace);
    623623#endif
    624624}
     
    639639        return;
    640640#if ENABLE(JIT)
    641     JITWorklist::ensureGlobalWorklist().completeAllPlansForVM(m_vm);
     641    JITWorklist::ensureGlobalWorklist().completeAllPlansForVM(vm());
    642642#endif // ENABLE(JIT)
    643643}
     
    649649#if ENABLE(JIT)
    650650    if (Options::useJIT())
    651         JITWorklist::ensureGlobalWorklist().iterateCodeBlocksForGC(visitor, m_vm, func);
     651        JITWorklist::ensureGlobalWorklist().iterateCodeBlocksForGC(visitor, vm(), func);
    652652#else
    653653    UNUSED_PARAM(visitor);
     
    701701{
    702702#if ENABLE(C_LOOP)
    703     m_vm.interpreter->cloopStack().gatherConservativeRoots(roots, *m_jitStubRoutines, *m_codeBlocks);
     703    vm().interpreter->cloopStack().gatherConservativeRoots(roots, *m_jitStubRoutines, *m_codeBlocks);
    704704#else
    705705    UNUSED_PARAM(roots);
     
    712712    if (!Options::useJIT())
    713713        return;
    714     m_vm.gatherScratchBufferRoots(roots);
    715     m_vm.scanSideState(roots);
     714    VM& vm = this->vm();
     715    vm.gatherScratchBufferRoots(roots);
     716    vm.scanSideState(roots);
    716717#else
    717718    UNUSED_PARAM(roots);
     
    732733        return;
    733734#if ENABLE(JIT)
    734     JITWorklist::ensureGlobalWorklist().removeDeadPlans(m_vm);
     735    JITWorklist::ensureGlobalWorklist().removeDeadPlans(vm());
    735736#endif // ENABLE(JIT)
    736737}
     
    760761    if (auto* analyzer = heapProfiler.activeHeapAnalyzer()) {
    761762        HeapIterationScope heapIterationScope(*this);
    762         GatherExtraHeapData functor(m_vm, *analyzer);
     763        GatherExtraHeapData functor(vm(), *analyzer);
    763764        m_objectSpace.forEachLiveCell(heapIterationScope, functor);
    764765    }
     
    911912        return;
    912913
    913     VM& vm = m_vm;
     914    VM& vm = this->vm();
    914915    PreventCollectionScope preventCollectionScope(*this);
    915916   
     
    956957        return;
    957958
    958     VM& vm = m_vm;
     959    VM& vm = this->vm();
    959960    PreventCollectionScope preventCollectionScope(*this);
    960961
     
    16151616                }
    16161617            } else {
    1617                 sanitizeStackForVM(m_vm);
     1618                sanitizeStackForVM(vm());
    16181619                handleNeedFinalize();
    16191620            }
     
    18301831            break;
    18311832        case RunCurrentPhaseResult::NeedCurrentThreadState:
    1832             sanitizeStackForVM(m_vm);
     1833            sanitizeStackForVM(vm());
    18331834            auto lambda = [&] (CurrentThreadState& state) {
    18341835                for (;;) {
     
    19741975        dataLog("Relinquished the conn.\n");
    19751976   
    1976     sanitizeStackForVM(m_vm);
     1977    sanitizeStackForVM(vm());
    19771978   
    19781979    Locker locker { *m_threadLock };
     
    22052206{
    22062207    if (m_lastCollectionScope && m_lastCollectionScope.value() == CollectionScope::Full)
    2207         m_vm.clearSourceProviderCaches();
     2208        vm().clearSourceProviderCaches();
    22082209}
    22092210
     
    23242325#endif
    23252326
    2326     if (HeapProfiler* heapProfiler = m_vm.heapProfiler()) {
     2327    if (HeapProfiler* heapProfiler = vm().heapProfiler()) {
    23272328        gatherExtraHeapData(*heapProfiler);
    23282329        removeDeadHeapSnapshotNodes(*heapProfiler);
     
    23822383bool Heap::isValidAllocation(size_t)
    23832384{
    2384     if (!isValidThreadState(m_vm))
     2385    if (!isValidThreadState(vm()))
    23852386        return false;
    23862387
     
    27502751        "Msr", "Misc Small Roots",
    27512752        MAKE_MARKING_CONSTRAINT_EXECUTOR_PAIR(([this] (auto& visitor) {
     2753            VM& vm = this->vm();
    27522754            if constexpr (objcAPIEnabled) {
    27532755                SetRootMarkReasonScope rootScope(visitor, RootMarkReason::ExternalRememberedSet);
    2754                 scanExternalRememberedSet(m_vm, visitor);
     2756                scanExternalRememberedSet(vm, visitor);
    27552757            }
    27562758
    2757             if (m_vm.smallStrings.needsToBeVisited(*m_collectionScope)) {
     2759            if (vm.smallStrings.needsToBeVisited(*m_collectionScope)) {
    27582760                SetRootMarkReasonScope rootScope(visitor, RootMarkReason::StrongReferences);
    2759                 m_vm.smallStrings.visitStrongReferences(visitor);
     2761                vm.smallStrings.visitStrongReferences(visitor);
    27602762            }
    27612763           
     
    27802782            {
    27812783                SetRootMarkReasonScope rootScope(visitor, RootMarkReason::VMExceptions);
    2782                 visitor.appendUnbarriered(m_vm.exception());
    2783                 visitor.appendUnbarriered(m_vm.lastException());
     2784                visitor.appendUnbarriered(vm.exception());
     2785                visitor.appendUnbarriered(vm.lastException());
    27842786
    27852787                // We're going to m_terminationException directly instead of going through
     
    27872789                // TerminationException has been reified. Here, we don't care if it is
    27882790                // reified or not.
    2789                 visitor.appendUnbarriered(m_vm.m_terminationException);
     2791                visitor.appendUnbarriered(vm.m_terminationException);
    27902792            }
    27912793        })),
     
    28052807            SetRootMarkReasonScope rootScope(visitor, RootMarkReason::Debugger);
    28062808
     2809            VM& vm = this->vm();
    28072810            if constexpr (samplingProfilerSupported)
    2808                 visitSamplingProfiler(m_vm, visitor);
    2809 
    2810             if (m_vm.typeProfiler())
    2811                 m_vm.typeProfilerLog()->visit(visitor);
     2811                visitSamplingProfiler(vm, visitor);
     2812
     2813            if (vm.typeProfiler())
     2814                vm.typeProfilerLog()->visit(visitor);
    28122815           
    2813             if (auto* shadowChicken = m_vm.shadowChicken())
     2816            if (auto* shadowChicken = vm.shadowChicken())
    28142817                shadowChicken->visitChildren(visitor);
    28152818        })),
     
    28692872                // https://bugs.webkit.org/show_bug.cgi?id=166829
    28702873                JITWorklist::ensureGlobalWorklist().iterateCodeBlocksForGC(visitor,
    2871                     m_vm,
     2874                    vm(),
    28722875                    [&] (CodeBlock* codeBlock) {
    28732876                        visitor.appendUnbarriered(codeBlock);
  • trunk/Source/JavaScriptCore/heap/Heap.h

    r284663 r284668  
    656656    unsigned m_barrierThreshold { Options::forceFencedBarrier() ? tautologicalThreshold : blackThreshold };
    657657
    658     VM& m_vm;
    659658    Seconds m_lastFullGCLength { 10_ms };
    660659    Seconds m_lastEdenGCLength { 10_ms };
Note: See TracChangeset for help on using the changeset viewer.