Bug 1509824 - Refactor ShouldTraceCrossCompartment to improve readability r=sfink
authorJon Coppeard <jcoppeard@mozilla.com>
Mon, 26 Nov 2018 13:34:01 +0000
changeset 507196 bec065574446df6a0a4ba3235809ae2e0515ea64
parent 507195 3e274fb14fa0e03a104db8ef001fb1684e9c8ac7
child 507197 3785e94a44d084a5698fb86bb1afe4218ee63e02
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1509824
milestone65.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 1509824 - Refactor ShouldTraceCrossCompartment to improve readability r=sfink
js/src/gc/Marking.cpp
--- a/js/src/gc/Marking.cpp
+++ b/js/src/gc/Marking.cpp
@@ -303,66 +303,72 @@ namespace js {
 #define IMPL_CHECK_TRACED_THING(_, type, __) \
     template void CheckTracedThing<type>(JSTracer*, type*);
 JS_FOR_EACH_TRACEKIND(IMPL_CHECK_TRACED_THING);
 #undef IMPL_CHECK_TRACED_THING
 } // namespace js
 
 static bool UnmarkGrayGCThing(JSRuntime* rt, JS::GCCellPtr thing);
 
-static bool
-ShouldTraceCrossCompartment(JSTracer* trc, JSObject* src, Cell* cell)
+static inline bool
+ShouldMarkCrossCompartment(GCMarker* marker, JSObject* src, Cell* dstCell)
 {
-    if (!trc->isMarkingTracer()) {
-        return true;
-    }
-
-    MarkColor color = GCMarker::fromTracer(trc)->markColor();
-
-    if (!cell->isTenured()) {
+    MarkColor color = marker->markColor();
+
+    if (!dstCell->isTenured()) {
         MOZ_ASSERT(color == MarkColor::Black);
         return false;
     }
-    TenuredCell& tenured = cell->asTenured();
-
-    JS::Zone* zone = tenured.zone();
-    if (!src->zone()->isGCMarking() && !zone->isGCMarking()) {
+    TenuredCell& dst = dstCell->asTenured();
+
+    JS::Zone* dstZone = dst.zone();
+    if (!src->zone()->isGCMarking() && !dstZone->isGCMarking()) {
         return false;
     }
 
     if (color == MarkColor::Black) {
         /*
          * Having black->gray edges violates our promise to the cycle
          * collector. This can happen if we're collecting a compartment and it
          * has an edge to an uncollected compartment: it's possible that the
          * source and destination of the cross-compartment edge should be gray,
          * but the source was marked black by the write barrier.
          */
-        if (tenured.isMarkedGray()) {
-            MOZ_ASSERT(!zone->isCollecting());
-            UnmarkGrayGCThing(trc->runtime(), JS::GCCellPtr(cell, cell->getTraceKind()));
+        if (dst.isMarkedGray()) {
+            MOZ_ASSERT(!dstZone->isCollecting());
+            UnmarkGrayGCThing(marker->runtime(), JS::GCCellPtr(&dst, dst.getTraceKind()));
         }
-        return zone->isGCMarking();
+        return dstZone->isGCMarking();
     } else {
-        if (zone->isGCMarkingBlack()) {
+        if (dstZone->isGCMarkingBlack()) {
             /*
              * The destination compartment is being not being marked gray now,
              * but it will be later, so record the cell so it can be marked gray
              * at the appropriate time.
              */
-            if (!tenured.isMarkedAny()) {
+            if (!dst.isMarkedAny()) {
                 DelayCrossCompartmentGrayMarking(src);
             }
             return false;
         }
-        return zone->isGCMarkingGray();
+        return dstZone->isGCMarkingGray();
     }
 }
 
 static bool
+ShouldTraceCrossCompartment(JSTracer* trc, JSObject* src, Cell* dstCell)
+{
+    if (!trc->isMarkingTracer()) {
+        return true;
+    }
+
+    return ShouldMarkCrossCompartment(GCMarker::fromTracer(trc), src, dstCell);
+}
+
+static bool
 ShouldTraceCrossCompartment(JSTracer* trc, JSObject* src, const Value& val)
 {
     return val.isGCThing() && ShouldTraceCrossCompartment(trc, src, val.toGCThing());
 }
 
 static void
 AssertShouldMarkInZone(Cell* thing)
 {