From 8dd16259287f58f9273002717ec4d27e97127719 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 07:43:14 +0200 Subject: Merging upstream version 127.0. Signed-off-by: Daniel Baumann --- js/src/gc/GC.cpp | 50 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 16 deletions(-) (limited to 'js/src/gc/GC.cpp') diff --git a/js/src/gc/GC.cpp b/js/src/gc/GC.cpp index 68dd66898c..bdd252907b 100644 --- a/js/src/gc/GC.cpp +++ b/js/src/gc/GC.cpp @@ -411,6 +411,8 @@ GCRuntime::GCRuntime(JSRuntime* rt) helperThreadRatio(TuningDefaults::HelperThreadRatio), maxHelperThreads(TuningDefaults::MaxHelperThreads), helperThreadCount(1), + maxMarkingThreads(TuningDefaults::MaxMarkingThreads), + markingThreadCount(1), createBudgetCallback(nullptr), minEmptyChunkCount_(TuningDefaults::MinEmptyChunkCount), maxEmptyChunkCount_(TuningDefaults::MaxEmptyChunkCount), @@ -1049,7 +1051,7 @@ bool GCRuntime::setParameter(JSContext* cx, JSGCParamKey key, uint32_t value) { static bool IsGCThreadParameter(JSGCParamKey key) { return key == JSGC_HELPER_THREAD_RATIO || key == JSGC_MAX_HELPER_THREADS || - key == JSGC_MARKING_THREAD_COUNT; + key == JSGC_MAX_MARKING_THREADS; } bool GCRuntime::setParameter(JSGCParamKey key, uint32_t value, @@ -1120,8 +1122,8 @@ bool GCRuntime::setThreadParameter(JSGCParamKey key, uint32_t value, } maxHelperThreads = value; break; - case JSGC_MARKING_THREAD_COUNT: - markingThreadCount = std::min(size_t(value), MaxParallelWorkers); + case JSGC_MAX_MARKING_THREADS: + maxMarkingThreads = std::min(size_t(value), MaxParallelWorkers); break; default: MOZ_CRASH("Unexpected parameter key"); @@ -1201,8 +1203,8 @@ void GCRuntime::resetThreadParameter(JSGCParamKey key, AutoLockGC& lock) { case JSGC_MAX_HELPER_THREADS: maxHelperThreads = TuningDefaults::MaxHelperThreads; break; - case JSGC_MARKING_THREAD_COUNT: - markingThreadCount = 0; + case JSGC_MAX_MARKING_THREADS: + maxMarkingThreads = TuningDefaults::MaxMarkingThreads; break; default: MOZ_CRASH("Unexpected parameter key"); @@ -1265,6 +1267,8 @@ uint32_t GCRuntime::getParameter(JSGCParamKey key, const AutoLockGC& lock) { return maxHelperThreads; case JSGC_HELPER_THREAD_COUNT: return helperThreadCount; + case JSGC_MAX_MARKING_THREADS: + return maxMarkingThreads; case JSGC_MARKING_THREAD_COUNT: return markingThreadCount; case JSGC_SYSTEM_PAGE_SIZE_KB: @@ -1316,8 +1320,12 @@ void GCRuntime::updateHelperThreadCount() { std::clamp(size_t(double(cpuCount) * helperThreadRatio.ref()), size_t(1), maxHelperThreads.ref()); + // Calculate the target thread count for parallel marking, which uses separate + // parameters to let us adjust this independently. + markingThreadCount = std::min(cpuCount / 2, maxMarkingThreads.ref()); + // Calculate the overall target thread count taking into account the separate - // parameter for parallel marking threads. Add spare threads to avoid blocking + // target for parallel marking threads. Add spare threads to avoid blocking // parallel marking when there is other GC work happening. size_t targetCount = std::max(helperThreadCount.ref(), @@ -1334,9 +1342,13 @@ void GCRuntime::updateHelperThreadCount() { MOZ_ASSERT(availableThreadCount != 0); targetCount = std::min(targetCount, availableThreadCount); helperThreadCount = std::min(helperThreadCount.ref(), availableThreadCount); - markingThreadCount = - std::min(markingThreadCount.ref(), - availableThreadCount - SpareThreadsDuringParallelMarking); + if (availableThreadCount < SpareThreadsDuringParallelMarking) { + markingThreadCount = 1; + } else { + markingThreadCount = + std::min(markingThreadCount.ref(), + availableThreadCount - SpareThreadsDuringParallelMarking); + } // Update the maximum number of threads that will be used for GC work. maxParallelThreads = targetCount; @@ -2948,6 +2960,10 @@ void GCRuntime::beginMarkPhase(AutoGCSession& session) { checkNoRuntimeRoots(session); } else { AutoUpdateLiveCompartments updateLive(this); +#ifdef DEBUG + AutoSetThreadIsMarking threadIsMarking; +#endif // DEBUG + marker().setRootMarkingMode(true); traceRuntimeForMajorGC(marker().tracer(), session); marker().setRootMarkingMode(false); @@ -3093,6 +3109,10 @@ IncrementalProgress GCRuntime::markUntilBudgetExhausted( } } +#ifdef DEBUG + AutoSetThreadIsMarking threadIsMarking; +#endif // DEBUG + if (processTestMarkQueue() == QueueYielded) { return NotFinished; } @@ -3112,10 +3132,6 @@ IncrementalProgress GCRuntime::markUntilBudgetExhausted( return Finished; } -#ifdef DEBUG - AutoSetThreadIsMarking threadIsMarking; -#endif // DEBUG - return marker().markUntilBudgetExhausted(sliceBudget, reportTime) ? Finished : NotFinished; @@ -5054,7 +5070,7 @@ void GCRuntime::checkHashTablesAfterMovingGC() { } for (ZonesIter zone(this, SkipAtoms); !zone.done(); zone.next()) { zone->checkUniqueIdTableAfterMovingGC(); - zone->shapeZone().checkTablesAfterMovingGC(); + zone->shapeZone().checkTablesAfterMovingGC(zone); zone->checkAllCrossCompartmentWrappersAfterMovingGC(); zone->checkScriptMapsAfterMovingGC(); @@ -5063,15 +5079,17 @@ void GCRuntime::checkHashTablesAfterMovingGC() { for (auto map = zone->cellIterUnsafe(); !map.done(); map.next()) { if (PropMapTable* table = map->asLinked()->maybeTable(nogc)) { - table->checkAfterMovingGC(); + table->checkAfterMovingGC(zone); } } for (auto map = zone->cellIterUnsafe(); !map.done(); map.next()) { if (PropMapTable* table = map->asLinked()->maybeTable(nogc)) { - table->checkAfterMovingGC(); + table->checkAfterMovingGC(zone); } } + + WeakMapBase::checkWeakMapsAfterMovingGC(zone); } for (CompartmentsIter c(this); !c.done(); c.next()) { -- cgit v1.2.3