Bug 806644 - Back out 782072 (r=terrence)
authorBill McCloskey <wmccloskey@mozilla.com>
Mon, 29 Oct 2012 17:34:59 -0700
changeset 111857 cb997ba8433bf03e4350a294ef7d52f756268d9a
parent 111856 9057eef5920abebc005e088749b57240285266da
child 111858 963873ff3081ca3001cb884903bae0894ef84c2d
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersterrence
bugs806644, 782072
milestone19.0a1
Bug 806644 - Back out 782072 (r=terrence)
js/src/jscntxt.cpp
js/src/jscompartment.cpp
--- a/js/src/jscntxt.cpp
+++ b/js/src/jscntxt.cpp
@@ -1405,25 +1405,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
@@ -71,17 +71,17 @@ JSCompartment::JSCompartment(JSRuntime *
     debugModeBits(rt->debugMode ? DebugFromC : 0),
     watchpointMap(NULL),
     scriptCountsMap(NULL),
     debugScriptMap(NULL)
 #ifdef JS_ION
     , ionCompartment_(NULL)
 #endif
 {
-    setGCMaxMallocBytes(rt->gcMaxMallocBytes);
+    setGCMaxMallocBytes(rt->gcMaxMallocBytes * 0.9);
 }
 
 JSCompartment::~JSCompartment()
 {
 #ifdef JS_ION
     js_delete(ionCompartment_);
 #endif