Bug 677079 - Part s: Make JS_TRACER_INIT a function instead of a macro; r=billm
authorMs2ger <ms2ger@gmail.com>
Sun, 15 Jan 2012 09:13:10 +0100
changeset 85696 346328bd1f2e11bf41c7ab6fba3f0085f59b108f
parent 85695 fee37d705c87843ca3125afded1589ec331a4eb8
child 85697 c8ba49dafe5e2fad9822ec590cdb3a486113410b
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm
bugs677079
milestone12.0a1
Bug 677079 - Part s: Make JS_TRACER_INIT a function instead of a macro; r=billm
js/src/jsapi.cpp
js/src/jsapi.h
js/src/jsfriendapi.cpp
js/src/jsgc.cpp
js/src/shell/js.cpp
js/src/shell/jsheaptools.cpp
js/xpconnect/src/nsXPConnect.cpp
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -2426,16 +2426,28 @@ JS_PUBLIC_API(void)
 JS_SetExtraGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data)
 {
     AssertNoGC(rt);
     rt->gcBlackRootsTraceOp = traceOp;
     rt->gcBlackRootsData = data;
 }
 
 JS_PUBLIC_API(void)
+JS_TracerInit(JSTracer *trc, JSContext *cx, JSTraceCallback callback)
+{
+    trc->runtime = cx->runtime;
+    trc->context = cx;
+    trc->callback = callback;
+    trc->debugPrinter = NULL;
+    trc->debugPrintArg = NULL;
+    trc->debugPrintIndex = size_t(-1);
+    trc->eagerlyTraceWeakMaps = true;
+}
+
+JS_PUBLIC_API(void)
 JS_TraceRuntime(JSTracer *trc)
 {
     AssertNoGC(trc->runtime);
     TraceRuntime(trc);
 }
 
 JS_PUBLIC_API(void)
 JS_TraceChildren(JSTracer *trc, void *thing, JSGCTraceKind kind)
@@ -2765,17 +2777,17 @@ JS_DumpHeap(JSContext *cx, FILE *fp, voi
     JSDumpingTracer dtrc;
     JSHeapDumpNode *node, *children, *next, *parent;
     size_t depth;
     JSBool thingToFindWasTraced;
 
     if (maxDepth == 0)
         return JS_TRUE;
 
-    JS_TRACER_INIT(&dtrc.base, cx, DumpNotify);
+    JS_TracerInit(&dtrc.base, cx, DumpNotify);
     if (!JS_DHashTableInit(&dtrc.visited, JS_DHashGetStubOps(),
                            NULL, sizeof(JSDHashEntryStub),
                            JS_DHASH_DEFAULT_CAPACITY(100))) {
         JS_ReportOutOfMemory(cx);
         return JS_FALSE;
     }
     dtrc.ok = JS_TRUE;
     dtrc.startThing = startThing;
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -3073,26 +3073,18 @@ JS_CallTracer(JSTracer *trc, void *thing
         JSString *str_ = (string);                                            \
         JS_ASSERT(str_);                                                      \
         JS_CALL_TRACER((trc), str_, JSTRACE_STRING, name);                    \
     JS_END_MACRO
 
 /*
  * API for JSTraceCallback implementations.
  */
-# define JS_TRACER_INIT(trc, cx_, callback_)                                  \
-    JS_BEGIN_MACRO                                                            \
-        (trc)->runtime = (cx_)->runtime;                                      \
-        (trc)->context = (cx_);                                               \
-        (trc)->callback = (callback_);                                        \
-        (trc)->debugPrinter = NULL;                                           \
-        (trc)->debugPrintArg = NULL;                                          \
-        (trc)->debugPrintIndex = (size_t)-1;                                  \
-        (trc)->eagerlyTraceWeakMaps = JS_TRUE;                                \
-    JS_END_MACRO
+extern JS_PUBLIC_API(void)
+JS_TracerInit(JSTracer *trc, JSContext *cx, JSTraceCallback callback);
 
 extern JS_PUBLIC_API(void)
 JS_TraceChildren(JSTracer *trc, void *thing, JSGCTraceKind kind);
 
 extern JS_PUBLIC_API(void)
 JS_TraceRuntime(JSTracer *trc);
 
 #ifdef DEBUG
--- a/js/src/jsfriendapi.cpp
+++ b/js/src/jsfriendapi.cpp
@@ -436,17 +436,17 @@ DumpHeapVisitChild(JSTracer *trc, void *
     fprintf(dtrc->output, "> %p %s\n", (void *)thing, edgeName);
     DumpHeapPushIfNew(dtrc, thing, kind);
 }
 
 void
 js::DumpHeapComplete(JSContext *cx, FILE *fp)
 {
     JSDumpHeapTracer dtrc(cx, fp);
-    JS_TRACER_INIT(&dtrc, cx, DumpHeapPushIfNew);
+    JS_TracerInit(&dtrc, cx, DumpHeapPushIfNew);
     if (!dtrc.visited.init(10000))
         return;
 
     /* Store and log the root information. */
     dtrc.rootTracing = true;
     TraceRuntime(&dtrc);
     fprintf(dtrc.output, "==========\n");
 
--- a/js/src/jsgc.cpp
+++ b/js/src/jsgc.cpp
@@ -1782,17 +1782,17 @@ namespace js {
  * from the stack until it empties.
  */
 
 GCMarker::GCMarker(JSContext *cx)
   : color(BLACK),
     unmarkedArenaStackTop(NULL),
     stack(cx->runtime->gcMarkStackArray)
 {
-    JS_TRACER_INIT(this, cx, NULL);
+    JS_TracerInit(this, cx, NULL);
     markLaterArenas = 0;
 #ifdef JS_DUMP_CONSERVATIVE_GC_ROOTS
     conservativeDumpFileName = getenv("JS_DUMP_CONSERVATIVE_GC_ROOTS");
     memset(&conservativeStats, 0, sizeof(conservativeStats));
 #endif
 
     /*
      * The GC is recomputing the liveness of WeakMap entries, so we
@@ -1880,17 +1880,17 @@ gc_root_traversal(JSTracer *trc, const R
 
     if (ptr && !trc->runtime->gcCurrentCompartment) {
         /*
          * Use conservative machinery to find if ptr is a valid GC thing.
          * We only do this during global GCs, to preserve the invariant
          * that mark callbacks are not in place during compartment GCs.
          */
         JSTracer checker;
-        JS_TRACER_INIT(&checker, trc->context, EmptyMarkCallback);
+        JS_TracerInit(&checker, trc->context, EmptyMarkCallback);
         ConservativeGCTest test = MarkIfGCThingWord(&checker, reinterpret_cast<uintptr_t>(ptr));
         if (test != CGCT_VALID && entry.value.name) {
             fprintf(stderr,
 "JS API usage error: the address passed to JS_AddNamedRoot currently holds an\n"
 "invalid gcthing.  This is usually caused by a missing call to JS_RemoveRoot.\n"
 "The root's name is \"%s\".\n",
                     entry.value.name);
         }
@@ -3702,17 +3702,17 @@ StartVerifyBarriers(JSContext *cx)
 #endif
 
     VerifyTracer *trc = new (js_malloc(sizeof(VerifyTracer))) VerifyTracer(cx);
 
     rt->gcNumber++;
     trc->number = rt->gcNumber;
     trc->count = 0;
 
-    JS_TRACER_INIT(trc, cx, AccumulateEdge);
+    JS_TracerInit(trc, cx, AccumulateEdge);
 
     const size_t size = 64 * 1024 * 1024;
     trc->root = (VerifyNode *)js_malloc(size);
     JS_ASSERT(trc->root);
     trc->edgeptr = (char *)trc->root;
     trc->term = trc->edgeptr + size;
 
     trc->nodemap.init();
@@ -3816,25 +3816,25 @@ EndVerifyBarriers(JSContext *cx)
     }
 
     if (rt->gcIncrementalTracer->hasDelayedChildren())
         rt->gcIncrementalTracer->markDelayedChildren();
 
     rt->gcVerifyData = NULL;
     rt->gcIncrementalTracer = NULL;
 
-    JS_TRACER_INIT(trc, cx, CheckAutorooter);
+    JS_TracerInit(trc, cx, CheckAutorooter);
 
     JSContext *iter = NULL;
     while (JSContext *acx = js_ContextIterator(rt, JS_TRUE, &iter)) {
         if (acx->autoGCRooters)
             acx->autoGCRooters->traceAll(trc);
     }
 
-    JS_TRACER_INIT(trc, cx, CheckEdge);
+    JS_TracerInit(trc, cx, CheckEdge);
 
     /* Start after the roots. */
     VerifyNode *node = NextNode(trc->root);
     int count = 0;
 
     while ((char *)node < trc->edgeptr) {
         trc->curnode = node;
         JS_TraceChildren(trc, node->thing, node->kind);
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -1490,17 +1490,17 @@ CountHeap(JSContext *cx, uintN argc, jsv
                 JSAutoByteString bytes(cx, str);
                 if (!!bytes)
                     JS_ReportError(cx, "trace kind name '%s' is unknown", bytes.ptr());
                 return JS_FALSE;
             }
         }
     }
 
-    JS_TRACER_INIT(&countTracer.base, cx, CountHeapNotify);
+    JS_TracerInit(&countTracer.base, cx, CountHeapNotify);
     if (!JS_DHashTableInit(&countTracer.visited, JS_DHashGetStubOps(),
                            NULL, sizeof(JSDHashEntryStub),
                            JS_DHASH_DEFAULT_CAPACITY(100))) {
         JS_ReportOutOfMemory(cx);
         return JS_FALSE;
     }
     countTracer.ok = JS_TRUE;
     countTracer.traceList = NULL;
--- a/js/src/shell/jsheaptools.cpp
+++ b/js/src/shell/jsheaptools.cpp
@@ -166,17 +166,17 @@ class HeapReverser : public JSTracer {
      * The result of a reversal is a map from Cells' addresses to Node
      * structures describing their incoming edges.
      */
     typedef HashMap<void *, Node> Map;
     Map map;
 
     /* Construct a HeapReverser for |context|'s heap. */
     HeapReverser(JSContext *cx) : map(cx), roots(cx), rooter(cx, 0, NULL), work(cx), parent(NULL) {
-        JS_TRACER_INIT(this, cx, traverseEdgeWithThis);
+        JS_TracerInit(this, cx, traverseEdgeWithThis);
     }
 
     bool init() { return map.init(); }
 
     /* Build a reversed map of the heap in |map|. */
     bool reverseHeap();
 
   private:    
--- a/js/xpconnect/src/nsXPConnect.cpp
+++ b/js/xpconnect/src/nsXPConnect.cpp
@@ -64,17 +64,17 @@
 #include "XPCQuickStubs.h"
 #include "dombindings.h"
 
 #include "mozilla/Assertions.h"
 #include "mozilla/Base64.h"
 
 #include "nsWrapperCacheInlines.h"
 
-#include "jscntxt.h" // JS_TRACER_INIT, context->stackLimit, sizeof(JSContext), js::CompartmentVector, cx->stack.empty()
+#include "jscntxt.h" // context->stackLimit, sizeof(JSContext), js::CompartmentVector, cx->stack.empty()
 
 NS_IMPL_THREADSAFE_ISUPPORTS7(nsXPConnect,
                               nsIXPConnect,
                               nsISupportsWeakReference,
                               nsIThreadObserver,
                               nsIJSRuntimeService,
                               nsIJSContextStack,
                               nsIThreadJSContextStack,
@@ -477,17 +477,17 @@ TraceWeakMappingChild(JSTracer *trc, voi
 }
 
 struct NoteWeakMapsTracer : public js::WeakMapTracer
 {
     NoteWeakMapsTracer(JSContext *cx, js::WeakMapTraceCallback cb,
                        nsCycleCollectionTraversalCallback &cccb)
         : js::WeakMapTracer(cx, cb), mCb(cccb), mChildTracer(cccb)
     {
-        JS_TRACER_INIT(&mChildTracer, cx, TraceWeakMappingChild);
+        JS_TracerInit(&mChildTracer, cx, TraceWeakMappingChild);
     }
     nsCycleCollectionTraversalCallback &mCb;
     NoteWeakMapChildrenTracer mChildTracer;
 };
 
 static void
 TraceWeakMapping(js::WeakMapTracer *trc, JSObject *m, 
                  void *k, JSGCTraceKind kkind,
@@ -569,17 +569,17 @@ nsXPConnect::BeginCycleCollection(nsCycl
         if (!PL_DHashTableInit(&mJSRoots, PL_DHashGetStubOps(), nsnull,
                                sizeof(PLDHashEntryStub), PL_DHASH_MIN_SIZE)) {
             mJSRoots.ops = nsnull;
 
             return NS_ERROR_OUT_OF_MEMORY;
         }
 
         NoteJSRootTracer trc(&mJSRoots, cb);
-        JS_TRACER_INIT(&trc, mCycleCollectionContext->GetJSContext(), NoteJSRoot);
+        JS_TracerInit(&trc, mCycleCollectionContext->GetJSContext(), NoteJSRoot);
         JS_TraceRuntime(&trc);
     }
 #else
     NS_ASSERTION(!explainLiveExpectedGarbage, "Didn't call nsXPConnect::Collect()?");
 #endif
 
     GetRuntime()->AddXPConnectRoots(mCycleCollectionContext->GetJSContext(), cb);
  
@@ -741,17 +741,17 @@ xpc_UnmarkGrayObjectRecursive(JSObject *
     nsXPConnect* xpc = nsXPConnect::GetXPConnect();
     if (!xpc || NS_FAILED(xpc->GetSafeJSContext(&cx)) || !cx) {
         NS_ERROR("Failed to get safe JSContext!");
         return;
     }
 
     // Trace children.
     JSTracer trc;
-    JS_TRACER_INIT(&trc, cx, UnmarkGrayChildren);
+    JS_TracerInit(&trc, cx, UnmarkGrayChildren);
     JS_TraceChildren(&trc, obj, JSTRACE_OBJECT);
 }
 
 struct TraversalTracer : public JSTracer
 {
     TraversalTracer(nsCycleCollectionTraversalCallback &aCb) : cb(aCb)
     {
     }
@@ -923,17 +923,17 @@ nsXPConnect::Traverse(void *p, nsCycleCo
     // GC. Any JS objects hanging from them will already be marked. Only do this
     // if DEBUG_CC is not defined, else we do want to know about all JS objects
     // to get better graphs and explanations.
     if (!cb.WantAllTraces() && isMarked)
         return NS_OK;
 
     TraversalTracer trc(cb);
 
-    JS_TRACER_INIT(&trc, cx, NoteJSChild);
+    JS_TracerInit(&trc, cx, NoteJSChild);
     trc.eagerlyTraceWeakMaps = false;
     JS_TraceChildren(&trc, p, traceKind);
 
     if (traceKind != JSTRACE_OBJECT || dontTraverse)
         return NS_OK;
 
     if (clazz == &XPC_WN_Tearoff_JSClass) {
         // A tearoff holds a strong reference to its native object
@@ -1179,17 +1179,17 @@ xpc_CreateGlobalObject(JSContext *cx, JS
         if (!tempGlobal)
             return UnexpectedFailure(NS_ERROR_FAILURE);
         *global = tempGlobal;
     }
 
 #ifdef DEBUG
     if (clasp->flags & JSCLASS_XPCONNECT_GLOBAL) {
         VerifyTraceXPCGlobalCalledTracer trc;
-        JS_TRACER_INIT(&trc.base, cx, VerifyTraceXPCGlobalCalled);
+        JS_TracerInit(&trc.base, cx, VerifyTraceXPCGlobalCalled);
         trc.ok = false;
         JS_TraceChildren(&trc.base, *global, JSTRACE_OBJECT);
         NS_ABORT_IF_FALSE(trc.ok, "Trace hook needs to call TraceXPCGlobal if JSCLASS_XPCONNECT_GLOBAL is set.");
     }
 #endif
 
     return NS_OK;
 }