diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index 2d47abbe23..5acc9ed692 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -2337,6 +2337,7 @@ SetMemoryGCModePrefChangedCallback(const char* aPrefName, void* aClosure) { bool enableCompartmentGC = Preferences::GetBool("javascript.options.mem.gc_per_compartment"); bool enableIncrementalGC = Preferences::GetBool("javascript.options.mem.gc_incremental"); + bool enableGenerationalGC = Preferences::GetBool("javascript.options.mem.gc_generational"); JSGCMode mode; if (enableIncrementalGC) { mode = JSGC_MODE_INCREMENTAL; @@ -2346,6 +2347,7 @@ SetMemoryGCModePrefChangedCallback(const char* aPrefName, void* aClosure) mode = JSGC_MODE_GLOBAL; } JS_SetGCParameter(sRuntime, JSGC_MODE, mode); + JS_SetGGCMode(sRuntime, enableGenerationalGC); } static void @@ -2626,6 +2628,9 @@ nsJSContext::EnsureStatics() Preferences::RegisterCallbackAndCall(SetMemoryGCSliceTimePrefChangedCallback, "javascript.options.mem.gc_incremental_slice_ms"); + Preferences::RegisterCallbackAndCall(SetMemoryGCModePrefChangedCallback, + "javascript.options.mem.gc_generational"); + Preferences::RegisterCallbackAndCall(SetMemoryGCCompactingPrefChangedCallback, "javascript.options.mem.gc_compacting"); diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index de936fb712..1be04890b5 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -1393,6 +1393,18 @@ JS_SetGCParameter(JSRuntime* rt, JSGCParamKey key, uint32_t value) rt->gc.setParameter(key, value); } +JS_PUBLIC_API(void) +JS_SetGGCMode(JSRuntime* rt, bool enabled) +{ + // Control GGC + if (enabled && !rt->gc.isGenerationalGCEnabled()) { + rt->gc.enableGenerationalGC(); + } else if (!enabled && rt->gc.isGenerationalGCEnabled()) { + rt->gc.disableGenerationalGC(); + } +} + + JS_PUBLIC_API(uint32_t) JS_GetGCParameter(JSRuntime* rt, JSGCParamKey key) { diff --git a/js/src/jsapi.h b/js/src/jsapi.h index 9b641c2ad4..733d890281 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -1850,6 +1850,9 @@ typedef enum JSGCParamKey { extern JS_PUBLIC_API(void) JS_SetGCParameter(JSRuntime* rt, JSGCParamKey key, uint32_t value); +extern JS_PUBLIC_API(void) +JS_SetGGCMode(JSRuntime* rt, bool enabled); + extern JS_PUBLIC_API(uint32_t) JS_GetGCParameter(JSRuntime* rt, JSGCParamKey key); diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index fd518b3f58..ef539eef4b 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -1058,6 +1058,7 @@ pref("javascript.options.mem.max", -1); pref("javascript.options.mem.gc_per_compartment", true); pref("javascript.options.mem.gc_incremental", true); pref("javascript.options.mem.gc_incremental_slice_ms", 20); +pref("javascript.options.mem.gc_generational", false); pref("javascript.options.mem.gc_compacting", true); pref("javascript.options.mem.log", false); pref("javascript.options.mem.notify", false);