Bug 836524 - Zone renaming part 6 (r=jonco)
authorBill McCloskey <wmccloskey@mozilla.com>
Wed, 06 Feb 2013 18:08:47 -0800
changeset 130999 7153a907e6b9a7f2b28f1d989efbc0c45bd6859e
parent 130998 e39eee4423143cb529f0a9b9e441f2a3ca424a7e
child 131000 1a489ff14285bc7631dd9dda33be35c604d2c630
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjonco
bugs836524
milestone21.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 836524 - Zone renaming part 6 (r=jonco)
js/src/jsapi-tests/testGCFinalizeCallback.cpp
js/src/jsapi.cpp
js/src/jscntxt.cpp
js/src/jscntxt.h
js/src/jscntxtinlines.h
js/src/jscompartment.cpp
js/src/jsgc.cpp
js/src/jsgc.h
js/src/jsinfer.cpp
js/src/jsobj.cpp
js/src/vm/String-inl.h
--- a/js/src/jsapi-tests/testGCFinalizeCallback.cpp
+++ b/js/src/jsapi-tests/testGCFinalizeCallback.cpp
@@ -51,49 +51,49 @@ BEGIN_TEST(testGCFinalizeCallback)
     js::RootedObject global2(cx, createGlobal());
     js::RootedObject global3(cx, createGlobal());
     CHECK(global1);
     CHECK(global2);
     CHECK(global3);
 
     /* Compartment GC, non-incremental, single compartment. */
     FinalizeCalls = 0;
-    js::PrepareZoneForGC(global1->compartment());
+    js::PrepareZoneForGC(global1->zone());
     js::GCForReason(rt, js::gcreason::API);
     CHECK(!rt->gcIsFull);
     CHECK(checkSingleGroup());
     CHECK(checkFinalizeStatus());
     CHECK(checkFinalizeIsCompartmentGC(true));
 
     /* Compartment GC, non-incremental, multiple compartments. */
     FinalizeCalls = 0;
-    js::PrepareZoneForGC(global1->compartment());
-    js::PrepareZoneForGC(global2->compartment());
-    js::PrepareZoneForGC(global3->compartment());
+    js::PrepareZoneForGC(global1->zone());
+    js::PrepareZoneForGC(global2->zone());
+    js::PrepareZoneForGC(global3->zone());
     js::GCForReason(rt, js::gcreason::API);
     CHECK(!rt->gcIsFull);
     CHECK(checkSingleGroup());
     CHECK(checkFinalizeStatus());
     CHECK(checkFinalizeIsCompartmentGC(true));
 
     /* Compartment GC, incremental, single compartment. */
     FinalizeCalls = 0;
-    js::PrepareZoneForGC(global1->compartment());
+    js::PrepareZoneForGC(global1->zone());
     js::IncrementalGC(rt, js::gcreason::API, 1000000);
     CHECK(rt->gcIncrementalState == js::gc::NO_INCREMENTAL);
     CHECK(!rt->gcIsFull);
     CHECK(checkSingleGroup());
     CHECK(checkFinalizeStatus());
     CHECK(checkFinalizeIsCompartmentGC(true));
 
     /* Compartment GC, incremental, multiple compartments. */
     FinalizeCalls = 0;
-    js::PrepareZoneForGC(global1->compartment());
-    js::PrepareZoneForGC(global2->compartment());
-    js::PrepareZoneForGC(global3->compartment());
+    js::PrepareZoneForGC(global1->zone());
+    js::PrepareZoneForGC(global2->zone());
+    js::PrepareZoneForGC(global3->zone());
     js::IncrementalGC(rt, js::gcreason::API, 1000000);
     CHECK(rt->gcIncrementalState == js::gc::NO_INCREMENTAL);
     CHECK(!rt->gcIsFull);
     CHECK(checkMultipleGroups());
     CHECK(checkFinalizeStatus());
     CHECK(checkFinalizeIsCompartmentGC(true));
 
 #ifdef JS_GC_ZEAL
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -2264,17 +2264,17 @@ JS_PUBLIC_API(JSFreeOp *)
 JS_GetDefaultFreeOp(JSRuntime *rt)
 {
     return rt->defaultFreeOp();
 }
 
 JS_PUBLIC_API(void)
 JS_updateMallocCounter(JSContext *cx, size_t nbytes)
 {
-    return cx->runtime->updateMallocCounter(cx->compartment, nbytes);
+    return cx->runtime->updateMallocCounter(cx->zone(), nbytes);
 }
 
 JS_PUBLIC_API(char *)
 JS_strdup(JSContext *cx, const char *s)
 {
     AssertHeapIsIdle(cx);
     size_t n = strlen(s) + 1;
     void *p = cx->malloc_(n);
--- a/js/src/jscntxt.cpp
+++ b/js/src/jscntxt.cpp
@@ -1333,18 +1333,18 @@ JSContext::restoreFrameChain()
 void
 JSRuntime::setGCMaxMallocBytes(size_t value)
 {
     /*
      * For compatibility treat any value that exceeds PTRDIFF_T_MAX to
      * mean that value.
      */
     gcMaxMallocBytes = (ptrdiff_t(value) >= 0) ? value : size_t(-1) >> 1;
-    for (CompartmentsIter c(this); !c.done(); c.next())
-        c->setGCMaxMallocBytes(value);
+    for (ZonesIter zone(this); !zone.done(); zone.next())
+        zone->setGCMaxMallocBytes(value);
 }
 
 void
 JSRuntime::updateMallocCounter(size_t nbytes)
 {
     updateMallocCounter(NULL, nbytes);
 }
 
--- a/js/src/jscntxt.h
+++ b/js/src/jscntxt.h
@@ -1635,19 +1635,17 @@ struct JSContext : js::ContextFriendFiel
   public:
     JSGenerator *innermostGenerator() const { return innermostGenerator_; }
     void enterGenerator(JSGenerator *gen);
     void leaveGenerator(JSGenerator *gen);
 
     void *onOutOfMemory(void *p, size_t nbytes) {
         return runtime->onOutOfMemory(p, nbytes, this);
     }
-    void updateMallocCounter(size_t nbytes) {
-        runtime->updateMallocCounter(compartment, nbytes);
-    }
+    void updateMallocCounter(size_t nbytes);
     void reportAllocationOverflow() {
         js_ReportAllocationOverflow(this);
     }
 
     void purge();
 
     bool isExceptionPending() {
         return throwing;
--- a/js/src/jscntxtinlines.h
+++ b/js/src/jscntxtinlines.h
@@ -582,9 +582,15 @@ JSContext::leaveCompartment(JSCompartmen
 }
 
 inline JS::Zone *
 JSContext::zone()
 {
     return compartment->zone();
 }
 
+inline void
+JSContext::updateMallocCounter(size_t nbytes)
+{
+    runtime->updateMallocCounter(zone(), nbytes);
+}
+
 #endif /* jscntxtinlines_h___ */
--- a/js/src/jscompartment.cpp
+++ b/js/src/jscompartment.cpp
@@ -609,33 +609,24 @@ JSCompartment::discardJitCode(FreeOp *fo
         }
 
         types.sweepCompilerOutputs(fop, discardConstraints);
     }
 
 #endif /* JS_METHODJIT */
 }
 
-bool
-JSCompartment::isDiscardingJitCode(JSTracer *trc)
-{
-    if (!IS_GC_MARKING_TRACER(trc))
-        return false;
-
-    return !gcPreserveCode;
-}
-
 void
 JSCompartment::sweep(FreeOp *fop, bool releaseTypes)
 {
     JS_ASSERT(!activeAnalysis);
 
     {
         gcstats::AutoPhase ap(rt->gcStats, gcstats::PHASE_SWEEP_DISCARD_CODE);
-        discardJitCode(fop, !gcPreserveCode);
+        discardJitCode(fop, !zone()->isPreservingCode());
     }
 
     /* This function includes itself in PHASE_SWEEP_TABLES. */
     sweepCrossCompartmentWrappers();
 
     {
         gcstats::AutoPhase ap(rt->gcStats, gcstats::PHASE_SWEEP_TABLES);
 
@@ -665,17 +656,17 @@ JSCompartment::sweep(FreeOp *fop, bool r
 
         if (debugScopes)
             debugScopes->sweep(rt);
 
         /* Finalize unreachable (key,value) pairs in all weak maps. */
         WeakMapBase::sweepCompartment(this);
     }
 
-    if (!gcPreserveCode) {
+    if (!zone()->isPreservingCode()) {
         JS_ASSERT(!types.constrainedOutputs);
         gcstats::AutoPhase ap(rt->gcStats, gcstats::PHASE_DISCARD_ANALYSIS);
 
         /*
          * Clear the analysis pool, but don't release its data yet. While
          * sweeping types any live data will be allocated into the pool.
          */
         LifoAlloc oldAlloc(typeLifoAlloc.defaultChunkSize());
@@ -770,36 +761,36 @@ JSCompartment::sweepCrossCompartmentWrap
 
 void
 JSCompartment::purge()
 {
     dtoaCache.purge();
 }
 
 void
-JSCompartment::resetGCMallocBytes()
+Zone::resetGCMallocBytes()
 {
     gcMallocBytes = ptrdiff_t(gcMaxMallocBytes);
 }
 
 void
-JSCompartment::setGCMaxMallocBytes(size_t value)
+Zone::setGCMaxMallocBytes(size_t value)
 {
     /*
      * For compatibility treat any value that exceeds PTRDIFF_T_MAX to
      * mean that value.
      */
     gcMaxMallocBytes = (ptrdiff_t(value) >= 0) ? value : size_t(-1) >> 1;
     resetGCMallocBytes();
 }
 
 void
-JSCompartment::onTooMuchMalloc()
+Zone::onTooMuchMalloc()
 {
-    TriggerZoneGC(zone(), gcreason::TOO_MUCH_MALLOC);
+    TriggerZoneGC(this, gcreason::TOO_MUCH_MALLOC);
 }
 
 bool
 JSCompartment::hasScriptsOnStack()
 {
     for (AllFramesIter afi(rt); !afi.done(); ++afi) {
 #ifdef JS_ION
         // If this is an Ion frame, check the IonActivation instead
@@ -1010,10 +1001,10 @@ JSCompartment::sizeOfIncludingThis(JSMal
     *crossCompartmentWrappersArg = crossCompartmentWrappers.sizeOfExcludingThis(mallocSizeOf);
     *regexpCompartment = regExps.sizeOfExcludingThis(mallocSizeOf);
     *debuggeesSet = debuggees.sizeOfExcludingThis(mallocSizeOf);
 }
 
 void
 JSCompartment::adoptWorkerAllocator(Allocator *workerAllocator)
 {
-    allocator.arenas.adoptArenas(rt, &workerAllocator->arenas);
+    zone()->allocator.arenas.adoptArenas(rt, &workerAllocator->arenas);
 }
--- a/js/src/jsgc.cpp
+++ b/js/src/jsgc.cpp
@@ -1183,30 +1183,30 @@ ArenaLists::prepareForIncrementalGC(JSRu
 static inline void
 PushArenaAllocatedDuringSweep(JSRuntime *runtime, ArenaHeader *arena)
 {
     arena->setNextAllocDuringSweep(runtime->gcArenasAllocatedDuringSweep);
     runtime->gcArenasAllocatedDuringSweep = arena;
 }
 
 void *
-ArenaLists::parallelAllocate(JSCompartment *comp, AllocKind thingKind, size_t thingSize)
+ArenaLists::parallelAllocate(Zone *zone, AllocKind thingKind, size_t thingSize)
 {
     /*
      * During parallel Rivertrail sections, no GC is permitted. If no
      * existing arena can satisfy the allocation, then a new one is
      * allocated. If that fails, then we return NULL which will cause
      * the parallel section to abort.
      */
 
     void *t = allocateFromFreeList(thingKind, thingSize);
     if (t)
         return t;
 
-    return allocateFromArena(comp, thingKind);
+    return allocateFromArena(zone, thingKind);
 }
 
 inline void *
 ArenaLists::allocateFromArena(Zone *zone, AllocKind thingKind)
 {
     /*
      * Parallel JS Note:
      *
@@ -2542,17 +2542,17 @@ SweepCompartments(FreeOp *fop, bool last
     JSCompartment **end = rt->compartments.end();
     JSCompartment **write = read;
     JS_ASSERT(rt->compartments.length() >= 1);
     JS_ASSERT(*rt->compartments.begin() == rt->atomsCompartment);
 
     while (read < end) {
         JSCompartment *compartment = *read++;
 
-        if (!compartment->hold && compartment->wasGCStarted() &&
+        if (!compartment->hold && compartment->zone()->wasGCStarted() &&
             (compartment->zone()->allocator.arenas.arenaListsAreEmpty() || lastGC))
         {
             compartment->zone()->allocator.arenas.checkEmptyFreeLists();
             if (callback)
                 callback(fop, compartment);
             if (compartment->principals)
                 JS_DropPrincipals(rt, compartment->principals);
             fop->delete_(compartment);
@@ -2561,18 +2561,18 @@ SweepCompartments(FreeOp *fop, bool last
         *write++ = compartment;
     }
     rt->compartments.resize(write - rt->compartments.begin());
 }
 
 static void
 PurgeRuntime(JSRuntime *rt)
 {
-    for (GCZonesIter zone(rt); !zone.done(); zone.next())
-        zone->purge();
+    for (GCCompartmentsIter comp(rt); !comp.done(); comp.next())
+        comp->purge();
 
     rt->freeLifoAlloc.transferUnusedFrom(&rt->tempLifoAlloc);
 
     rt->gsnCache.purge();
     rt->propertyCache.purge(rt);
     rt->newObjectCache.purge();
     rt->nativeIterCache.purge();
     rt->sourceDataCache.purge();
@@ -3948,21 +3948,20 @@ 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 (ZonesIter zone(runtime); !zone.done(); zone.next())
+    for (ZonesIter zone(runtime); !zone.done(); zone.next()) {
+        zone->resetGCMallocBytes();
         zone->unscheduleGC();
+    }
 
     runtime->resetGCMallocBytes();
 }
 
 AutoCopyFreeListToArenas::AutoCopyFreeListToArenas(JSRuntime *rt)
   : runtime(rt)
 {
     for (ZonesIter zone(rt); !zone.done(); zone.next())
@@ -4278,20 +4277,18 @@ BudgetIncrementalGC(JSRuntime *rt, int64
             rt->gcStats.nonincremental("allocation trigger");
         }
 
         if (rt->gcIncrementalState != NO_INCREMENTAL &&
             zone->isGCScheduled() != zone->wasGCStarted())
         {
             reset = true;
         }
-    }
-
-    for (CompartmentsIter c(rt); !c.done(); c.next()) {
-        if (c->isTooMuchMalloc()) {
+
+        if (zone->isTooMuchMalloc()) {
             *budget = SliceBudget::Unlimited;
             rt->gcStats.nonincremental("malloc bytes trigger");
         }
     }
 
     if (reset)
         ResetIncrementalGC(rt, "zone change");
 }
--- a/js/src/jsgc.h
+++ b/js/src/jsgc.h
@@ -440,17 +440,17 @@ struct ArenaLists {
     static void backgroundFinalize(FreeOp *fop, ArenaHeader *listHead, bool onBackgroundThread);
 
     /*
      * Invoked from IonMonkey-compiled parallel worker threads to
      * perform an allocation.  In this case, |this| will be
      * thread-local, but the compartment |comp| is shared between all
      * threads.
      */
-    void *parallelAllocate(JSCompartment *comp, AllocKind thingKind, size_t thingSize);
+    void *parallelAllocate(JS::Zone *zone, AllocKind thingKind, size_t thingSize);
 
   private:
     inline void finalizeNow(FreeOp *fop, AllocKind thingKind);
     inline void queueForForegroundSweep(FreeOp *fop, AllocKind thingKind);
     inline void queueForBackgroundSweep(FreeOp *fop, AllocKind thingKind);
 
     inline void *allocateFromArena(JS::Zone *zone, AllocKind thingKind);
 };
--- a/js/src/jsinfer.cpp
+++ b/js/src/jsinfer.cpp
@@ -6387,32 +6387,24 @@ TypeObject::sweep(FreeOp *fop)
      * The GC will clear out the constraints ensuring the correctness of the
      * newScript information, these constraints will need to be regenerated
      * the next time we compile code which depends on this info.
      */
     if (newScript)
         flags |= OBJECT_FLAG_NEW_SCRIPT_REGENERATE;
 }
 
-struct SweepTypeObjectOp
-{
-    FreeOp *fop;
-    SweepTypeObjectOp(FreeOp *fop) : fop(fop) {}
-    void operator()(gc::Cell *cell) {
-        TypeObject *object = static_cast<TypeObject *>(cell);
-        object->sweep(fop);
-    }
-};
-
 void
 SweepTypeObjects(FreeOp *fop, JSCompartment *compartment)
 {
     JS_ASSERT(compartment->zone()->isGCSweeping());
-    SweepTypeObjectOp op(fop);
-    gc::ForEachArenaAndCell(compartment, gc::FINALIZE_TYPE_OBJECT, gc::EmptyArenaOp, op);
+    for (gc::CellIterUnderGC iter(compartment, gc::FINALIZE_TYPE_OBJECT); !iter.done(); iter.next()) {
+        TypeObject *object = iter.get<TypeObject>();
+        object->sweep(fop);
+    }
 }
 
 void
 TypeCompartment::sweep(FreeOp *fop)
 {
     JSCompartment *compartment = this->compartment();
     JS_ASSERT(compartment->zone()->isGCSweeping());
 
--- a/js/src/jsobj.cpp
+++ b/js/src/jsobj.cpp
@@ -2662,17 +2662,17 @@ JSObject::maybeDensifySparseElements(JSC
     return ED_OK;
 }
 
 bool
 JSObject::growElements(JSContext *cx, unsigned newcap)
 {
     size_t oldSize = Probes::objectResizeActive() ? computedSizeOfThisSlotsElements() : 0;
 
-    if (!growElements(&cx->compartment->allocator, newcap)) {
+    if (!growElements(&cx->zone()->allocator, newcap)) {
         JS_ReportOutOfMemory(cx);
         return false;
     }
 
     if (Probes::objectResizeActive())
         Probes::resizeObject(cx, this, oldSize, computedSizeOfThisSlotsElements());
 
     return true;
--- a/js/src/vm/String-inl.h
+++ b/js/src/vm/String-inl.h
@@ -359,17 +359,17 @@ JSExternalString::new_(JSContext *cx, co
     JS_ASSERT(chars[length] == 0);
 
     if (!validateLength(cx, length))
         return NULL;
     JSExternalString *str = js_NewGCExternalString(cx);
     if (!str)
         return NULL;
     str->init(chars, length, fin);
-    cx->runtime->updateMallocCounter(cx->compartment, (length + 1) * sizeof(jschar));
+    cx->runtime->updateMallocCounter(cx->compartment->zone(), (length + 1) * sizeof(jschar));
     return str;
 }
 
 inline bool
 js::StaticStrings::fitsInSmallChar(jschar c)
 {
     return c < SMALL_CHAR_LIMIT && toSmallChar[c] != INVALID_SMALL_CHAR;
 }