Bug 1138390 - Wait for GC to finish if necessary in runOffThreadScript() r=terrence

This commit is contained in:
Jon Coppeard 2015-03-03 10:28:06 +00:00
parent 71d94d71fd
commit 1184b19cd8
2 changed files with 34 additions and 1 deletions

View File

@ -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");

View File

@ -58,6 +58,7 @@
#include "builtin/TestingFunctions.h"
#include "frontend/Parser.h"
#include "gc/GCInternals.h"
#include "jit/arm/Simulator-arm.h"
#include "jit/Ion.h"
#include "jit/JitcodeMap.h"
@ -3581,13 +3582,17 @@ 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;