Bug 671482 - Rename some identifiers to improve clarity. r=anygregor.
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 15 Jul 2011 09:31:52 +1000
changeset 72853 54af1e1bda1af69e25302bca1f67c504dc0e1491
parent 72852 c5bddfd1bbe1605702379b3866e92eb04c94b8b9
child 72854 2f993221e1906d1adf6a498b087e5a48ce8741e7
push id20776
push usereakhgari@mozilla.com
push dateFri, 15 Jul 2011 12:13:35 +0000
treeherdermozilla-central@9349ae9094f6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersanygregor
bugs671482
milestone8.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 671482 - Rename some identifiers to improve clarity. r=anygregor.
js/src/jsapi-tests/testGCChunkAlloc.cpp
js/src/jsapi.cpp
js/src/jscntxt.h
js/src/jscompartment.h
js/src/jsgc.cpp
--- a/js/src/jsapi-tests/testGCChunkAlloc.cpp
+++ b/js/src/jsapi-tests/testGCChunkAlloc.cpp
@@ -7,45 +7,47 @@
  */
 
 #include "tests.h"
 #include "jsgcchunk.h"
 #include "jscntxt.h"
 
 /* We allow to allocate 2 (system/user) chunks. */
 
-/* XXX: using pool[0] and pool[1] is a hack;  bug 669123 will fix this. */
+static const int SYSTEM  = 0;
+static const int USER    = 1;
+static const int N_POOLS = 2;
 
 class CustomGCChunkAllocator: public js::GCChunkAllocator {
   public:
-    CustomGCChunkAllocator() { pool[0] = NULL; pool[1] = NULL; }
-    void *pool[2];
+    CustomGCChunkAllocator() { pool[SYSTEM] = NULL; pool[USER] = NULL; }
+    void *pool[N_POOLS];
     
   private:
 
     virtual void *doAlloc() {
-        if (!pool[0] && !pool[1])
+        if (!pool[SYSTEM] && !pool[USER])
             return NULL;
         void *chunk = NULL;
-        if (pool[0]) {
-            chunk = pool[0];
-            pool[0] = NULL;
+        if (pool[SYSTEM]) {
+            chunk = pool[SYSTEM];
+            pool[SYSTEM] = NULL;
         } else {
-            chunk = pool[1];
-            pool[1] = NULL;
+            chunk = pool[USER];
+            pool[USER] = NULL;
         }
         return chunk;
     }
         
     virtual void doFree(void *chunk) {
-        JS_ASSERT(!pool[0] || !pool[1]);
-        if (!pool[0]) {
-            pool[0] = chunk;
+        JS_ASSERT(!pool[SYSTEM] || !pool[USER]);
+        if (!pool[SYSTEM]) {
+            pool[SYSTEM] = chunk;
         } else {
-            pool[1] = chunk;
+            pool[USER] = chunk;
         }
     }
 };
 
 static CustomGCChunkAllocator customGCChunkAllocator;
 
 static unsigned errorCount = 0;
 
@@ -76,18 +78,18 @@ BEGIN_TEST(testGCChunkAlloc)
         "})();";
     JSBool ok = JS_EvaluateScript(cx, global, source, strlen(source), "", 1,
                                   root.addr());
 
     /* Check that we get OOM. */
     CHECK(!ok);
     CHECK(!JS_IsExceptionPending(cx));
     CHECK_EQUAL(errorCount, 1);
-    CHECK(!customGCChunkAllocator.pool[0]);
-    CHECK(!customGCChunkAllocator.pool[1]);
+    CHECK(!customGCChunkAllocator.pool[SYSTEM]);
+    CHECK(!customGCChunkAllocator.pool[USER]);
     JS_GC(cx);
     JS_ToggleOptions(cx, JSOPTION_JIT);
     EVAL("(function() {"
          "    var array = [];"
          "    for (var i = max >> 1; i != 0;) {"
          "        --i;"
          "        array.push({});"
          "    }"
@@ -100,30 +102,30 @@ virtual JSRuntime * createRuntime() {
     /*
      * To test failure of chunk allocation allow to use GC twice the memory
      * the single chunk contains.
      */
     JSRuntime *rt = JS_NewRuntime(2 * js::GC_CHUNK_SIZE);
     if (!rt)
         return NULL;
 
-    customGCChunkAllocator.pool[0] = js::AllocGCChunk();
-    customGCChunkAllocator.pool[1] = js::AllocGCChunk();
-    JS_ASSERT(customGCChunkAllocator.pool[0]);
-    JS_ASSERT(customGCChunkAllocator.pool[1]);
+    customGCChunkAllocator.pool[SYSTEM] = js::AllocGCChunk();
+    customGCChunkAllocator.pool[USER] = js::AllocGCChunk();
+    JS_ASSERT(customGCChunkAllocator.pool[SYSTEM]);
+    JS_ASSERT(customGCChunkAllocator.pool[USER]);
 
     rt->setCustomGCChunkAllocator(&customGCChunkAllocator);
     return rt;
 }
 
 virtual void destroyRuntime() {
     JS_DestroyRuntime(rt);
 
     /* We should get the initial chunk back at this point. */
-    JS_ASSERT(customGCChunkAllocator.pool[0]);
-    JS_ASSERT(customGCChunkAllocator.pool[1]);
-    js::FreeGCChunk(customGCChunkAllocator.pool[0]);
-    js::FreeGCChunk(customGCChunkAllocator.pool[1]);
-    customGCChunkAllocator.pool[0] = NULL;
-    customGCChunkAllocator.pool[1] = NULL;
+    JS_ASSERT(customGCChunkAllocator.pool[SYSTEM]);
+    JS_ASSERT(customGCChunkAllocator.pool[USER]);
+    js::FreeGCChunk(customGCChunkAllocator.pool[SYSTEM]);
+    js::FreeGCChunk(customGCChunkAllocator.pool[USER]);
+    customGCChunkAllocator.pool[SYSTEM] = NULL;
+    customGCChunkAllocator.pool[USER] = NULL;
 }
 
 END_TEST(testGCChunkAlloc)
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -661,17 +661,17 @@ JSRuntime::init(uint32 maxbytes)
 
     if (!(atomsCompartment = this->new_<JSCompartment>(this)) ||
         !atomsCompartment->init() ||
         !compartments.append(atomsCompartment)) {
         Foreground::delete_(atomsCompartment);
         return false;
     }
 
-    atomsCompartment->systemGCChunks = true;
+    atomsCompartment->isSystemCompartment = true;
     atomsCompartment->setGCLastBytes(8192, GC_NORMAL);
 
     if (!js_InitAtomState(this))
         return false;
 
     wrapObjectCallback = js::TransparentObjectWrapper;
 
 #ifdef JS_THREADSAFE
--- a/js/src/jscntxt.h
+++ b/js/src/jscntxt.h
@@ -370,17 +370,17 @@ struct JSRuntime {
      * See bug 492355 for more details.
      *
      * This comes early in JSRuntime to minimize the immediate format used by
      * trace-JITted code that reads it.
      */
     uint32              protoHazardShape;
 
     /* Garbage collector state, used by jsgc.c. */
-    js::GCChunkSet      gcChunkSet;
+    js::GCChunkSet      gcUserChunkSet;
     js::GCChunkSet      gcSystemChunkSet;
 
     js::RootedValueMap  gcRootsHash;
     js::GCLocks         gcLocksHash;
     jsrefcount          gcKeepAtoms;
     uint32              gcBytes;
     uint32              gcTriggerBytes;
     size_t              gcLastBytes;
--- a/js/src/jscompartment.h
+++ b/js/src/jscompartment.h
@@ -392,17 +392,17 @@ struct JS_FRIEND_API(JSCompartment) {
     js::gc::ArenaList            arenas[js::gc::FINALIZE_LIMIT];
     js::gc::FreeLists            freeLists;
 
     uint32                       gcBytes;
     uint32                       gcTriggerBytes;
     size_t                       gcLastBytes;
 
     bool                         hold;
-    bool                         systemGCChunks;
+    bool                         isSystemCompartment;
 
 #ifdef JS_TRACER
   private:
     /*
      * Trace-tree JIT recorder/interpreter state.  It's created lazily because
      * many compartments don't end up needing it.
      */
     js::TraceMonitor             *traceMonitor_;
--- a/js/src/jsgc.cpp
+++ b/js/src/jsgc.cpp
@@ -460,62 +460,63 @@ ReleaseGCChunk(JSRuntime *rt, Chunk *p)
 inline Chunk *
 PickChunk(JSContext *cx)
 {
     Chunk *chunk = cx->compartment->chunk;
     if (chunk && chunk->hasAvailableArenas())
         return chunk;
 
     JSRuntime *rt = cx->runtime;
-    bool systemGCChunks = cx->compartment->systemGCChunks;
+    bool isSystemCompartment = cx->compartment->isSystemCompartment;
 
     /*
      * The chunk used for the last allocation is full, search all chunks for
      * free arenas.
      */
-    GCChunkSet::Range r(systemGCChunks ? rt->gcSystemChunkSet.all() : rt->gcChunkSet.all());
+    GCChunkSet::Range
+        r(isSystemCompartment ? rt->gcSystemChunkSet.all() : rt->gcUserChunkSet.all());
     for (; !r.empty(); r.popFront()) {
         chunk = r.front();
         if (chunk->hasAvailableArenas()) {
             cx->compartment->chunk = chunk;
             return chunk;
         }
     }
 
     chunk = AllocateGCChunk(rt);
     if (!chunk) {
         /* Our last chance is to find an empty chunk in the other chunk set. */
-        GCChunkSet::Enum e(systemGCChunks ? rt->gcChunkSet : rt->gcSystemChunkSet);
+        GCChunkSet::Enum e(isSystemCompartment ? rt->gcUserChunkSet : rt->gcSystemChunkSet);
         for (; !e.empty(); e.popFront()) {
             if (e.front()->info.numFree == ArenasPerChunk) {
                 chunk = e.front();
                 e.removeFront();
                 break;
             }
         }
 
         if (!chunk)
             return NULL;
     }
 
     /*
      * FIXME bug 583732 - chunk is newly allocated and cannot be present in
      * the table so using ordinary lookupForAdd is suboptimal here.
      */
-    GCChunkSet::AddPtr p = systemGCChunks ?
+    GCChunkSet::AddPtr p = isSystemCompartment ?
                            rt->gcSystemChunkSet.lookupForAdd(chunk) :
-                           rt->gcChunkSet.lookupForAdd(chunk);
+                           rt->gcUserChunkSet.lookupForAdd(chunk);
     JS_ASSERT(!p);
-    if (systemGCChunks) {
+    if (isSystemCompartment) {
         if (!rt->gcSystemChunkSet.add(p, chunk)) {
             ReleaseGCChunk(rt, chunk);
             return NULL;
         }
     } else {
-        if (!rt->gcChunkSet.add(p, chunk)) {
+        if (!rt->gcUserChunkSet.add(p, chunk)) {
             ReleaseGCChunk(rt, chunk);
             return NULL;
         }
     }
 
     chunk->init(rt);
     cx->compartment->chunk = chunk;
     rt->gcChunkAllocationSinceLastGC = true;
@@ -526,17 +527,17 @@ static void
 ExpireGCChunks(JSRuntime *rt, JSGCInvocationKind gckind)
 {
     static const size_t MaxAge = 3;
 
     /* Remove unused chunks. */
     AutoLockGC lock(rt);
 
     rt->gcChunksWaitingToExpire = 0;
-    for (GCChunkSet::Enum e(rt->gcChunkSet); !e.empty(); e.popFront()) {
+    for (GCChunkSet::Enum e(rt->gcUserChunkSet); !e.empty(); e.popFront()) {
         Chunk *chunk = e.front();
         JS_ASSERT(chunk->info.runtime == rt);
         if (chunk->unused()) {
             if (gckind == GC_SHRINK || chunk->info.age++ > MaxAge) {
                 e.removeFront();
                 ReleaseGCChunk(rt, chunk);
                 continue;
             }
@@ -591,17 +592,17 @@ static const int64 JIT_SCRIPT_EIGHTH_LIF
 
 JSBool
 js_InitGC(JSRuntime *rt, uint32 maxbytes)
 {
     /*
      * Make room for at least 16 chunks so the table would not grow before
      * the browser starts up.
      */
-    if (!rt->gcChunkSet.init(16))
+    if (!rt->gcUserChunkSet.init(16))
         return false;
 
     if (!rt->gcSystemChunkSet.init(16))
         return false;
 
     if (!rt->gcRootsHash.init(256))
         return false;
 
@@ -736,17 +737,17 @@ MarkIfGCThingWord(JSTracer *trc, jsuword
 #if JS_BITS_PER_WORD == 32
     jsuword addr = w & JSID_PAYLOAD_MASK;
 #elif JS_BITS_PER_WORD == 64
     jsuword addr = w & JSID_PAYLOAD_MASK & JSVAL_PAYLOAD_MASK;
 #endif
 
     Chunk *chunk = Chunk::fromAddress(addr);
 
-    if (!trc->context->runtime->gcChunkSet.has(chunk) && 
+    if (!trc->context->runtime->gcUserChunkSet.has(chunk) && 
         !trc->context->runtime->gcSystemChunkSet.has(chunk))
         return CGCT_NOTCHUNK;
 
     /*
      * We query for pointers outside the arena array after checking for an
      * allocated chunk. Such pointers are rare and we want to reject them
      * after doing more likely rejections.
      */
@@ -944,21 +945,21 @@ js_FinishGC(JSRuntime *rt)
     for (JSCompartment **c = rt->compartments.begin(); c != rt->compartments.end(); ++c) {
         JSCompartment *comp = *c;
         comp->finishArenaLists();
         Foreground::delete_(comp);
     }
     rt->compartments.clear();
     rt->atomsCompartment = NULL;
 
-    for (GCChunkSet::Range r(rt->gcChunkSet.all()); !r.empty(); r.popFront())
+    for (GCChunkSet::Range r(rt->gcUserChunkSet.all()); !r.empty(); r.popFront())
         ReleaseGCChunk(rt, r.front());
     for (GCChunkSet::Range r(rt->gcSystemChunkSet.all()); !r.empty(); r.popFront())
         ReleaseGCChunk(rt, r.front());
-    rt->gcChunkSet.clear();
+    rt->gcUserChunkSet.clear();
     rt->gcSystemChunkSet.clear();
 
 #ifdef JS_THREADSAFE
     rt->gcHelperThread.finish(rt);
 #endif
 
 #ifdef DEBUG
     if (!rt->gcRootsHash.empty())
@@ -2274,17 +2275,17 @@ MarkAndSweep(JSContext *cx, JSCompartmen
      * Mark phase.
      */
     GCTIMESTAMP(startMark);
     GCMarker gcmarker(cx);
     JS_ASSERT(IS_GC_MARKING_TRACER(&gcmarker));
     JS_ASSERT(gcmarker.getMarkColor() == BLACK);
     rt->gcMarkingTracer = &gcmarker;
 
-    for (GCChunkSet::Range r(rt->gcChunkSet.all()); !r.empty(); r.popFront())
+    for (GCChunkSet::Range r(rt->gcUserChunkSet.all()); !r.empty(); r.popFront())
         r.front()->bitmap.clear();
 
     for (GCChunkSet::Range r(rt->gcSystemChunkSet.all()); !r.empty(); r.popFront())
         r.front()->bitmap.clear();
 
     if (comp) {
         for (JSCompartment **c = rt->compartments.begin(); c != rt->compartments.end(); ++c)
             (*c)->markCrossCompartmentWrappers(&gcmarker);
@@ -2872,17 +2873,17 @@ IterateCompartmentsArenasCells(JSContext
 namespace gc {
 
 JSCompartment *
 NewCompartment(JSContext *cx, JSPrincipals *principals)
 {
     JSRuntime *rt = cx->runtime;
     JSCompartment *compartment = cx->new_<JSCompartment>(rt);
     if (compartment && compartment->init()) {
-        compartment->systemGCChunks = principals && !strcmp(principals->codebase, "[System Principal]");
+        compartment->isSystemCompartment = principals && !strcmp(principals->codebase, "[System Principal]");
         if (principals) {
             compartment->principals = principals;
             JSPRINCIPALS_HOLD(cx, principals);
         }
 
         compartment->setGCLastBytes(8192, GC_NORMAL);
 
         /*