Bug 806644 - Back out 778993 (r=terrence,a=lsblakk)
authorBill McCloskey <wmccloskey@mozilla.com>
Mon, 29 Oct 2012 17:34:59 -0700
changeset 109730 2a61e12f904bd5d8c6c81b4efe9dc1831fd3a55e
parent 109729 ae3b21c9a5693e8c9d17e849f7c2d309d2b9908f
child 109731 52dc10beff66a1669a0016e8b8b144c3d2289373
push id1637
push userwmccloskey@mozilla.com
push dateTue, 30 Oct 2012 01:08:32 +0000
treeherdermozilla-beta@2a61e12f904b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence, lsblakk
bugs806644, 778993
milestone17.0
Bug 806644 - Back out 778993 (r=terrence,a=lsblakk)
js/src/jscntxt.cpp
js/src/jscompartment.cpp
--- a/js/src/jscntxt.cpp
+++ b/js/src/jscntxt.cpp
@@ -1223,25 +1223,24 @@ JSRuntime::setGCMaxMallocBytes(size_t va
     gcMaxMallocBytes = (ptrdiff_t(value) >= 0) ? value : size_t(-1) >> 1;
     for (CompartmentsIter c(this); !c.done(); c.next())
         c->setGCMaxMallocBytes(value);
 }
 
 void
 JSRuntime::updateMallocCounter(JSContext *cx, size_t nbytes)
 {
-    if (cx && cx->compartment) {
+    /* We tolerate any thread races when updating gcMallocBytes. */
+    ptrdiff_t oldCount = gcMallocBytes;
+    ptrdiff_t newCount = oldCount - ptrdiff_t(nbytes);
+    gcMallocBytes = newCount;
+    if (JS_UNLIKELY(newCount <= 0 && oldCount > 0))
+        onTooMuchMalloc();
+    else if (cx && cx->compartment)
         cx->compartment->updateMallocCounter(nbytes);
-    } else {
-        ptrdiff_t oldCount = gcMallocBytes;
-        ptrdiff_t newCount = oldCount - ptrdiff_t(nbytes);
-        gcMallocBytes = newCount;
-        if (JS_UNLIKELY(newCount <= 0 && oldCount > 0))
-            onTooMuchMalloc();
-    }
 }
 
 JS_FRIEND_API(void)
 JSRuntime::onTooMuchMalloc()
 {
     TriggerGC(this, gcreason::TOO_MUCH_MALLOC);
 }
 
--- a/js/src/jscompartment.cpp
+++ b/js/src/jscompartment.cpp
@@ -66,17 +66,17 @@ JSCompartment::JSCompartment(JSRuntime *
     gcMallocAndFreeBytes(0),
     gcTriggerMallocAndFreeBytes(0),
     gcMallocBytes(0),
     debugModeBits(rt->debugMode ? DebugFromC : 0),
     watchpointMap(NULL),
     scriptCountsMap(NULL),
     debugScriptMap(NULL)
 {
-    setGCMaxMallocBytes(rt->gcMaxMallocBytes);
+    setGCMaxMallocBytes(rt->gcMaxMallocBytes * 0.9);
 }
 
 JSCompartment::~JSCompartment()
 {
     Foreground::delete_(watchpointMap);
     Foreground::delete_(scriptCountsMap);
     Foreground::delete_(debugScriptMap);
 }