Bug 1787526 - Part 1: Add configuration for semispace nursery r=sfink

Add a GC parameter and pref for semispace nursery which is disabled by default.

Enable it for the shell rootanalysis job to get get some test coverage.

Differential Revision: https://phabricator.services.mozilla.com/D196431
This commit is contained in:
Jon Coppeard 2024-03-18 16:13:50 +00:00
parent 0ab737bb68
commit 2ae057efaf
11 changed files with 67 additions and 2 deletions

View file

@ -2121,6 +2121,13 @@ void nsJSContext::EnsureStatics() {
"javascript.options.mem.gc_compacting", "javascript.options.mem.gc_compacting",
(void*)JSGC_COMPACTING_ENABLED); (void*)JSGC_COMPACTING_ENABLED);
#ifdef NIGHTLY_BUILD
Preferences::RegisterCallbackAndCall(
SetMemoryPrefChangedCallbackBool,
"javascript.options.mem.gc_experimental_semispace_nursery",
(void*)JSGC_SEMISPACE_NURSERY_ENABLED);
#endif
Preferences::RegisterCallbackAndCall( Preferences::RegisterCallbackAndCall(
SetMemoryPrefChangedCallbackBool, SetMemoryPrefChangedCallbackBool,
"javascript.options.mem.gc_parallel_marking", "javascript.options.mem.gc_parallel_marking",

View file

@ -372,6 +372,9 @@ void LoadJSGCMemoryOptions(const char* aPrefName, void* /* aClosure */) {
PREF("gc_parallel_marking", JSGC_PARALLEL_MARKING_ENABLED), PREF("gc_parallel_marking", JSGC_PARALLEL_MARKING_ENABLED),
PREF("gc_parallel_marking_threshold_mb", PREF("gc_parallel_marking_threshold_mb",
JSGC_PARALLEL_MARKING_THRESHOLD_MB), JSGC_PARALLEL_MARKING_THRESHOLD_MB),
#ifdef NIGHTLY_BUILD
PREF("gc_experimental_semispace_nursery", JSGC_SEMISPACE_NURSERY_ENABLED),
#endif
// Note: Workers do not currently trigger eager minor GC, but if that is // Note: Workers do not currently trigger eager minor GC, but if that is
// desired the following parameters should be added: // desired the following parameters should be added:
// javascript.options.mem.nursery_eager_collection_threshold_kb // javascript.options.mem.nursery_eager_collection_threshold_kb
@ -426,6 +429,9 @@ void LoadJSGCMemoryOptions(const char* aPrefName, void* /* aClosure */) {
} }
case JSGC_COMPACTING_ENABLED: case JSGC_COMPACTING_ENABLED:
case JSGC_PARALLEL_MARKING_ENABLED: case JSGC_PARALLEL_MARKING_ENABLED:
#ifdef NIGHTLY_BUILD
case JSGC_SEMISPACE_NURSERY_ENABLED:
#endif
case JSGC_BALANCED_HEAP_LIMITS_ENABLED: { case JSGC_BALANCED_HEAP_LIMITS_ENABLED: {
bool present; bool present;
bool prefValue = GetPref(pref->fullName, false, &present); bool prefValue = GetPref(pref->fullName, false, &present);

View file

@ -459,6 +459,15 @@ typedef enum JSGCParamKey {
* Default: ParallelMarkingThresholdMB * Default: ParallelMarkingThresholdMB
*/ */
JSGC_PARALLEL_MARKING_THRESHOLD_MB = 50, JSGC_PARALLEL_MARKING_THRESHOLD_MB = 50,
/**
* Whether the semispace nursery is enabled.
*
* Pref: javascript.options.mem.gc_experimental_semispace_nursery
* Default: SemispaceNurseryEnabled
*/
JSGC_SEMISPACE_NURSERY_ENABLED = 51,
} JSGCParamKey; } JSGCParamKey;
/* /*

View file

@ -4,6 +4,6 @@
"debug": true, "debug": true,
"env": { "env": {
"JS_GC_ZEAL": "GenerationalGC", "JS_GC_ZEAL": "GenerationalGC",
"JSTESTS_EXTRA_ARGS": "--jitflags=debug" "JSTESTS_EXTRA_ARGS": "--jitflags=debug --args='--gc-param=semispaceNurseryEnabled=1'"
} }
} }

View file

@ -1073,6 +1073,11 @@ bool GCRuntime::setParameter(JSGCParamKey key, uint32_t value,
marker->incrementalWeakMapMarkingEnabled = value != 0; marker->incrementalWeakMapMarkingEnabled = value != 0;
} }
break; break;
case JSGC_SEMISPACE_NURSERY_ENABLED: {
AutoUnlockGC unlock(lock);
nursery().setSemispaceEnabled(value);
break;
}
case JSGC_MIN_EMPTY_CHUNK_COUNT: case JSGC_MIN_EMPTY_CHUNK_COUNT:
setMinEmptyChunkCount(value, lock); setMinEmptyChunkCount(value, lock);
break; break;
@ -1160,6 +1165,11 @@ void GCRuntime::resetParameter(JSGCParamKey key, AutoLockGC& lock) {
TuningDefaults::IncrementalWeakMapMarkingEnabled; TuningDefaults::IncrementalWeakMapMarkingEnabled;
} }
break; break;
case JSGC_SEMISPACE_NURSERY_ENABLED: {
AutoUnlockGC unlock(lock);
nursery().setSemispaceEnabled(TuningDefaults::SemispaceNurseryEnabled);
break;
}
case JSGC_MIN_EMPTY_CHUNK_COUNT: case JSGC_MIN_EMPTY_CHUNK_COUNT:
setMinEmptyChunkCount(TuningDefaults::MinEmptyChunkCount, lock); setMinEmptyChunkCount(TuningDefaults::MinEmptyChunkCount, lock);
break; break;
@ -1241,6 +1251,8 @@ uint32_t GCRuntime::getParameter(JSGCParamKey key, const AutoLockGC& lock) {
return parallelMarkingEnabled; return parallelMarkingEnabled;
case JSGC_INCREMENTAL_WEAKMAP_ENABLED: case JSGC_INCREMENTAL_WEAKMAP_ENABLED:
return marker().incrementalWeakMapMarkingEnabled; return marker().incrementalWeakMapMarkingEnabled;
case JSGC_SEMISPACE_NURSERY_ENABLED:
return nursery().semispaceEnabled();
case JSGC_CHUNK_BYTES: case JSGC_CHUNK_BYTES:
return ChunkSize; return ChunkSize;
case JSGC_HELPER_THREAD_RATIO: case JSGC_HELPER_THREAD_RATIO:

View file

@ -83,7 +83,8 @@ class TenuredChunk;
_("maxHelperThreads", JSGC_MAX_HELPER_THREADS, true) \ _("maxHelperThreads", JSGC_MAX_HELPER_THREADS, true) \
_("helperThreadCount", JSGC_HELPER_THREAD_COUNT, false) \ _("helperThreadCount", JSGC_HELPER_THREAD_COUNT, false) \
_("markingThreadCount", JSGC_MARKING_THREAD_COUNT, true) \ _("markingThreadCount", JSGC_MARKING_THREAD_COUNT, true) \
_("systemPageSizeKB", JSGC_SYSTEM_PAGE_SIZE_KB, false) _("systemPageSizeKB", JSGC_SYSTEM_PAGE_SIZE_KB, false) \
_("semispaceNurseryEnabled", JSGC_SEMISPACE_NURSERY_ENABLED, true)
// Get the key and writability give a GC parameter name. // Get the key and writability give a GC parameter name.
extern bool GetGCParameterInfo(const char* name, JSGCParamKey* keyOut, extern bool GetGCParameterInfo(const char* name, JSGCParamKey* keyOut,

View file

@ -223,6 +223,7 @@ js::Nursery::Nursery(GCRuntime* gc)
startPosition_(0), startPosition_(0),
capacity_(0), capacity_(0),
enableProfiling_(false), enableProfiling_(false),
semispaceEnabled_(gc::TuningDefaults::SemispaceNurseryEnabled),
canAllocateStrings_(true), canAllocateStrings_(true),
canAllocateBigInts_(true), canAllocateBigInts_(true),
reportDeduplications_(false), reportDeduplications_(false),
@ -464,6 +465,20 @@ void js::Nursery::discardCodeAndSetJitFlagsForZone(JS::Zone* zone) {
} }
} }
void js::Nursery::setSemispaceEnabled(bool enabled) {
if (semispaceEnabled() == enabled) {
return;
}
if (!isEmpty()) {
gc->minorGC(JS::GCReason::EVICT_NURSERY);
}
disable();
semispaceEnabled_ = enabled;
enable();
}
bool js::Nursery::isEmpty() const { bool js::Nursery::isEmpty() const {
if (!isEnabled()) { if (!isEnabled()) {
return true; return true;

View file

@ -103,6 +103,9 @@ class Nursery {
void disableBigInts(); void disableBigInts();
bool canAllocateBigInts() const { return canAllocateBigInts_; } bool canAllocateBigInts() const { return canAllocateBigInts_; }
void setSemispaceEnabled(bool enabled);
bool semispaceEnabled() const { return semispaceEnabled_; }
// Return true if no allocations have been made since the last collection. // Return true if no allocations have been made since the last collection.
bool isEmpty() const; bool isEmpty() const;
@ -553,6 +556,9 @@ class Nursery {
mozilla::TimeDuration profileThreshold_; mozilla::TimeDuration profileThreshold_;
// Whether to use semispace collection.
bool semispaceEnabled_;
// Whether we will nursery-allocate strings. // Whether we will nursery-allocate strings.
bool canAllocateStrings_; bool canAllocateStrings_;

View file

@ -536,6 +536,9 @@ static const bool ParallelMarkingEnabled = false;
/* JSGC_INCREMENTAL_WEAKMAP_ENABLED */ /* JSGC_INCREMENTAL_WEAKMAP_ENABLED */
static const bool IncrementalWeakMapMarkingEnabled = true; static const bool IncrementalWeakMapMarkingEnabled = true;
/* JSGC_SEMISPACE_NURSERY_ENABLED */
static const bool SemispaceNurseryEnabled = false;
/* JSGC_HELPER_THREAD_RATIO */ /* JSGC_HELPER_THREAD_RATIO */
static const double HelperThreadRatio = 0.5; static const double HelperThreadRatio = 0.5;

View file

@ -60,3 +60,4 @@ testChangeParam("mallocThresholdBase");
testChangeParam("urgentThreshold"); testChangeParam("urgentThreshold");
testChangeParam("helperThreadRatio"); testChangeParam("helperThreadRatio");
testChangeParam("maxHelperThreads"); testChangeParam("maxHelperThreads");
testChangeParam("semispaceNurseryEnabled");

View file

@ -959,6 +959,11 @@ pref("javascript.options.mem.gc_incremental_slice_ms", 5);
// JSGC_COMPACTING_ENABLED // JSGC_COMPACTING_ENABLED
pref("javascript.options.mem.gc_compacting", true); pref("javascript.options.mem.gc_compacting", true);
#ifdef NIGHTLY_BUILD
// JSGC_SEMISPACE_NURSERY_ENABLED
pref("javascript.options.mem.gc_experimental_semispace_nursery", false);
#endif
// JSGC_PARALLEL_MARKING_ENABLED // JSGC_PARALLEL_MARKING_ENABLED
// This only applies to the main runtime and does not affect workers. // This only applies to the main runtime and does not affect workers.
#ifndef ANDROID #ifndef ANDROID