Bug 1038274 - Add max heap size constants to pass to JS_NewRuntime() r=terrence
authorJon Coppeard <jcoppeard@mozilla.com>
Wed, 16 Jul 2014 10:01:20 +0100
changeset 216278 a512db24690c42f5b1b1da51b601743de9fbb82c
parent 216277 e4761223f269153eea3d39dc635668fc1386cc36
child 216279 0d140d36f2e0dd09959376e1ae8dc2669ef389ed
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs1038274
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1038274 - Add max heap size constants to pass to JS_NewRuntime() r=terrence
js/public/HeapAPI.h
js/src/shell/js.cpp
js/xpconnect/src/XPCJSRuntime.cpp
--- a/js/public/HeapAPI.h
+++ b/js/public/HeapAPI.h
@@ -95,16 +95,22 @@ AssertGCThingHasType(js::gc::Cell *cell,
 } /* namespace js */
 
 namespace JS {
 struct Zone;
 
 /* Default size for the generational nursery in bytes. */
 const uint32_t DefaultNurseryBytes = 16 * 1024 * 1024;
 
+/* Default maximum heap size in bytes to pass to JS_NewRuntime(). */
+const uint32_t DefaultHeapMaxBytes = 32 * 1024 * 1024;
+
+/* Value indicating no maximum heap size to pass to JS_NewRuntime(). */
+const uint32_t UnlimitedHeapMaxBytes = 0xffffffff;
+
 /*
  * We cannot expose the class hierarchy: the implementation is hidden. Instead
  * we provide cast functions with strong debug-mode assertions.
  */
 static MOZ_ALWAYS_INLINE js::gc::Cell *
 AsCell(JSObject *obj)
 {
     js::gc::Cell *cell = reinterpret_cast<js::gc::Cell *>(obj);
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -6414,27 +6414,26 @@ main(int argc, char **argv, char **envp)
         return 1;
 
     size_t nurseryBytes = JS::DefaultNurseryBytes;
 #ifdef JSGC_GENERATIONAL
     nurseryBytes = op.getIntOption("nursery-size") * 1024L * 1024L;
 #endif
 
     /* Use the same parameters as the browser in xpcjsruntime.cpp. */
-    rt = JS_NewRuntime(32L * 1024L * 1024L, nurseryBytes);
+    rt = JS_NewRuntime(JS::UnlimitedHeapMaxBytes, nurseryBytes);
     if (!rt)
         return 1;
 
     JS::SetOutOfMemoryCallback(rt, my_OOMCallback, nullptr);
     if (!SetRuntimeOptions(rt, op))
         return 1;
 
     gInterruptFunc.construct(rt, NullValue());
 
-    JS_SetGCParameter(rt, JSGC_MAX_BYTES, 0xffffffff);
 #ifdef JSGC_GENERATIONAL
     Maybe<JS::AutoDisableGenerationalGC> noggc;
     if (op.getBoolOption("no-ggc"))
         noggc.construct(rt);
 #endif
 
     size_t availMem = op.getIntOption("available-memory");
     if (availMem > 0)
--- a/js/xpconnect/src/XPCJSRuntime.cpp
+++ b/js/xpconnect/src/XPCJSRuntime.cpp
@@ -3064,17 +3064,17 @@ class XPCJSSourceHook: public js::Source
 };
 
 static const JSWrapObjectCallbacks WrapObjectCallbacks = {
     xpc::WrapperFactory::Rewrap,
     xpc::WrapperFactory::PrepareForWrapping
 };
 
 XPCJSRuntime::XPCJSRuntime(nsXPConnect* aXPConnect)
-   : CycleCollectedJSRuntime(nullptr, 32L * 1024L * 1024L),
+   : CycleCollectedJSRuntime(nullptr, JS::UnlimitedHeapMaxBytes),
    mJSContextStack(new XPCJSContextStack(MOZ_THIS_IN_INITIALIZER_LIST())),
    mCallContext(nullptr),
    mAutoRoots(nullptr),
    mResolveName(JSID_VOID),
    mResolvingWrapper(nullptr),
    mWrappedJSMap(JSObject2WrappedJSMap::newMap(XPC_JS_MAP_SIZE)),
    mWrappedJSClassMap(IID2WrappedJSClassMap::newMap(XPC_JS_CLASS_MAP_SIZE)),
    mIID2NativeInterfaceMap(IID2NativeInterfaceMap::newMap(XPC_NATIVE_INTERFACE_MAP_SIZE)),
@@ -3103,24 +3103,16 @@ XPCJSRuntime::XPCJSRuntime(nsXPConnect* 
 
     MOZ_ASSERT(Runtime());
     JSRuntime* runtime = Runtime();
 
     auto rtPrivate = new PerThreadAtomCache();
     memset(rtPrivate, 0, sizeof(PerThreadAtomCache));
     JS_SetRuntimePrivate(runtime, rtPrivate);
 
-    // Unconstrain the runtime's threshold on nominal heap size, to avoid
-    // triggering GC too often if operating continuously near an arbitrary
-    // finite threshold (0xffffffff is infinity for uint32_t parameters).
-    // This leaves the maximum-JS_malloc-bytes threshold still in effect
-    // to cause period, and we hope hygienic, last-ditch GCs from within
-    // the GC's allocator.
-    JS_SetGCParameter(runtime, JSGC_MAX_BYTES, 0xffffffff);
-
     // The JS engine permits us to set different stack limits for system code,
     // trusted script, and untrusted script. We have tests that ensure that
     // we can always execute 10 "heavy" (eval+with) stack frames deeper in
     // privileged code. Our stack sizes vary greatly in different configurations,
     // so satisfying those tests requires some care. Manual measurements of the
     // number of heavy stack frames achievable gives us the following rough data,
     // ordered by the effective categories in which they are grouped in the
     // JS_SetNativeStackQuota call (which predates this analysis).