From 2e3db4ed0965a761d15cf7ef57234cb2f68b46bf Mon Sep 17 00:00:00 2001 From: Bill McCloskey Date: Thu, 20 Jun 2013 18:06:53 -0700 Subject: [PATCH] Bug 871005 - Add a pref for GC decommit threshold (r=gregor) --- b2g/app/b2g.js | 1 + dom/base/nsJSEnvironment.cpp | 5 +++++ js/src/gc/Heap.h | 6 ------ js/src/jsapi.cpp | 4 ++++ js/src/jsapi.h | 9 ++++++++- js/src/jscntxt.h | 1 + js/src/jsgc.cpp | 2 +- mobile/android/app/mobile.js | 1 + modules/libpref/src/init/all.js | 1 + 9 files changed, 22 insertions(+), 8 deletions(-) diff --git a/b2g/app/b2g.js b/b2g/app/b2g.js index 2de8d2f4a8f9..c323888d9117 100644 --- a/b2g/app/b2g.js +++ b/b2g/app/b2g.js @@ -563,6 +563,7 @@ pref("javascript.options.mem.gc_high_frequency_low_limit_mb", 10); pref("javascript.options.mem.gc_low_frequency_heap_growth", 120); pref("javascript.options.mem.high_water_mark", 6); pref("javascript.options.mem.gc_allocation_threshold_mb", 1); +pref("javascript.options.mem.gc_decommit_threshold_mb", 1); // Show/Hide scrollbars when active/inactive pref("ui.showHideScrollbars", 1); diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index aacc517c0407..bf59de504ec5 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -3430,6 +3430,11 @@ nsJSRuntime::Init() Preferences::RegisterCallbackAndCall(SetMemoryGCPrefChangedCallback, "javascript.options.mem.gc_allocation_threshold_mb", (void *)JSGC_ALLOCATION_THRESHOLD); + + Preferences::RegisterCallbackAndCall(SetMemoryGCPrefChangedCallback, + "javascript.options.mem.gc_decommit_threshold_mb", + (void *)JSGC_DECOMMIT_THRESHOLD); + nsCOMPtr obs = mozilla::services::GetObserverService(); if (!obs) return NS_ERROR_FAILURE; diff --git a/js/src/gc/Heap.h b/js/src/gc/Heap.h index ae4245be4e84..4f04ace8a66a 100644 --- a/js/src/gc/Heap.h +++ b/js/src/gc/Heap.h @@ -110,12 +110,6 @@ struct Cell inline Chunk *chunk() const; }; -/* - * This is the maximum number of arenas we allow in the FreeCommitted state - * before we trigger a GC_SHRINK to release free arenas to the OS. - */ -const static uint32_t FreeCommittedArenasThreshold = (32 << 20) / ArenaSize; - /* * The mark bitmap has one bit per each GC cell. For multi-cell GC things this * wastes space but allows to avoid expensive devisions by thing's size when diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 549ca7565558..153281218d61 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -781,6 +781,7 @@ JSRuntime::JSRuntime(JSUseHelperThreads useHelperThreads) gcLowFrequencyHeapGrowth(1.5), gcDynamicHeapGrowth(false), gcDynamicMarkSlice(false), + gcDecommitThreshold(32 * 1024 * 1024), gcShouldCleanUpEverything(false), gcGrayBitsValid(false), gcIsNeeded(0), @@ -2891,6 +2892,9 @@ JS_SetGCParameter(JSRuntime *rt, JSGCParamKey key, uint32_t value) case JSGC_ALLOCATION_THRESHOLD: rt->gcAllocationThreshold = value * 1024 * 1024; break; + case JSGC_DECOMMIT_THRESHOLD: + rt->gcDecommitThreshold = value * 1024 * 1024; + break; default: JS_ASSERT(key == JSGC_MODE); rt->gcMode = JSGCMode(value); diff --git a/js/src/jsapi.h b/js/src/jsapi.h index 9cffbaef2a65..8aa8bf3bc13a 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -2699,7 +2699,14 @@ typedef enum JSGCParamKey { JSGC_ANALYSIS_PURGE_TRIGGER = 19, /* Lower limit after which we limit the heap growth. */ - JSGC_ALLOCATION_THRESHOLD = 20 + JSGC_ALLOCATION_THRESHOLD = 20, + + /* + * We decommit memory lazily. If more than this number of megabytes is + * available to be decommitted, then JS_MaybeGC will trigger a shrinking GC + * to decommit it. + */ + JSGC_DECOMMIT_THRESHOLD = 21 } JSGCParamKey; typedef enum JSGCMode { diff --git a/js/src/jscntxt.h b/js/src/jscntxt.h index 9af7ff3c90d8..2f4c12ab135b 100644 --- a/js/src/jscntxt.h +++ b/js/src/jscntxt.h @@ -897,6 +897,7 @@ struct JSRuntime : public JS::shadow::Runtime, double gcLowFrequencyHeapGrowth; bool gcDynamicHeapGrowth; bool gcDynamicMarkSlice; + uint64_t gcDecommitThreshold; /* During shutdown, the GC needs to clean up every possible object. */ bool gcShouldCleanUpEverything; diff --git a/js/src/jsgc.cpp b/js/src/jsgc.cpp index 8e868e149f49..e327564d5fb6 100644 --- a/js/src/jsgc.cpp +++ b/js/src/jsgc.cpp @@ -1982,7 +1982,7 @@ js::MaybeGC(JSContext *cx) int64_t now = PRMJ_Now(); if (rt->gcNextFullGCTime && rt->gcNextFullGCTime <= now) { if (rt->gcChunkAllocationSinceLastGC || - rt->gcNumArenasFreeCommitted > FreeCommittedArenasThreshold) + rt->gcNumArenasFreeCommitted > rt->gcDecommitThreshold) { JS::PrepareForFullGC(rt); GCSlice(rt, GC_SHRINK, JS::gcreason::MAYBEGC); diff --git a/mobile/android/app/mobile.js b/mobile/android/app/mobile.js index f9f23da57a40..841e2b4ac66b 100644 --- a/mobile/android/app/mobile.js +++ b/mobile/android/app/mobile.js @@ -413,6 +413,7 @@ pref("javascript.options.mem.gc_high_frequency_low_limit_mb", 10); pref("javascript.options.mem.gc_low_frequency_heap_growth", 105); pref("javascript.options.mem.high_water_mark", 16); pref("javascript.options.mem.gc_allocation_threshold_mb", 3); +pref("javascript.options.mem.gc_decommit_threshold_mb", 1); #else pref("javascript.options.mem.high_water_mark", 32); #endif diff --git a/modules/libpref/src/init/all.js b/modules/libpref/src/init/all.js index 1b8cdd8a6f95..8b3b736c0e00 100644 --- a/modules/libpref/src/init/all.js +++ b/modules/libpref/src/init/all.js @@ -827,6 +827,7 @@ pref("javascript.options.mem.gc_low_frequency_heap_growth", 150); pref("javascript.options.mem.gc_dynamic_heap_growth", true); pref("javascript.options.mem.gc_dynamic_mark_slice", true); pref("javascript.options.mem.gc_allocation_threshold_mb", 30); +pref("javascript.options.mem.gc_decommit_threshold_mb", 32); pref("javascript.options.mem.analysis_purge_mb", 100);