Bug 1138390 - Wait for GC to finish if necessary in runOffThreadScript() r=terrence a=lsblakk
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
{