Bug 650161 - We don't need special fixup for CCWs after compacting GC r=terrence
authorJon Coppeard <jcoppeard@mozilla.com>
Fri, 03 Oct 2014 10:04:19 +0100
changeset 208558 978df8aa78baf8bc8e73c30d8bf6619bc82dc929
parent 208557 b8b6ded7370d84e3e367d5dfb028e1d92744c4e6
child 208559 3aade35d80936c4df6c75dac6838825d02dab0df
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersterrence
bugs650161
milestone35.0a1
Bug 650161 - We don't need special fixup for CCWs after compacting GC r=terrence
js/src/jscompartment.cpp
js/src/jscompartment.h
js/src/jsgc.cpp
--- a/js/src/jscompartment.cpp
+++ b/js/src/jscompartment.cpp
@@ -507,19 +507,17 @@ JSCompartment::markCrossCompartmentWrapp
         Value v = e.front().value();
         if (e.front().key().kind == CrossCompartmentKey::ObjectWrapper) {
             ProxyObject *wrapper = &v.toObject().as<ProxyObject>();
 
             /*
              * We have a cross-compartment wrapper. Its private pointer may
              * point into the compartment being collected, so we should mark it.
              */
-            Value referent = wrapper->private_();
-            MarkValueRoot(trc, &referent, "cross-compartment wrapper");
-            MOZ_ASSERT(referent == wrapper->private_());
+            MarkSlot(trc, wrapper->slotOfPrivate(), "cross-compartment wrapper");
         }
     }
 }
 
 void
 JSCompartment::trace(JSTracer *trc)
 {
     savedStacks_.trace(trc);
@@ -649,49 +647,16 @@ JSCompartment::sweepCrossCompartmentWrap
         {
             e.rekeyFront(key);
         }
     }
 }
 
 #ifdef JSGC_COMPACTING
 
-/*
- * Fixup wrappers with moved keys or values.
- */
-void
-JSCompartment::fixupCrossCompartmentWrappers(JSTracer *trc)
-{
-    for (WrapperMap::Enum e(crossCompartmentWrappers); !e.empty(); e.popFront()) {
-        Value val = e.front().value();
-        if (IsForwarded(val)) {
-            val = Forwarded(val);
-            e.front().value().set(val);
-        }
-
-        // CrossCompartmentKey's hash does not depend on the debugger object,
-        // so update it but do not rekey if it changes
-        CrossCompartmentKey key = e.front().key();
-        if (key.debugger)
-            key.debugger = MaybeForwarded(key.debugger);
-        if (key.wrapped && IsForwarded(key.wrapped)) {
-            key.wrapped = Forwarded(key.wrapped);
-            e.rekeyFront(key, key);
-        }
-
-        if (!zone()->isCollecting() && val.isObject()) {
-            // Call the trace hook to update any pointers to relocated things.
-            JSObject *obj = &val.toObject();
-            const Class *clasp = obj->getClass();
-            if (clasp->trace)
-                clasp->trace(trc, obj);
-        }
-    }
-}
-
 void JSCompartment::fixupAfterMovingGC()
 {
     fixupGlobal();
     fixupNewTypeObjectTable(newTypeObjects);
     fixupNewTypeObjectTable(lazyTypeObjects);
     fixupInitialShapeTable();
 }
 
--- a/js/src/jscompartment.h
+++ b/js/src/jscompartment.h
@@ -362,17 +362,16 @@ struct JSCompartment
     void sweepNativeIterators();
 
     void purge();
     void clearTables();
 
 #ifdef JSGC_COMPACTING
     void fixupInitialShapeTable();
     void fixupNewTypeObjectTable(js::types::TypeObjectWithNewScriptSet &table);
-    void fixupCrossCompartmentWrappers(JSTracer *trc);
     void fixupAfterMovingGC();
     void fixupGlobal();
 #endif
 
     bool hasObjectMetadataCallback() const { return objectMetadataCallback; }
     void setObjectMetadataCallback(js::ObjectMetadataCallback callback);
     void forgetObjectMetadataCallback() {
         objectMetadataCallback = nullptr;
--- a/js/src/jsgc.cpp
+++ b/js/src/jsgc.cpp
@@ -2339,42 +2339,37 @@ MovingTracer::Visit(JSTracer *jstrc, voi
         Cell *dst = Forwarded(thing);
         *thingp = dst;
     }
 }
 
 void
 GCRuntime::sweepZoneAfterCompacting(Zone *zone)
 {
+    MOZ_ASSERT(zone->isCollecting());
     FreeOp *fop = rt->defaultFreeOp();
-    if (zone->isCollecting()) {
-        zone->discardJitCode(fop);
-        zone->sweepAnalysis(fop, rt->gc.releaseObservedTypes && !zone->isPreservingCode());
-        zone->sweepBreakpoints(fop);
-
-        for (CompartmentsInZoneIter c(zone); !c.done(); c.next()) {
-            c->sweepInnerViews();
-            c->sweepCrossCompartmentWrappers();
-            c->sweepBaseShapeTable();
-            c->sweepInitialShapeTable();
-            c->sweepTypeObjectTables();
-            c->sweepRegExps();
-            c->sweepCallsiteClones();
-            c->sweepSavedStacks();
-            c->sweepGlobalObject(fop);
-            c->sweepSelfHostingScriptSource();
-            c->sweepDebugScopes();
-            c->sweepJitCompartment(fop);
-            c->sweepWeakMaps();
-            c->sweepNativeIterators();
-        }
-    } else {
-        /* Update cross compartment wrappers into moved zones. */
-        for (CompartmentsInZoneIter c(zone); !c.done(); c.next())
-            c->sweepCrossCompartmentWrappers();
+    zone->discardJitCode(fop);
+    zone->sweepAnalysis(fop, rt->gc.releaseObservedTypes && !zone->isPreservingCode());
+    zone->sweepBreakpoints(fop);
+
+    for (CompartmentsInZoneIter c(zone); !c.done(); c.next()) {
+        c->sweepInnerViews();
+        c->sweepCrossCompartmentWrappers();
+        c->sweepBaseShapeTable();
+        c->sweepInitialShapeTable();
+        c->sweepTypeObjectTables();
+        c->sweepRegExps();
+        c->sweepCallsiteClones();
+        c->sweepSavedStacks();
+        c->sweepGlobalObject(fop);
+        c->sweepSelfHostingScriptSource();
+        c->sweepDebugScopes();
+        c->sweepJitCompartment(fop);
+        c->sweepWeakMaps();
+        c->sweepNativeIterators();
     }
 }
 
 /*
  * Update the interal pointers in a single cell.
  */
 static void
 UpdateCellPointers(MovingTracer *trc, Cell *cell, JSGCTraceKind traceKind) {
@@ -2412,17 +2407,17 @@ GCRuntime::updatePointersToRelocatedCell
     // TODO: We may need to fix up other weak pointers here.
 
     // Fixup compartment global pointers as these get accessed during marking.
     for (GCCompartmentsIter comp(rt); !comp.done(); comp.next())
         comp->fixupAfterMovingGC();
 
     // Fixup cross compartment wrappers as we assert the existence of wrappers in the map.
     for (CompartmentsIter comp(rt, SkipAtoms); !comp.done(); comp.next())
-        comp->fixupCrossCompartmentWrappers(&trc);
+        comp->sweepCrossCompartmentWrappers();
 
     // Fixup generators as these are not normally traced.
     for (ContextIter i(rt); !i.done(); i.next()) {
         for (JSGenerator *gen = i.get()->innermostGenerator(); gen; gen = gen->prevGenerator)
             gen->obj = MaybeForwarded(gen->obj.get());
     }
 
     // Iterate through all allocated cells to update internal pointers.
@@ -2453,19 +2448,20 @@ GCRuntime::updatePointersToRelocatedCell
     // Mark all gray roots, making sure we call the trace callback to get the
     // current set.
     if (JSTraceDataOp op = grayRootTracer.op)
         (*op)(&trc, grayRootTracer.data);
 
     // Sweep everything to fix up weak pointers
     WatchpointMap::sweepAll(rt);
     Debugger::sweepAll(rt->defaultFreeOp());
-
-    for (ZonesIter zone(rt, SkipAtoms); !zone.done(); zone.next())
-        rt->gc.sweepZoneAfterCompacting(zone);
+    for (GCZonesIter zone(rt); !zone.done(); zone.next()) {
+        if (!rt->isAtomsZone(zone))
+            rt->gc.sweepZoneAfterCompacting(zone);
+    }
 
     // Type inference may put more blocks here to free.
     rt->freeLifoAlloc.freeAll();
 
     // Clear runtime caches that can contain cell pointers.
     // TODO: Should possibly just call PurgeRuntime() here.
     rt->newObjectCache.purge();
     rt->nativeIterCache.purge();