Bug 1386660 - Part 4: Refactor pref code in nsJSEnvironment.cpp. r=jonco

This commit is contained in:
Paul Bone 2017-08-08 13:11:24 +10:00
Родитель 73cca4c47d
Коммит e576261a1f
1 изменённых файлов: 68 добавлений и 72 удалений

Просмотреть файл

@ -2416,30 +2416,56 @@ SetGCParameter(JSGCParamKey aParam, uint32_t aValue)
}
static void
SetMemoryHighWaterMarkPrefChangedCallback(const char* aPrefName, void* aClosure)
ResetGCParameter(JSGCParamKey aParam)
{
int32_t highwatermark = Preferences::GetInt(aPrefName, 128);
SetGCParameter(JSGC_MAX_MALLOC_BYTES,
highwatermark * 1024L * 1024L);
AutoJSAPI jsapi;
jsapi.Init();
JS_ResetGCParameter(jsapi.cx(), aParam);
}
static void
SetMemoryMaxPrefChangedCallback(const char* aPrefName, void* aClosure)
SetMemoryPrefChangedCallbackMB(const char* aPrefName, void* aClosure)
{
int32_t pref = Preferences::GetInt(aPrefName, -1);
int32_t prefMB = Preferences::GetInt(aPrefName, -1);
// handle overflow and negative pref values
CheckedInt<uint32_t> max = CheckedInt<uint32_t>(pref) * 1024 * 1024;
SetGCParameter(JSGC_MAX_BYTES, max.isValid() ? max.value() : -1);
CheckedInt<int32_t> prefB = CheckedInt<int32_t>(prefMB) * 1024 * 1024;
if (prefB.isValid() && prefB.value() >= 0) {
SetGCParameter((JSGCParamKey)(uintptr_t)aClosure, prefB.value());
} else {
ResetGCParameter((JSGCParamKey)(uintptr_t)aClosure);
}
}
static void
SetMemoryNurseryMaxPrefChangedCallback(const char* aPrefName, void* aClosure)
{
int32_t prefMB = Preferences::GetInt(aPrefName, -1);
// handle overflow and negative pref values
CheckedInt<int32_t> prefB = CheckedInt<int32_t>(prefMB) * 1024;
if (prefB.isValid() && prefB.value() >= 0) {
SetGCParameter((JSGCParamKey)(uintptr_t)aClosure, prefB.value());
} else {
ResetGCParameter((JSGCParamKey)(uintptr_t)aClosure);
}
}
static void
SetMemoryPrefChangedCallbackInt(const char* aPrefName, void* aClosure)
{
int32_t pref = Preferences::GetInt(aPrefName, -1);
// handle overflow and negative pref values
CheckedInt<uint32_t> max = CheckedInt<uint32_t>(pref) * 1024;
SetGCParameter(JSGC_MAX_NURSERY_BYTES,
max.isValid() ? max.value() : JS::DefaultNurseryBytes);
if (pref >= 0 && pref < 10000) {
SetGCParameter((JSGCParamKey)(uintptr_t)aClosure, pref);
} else {
ResetGCParameter((JSGCParamKey)(uintptr_t)aClosure);
}
}
static void
SetMemoryPrefChangedCallbackBool(const char* aPrefName, void* aClosure)
{
bool pref = Preferences::GetBool(aPrefName);
SetGCParameter((JSGCParamKey)(uintptr_t)aClosure, pref);
}
static void
@ -2467,48 +2493,11 @@ SetMemoryGCSliceTimePrefChangedCallback(const char* aPrefName, void* aClosure)
if (pref > 0 && pref < 100000) {
sActiveIntersliceGCBudget = pref;
SetGCParameter(JSGC_SLICE_TIME_BUDGET, pref);
} else {
ResetGCParameter(JSGC_SLICE_TIME_BUDGET);
}
}
static void
SetMemoryGCCompactingPrefChangedCallback(const char* aPrefName, void* aClosure)
{
bool pref = Preferences::GetBool(aPrefName);
SetGCParameter(JSGC_COMPACTING_ENABLED, pref);
}
static void
SetMemoryGCPrefChangedCallback(const char* aPrefName, void* aClosure)
{
int32_t pref = Preferences::GetInt(aPrefName, -1);
// handle overflow and negative pref values
if (pref >= 0 && pref < 10000) {
SetGCParameter((JSGCParamKey)(intptr_t)aClosure, pref);
}
}
static void
SetMemoryGCDynamicHeapGrowthPrefChangedCallback(const char* aPrefName, void* aClosure)
{
bool pref = Preferences::GetBool(aPrefName);
SetGCParameter(JSGC_DYNAMIC_HEAP_GROWTH, pref);
}
static void
SetMemoryGCDynamicMarkSlicePrefChangedCallback(const char* aPrefName, void* aClosure)
{
bool pref = Preferences::GetBool(aPrefName);
SetGCParameter(JSGC_DYNAMIC_MARK_SLICE, pref);
}
static void
SetMemoryGCRefreshFrameSlicesEnabledPrefChangedCallback(const char* aPrefName, void* aClosure)
{
bool pref = Preferences::GetBool(aPrefName);
SetGCParameter(JSGC_REFRESH_FRAME_SLICES_ENABLED, pref);
}
static void
SetIncrementalCCPrefChangedCallback(const char* aPrefName, void* aClosure)
{
@ -2630,13 +2619,16 @@ nsJSContext::EnsureStatics()
JS::InitDispatchToEventLoop(jsapi.cx(), DispatchToEventLoop, nullptr);
// Set these global xpconnect options...
Preferences::RegisterCallbackAndCall(SetMemoryHighWaterMarkPrefChangedCallback,
"javascript.options.mem.high_water_mark");
Preferences::RegisterCallbackAndCall(SetMemoryPrefChangedCallbackMB,
"javascript.options.mem.high_water_mark",
(void*)JSGC_MAX_MALLOC_BYTES);
Preferences::RegisterCallbackAndCall(SetMemoryMaxPrefChangedCallback,
"javascript.options.mem.max");
Preferences::RegisterCallbackAndCall(SetMemoryPrefChangedCallbackMB,
"javascript.options.mem.max",
(void*)JSGC_MAX_BYTES);
Preferences::RegisterCallbackAndCall(SetMemoryNurseryMaxPrefChangedCallback,
"javascript.options.mem.nursery.max_kb");
"javascript.options.mem.nursery.max_kb",
(void*)JSGC_MAX_NURSERY_BYTES);
Preferences::RegisterCallbackAndCall(SetMemoryGCModePrefChangedCallback,
"javascript.options.mem.gc_per_zone");
@ -2647,54 +2639,58 @@ nsJSContext::EnsureStatics()
Preferences::RegisterCallbackAndCall(SetMemoryGCSliceTimePrefChangedCallback,
"javascript.options.mem.gc_incremental_slice_ms");
Preferences::RegisterCallbackAndCall(SetMemoryGCCompactingPrefChangedCallback,
"javascript.options.mem.gc_compacting");
Preferences::RegisterCallbackAndCall(SetMemoryPrefChangedCallbackBool,
"javascript.options.mem.gc_compacting",
(void *)JSGC_COMPACTING_ENABLED);
Preferences::RegisterCallbackAndCall(SetMemoryGCPrefChangedCallback,
Preferences::RegisterCallbackAndCall(SetMemoryPrefChangedCallbackInt,
"javascript.options.mem.gc_high_frequency_time_limit_ms",
(void *)JSGC_HIGH_FREQUENCY_TIME_LIMIT);
Preferences::RegisterCallbackAndCall(SetMemoryGCDynamicMarkSlicePrefChangedCallback,
"javascript.options.mem.gc_dynamic_mark_slice");
Preferences::RegisterCallbackAndCall(SetMemoryPrefChangedCallbackBool,
"javascript.options.mem.gc_dynamic_mark_slice",
(void *)JSGC_DYNAMIC_MARK_SLICE);
Preferences::RegisterCallbackAndCall(SetMemoryGCRefreshFrameSlicesEnabledPrefChangedCallback,
"javascript.options.mem.gc_refresh_frame_slices_enabled");
Preferences::RegisterCallbackAndCall(SetMemoryPrefChangedCallbackBool,
"javascript.options.mem.gc_refresh_frame_slices_enabled",
(void *)JSGC_REFRESH_FRAME_SLICES_ENABLED);
Preferences::RegisterCallbackAndCall(SetMemoryGCDynamicHeapGrowthPrefChangedCallback,
"javascript.options.mem.gc_dynamic_heap_growth");
Preferences::RegisterCallbackAndCall(SetMemoryPrefChangedCallbackBool,
"javascript.options.mem.gc_dynamic_heap_growth",
(void *)JSGC_DYNAMIC_HEAP_GROWTH);
Preferences::RegisterCallbackAndCall(SetMemoryGCPrefChangedCallback,
Preferences::RegisterCallbackAndCall(SetMemoryPrefChangedCallbackInt,
"javascript.options.mem.gc_low_frequency_heap_growth",
(void *)JSGC_LOW_FREQUENCY_HEAP_GROWTH);
Preferences::RegisterCallbackAndCall(SetMemoryGCPrefChangedCallback,
Preferences::RegisterCallbackAndCall(SetMemoryPrefChangedCallbackInt,
"javascript.options.mem.gc_high_frequency_heap_growth_min",
(void *)JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MIN);
Preferences::RegisterCallbackAndCall(SetMemoryGCPrefChangedCallback,
Preferences::RegisterCallbackAndCall(SetMemoryPrefChangedCallbackInt,
"javascript.options.mem.gc_high_frequency_heap_growth_max",
(void *)JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MAX);
Preferences::RegisterCallbackAndCall(SetMemoryGCPrefChangedCallback,
Preferences::RegisterCallbackAndCall(SetMemoryPrefChangedCallbackInt,
"javascript.options.mem.gc_high_frequency_low_limit_mb",
(void *)JSGC_HIGH_FREQUENCY_LOW_LIMIT);
Preferences::RegisterCallbackAndCall(SetMemoryGCPrefChangedCallback,
Preferences::RegisterCallbackAndCall(SetMemoryPrefChangedCallbackInt,
"javascript.options.mem.gc_high_frequency_high_limit_mb",
(void *)JSGC_HIGH_FREQUENCY_HIGH_LIMIT);
Preferences::RegisterCallbackAndCall(SetMemoryGCPrefChangedCallback,
Preferences::RegisterCallbackAndCall(SetMemoryPrefChangedCallbackInt,
"javascript.options.mem.gc_allocation_threshold_mb",
(void *)JSGC_ALLOCATION_THRESHOLD);
Preferences::RegisterCallbackAndCall(SetIncrementalCCPrefChangedCallback,
"dom.cycle_collector.incremental");
Preferences::RegisterCallbackAndCall(SetMemoryGCPrefChangedCallback,
Preferences::RegisterCallbackAndCall(SetMemoryPrefChangedCallbackInt,
"javascript.options.mem.gc_min_empty_chunk_count",
(void *)JSGC_MIN_EMPTY_CHUNK_COUNT);
Preferences::RegisterCallbackAndCall(SetMemoryGCPrefChangedCallback,
Preferences::RegisterCallbackAndCall(SetMemoryPrefChangedCallbackInt,
"javascript.options.mem.gc_max_empty_chunk_count",
(void *)JSGC_MAX_EMPTY_CHUNK_COUNT);