Bug 1895661 - Part 2: Add browser prefs for GC zeal r=sfink

There was existing code to read the prefs, but the prefs themselves had been removed.

I renamed the prefs in line with all the other JS GC options, so starting
javascript.options.mem.gc_.

Differential Revision: https://phabricator.services.mozilla.com/D210059
This commit is contained in:
Jon Coppeard 2024-05-13 16:31:20 +00:00
parent e38e561b0a
commit 0cf7156d6d
3 changed files with 23 additions and 18 deletions

View file

@ -131,7 +131,9 @@ static_assert(MAX_WORKERS_PER_DOMAIN >= 1,
// Prefixes for observing preference changes.
#define PREF_JS_OPTIONS_PREFIX "javascript.options."
#define PREF_MEM_OPTIONS_PREFIX "mem."
#define PREF_GCZEAL "gczeal"
#define PREF_GCZEAL_OPTIONS_PREFIX "mem.gc_zeal."
#define PREF_MODE "mode"
#define PREF_FREQUENCY "frequency"
static NS_DEFINE_CID(kStreamTransportServiceCID, NS_STREAMTRANSPORTSERVICE_CID);
@ -229,12 +231,6 @@ void LoadContextOptions(const char* aPrefName, void* /* aClosure */) {
return;
}
#ifdef JS_GC_ZEAL
if (prefName.EqualsLiteral(PREF_JS_OPTIONS_PREFIX PREF_GCZEAL)) {
return;
}
#endif
JS::ContextOptions contextOptions;
xpc::SetPrefableContextOptions(contextOptions);
@ -264,18 +260,19 @@ void LoadGCZealOptions(const char* /* aPrefName */, void* /* aClosure */) {
return;
}
int32_t gczeal = GetPref<int32_t>(PREF_JS_OPTIONS_PREFIX PREF_GCZEAL, -1);
if (gczeal < 0) {
gczeal = 0;
int32_t mode = GetPref<int32_t>(
PREF_JS_OPTIONS_PREFIX PREF_GCZEAL_OPTIONS_PREFIX PREF_MODE, -1);
if (mode < 0) {
mode = 0;
}
int32_t frequency =
GetPref<int32_t>(PREF_JS_OPTIONS_PREFIX PREF_GCZEAL ".frequency", -1);
int32_t frequency = GetPref<int32_t>(
PREF_JS_OPTIONS_PREFIX PREF_GCZEAL_OPTIONS_PREFIX PREF_FREQUENCY, -1);
if (frequency < 0) {
frequency = JS::BrowserDefaultGCZealFrequency;
}
RuntimeService::SetDefaultGCZeal(uint8_t(gczeal), uint32_t(frequency));
RuntimeService::SetDefaultGCZeal(uint8_t(mode), uint32_t(frequency));
if (rts) {
rts->UpdateAllWorkerGCZeal();
@ -1406,7 +1403,8 @@ nsresult RuntimeService::Init() {
PREF_JS_OPTIONS_PREFIX PREF_MEM_OPTIONS_PREFIX)) ||
#ifdef JS_GC_ZEAL
NS_FAILED(Preferences::RegisterCallback(
LoadGCZealOptions, PREF_JS_OPTIONS_PREFIX PREF_GCZEAL)) ||
LoadGCZealOptions,
PREF_JS_OPTIONS_PREFIX PREF_GCZEAL_OPTIONS_PREFIX)) ||
#endif
WORKER_PREF("intl.accept_languages", PrefLanguagesChanged) ||
WORKER_PREF("general.appversion.override", AppVersionOverrideChanged) ||
@ -1665,7 +1663,8 @@ void RuntimeService::Cleanup() {
WORKER_PREF("general.platform.override", PlatformOverrideChanged) ||
#ifdef JS_GC_ZEAL
NS_FAILED(Preferences::UnregisterCallback(
LoadGCZealOptions, PREF_JS_OPTIONS_PREFIX PREF_GCZEAL)) ||
LoadGCZealOptions,
PREF_JS_OPTIONS_PREFIX PREF_GCZEAL_OPTIONS_PREFIX)) ||
#endif
NS_FAILED(Preferences::UnregisterPrefixCallback(
LoadJSGCMemoryOptions,

View file

@ -969,9 +969,10 @@ static void ReloadPrefsCallback(const char* pref, void* aXpccx) {
sStreamsEnabled = Preferences::GetBool(JS_OPTIONS_DOT_STR "streams");
#ifdef JS_GC_ZEAL
int32_t zeal = Preferences::GetInt(JS_OPTIONS_DOT_STR "gczeal", -1);
int32_t zeal_frequency = Preferences::GetInt(
JS_OPTIONS_DOT_STR "gczeal.frequency", JS::BrowserDefaultGCZealFrequency);
int32_t zeal = Preferences::GetInt(JS_OPTIONS_DOT_STR "mem.gc_zeal.mode", -1);
int32_t zeal_frequency =
Preferences::GetInt(JS_OPTIONS_DOT_STR "mem.gc_zeal.frequency",
JS::BrowserDefaultGCZealFrequency);
if (zeal >= 0) {
JS::SetGCZeal(cx, (uint8_t)zeal, zeal_frequency);
}

View file

@ -1020,6 +1020,11 @@ pref("javascript.options.mem.nursery_eager_collection_threshold_percent", 25);
// JSGC_NURSERY_EAGER_COLLECTION_TIMEOUT_MS
pref("javascript.options.mem.nursery_eager_collection_timeout_ms", 5000);
#ifdef JS_GC_ZEAL
pref("javascript.options.mem.gc_zeal.mode", 0);
pref("javascript.options.mem.gc_zeal.frequency", 5000);
#endif
pref("javascript.options.shared_memory", true);
pref("javascript.options.throw_on_debuggee_would_run", false);