Bug 1301496 - Simplify runtime check when tracing helper threads. r=terrence, a=ritu
authorJon Coppeard <jcoppeard@mozilla.com>
Thu, 22 Sep 2016 13:02:40 +0100
changeset 350441 d62aa3e31e3fe83b2417ce1a0a4a5ac07cad484a
parent 350440 84899036528a2504b2da757c25f1d79bebf0c6b5
child 350442 0c6ccccaee828bc55a32d17ce875f0d6db0f9bb3
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence, ritu
bugs1301496
milestone50.0
Bug 1301496 - Simplify runtime check when tracing helper threads. r=terrence, a=ritu
js/src/jit-test/tests/gc/bug-1301496.js
js/src/jit/CompileWrappers.cpp
js/src/jit/CompileWrappers.h
js/src/jit/IonBuilder.cpp
js/src/jscntxt.h
js/src/vm/HelperThreads.cpp
js/src/vm/HelperThreads.h
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/gc/bug-1301496.js
@@ -0,0 +1,7 @@
+if (helperThreadCount() == 0)
+    quit();
+startgc(1, 'shrinking');
+offThreadCompileScript("");
+// Adapted from randomly chosen test: js/src/jit-test/tests/parser/bug-1263355-13.js
+gczeal(9);
+newGlobal();
--- a/js/src/jit/CompileWrappers.cpp
+++ b/js/src/jit/CompileWrappers.cpp
@@ -189,16 +189,22 @@ CompileRuntime::gcNursery()
 
 void
 CompileRuntime::setMinorGCShouldCancelIonCompilations()
 {
     MOZ_ASSERT(onMainThread());
     runtime()->gc.storeBuffer.setShouldCancelIonCompilations();
 }
 
+bool
+CompileRuntime::runtimeMatches(JSRuntime* rt)
+{
+    return rt == runtime();
+}
+
 Zone*
 CompileZone::zone()
 {
     return reinterpret_cast<Zone*>(this);
 }
 
 /* static */ CompileZone*
 CompileZone::get(Zone* zone)
--- a/js/src/jit/CompileWrappers.h
+++ b/js/src/jit/CompileWrappers.h
@@ -84,16 +84,18 @@ class CompileRuntime
     bool isInsideNursery(gc::Cell* cell);
 #endif
 
     // DOM callbacks must be threadsafe (and will hopefully be removed soon).
     const DOMCallbacks* DOMcallbacks();
 
     const Nursery& gcNursery();
     void setMinorGCShouldCancelIonCompilations();
+
+    bool runtimeMatches(JSRuntime* rt);
 };
 
 class CompileZone
 {
     Zone* zone();
 
   public:
     static CompileZone* get(Zone* zone);
--- a/js/src/jit/IonBuilder.cpp
+++ b/js/src/jit/IonBuilder.cpp
@@ -14575,15 +14575,15 @@ IonBuilder::convertToBoolean(MDefinition
     current->add(result);
 
     return result;
 }
 
 void
 IonBuilder::trace(JSTracer* trc)
 {
-    if (script_->zoneFromAnyThread()->runtimeFromAnyThread() != trc->runtime())
+    if (!compartment->runtime()->runtimeMatches(trc->runtime()))
         return;
 
     TraceManuallyBarrieredEdge(trc, &script_, "IonBuiler::script_");
     if (actionableAbortScript_)
         TraceManuallyBarrieredEdge(trc, &actionableAbortScript_, "IonBuiler::actionableAbortScript_");
 }
--- a/js/src/jscntxt.h
+++ b/js/src/jscntxt.h
@@ -158,16 +158,20 @@ class ExclusiveContext : public ContextF
         MOZ_ASSERT(isJSContext());
         return isJSContext();
     }
 
     const JS::ContextOptions& options() const {
         return options_;
     }
 
+    bool runtimeMatches(JSRuntime* rt) const {
+        return runtime_ == rt;
+    }
+
   protected:
     js::gc::ArenaLists* arenas_;
 
   public:
     inline js::gc::ArenaLists* arenas() const { return arenas_; }
 
     template <typename T>
     bool isInsideCurrentZone(T thing) const {
--- a/js/src/vm/HelperThreads.cpp
+++ b/js/src/vm/HelperThreads.cpp
@@ -250,17 +250,17 @@ ParseTask::~ParseTask()
 
     for (size_t i = 0; i < errors.length(); i++)
         js_delete(errors[i]);
 }
 
 void
 ParseTask::trace(JSTracer* trc)
 {
-    if (exclusiveContextGlobal->zoneFromAnyThread()->runtimeFromAnyThread() != trc->runtime())
+    if (!cx->runtimeMatches(trc->runtime()))
         return;
 
     TraceManuallyBarrieredEdge(trc, &exclusiveContextGlobal, "ParseTask::exclusiveContextGlobal");
     if (script)
         TraceManuallyBarrieredEdge(trc, &script, "ParseTask::script");
     if (sourceObject)
         TraceManuallyBarrieredEdge(trc, &sourceObject, "ParseTask::sourceObject");
 }
--- a/js/src/vm/HelperThreads.h
+++ b/js/src/vm/HelperThreads.h
@@ -540,17 +540,17 @@ struct ParseTask
               JS::OffThreadCompileCallback callback, void* callbackData);
     bool init(JSContext* cx, const ReadOnlyCompileOptions& options);
 
     void activate(JSRuntime* rt);
     virtual void parse() = 0;
     bool finish(JSContext* cx);
 
     bool runtimeMatches(JSRuntime* rt) {
-        return exclusiveContextGlobal->runtimeFromAnyThread() == rt;
+        return cx->runtimeMatches(rt);
     }
 
     virtual ~ParseTask();
 
     void trace(JSTracer* trc);
 };
 
 struct ScriptParseTask : public ParseTask