From fdf1d4fe0c848b45daf899388703f0d0d1e7c496 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Mon, 20 Jan 2014 20:09:59 -0500 Subject: [PATCH] Backout dc82a01d0cfe (bug 961318) for various JavaScript test failures on this CLOSED TREE --- content/base/src/nsScriptLoader.cpp | 2 +- content/xul/content/src/nsXULElement.cpp | 2 +- js/src/jsapi.cpp | 18 ++---------------- js/src/jsapi.h | 2 +- js/src/jsworkers.cpp | 22 ++++++++-------------- js/src/jsworkers.h | 5 ----- js/src/shell/js.cpp | 10 +++++----- 7 files changed, 18 insertions(+), 43 deletions(-) diff --git a/content/base/src/nsScriptLoader.cpp b/content/base/src/nsScriptLoader.cpp index 76d6bbe9d99f..dd1a8e1f3f7a 100644 --- a/content/base/src/nsScriptLoader.cpp +++ b/content/base/src/nsScriptLoader.cpp @@ -841,7 +841,7 @@ nsScriptLoader::AttemptAsyncScriptParse(nsScriptLoadRequest* aRequest) JS::CompileOptions options(cx); FillCompileOptionsForRequest(aRequest, global, &options); - if (!JS::CanCompileOffThread(cx, options, aRequest->mScriptText.Length())) { + if (!JS::CanCompileOffThread(cx, options)) { return NS_ERROR_FAILURE; } diff --git a/content/xul/content/src/nsXULElement.cpp b/content/xul/content/src/nsXULElement.cpp index c9a0cfd2fc80..af263d880df0 100644 --- a/content/xul/content/src/nsXULElement.cpp +++ b/content/xul/content/src/nsXULElement.cpp @@ -2656,7 +2656,7 @@ nsXULPrototypeScript::Compile(const char16_t* aText, JS::ExposeObjectToActiveJS(scope); } - if (aOffThreadReceiver && JS::CanCompileOffThread(cx, options, aTextLength)) { + if (aOffThreadReceiver && JS::CanCompileOffThread(cx, options)) { if (!JS::CompileOffThread(cx, scope, options, static_cast(aText), aTextLength, OffThreadScriptReceiverCallback, diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index e82ff8f40e8b..9b473eeef180 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -4442,22 +4442,8 @@ JS::Compile(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &optio } JS_PUBLIC_API(bool) -JS::CanCompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, size_t length) +JS::CanCompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options) { - static const unsigned TINY_LENGTH = 1000; - static const unsigned HUGE_LENGTH = 100*1000; - - // Compiling off the main thread inolves creating a new Zone and other - // significant overheads. Don't bother if the script is tiny. - if (length < TINY_LENGTH) - return false; - - // If the parsing task would have to wait for GC to complete, it'll probably - // be faster to just start it synchronously on the main thread unless the - // script is huge. - if (OffThreadParsingMustWaitForGC(cx->runtime()) && length < HUGE_LENGTH) - return false; - return cx->runtime()->canUseParallelParsing(); } @@ -4466,7 +4452,7 @@ JS::CompileOffThread(JSContext *cx, Handle obj, const ReadOnlyCompile const jschar *chars, size_t length, OffThreadCompileCallback callback, void *callbackData) { - JS_ASSERT(CanCompileOffThread(cx, options, length)); + JS_ASSERT(CanCompileOffThread(cx, options)); return StartOffThreadParseScript(cx, options, chars, length, obj, callback, callbackData); } diff --git a/js/src/jsapi.h b/js/src/jsapi.h index beee51938b61..80670b18ae36 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -3647,7 +3647,7 @@ extern JS_PUBLIC_API(JSScript *) Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, const char *filename); extern JS_PUBLIC_API(bool) -CanCompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options, size_t length); +CanCompileOffThread(JSContext *cx, const ReadOnlyCompileOptions &options); /* * Off thread compilation control flow. diff --git a/js/src/jsworkers.cpp b/js/src/jsworkers.cpp index 49b2035f4e69..67bc437520e4 100644 --- a/js/src/jsworkers.cpp +++ b/js/src/jsworkers.cpp @@ -229,18 +229,6 @@ ParseTask::~ParseTask() js_delete(errors[i]); } -bool -js::OffThreadParsingMustWaitForGC(JSRuntime *rt) -{ - // Off thread parsing can't occur during incremental collections on the - // atoms compartment, to avoid triggering barriers. (Outside the atoms - // compartment, the compilation will use a new zone that is never - // collected.) If an atoms-zone GC is in progress, hold off on executing the - // parse task until the atoms-zone GC completes (see - // EnqueuePendingParseTasksAfterGC). - return rt->activeGCInAtomsZone(); -} - bool js::StartOffThreadParseScript(JSContext *cx, const ReadOnlyCompileOptions &options, const jschar *chars, size_t length, HandleObject scopeChain, @@ -311,7 +299,13 @@ js::StartOffThreadParseScript(JSContext *cx, const ReadOnlyCompileOptions &optio WorkerThreadState &state = *cx->runtime()->workerThreadState; JS_ASSERT(state.numThreads); - if (OffThreadParsingMustWaitForGC(cx->runtime())) { + // Off thread parsing can't occur during incremental collections on the + // atoms compartment, to avoid triggering barriers. (Outside the atoms + // compartment, the compilation will use a new zone which doesn't require + // barriers itself.) If an atoms-zone GC is in progress, hold off on + // executing the parse task until the atoms-zone GC completes (see + // EnqueuePendingParseTasksAfterGC). + if (cx->runtime()->activeGCInAtomsZone()) { if (!state.parseWaitingOnGC.append(task.get())) return false; } else { @@ -333,7 +327,7 @@ js::StartOffThreadParseScript(JSContext *cx, const ReadOnlyCompileOptions &optio void js::EnqueuePendingParseTasksAfterGC(JSRuntime *rt) { - JS_ASSERT(!OffThreadParsingMustWaitForGC(rt)); + JS_ASSERT(!rt->activeGCInAtomsZone()); if (!rt->workerThreadState || rt->workerThreadState->parseWaitingOnGC.empty()) return; diff --git a/js/src/jsworkers.h b/js/src/jsworkers.h index 3c39af349a9d..e428a35b1e77 100644 --- a/js/src/jsworkers.h +++ b/js/src/jsworkers.h @@ -371,11 +371,6 @@ struct ParseTask ~ParseTask(); }; -// Return whether, if a new parse task was started, it would need to wait for -// an in-progress GC to complete before starting. -extern bool -OffThreadParsingMustWaitForGC(JSRuntime *rt); - // Compression tasks are allocated on the stack by their triggering thread, // which will block on the compression completing as the task goes out of scope // to ensure it completes at the required time. diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index a050888c953b..55213a4d2c27 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -3304,16 +3304,16 @@ OffThreadCompileScript(JSContext *cx, unsigned argc, jsval *vp) .setCompileAndGo(true) .setSourcePolicy(CompileOptions::SAVE_SOURCE); + if (!JS::CanCompileOffThread(cx, options)) { + JS_ReportError(cx, "cannot compile code on worker thread"); + return false; + } + const jschar *chars = JS_GetStringCharsZ(cx, scriptContents); if (!chars) return false; size_t length = JS_GetStringLength(scriptContents); - if (!JS::CanCompileOffThread(cx, options, length)) { - JS_ReportError(cx, "cannot compile code on worker thread"); - return false; - } - if (!offThreadState.startIfIdle(cx, scriptContents)) { JS_ReportError(cx, "called offThreadCompileScript without calling runOffThreadScript" " to receive prior off-thread compilation");