Bug 1138390 - Wait for GC to finish if necessary in runOffThreadScript() r=terrence a=lsblakk
authorJon Coppeard <jcoppeard@mozilla.com>
Tue, 03 Mar 2015 10:28:06 +0000
changeset 248175 bde39a58935d277f7e0abaecf86969b0a879e89c
parent 248174 4acd7286be9e3a4b207629722127875828da836f
child 248176 cad8615a378ce93965d4d7e41a4705509d45fb62
push id7777
push userjcoppeard@mozilla.com
push dateWed, 18 Mar 2015 11:21:52 +0000
treeherdermozilla-aurora@cad8615a378c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence, lsblakk
bugs1138390
milestone38.0a2
Bug 1138390 - Wait for GC to finish if necessary in runOffThreadScript() r=terrence a=lsblakk
js/src/jit-test/tests/gc/bug-1138390.js
js/src/shell/js.cpp
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/gc/bug-1138390.js
@@ -0,0 +1,28 @@
+if (!("startgc" in this &&
+      "offThreadCompileScript" in this &&
+      "runOffThreadScript" in this))
+{
+    quit();
+}
+
+if (helperThreadCount() == 0)
+    quit();
+
+if ("gczeal" in this)
+   gczeal(0);
+
+// Start an incremental GC that includes the atoms zone
+startgc(0);
+var g = newGlobal();
+
+// Start an off thread compilation that will not run until GC has finished
+if ("gcstate" in this)
+   assertEq("mark", gcstate());
+g.offThreadCompileScript('23;', {});
+
+// Wait for the compilation to finish, which must finish the GC first
+assertEq(23, g.runOffThreadScript());
+if ("gcstate" in this)
+   assertEq("none", gcstate());
+
+print("done");
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -53,16 +53,17 @@
 #ifdef XP_WIN
 # include "jswin.h"
 #endif
 #include "jswrapper.h"
 #include "prmjtime.h"
 
 #include "builtin/TestingFunctions.h"
 #include "frontend/Parser.h"
+#include "gc/GCInternals.h"
 #include "jit/arm/Simulator-arm.h"
 #include "jit/Ion.h"
 #include "js/Debug.h"
 #include "js/GCAPI.h"
 #include "js/StructuredClone.h"
 #include "perf/jsperf.h"
 #include "shell/jsheaptools.h"
 #include "shell/jsoptparse.h"
@@ -3549,23 +3550,27 @@ OffThreadCompileScript(JSContext *cx, un
     return true;
 }
 
 static bool
 runOffThreadScript(JSContext *cx, unsigned argc, jsval *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
 
+    JSRuntime *rt = cx->runtime();
+    if (OffThreadParsingMustWaitForGC(rt))
+        gc::AutoFinishGC finishgc(rt);
+
     void *token = offThreadState.waitUntilDone(cx);
     if (!token) {
         JS_ReportError(cx, "called runOffThreadScript when no compilation is pending");
         return false;
     }
 
-    RootedScript script(cx, JS::FinishOffThreadScript(cx, cx->runtime(), token));
+    RootedScript script(cx, JS::FinishOffThreadScript(cx, rt, token));
     if (!script)
         return false;
 
     return JS_ExecuteScript(cx, cx->global(), script, args.rval());
 }
 
 struct FreeOnReturn
 {