Bug 1082178 - JS initialization must happen using the correct preferences in workers, r=khuey

This commit is contained in:
Andrea Marchesini 2014-10-27 09:38:14 +00:00
Родитель 013e220f84
Коммит 9c560b7613
1 изменённых файлов: 29 добавлений и 15 удалений

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

@ -174,6 +174,9 @@ uint32_t gMaxWorkersPerDomain = MAX_WORKERS_PER_DOMAIN;
// Does not hold an owning reference. // Does not hold an owning reference.
RuntimeService* gRuntimeService = nullptr; RuntimeService* gRuntimeService = nullptr;
// Only true during the call to Init.
bool gRuntimeServiceDuringInit = false;
#ifdef ENABLE_TESTS #ifdef ENABLE_TESTS
bool gTestPBackground = false; bool gTestPBackground = false;
#endif // ENABLE_TESTS #endif // ENABLE_TESTS
@ -464,13 +467,14 @@ LoadJSGCMemoryOptions(const char* aPrefName, void* /* aClosure */)
// If we're running in Init() then do this for every pref we care about. // If we're running in Init() then do this for every pref we care about.
// Otherwise we just want to update the parameter that changed. // Otherwise we just want to update the parameter that changed.
for (uint32_t index = rts ? JSSettings::kGCSettingsArraySize - 1 : 0; for (uint32_t index = !gRuntimeServiceDuringInit
? JSSettings::kGCSettingsArraySize - 1 : 0;
index < JSSettings::kGCSettingsArraySize; index < JSSettings::kGCSettingsArraySize;
index++) { index++) {
LiteralRebindingCString matchName; LiteralRebindingCString matchName;
matchName.RebindLiteral(PREF_MEM_OPTIONS_PREFIX "max"); matchName.RebindLiteral(PREF_MEM_OPTIONS_PREFIX "max");
if (memPrefName == matchName || (!rts && index == 0)) { if (memPrefName == matchName || (gRuntimeServiceDuringInit && index == 0)) {
int32_t prefValue = GetWorkerPref(matchName, -1); int32_t prefValue = GetWorkerPref(matchName, -1);
uint32_t value = (prefValue <= 0 || prefValue >= 0x1000) ? uint32_t value = (prefValue <= 0 || prefValue >= 0x1000) ?
uint32_t(-1) : uint32_t(-1) :
@ -480,7 +484,7 @@ LoadJSGCMemoryOptions(const char* aPrefName, void* /* aClosure */)
} }
matchName.RebindLiteral(PREF_MEM_OPTIONS_PREFIX "high_water_mark"); matchName.RebindLiteral(PREF_MEM_OPTIONS_PREFIX "high_water_mark");
if (memPrefName == matchName || (!rts && index == 1)) { if (memPrefName == matchName || (gRuntimeServiceDuringInit && index == 1)) {
int32_t prefValue = GetWorkerPref(matchName, 128); int32_t prefValue = GetWorkerPref(matchName, 128);
UpdatOtherJSGCMemoryOption(rts, JSGC_MAX_MALLOC_BYTES, UpdatOtherJSGCMemoryOption(rts, JSGC_MAX_MALLOC_BYTES,
uint32_t(prefValue) * 1024 * 1024); uint32_t(prefValue) * 1024 * 1024);
@ -489,7 +493,7 @@ LoadJSGCMemoryOptions(const char* aPrefName, void* /* aClosure */)
matchName.RebindLiteral(PREF_MEM_OPTIONS_PREFIX matchName.RebindLiteral(PREF_MEM_OPTIONS_PREFIX
"gc_high_frequency_time_limit_ms"); "gc_high_frequency_time_limit_ms");
if (memPrefName == matchName || (!rts && index == 2)) { if (memPrefName == matchName || (gRuntimeServiceDuringInit && index == 2)) {
UpdateCommonJSGCMemoryOption(rts, matchName, UpdateCommonJSGCMemoryOption(rts, matchName,
JSGC_HIGH_FREQUENCY_TIME_LIMIT); JSGC_HIGH_FREQUENCY_TIME_LIMIT);
continue; continue;
@ -497,7 +501,7 @@ LoadJSGCMemoryOptions(const char* aPrefName, void* /* aClosure */)
matchName.RebindLiteral(PREF_MEM_OPTIONS_PREFIX matchName.RebindLiteral(PREF_MEM_OPTIONS_PREFIX
"gc_low_frequency_heap_growth"); "gc_low_frequency_heap_growth");
if (memPrefName == matchName || (!rts && index == 3)) { if (memPrefName == matchName || (gRuntimeServiceDuringInit && index == 3)) {
UpdateCommonJSGCMemoryOption(rts, matchName, UpdateCommonJSGCMemoryOption(rts, matchName,
JSGC_LOW_FREQUENCY_HEAP_GROWTH); JSGC_LOW_FREQUENCY_HEAP_GROWTH);
continue; continue;
@ -505,7 +509,7 @@ LoadJSGCMemoryOptions(const char* aPrefName, void* /* aClosure */)
matchName.RebindLiteral(PREF_MEM_OPTIONS_PREFIX matchName.RebindLiteral(PREF_MEM_OPTIONS_PREFIX
"gc_high_frequency_heap_growth_min"); "gc_high_frequency_heap_growth_min");
if (memPrefName == matchName || (!rts && index == 4)) { if (memPrefName == matchName || (gRuntimeServiceDuringInit && index == 4)) {
UpdateCommonJSGCMemoryOption(rts, matchName, UpdateCommonJSGCMemoryOption(rts, matchName,
JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MIN); JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MIN);
continue; continue;
@ -513,7 +517,7 @@ LoadJSGCMemoryOptions(const char* aPrefName, void* /* aClosure */)
matchName.RebindLiteral(PREF_MEM_OPTIONS_PREFIX matchName.RebindLiteral(PREF_MEM_OPTIONS_PREFIX
"gc_high_frequency_heap_growth_max"); "gc_high_frequency_heap_growth_max");
if (memPrefName == matchName || (!rts && index == 5)) { if (memPrefName == matchName || (gRuntimeServiceDuringInit && index == 5)) {
UpdateCommonJSGCMemoryOption(rts, matchName, UpdateCommonJSGCMemoryOption(rts, matchName,
JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MAX); JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MAX);
continue; continue;
@ -521,7 +525,7 @@ LoadJSGCMemoryOptions(const char* aPrefName, void* /* aClosure */)
matchName.RebindLiteral(PREF_MEM_OPTIONS_PREFIX matchName.RebindLiteral(PREF_MEM_OPTIONS_PREFIX
"gc_high_frequency_low_limit_mb"); "gc_high_frequency_low_limit_mb");
if (memPrefName == matchName || (!rts && index == 6)) { if (memPrefName == matchName || (gRuntimeServiceDuringInit && index == 6)) {
UpdateCommonJSGCMemoryOption(rts, matchName, UpdateCommonJSGCMemoryOption(rts, matchName,
JSGC_HIGH_FREQUENCY_LOW_LIMIT); JSGC_HIGH_FREQUENCY_LOW_LIMIT);
continue; continue;
@ -529,7 +533,7 @@ LoadJSGCMemoryOptions(const char* aPrefName, void* /* aClosure */)
matchName.RebindLiteral(PREF_MEM_OPTIONS_PREFIX matchName.RebindLiteral(PREF_MEM_OPTIONS_PREFIX
"gc_high_frequency_high_limit_mb"); "gc_high_frequency_high_limit_mb");
if (memPrefName == matchName || (!rts && index == 7)) { if (memPrefName == matchName || (gRuntimeServiceDuringInit && index == 7)) {
UpdateCommonJSGCMemoryOption(rts, matchName, UpdateCommonJSGCMemoryOption(rts, matchName,
JSGC_HIGH_FREQUENCY_HIGH_LIMIT); JSGC_HIGH_FREQUENCY_HIGH_LIMIT);
continue; continue;
@ -537,13 +541,13 @@ LoadJSGCMemoryOptions(const char* aPrefName, void* /* aClosure */)
matchName.RebindLiteral(PREF_MEM_OPTIONS_PREFIX matchName.RebindLiteral(PREF_MEM_OPTIONS_PREFIX
"gc_allocation_threshold_mb"); "gc_allocation_threshold_mb");
if (memPrefName == matchName || (!rts && index == 8)) { if (memPrefName == matchName || (gRuntimeServiceDuringInit && index == 8)) {
UpdateCommonJSGCMemoryOption(rts, matchName, JSGC_ALLOCATION_THRESHOLD); UpdateCommonJSGCMemoryOption(rts, matchName, JSGC_ALLOCATION_THRESHOLD);
continue; continue;
} }
matchName.RebindLiteral(PREF_MEM_OPTIONS_PREFIX "gc_incremental_slice_ms"); matchName.RebindLiteral(PREF_MEM_OPTIONS_PREFIX "gc_incremental_slice_ms");
if (memPrefName == matchName || (!rts && index == 9)) { if (memPrefName == matchName || (gRuntimeServiceDuringInit && index == 9)) {
int32_t prefValue = GetWorkerPref(matchName, -1); int32_t prefValue = GetWorkerPref(matchName, -1);
uint32_t value = uint32_t value =
(prefValue <= 0 || prefValue >= 100000) ? 0 : uint32_t(prefValue); (prefValue <= 0 || prefValue >= 100000) ? 0 : uint32_t(prefValue);
@ -552,7 +556,8 @@ LoadJSGCMemoryOptions(const char* aPrefName, void* /* aClosure */)
} }
matchName.RebindLiteral(PREF_MEM_OPTIONS_PREFIX "gc_dynamic_heap_growth"); matchName.RebindLiteral(PREF_MEM_OPTIONS_PREFIX "gc_dynamic_heap_growth");
if (memPrefName == matchName || (!rts && index == 10)) { if (memPrefName == matchName ||
(gRuntimeServiceDuringInit && index == 10)) {
bool prefValue = GetWorkerPref(matchName, false); bool prefValue = GetWorkerPref(matchName, false);
UpdatOtherJSGCMemoryOption(rts, JSGC_DYNAMIC_HEAP_GROWTH, UpdatOtherJSGCMemoryOption(rts, JSGC_DYNAMIC_HEAP_GROWTH,
prefValue ? 0 : 1); prefValue ? 0 : 1);
@ -560,7 +565,8 @@ LoadJSGCMemoryOptions(const char* aPrefName, void* /* aClosure */)
} }
matchName.RebindLiteral(PREF_MEM_OPTIONS_PREFIX "gc_dynamic_mark_slice"); matchName.RebindLiteral(PREF_MEM_OPTIONS_PREFIX "gc_dynamic_mark_slice");
if (memPrefName == matchName || (!rts && index == 11)) { if (memPrefName == matchName ||
(gRuntimeServiceDuringInit && index == 11)) {
bool prefValue = GetWorkerPref(matchName, false); bool prefValue = GetWorkerPref(matchName, false);
UpdatOtherJSGCMemoryOption(rts, JSGC_DYNAMIC_MARK_SLICE, UpdatOtherJSGCMemoryOption(rts, JSGC_DYNAMIC_MARK_SLICE,
prefValue ? 0 : 1); prefValue ? 0 : 1);
@ -568,13 +574,15 @@ LoadJSGCMemoryOptions(const char* aPrefName, void* /* aClosure */)
} }
matchName.RebindLiteral(PREF_MEM_OPTIONS_PREFIX "gc_min_empty_chunk_count"); matchName.RebindLiteral(PREF_MEM_OPTIONS_PREFIX "gc_min_empty_chunk_count");
if (memPrefName == matchName || (!rts && index == 12)) { if (memPrefName == matchName ||
(gRuntimeServiceDuringInit && index == 12)) {
UpdateCommonJSGCMemoryOption(rts, matchName, JSGC_MIN_EMPTY_CHUNK_COUNT); UpdateCommonJSGCMemoryOption(rts, matchName, JSGC_MIN_EMPTY_CHUNK_COUNT);
continue; continue;
} }
matchName.RebindLiteral(PREF_MEM_OPTIONS_PREFIX "gc_max_empty_chunk_count"); matchName.RebindLiteral(PREF_MEM_OPTIONS_PREFIX "gc_max_empty_chunk_count");
if (memPrefName == matchName || (!rts && index == 13)) { if (memPrefName == matchName ||
(gRuntimeServiceDuringInit && index == 13)) {
UpdateCommonJSGCMemoryOption(rts, matchName, JSGC_MAX_EMPTY_CHUNK_COUNT); UpdateCommonJSGCMemoryOption(rts, matchName, JSGC_MAX_EMPTY_CHUNK_COUNT);
continue; continue;
} }
@ -1765,6 +1773,9 @@ RuntimeService::Init()
NS_WARNING("Failed to register for offline notification event!"); NS_WARNING("Failed to register for offline notification event!");
} }
MOZ_ASSERT(!gRuntimeServiceDuringInit, "This should be false!");
gRuntimeServiceDuringInit = true;
if (NS_FAILED(Preferences::RegisterCallback( if (NS_FAILED(Preferences::RegisterCallback(
LoadJSGCMemoryOptions, LoadJSGCMemoryOptions,
PREF_JS_OPTIONS_PREFIX PREF_MEM_OPTIONS_PREFIX, PREF_JS_OPTIONS_PREFIX PREF_MEM_OPTIONS_PREFIX,
@ -1822,6 +1833,9 @@ RuntimeService::Init()
NS_WARNING("Failed to register pref callbacks!"); NS_WARNING("Failed to register pref callbacks!");
} }
MOZ_ASSERT(gRuntimeServiceDuringInit, "Should be true!");
gRuntimeServiceDuringInit = false;
// We assume atomic 32bit reads/writes. If this assumption doesn't hold on // We assume atomic 32bit reads/writes. If this assumption doesn't hold on
// some wacky platform then the worst that could happen is that the close // some wacky platform then the worst that could happen is that the close
// handler will run for a slightly different amount of time. // handler will run for a slightly different amount of time.