summaryrefslogtreecommitdiffstats
path: root/js/src/gc/GC.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:35:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:35:29 +0000
commit59203c63bb777a3bacec32fb8830fba33540e809 (patch)
tree58298e711c0ff0575818c30485b44a2f21bf28a0 /js/src/gc/GC.cpp
parentAdding upstream version 126.0.1. (diff)
downloadfirefox-59203c63bb777a3bacec32fb8830fba33540e809.tar.xz
firefox-59203c63bb777a3bacec32fb8830fba33540e809.zip
Adding upstream version 127.0.upstream/127.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/gc/GC.cpp')
-rw-r--r--js/src/gc/GC.cpp50
1 files changed, 34 insertions, 16 deletions
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<NormalPropMap>(); !map.done();
map.next()) {
if (PropMapTable* table = map->asLinked()->maybeTable(nogc)) {
- table->checkAfterMovingGC();
+ table->checkAfterMovingGC(zone);
}
}
for (auto map = zone->cellIterUnsafe<DictionaryPropMap>(); !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()) {