Bug 742843 - Clean up weakmap header (r=terrence)
authorBill McCloskey <wmccloskey@mozilla.com>
Mon, 09 Apr 2012 11:42:04 -0700
changeset 94867 4635be397546bd546dac23f496303caafe42a546
parent 94866 8cf633d7a0318439b8ad3bc0343f7e5287ba4de5
child 94868 ae32cca25ce0e844716b7ea7df812659008fa07e
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs742843
milestone14.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 742843 - Clean up weakmap header (r=terrence)
js/src/jsgcmark.h
js/src/jsweakmap.h
--- a/js/src/jsgcmark.h
+++ b/js/src/jsgcmark.h
@@ -186,16 +186,22 @@ Mark(JSTracer *trc, HeapValue *v, const 
 
 inline void
 Mark(JSTracer *trc, HeapPtr<JSObject> *o, const char *name)
 {
     MarkObject(trc, o, name);
 }
 
 inline void
+Mark(JSTracer *trc, HeapPtr<JSScript> *o, const char *name)
+{
+    MarkScript(trc, o, name);
+}
+
+inline void
 Mark(JSTracer *trc, HeapPtr<JSXML> *xml, const char *name)
 {
     MarkXML(trc, xml, name);
 }
 
 inline bool
 IsMarked(const Value &v)
 {
@@ -205,16 +211,51 @@ IsMarked(const Value &v)
 }
 
 inline bool
 IsMarked(Cell *cell)
 {
     return !IsAboutToBeFinalized(cell);
 }
 
+inline Cell *
+ToMarkable(const Value &v)
+{
+    if (v.isMarkable())
+        return (Cell *)v.toGCThing();
+    return NULL;
+}
+
+inline Cell *
+ToMarkable(Cell *cell)
+{
+    return cell;
+}
+
+inline JSGCTraceKind
+TraceKind(const Value &v)
+{
+    JS_ASSERT(v.isMarkable());
+    if (v.isObject())
+        return JSTRACE_OBJECT;
+    return JSTRACE_STRING;
+}
+
+inline JSGCTraceKind
+TraceKind(JSObject *obj)
+{
+    return JSTRACE_OBJECT;
+}
+
+inline JSGCTraceKind
+TraceKind(JSScript *script)
+{
+    return JSTRACE_SCRIPT;
+}
+
 } /* namespace gc */
 
 void
 TraceChildren(JSTracer *trc, void *thing, JSGCTraceKind kind);
 
 void
 CallTracer(JSTracer *trc, void *thing, JSGCTraceKind kind);
 
--- a/js/src/jsweakmap.h
+++ b/js/src/jsweakmap.h
@@ -193,97 +193,69 @@ class WeakMap : public HashMap<Key, Valu
     explicit WeakMap(JSContext *cx, JSObject *memOf=NULL) : Base(cx), WeakMapBase(memOf) { }
 
     /* Use with caution, as result can be affected by garbage collection. */
     Range nondeterministicAll() {
         return Base::all();
     }
 
   private:
-    bool IsMarked(const HeapValue &x) {
-        if (x.isMarkable())
-            return !IsAboutToBeFinalized(x);
-        return true;
-    }
-    bool IsMarked(const HeapPtrObject &x) {
-        return !IsAboutToBeFinalized(x);
-    }
-    bool IsMarked(const HeapPtrScript&x) {
-        return !IsAboutToBeFinalized(x);
-    }
-
-    bool Mark(JSTracer *trc, HeapValue *x) {
-        if (IsMarked(*x))
+    bool markValue(JSTracer *trc, Value *x) {
+        if (gc::IsMarked(*x))
             return false;
-        js::gc::MarkValue(trc, x, "WeakMap entry value");
-        return true;
-    }
-    bool Mark(JSTracer *trc, HeapPtrObject *x) {
-        if (IsMarked(*x))
-            return false;
-        js::gc::MarkObject(trc, x, "WeakMap entry value");
-        return true;
-    }
-    bool Mark(JSTracer *trc, HeapPtrScript *x) {
-        if (IsMarked(*x))
-            return false;
-        js::gc::MarkScript(trc, x, "WeakMap entry value");
+        gc::Mark(trc, x, "WeakMap entry");
         return true;
     }
 
     void nonMarkingTrace(JSTracer *trc) {
         for (Range r = Base::all(); !r.empty(); r.popFront())
-            Mark(trc, &r.front().value);
+            markValue(trc, &r.front().value);
     }
 
     bool markIteratively(JSTracer *trc) {
         bool markedAny = false;
         for (Range r = Base::all(); !r.empty(); r.popFront()) {
             /* If the entry is live, ensure its key and value are marked. */
-            if (IsMarked(r.front().key) && Mark(trc, &r.front().value))
+            if (gc::IsMarked(r.front().key) && markValue(trc, &r.front().value))
                 markedAny = true;
-            JS_ASSERT_IF(IsMarked(r.front().key), IsMarked(r.front().value));
+            JS_ASSERT_IF(gc::IsMarked(r.front().key), gc::IsMarked(r.front().value));
         }
         return markedAny;
     }
 
     void sweep(JSTracer *trc) {
         /* Remove all entries whose keys remain unmarked. */
         for (Enum e(*this); !e.empty(); e.popFront()) {
-            if (!IsMarked(e.front().key))
+            if (!gc::IsMarked(e.front().key))
                 e.removeFront();
         }
 
 #if DEBUG
         /*
          * Once we've swept, all remaining edges should stay within the
          * known-live part of the graph.
          */
         for (Range r = Base::all(); !r.empty(); r.popFront()) {
-            JS_ASSERT(IsMarked(r.front().key));
-            JS_ASSERT(IsMarked(r.front().value));
+            JS_ASSERT(gc::IsMarked(r.front().key));
+            JS_ASSERT(gc::IsMarked(r.front().value));
         }
 #endif
     }
 
-    void CallTracer(WeakMapTracer *trc, const HeapPtrObject &k, const HeapValue &v) {
-        if (v.isMarkable())
-            trc->callback(trc, memberOf, k.get(), JSTRACE_OBJECT, v.toGCThing(), v.gcKind());
-    }
-    void CallTracer(WeakMapTracer *trc, const HeapPtrObject &k, const HeapPtrObject &v) {
-        trc->callback(trc, memberOf, k.get(), JSTRACE_OBJECT, v.get(), JSTRACE_OBJECT);
-    }
-    void CallTracer(WeakMapTracer *trc, const HeapPtrScript &k, const HeapPtrObject &v) {
-        trc->callback(trc, memberOf, k.get(), JSTRACE_SCRIPT, v.get(), JSTRACE_OBJECT);
-    }
-
-    /* mapObj can be NULL, which means that the map is not part of a JSObject. */
+    /* memberOf can be NULL, which means that the map is not part of a JSObject. */
     void traceMappings(WeakMapTracer *tracer) {
-        for (Range r = Base::all(); !r.empty(); r.popFront())
-            CallTracer(tracer, r.front().key, r.front().value);
+        for (Range r = Base::all(); !r.empty(); r.popFront()) {
+            gc::Cell *key = gc::ToMarkable(r.front().key);
+            gc::Cell *value = gc::ToMarkable(r.front().value);
+            if (key && value) {
+                tracer->callback(tracer, memberOf,
+                                 key, gc::TraceKind(r.front().key),
+                                 value, gc::TraceKind(r.front().value));
+            }
+        }
     }
 };
 
 } /* namespace js */
 
 extern JSObject *
 js_InitWeakMapClass(JSContext *cx, JSObject *obj);