Bug 778993 - Separate runtime's gcMallocBytes from compartment's gcMallocBytes (r=gwagner,till)
authorBill McCloskey <wmccloskey@mozilla.com>
Fri, 02 Nov 2012 15:06:56 -0700
changeset 112204 63defe9bc7d5d7fb5a4596a5621871ec2b09f8ee
parent 112203 7c56dd925c253a2d8e255fe70f8c0e7548e8e39f
child 112205 d8711e947ce9f1d7fb7eac680aac319bb6a8b2bb
push id17455
push userwmccloskey@mozilla.com
push dateFri, 02 Nov 2012 22:08:14 +0000
treeherdermozilla-inbound@63defe9bc7d5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgwagner, till
bugs778993
milestone19.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 778993 - Separate runtime's gcMallocBytes from compartment's gcMallocBytes (r=gwagner,till)
js/src/jscntxt.cpp
js/src/jscompartment.cpp
js/src/jsgc.cpp
--- a/js/src/jscntxt.cpp
+++ b/js/src/jscntxt.cpp
@@ -1405,24 +1405,25 @@ 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)
 {
-    /* 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)
+    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
@@ -72,17 +72,17 @@ JSCompartment::JSCompartment(JSRuntime *
     debugModeBits(rt->debugMode ? DebugFromC : 0),
     watchpointMap(NULL),
     scriptCountsMap(NULL),
     debugScriptMap(NULL)
 #ifdef JS_ION
     , ionCompartment_(NULL)
 #endif
 {
-    setGCMaxMallocBytes(rt->gcMaxMallocBytes * 0.9);
+    setGCMaxMallocBytes(rt->gcMaxMallocBytes / 2);
 }
 
 JSCompartment::~JSCompartment()
 {
 #ifdef JS_ION
     js_delete(ionCompartment_);
 #endif
 
--- a/js/src/jsgc.cpp
+++ b/js/src/jsgc.cpp
@@ -3269,23 +3269,28 @@ BeginMarkPhase(JSRuntime *rt)
         for (unsigned i = 0; i < FINALIZE_LIMIT; ++i)
             JS_ASSERT(!c->arenas.arenaListsToSweep[i]);
 
         /* Set up which compartments will be collected. */
         if (c->isGCScheduled()) {
             any = true;
             if (c != rt->atomsCompartment)
                 c->setGCState(JSCompartment::Mark);
+
+            c->resetGCMallocBytes();
         } else {
             rt->gcIsFull = false;
         }
 
         c->setPreservingCode(ShouldPreserveJITCode(c, currentTime));
     }
 
+    if (rt->gcIsFull)
+        rt->resetGCMallocBytes();
+
     /* Check that at least one compartment is scheduled for collection. */
     JS_ASSERT(any);
 
     /*
      * Atoms are not in the cross-compartment map. So if there are any
      * compartments that are not being collected, we are not allowed to collect
      * atoms. Otherwise, the non-collected compartments could contain pointers
      * to atoms that we would miss.
@@ -4031,23 +4036,18 @@ AutoGCSession::~AutoGCSession()
 
     runtime->gcChunkAllocationSinceLastGC = false;
 
 #ifdef JS_GC_ZEAL
     /* Keeping these around after a GC is dangerous. */
     runtime->gcSelectedForMarking.clearAndFree();
 #endif
 
-    /* Clear gcMallocBytes for all compartments */
-    for (CompartmentsIter c(runtime); !c.done(); c.next()) {
-        c->resetGCMallocBytes();
+    for (CompartmentsIter c(runtime); !c.done(); c.next())
         c->unscheduleGC();
-    }
-
-    runtime->resetGCMallocBytes();
 }
 
 class AutoCopyFreeListToArenas {
     JSRuntime *rt;
 
   public:
     AutoCopyFreeListToArenas(JSRuntime *rt)
       : rt(rt) {