Bug 1458217: Abort early in verifyprebarriers if wasm gc is enabled; r=jonco
authorBenjamin Bouvier <benj@benj.me>
Wed, 02 May 2018 15:35:24 +0200
changeset 416685 ddba51846e2f8be8d32d6a1168c0bfc8e9841cff
parent 416684 2c2199bb1e91370ac0f100eaab9469109f4ac7fc
child 416686 1781bcae61d083aa76dc754b7926329e65cf3213
push id102829
push userbbouvier@mozilla.com
push dateWed, 02 May 2018 15:52:15 +0000
treeherdermozilla-inbound@1781bcae61d0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjonco
bugs1458217
milestone61.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 1458217: Abort early in verifyprebarriers if wasm gc is enabled; r=jonco
js/src/gc/GC.cpp
js/src/gc/GCRuntime.h
js/src/gc/Verifier.cpp
js/src/jit-test/tests/wasm/gc/block-verifyprebarriers.js
--- a/js/src/gc/GC.cpp
+++ b/js/src/gc/GC.cpp
@@ -1069,30 +1069,18 @@ static const mozilla::EnumSet<ZealMode> 
     ZealMode::YieldBeforeSweepingShapeTrees
 };
 
 void
 GCRuntime::setZeal(uint8_t zeal, uint32_t frequency)
 {
     MOZ_ASSERT(zeal <= unsigned(ZealMode::Limit));
 
-#ifdef ENABLE_WASM_GC
-    // If we run with wasm-gc enabled and there's wasm frames on the stack,
-    // then GCs are suppressed and we should not allow to set the GC zeal,
-    // which presupposes that GC can be run right away.
-    // TODO (bug 1456824) This is temporary and should be removed once proper
-    // GC support is implemented.
-    JSContext* cx = rt->mainContextFromOwnThread();
-    if (cx->options().wasmGc()) {
-        for (FrameIter iter(cx); !iter.done(); ++iter) {
-            if (iter.isWasm())
-                return;
-        }
-    }
-#endif
+    if (temporaryAbortIfWasmGc(rt->mainContextFromOwnThread()))
+        return;
 
     if (verifyPreData)
         VerifyBarriers(rt, PreBarrierVerifier);
 
     if (zeal == 0) {
         if (hasZealMode(ZealMode::GenerationalGC)) {
             evictNursery(JS::gcreason::DEBUG_GC);
             nursery().leaveZealMode();
@@ -8240,16 +8228,23 @@ GCRuntime::clearSelectedForMarking()
 void
 GCRuntime::setDeterministic(bool enabled)
 {
     MOZ_ASSERT(!JS::CurrentThreadIsHeapMajorCollecting());
     deterministicOnly = enabled;
 }
 #endif
 
+#ifdef ENABLE_WASM_GC
+/* static */ bool
+GCRuntime::temporaryAbortIfWasmGc(JSContext* cx) {
+    return cx->options().wasmGc() && cx->suppressGC;
+}
+#endif
+
 #ifdef DEBUG
 
 /* Should only be called manually under gdb */
 void PreventGCDuringInteractiveDebug()
 {
     TlsContext.get()->suppressGC++;
 }
 
--- a/js/src/gc/GCRuntime.h
+++ b/js/src/gc/GCRuntime.h
@@ -282,16 +282,26 @@ class GCRuntime
     void setNextScheduled(uint32_t count);
     void verifyPreBarriers();
     void maybeVerifyPreBarriers(bool always);
     bool selectForMarking(JSObject* object);
     void clearSelectedForMarking();
     void setDeterministic(bool enable);
 #endif
 
+#ifdef ENABLE_WASM_GC
+    // If we run with wasm-gc enabled and there's wasm frames on the stack,
+    // then GCs are suppressed and many APIs should not be available.
+    // TODO (bug 1456824) This is temporary and should be removed once proper
+    // GC support is implemented.
+    static bool temporaryAbortIfWasmGc(JSContext* cx);
+#else
+    static bool temporaryAbortIfWasmGc(JSContext* cx) { return false; }
+#endif
+
     uint64_t nextCellUniqueId() {
         MOZ_ASSERT(nextCellUniqueId_ > 0);
         uint64_t uid = ++nextCellUniqueId_;
         return uid;
     }
 
 #ifdef DEBUG
     bool shutdownCollectedEverything() const {
--- a/js/src/gc/Verifier.cpp
+++ b/js/src/gc/Verifier.cpp
@@ -174,30 +174,33 @@ NextNode(VerifyNode* node)
 }
 
 void
 gc::GCRuntime::startVerifyPreBarriers()
 {
     if (verifyPreData || isIncrementalGCInProgress())
         return;
 
+    JSContext* cx = rt->mainContextFromOwnThread();
+    if (temporaryAbortIfWasmGc(cx))
+        return;
+
     if (IsIncrementalGCUnsafe(rt) != AbortReason::None ||
-        rt->mainContextFromOwnThread()->keepAtoms ||
+        cx->keepAtoms ||
         rt->hasHelperThreadZones())
     {
         return;
     }
 
     number++;
 
     VerifyPreTracer* trc = js_new<VerifyPreTracer>(rt);
     if (!trc)
         return;
 
-    JSContext* cx = rt->mainContextFromOwnThread();
     AutoPrepareForTracing prep(cx);
 
     {
         AutoLockGC lock(cx->runtime());
         for (auto chunk = allNonEmptyChunks(lock); !chunk.done(); chunk.next())
             chunk->bitmap.clear();
     }
 
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/gc/block-verifyprebarriers.js
@@ -0,0 +1,14 @@
+wasmEvalText(`
+    (module
+        (import "global" "func" (result i32))
+        (func (export "func_0") (result i32)
+         call 0
+        )
+    )
+`, {
+    global: {
+        func() {
+            verifyprebarriers();
+        }
+    }
+}).exports.func_0();