Bug 815931 - Move GC auto classes to header (r=jonco)
authorBill McCloskey <wmccloskey@mozilla.com>
Tue, 27 Nov 2012 18:12:58 -0800
changeset 114430 e94baab35c6321727405efb9377b8729b566497f
parent 114429 7fe5182d67862f691375879eb9dabf8b7e7e7f9d
child 114431 15115c5169da9fb9ce82e821ec08c7be916d6684
push id23917
push useremorley@mozilla.com
push dateThu, 29 Nov 2012 14:20:29 +0000
treeherdermozilla-central@c72d38e7a212 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjonco
bugs815931
milestone20.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 815931 - Move GC auto classes to header (r=jonco)
js/src/gc/GCInternals.h
js/src/jsapi.cpp
js/src/jscntxt.h
js/src/jsgc.cpp
js/src/jsgc.h
--- a/js/src/gc/GCInternals.h
+++ b/js/src/gc/GCInternals.h
@@ -11,12 +11,53 @@
 #include "jsapi.h"
 
 namespace js {
 namespace gc {
 
 void
 MarkRuntime(JSTracer *trc, bool useSavedRoots = false);
 
+class AutoCopyFreeListToArenas {
+    JSRuntime *runtime;
+
+  public:
+    AutoCopyFreeListToArenas(JSRuntime *rt);
+    ~AutoCopyFreeListToArenas();
+};
+
+struct AutoFinishGC
+{
+    AutoFinishGC(JSRuntime *rt);
+};
+
+/*
+ * This class should be used by any code that needs to exclusive access to the
+ * heap in order to trace through it...
+ */
+class AutoTraceSession {
+  public:
+    AutoTraceSession(JSRuntime *rt, HeapState state = Tracing);
+    ~AutoTraceSession();
+
+  protected:
+    JSRuntime *runtime;
+
+  private:
+    AutoTraceSession(const AutoTraceSession&) MOZ_DELETE;
+    void operator=(const AutoTraceSession&) MOZ_DELETE;
+
+    js::HeapState prevState;
+};
+
+struct AutoPrepareForTracing
+{
+    AutoFinishGC finish;
+    AutoTraceSession session;
+    AutoCopyFreeListToArenas copy;
+
+    AutoPrepareForTracing(JSRuntime *rt);
+};
+
 } /* namespace gc */
 } /* namespace js */
 
 #endif /* jsgc_internal_h___ */
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -228,29 +228,29 @@ JS_GetEmptyString(JSRuntime *rt)
 {
     JS_ASSERT(rt->hasContexts());
     return rt->emptyString;
 }
 
 static void
 AssertHeapIsIdle(JSRuntime *rt)
 {
-    JS_ASSERT(rt->heapState == JSRuntime::Idle);
+    JS_ASSERT(rt->heapState == js::Idle);
 }
 
 static void
 AssertHeapIsIdle(JSContext *cx)
 {
     AssertHeapIsIdle(cx->runtime);
 }
 
 static void
 AssertHeapIsIdleOrIterating(JSRuntime *rt)
 {
-    JS_ASSERT(rt->heapState != JSRuntime::Collecting);
+    JS_ASSERT(rt->heapState != js::Collecting);
 }
 
 static void
 AssertHeapIsIdleOrIterating(JSContext *cx)
 {
     AssertHeapIsIdleOrIterating(cx->runtime);
 }
 
--- a/js/src/jscntxt.h
+++ b/js/src/jscntxt.h
@@ -760,27 +760,21 @@ struct JSRuntime : js::RuntimeFriendFiel
      * stuff. At various times we check this counter and, if it has changed, we
      * run an immediate, non-incremental GC to clean up the dead
      * compartments. This should happen very rarely.
      */
     unsigned            gcObjectsMarkedInDeadCompartments;
 
     bool                gcPoke;
 
-    enum HeapState {
-        Idle,       // doing nothing with the GC heap
-        Tracing,    // tracing the GC heap without collecting, e.g. IterateCompartments()
-        Collecting  // doing a GC of the heap
-    };
+    js::HeapState       heapState;
 
-    HeapState           heapState;
+    bool isHeapBusy() { return heapState != js::Idle; }
 
-    bool isHeapBusy() { return heapState != Idle; }
-
-    bool isHeapCollecting() { return heapState == Collecting; }
+    bool isHeapCollecting() { return heapState == js::Collecting; }
 
     /*
      * These options control the zealousness of the GC. The fundamental values
      * are gcNextScheduled and gcDebugCompartmentGC. At every allocation,
      * gcNextScheduled is decremented. When it reaches zero, we do either a
      * full or a compartmental GC, based on gcDebugCompartmentGC.
      *
      * At this point, if gcZeal_ is one of the types that trigger periodic
--- a/js/src/jsgc.cpp
+++ b/js/src/jsgc.cpp
@@ -3579,61 +3579,42 @@ EndSweepPhase(JSRuntime *rt, JSGCInvocat
                          !c->arenas.arenaListsToSweep[i]);
         }
 #endif
     }
 
     rt->gcLastGCTime = PRMJ_Now();
 }
 
-/*
- * This class should be used by any code that needs to exclusive access to the
- * heap in order to trace through it...
- */
-class AutoTraceSession {
-  public:
-    AutoTraceSession(JSRuntime *rt, JSRuntime::HeapState state = JSRuntime::Tracing);
-    ~AutoTraceSession();
-
-  protected:
-    JSRuntime *runtime;
-
-  private:
-    AutoTraceSession(const AutoTraceSession&) MOZ_DELETE;
-    void operator=(const AutoTraceSession&) MOZ_DELETE;
-
-    JSRuntime::HeapState prevState;
-};
-
 /* ...while this class is to be used only for garbage collection. */
 class AutoGCSession : AutoTraceSession {
   public:
     explicit AutoGCSession(JSRuntime *rt);
     ~AutoGCSession();
 };
 
 /* Start a new heap session. */
-AutoTraceSession::AutoTraceSession(JSRuntime *rt, JSRuntime::HeapState heapState)
+AutoTraceSession::AutoTraceSession(JSRuntime *rt, js::HeapState heapState)
   : runtime(rt),
     prevState(rt->heapState)
 {
     JS_ASSERT(!rt->noGCOrAllocationCheck);
     JS_ASSERT(!rt->isHeapBusy());
-    JS_ASSERT(heapState == JSRuntime::Collecting || heapState == JSRuntime::Tracing);
+    JS_ASSERT(heapState == Collecting || heapState == Tracing);
     rt->heapState = heapState;
 }
 
 AutoTraceSession::~AutoTraceSession()
 {
     JS_ASSERT(runtime->isHeapBusy());
     runtime->heapState = prevState;
 }
 
 AutoGCSession::AutoGCSession(JSRuntime *rt)
-  : AutoTraceSession(rt, JSRuntime::Collecting)
+  : AutoTraceSession(rt, Collecting)
 {
     runtime->gcIsNeeded = false;
     runtime->gcInterFrameGC = true;
 
     runtime->gcNumber++;
 }
 
 AutoGCSession::~AutoGCSession()
@@ -3653,31 +3634,28 @@ AutoGCSession::~AutoGCSession()
     for (CompartmentsIter c(runtime); !c.done(); c.next()) {
         c->resetGCMallocBytes();
         c->unscheduleGC();
     }
 
     runtime->resetGCMallocBytes();
 }
 
-class AutoCopyFreeListToArenas {
-    JSRuntime *rt;
-
-  public:
-    AutoCopyFreeListToArenas(JSRuntime *rt)
-      : rt(rt) {
-        for (CompartmentsIter c(rt); !c.done(); c.next())
-            c->arenas.copyFreeListsToArenas();
-    }
-
-    ~AutoCopyFreeListToArenas() {
-        for (CompartmentsIter c(rt); !c.done(); c.next())
-            c->arenas.clearFreeListsInArenas();
-    }
-};
+AutoCopyFreeListToArenas::AutoCopyFreeListToArenas(JSRuntime *rt)
+  : runtime(rt)
+{
+    for (CompartmentsIter c(rt); !c.done(); c.next())
+        c->arenas.copyFreeListsToArenas();
+}
+
+AutoCopyFreeListToArenas::~AutoCopyFreeListToArenas()
+{
+    for (CompartmentsIter c(runtime); !c.done(); c.next())
+        c->arenas.clearFreeListsInArenas();
+}
 
 static void
 IncrementalCollectSlice(JSRuntime *rt,
                         int64_t budget,
                         gcreason::Reason gcReason,
                         JSGCInvocationKind gcKind);
 
 static void
@@ -4256,48 +4234,40 @@ js::ShrinkGCBuffers(JSRuntime *rt)
     JS_ASSERT(!rt->isHeapBusy());
 
     if (!rt->useHelperThreads())
         ExpireChunksAndArenas(rt, true);
     else
         rt->gcHelperThread.startBackgroundShrink();
 }
 
-struct AutoFinishGC
-{
-    AutoFinishGC(JSRuntime *rt) {
-        if (IsIncrementalGCInProgress(rt)) {
-            PrepareForIncrementalGC(rt);
-            FinishIncrementalGC(rt, gcreason::API);
-        }
-
-        rt->gcHelperThread.waitBackgroundSweepEnd();
+AutoFinishGC::AutoFinishGC(JSRuntime *rt)
+{
+    if (IsIncrementalGCInProgress(rt)) {
+        PrepareForIncrementalGC(rt);
+        FinishIncrementalGC(rt, gcreason::API);
     }
-};
-
-struct AutoPrepareForTracing
-{
-    AutoFinishGC finish;
-    AutoTraceSession session;
-    AutoCopyFreeListToArenas copy;
-
-    AutoPrepareForTracing(JSRuntime *rt)
-      : finish(rt),
-        session(rt),
-        copy(rt)
-    {}
-};
+
+    rt->gcHelperThread.waitBackgroundSweepEnd();
+}
+
+AutoPrepareForTracing::AutoPrepareForTracing(JSRuntime *rt)
+  : finish(rt),
+    session(rt),
+    copy(rt)
+{
+    RecordNativeStackTopForGC(rt);
+}
 
 void
 js::TraceRuntime(JSTracer *trc)
 {
     JS_ASSERT(!IS_GC_MARKING_TRACER(trc));
 
     AutoPrepareForTracing prep(trc->runtime);
-    RecordNativeStackTopForGC(trc->runtime);
     MarkRuntime(trc);
 }
 
 struct IterateArenaCallbackOp
 {
     JSRuntime *rt;
     void *data;
     IterateArenaCallback callback;
--- a/js/src/jsgc.h
+++ b/js/src/jsgc.h
@@ -32,16 +32,22 @@
 struct JSCompartment;
 
 namespace js {
 
 class GCHelperThread;
 struct Shape;
 struct SliceBudget;
 
+enum HeapState {
+    Idle,       // doing nothing with the GC heap
+    Tracing,    // tracing the GC heap without collecting, e.g. IterateCompartments()
+    Collecting  // doing a GC of the heap
+};
+
 namespace ion {
     class IonCode;
 }
 
 namespace gc {
 
 enum State {
     NO_INCREMENTAL,