Bug 1899090 - Part 3: Stop using JS::DuplicateStencil in ScriptLoader. r=nbp
Incremental-encoding API no longer requires exclusive ownership of JS::Stencil, and the consumers no longer need to duplicate. Differential Revision: https://phabricator.services.mozilla.com/D230379
This commit is contained in:
@@ -2745,8 +2745,8 @@ static void Decode(JSContext* aCx, JS::CompileOptions& aCompileOptions,
|
|||||||
// Instantiate (on main-thread) a JS::Stencil generated by off-thread or
|
// Instantiate (on main-thread) a JS::Stencil generated by off-thread or
|
||||||
// main-thread parsing or decoding.
|
// main-thread parsing or decoding.
|
||||||
static void InstantiateStencil(
|
static void InstantiateStencil(
|
||||||
JSContext* aCx, JS::CompileOptions& aCompileOptions,
|
JSContext* aCx, JS::CompileOptions& aCompileOptions, JS::Stencil* aStencil,
|
||||||
RefPtr<JS::Stencil>&& aStencil, JS::MutableHandle<JSScript*> aScript,
|
JS::MutableHandle<JSScript*> aScript,
|
||||||
bool& incrementalEncodingAlreadyStarted,
|
bool& incrementalEncodingAlreadyStarted,
|
||||||
JS::Handle<JS::Value> aDebuggerPrivateValue,
|
JS::Handle<JS::Value> aDebuggerPrivateValue,
|
||||||
JS::Handle<JSScript*> aDebuggerIntroductionScript, ErrorResult& aRv,
|
JS::Handle<JSScript*> aDebuggerIntroductionScript, ErrorResult& aRv,
|
||||||
@@ -2783,7 +2783,7 @@ static void InstantiateStencil(
|
|||||||
void ScriptLoader::InstantiateClassicScriptFromMaybeEncodedSource(
|
void ScriptLoader::InstantiateClassicScriptFromMaybeEncodedSource(
|
||||||
JSContext* aCx, JS::CompileOptions& aCompileOptions,
|
JSContext* aCx, JS::CompileOptions& aCompileOptions,
|
||||||
ScriptLoadRequest* aRequest, JS::MutableHandle<JSScript*> aScript,
|
ScriptLoadRequest* aRequest, JS::MutableHandle<JSScript*> aScript,
|
||||||
bool aKeepStencil, RefPtr<JS::Stencil>& aStencilDup,
|
RefPtr<JS::Stencil>& aStencilOut,
|
||||||
JS::Handle<JS::Value> aDebuggerPrivateValue,
|
JS::Handle<JS::Value> aDebuggerPrivateValue,
|
||||||
JS::Handle<JSScript*> aDebuggerIntroductionScript, ErrorResult& aRv) {
|
JS::Handle<JSScript*> aDebuggerIntroductionScript, ErrorResult& aRv) {
|
||||||
nsAutoCString profilerLabelString;
|
nsAutoCString profilerLabelString;
|
||||||
@@ -2802,18 +2802,12 @@ void ScriptLoader::InstantiateClassicScriptFromMaybeEncodedSource(
|
|||||||
aRv.NoteJSContextException(aCx);
|
aRv.NoteJSContextException(aCx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!aRv.Failed() && aKeepStencil) {
|
aStencilOut = stencil.get();
|
||||||
aStencilDup = JS::DuplicateStencil(aCx, stencil.get());
|
|
||||||
if (!aStencilDup) {
|
|
||||||
aRv.NoteJSContextException(aCx);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool unused;
|
bool unused;
|
||||||
InstantiateStencil(aCx, aCompileOptions, std::move(stencil), aScript,
|
InstantiateStencil(aCx, aCompileOptions, stencil, aScript, unused,
|
||||||
unused, aDebuggerPrivateValue,
|
aDebuggerPrivateValue, aDebuggerIntroductionScript,
|
||||||
aDebuggerIntroductionScript, aRv, false, &storage);
|
aRv, false, &storage);
|
||||||
} else {
|
} else {
|
||||||
LOG(("ScriptLoadRequest (%p): Decode Bytecode and Execute", aRequest));
|
LOG(("ScriptLoadRequest (%p): Decode Bytecode and Execute", aRequest));
|
||||||
AUTO_PROFILER_MARKER_TEXT("BytecodeDecodeMainThread", JS,
|
AUTO_PROFILER_MARKER_TEXT("BytecodeDecodeMainThread", JS,
|
||||||
@@ -2822,19 +2816,13 @@ void ScriptLoader::InstantiateClassicScriptFromMaybeEncodedSource(
|
|||||||
|
|
||||||
RefPtr<JS::Stencil> stencil;
|
RefPtr<JS::Stencil> stencil;
|
||||||
Decode(aCx, aCompileOptions, aRequest->Bytecode(), stencil, aRv);
|
Decode(aCx, aCompileOptions, aRequest->Bytecode(), stencil, aRv);
|
||||||
if (!aRv.Failed() && aKeepStencil) {
|
aStencilOut = stencil.get();
|
||||||
aStencilDup = JS::DuplicateStencil(aCx, stencil.get());
|
|
||||||
if (!aStencilDup) {
|
|
||||||
aRv.NoteJSContextException(aCx);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stencil) {
|
if (stencil) {
|
||||||
bool unused;
|
bool unused;
|
||||||
InstantiateStencil(aCx, aCompileOptions, std::move(stencil), aScript,
|
InstantiateStencil(aCx, aCompileOptions, stencil, aScript, unused,
|
||||||
unused, aDebuggerPrivateValue,
|
aDebuggerPrivateValue, aDebuggerIntroductionScript,
|
||||||
aDebuggerIntroductionScript, aRv);
|
aRv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2864,19 +2852,12 @@ void ScriptLoader::InstantiateClassicScriptFromMaybeEncodedSource(
|
|||||||
aRv.NoteJSContextException(aCx);
|
aRv.NoteJSContextException(aCx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!aRv.Failed() && aKeepStencil) {
|
aStencilOut = stencil.get();
|
||||||
aStencilDup = JS::DuplicateStencil(aCx, stencil.get());
|
|
||||||
if (!aStencilDup) {
|
|
||||||
aRv.NoteJSContextException(aCx);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool unused;
|
bool unused;
|
||||||
InstantiateStencil(aCx, aCompileOptions, std::move(stencil), aScript,
|
InstantiateStencil(aCx, aCompileOptions, stencil, aScript, unused,
|
||||||
unused, aDebuggerPrivateValue,
|
aDebuggerPrivateValue, aDebuggerIntroductionScript, aRv,
|
||||||
aDebuggerIntroductionScript, aRv, encodeBytecode,
|
encodeBytecode, &storage);
|
||||||
&storage);
|
|
||||||
} else {
|
} else {
|
||||||
// Main thread parsing (inline and small scripts)
|
// Main thread parsing (inline and small scripts)
|
||||||
LOG(("ScriptLoadRequest (%p): Compile And Exec", aRequest));
|
LOG(("ScriptLoadRequest (%p): Compile And Exec", aRequest));
|
||||||
@@ -2901,18 +2882,13 @@ void ScriptLoader::InstantiateClassicScriptFromMaybeEncodedSource(
|
|||||||
MOZ_ASSERT(!maybeSource.empty());
|
MOZ_ASSERT(!maybeSource.empty());
|
||||||
TimeStamp startTime = TimeStamp::Now();
|
TimeStamp startTime = TimeStamp::Now();
|
||||||
maybeSource.mapNonEmpty(compile);
|
maybeSource.mapNonEmpty(compile);
|
||||||
if (!erv.Failed() && aKeepStencil) {
|
aStencilOut = stencil.get();
|
||||||
aStencilDup = JS::DuplicateStencil(aCx, stencil.get());
|
|
||||||
if (!aStencilDup) {
|
|
||||||
erv.NoteJSContextException(aCx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stencil) {
|
if (stencil) {
|
||||||
bool unused;
|
bool unused;
|
||||||
InstantiateStencil(aCx, aCompileOptions, std::move(stencil), aScript,
|
InstantiateStencil(aCx, aCompileOptions, stencil, aScript, unused,
|
||||||
unused, aDebuggerPrivateValue,
|
aDebuggerPrivateValue, aDebuggerIntroductionScript,
|
||||||
aDebuggerIntroductionScript, erv, encodeBytecode);
|
erv, encodeBytecode);
|
||||||
}
|
}
|
||||||
|
|
||||||
mMainThreadParseTime += TimeStamp::Now() - startTime;
|
mMainThreadParseTime += TimeStamp::Now() - startTime;
|
||||||
@@ -2927,14 +2903,8 @@ void ScriptLoader::InstantiateClassicScriptFromCachedStencil(
|
|||||||
JS::MutableHandle<JSScript*> aScript,
|
JS::MutableHandle<JSScript*> aScript,
|
||||||
JS::Handle<JS::Value> aDebuggerPrivateValue,
|
JS::Handle<JS::Value> aDebuggerPrivateValue,
|
||||||
JS::Handle<JSScript*> aDebuggerIntroductionScript, ErrorResult& aRv) {
|
JS::Handle<JSScript*> aDebuggerIntroductionScript, ErrorResult& aRv) {
|
||||||
RefPtr<JS::Stencil> stencil = JS::DuplicateStencil(aCx, aStencil);
|
|
||||||
if (!stencil) {
|
|
||||||
aRv = NS_ERROR_FAILURE;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool incrementalEncodingAlreadyStarted = false;
|
bool incrementalEncodingAlreadyStarted = false;
|
||||||
InstantiateStencil(aCx, aCompileOptions, std::move(stencil), aScript,
|
InstantiateStencil(aCx, aCompileOptions, aStencil, aScript,
|
||||||
incrementalEncodingAlreadyStarted, aDebuggerPrivateValue,
|
incrementalEncodingAlreadyStarted, aDebuggerPrivateValue,
|
||||||
aDebuggerIntroductionScript, aRv,
|
aDebuggerIntroductionScript, aRv,
|
||||||
/* aEncodeBytecode */ true);
|
/* aEncodeBytecode */ true);
|
||||||
@@ -2969,15 +2939,15 @@ void ScriptLoader::InstantiateClassicScriptFromAny(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<JS::Stencil> stencilDup;
|
RefPtr<JS::Stencil> stencil;
|
||||||
InstantiateClassicScriptFromMaybeEncodedSource(
|
InstantiateClassicScriptFromMaybeEncodedSource(
|
||||||
aCx, aCompileOptions, aRequest, aScript, createCache, stencilDup,
|
aCx, aCompileOptions, aRequest, aScript, stencil, aDebuggerPrivateValue,
|
||||||
aDebuggerPrivateValue, aDebuggerIntroductionScript, aRv);
|
aDebuggerIntroductionScript, aRv);
|
||||||
if (!aRv.Failed()) {
|
if (!aRv.Failed()) {
|
||||||
if (createCache) {
|
if (createCache) {
|
||||||
MOZ_ASSERT(mCache);
|
MOZ_ASSERT(mCache);
|
||||||
MOZ_ASSERT(stencilDup);
|
MOZ_ASSERT(stencil);
|
||||||
aRequest->SetStencil(stencilDup.forget());
|
aRequest->SetStencil(stencil.forget());
|
||||||
auto loadData = MakeRefPtr<ScriptLoadData>(this, aRequest);
|
auto loadData = MakeRefPtr<ScriptLoadData>(this, aRequest);
|
||||||
mCache->Insert(*loadData);
|
mCache->Insert(*loadData);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -647,12 +647,11 @@ class ScriptLoader final : public JS::loader::ScriptLoaderInterface {
|
|||||||
// * text source
|
// * text source
|
||||||
// * encoded bytecode
|
// * encoded bytecode
|
||||||
//
|
//
|
||||||
// If keepStencil is true and this function is successful, aStencilDup will
|
// aStencilOut is set to the compiled stencil.
|
||||||
// contain a copy of the compiled stencil for use by the caller.
|
|
||||||
void InstantiateClassicScriptFromMaybeEncodedSource(
|
void InstantiateClassicScriptFromMaybeEncodedSource(
|
||||||
JSContext* aCx, JS::CompileOptions& aCompileOptions,
|
JSContext* aCx, JS::CompileOptions& aCompileOptions,
|
||||||
ScriptLoadRequest* aRequest, JS::MutableHandle<JSScript*> aScript,
|
ScriptLoadRequest* aRequest, JS::MutableHandle<JSScript*> aScript,
|
||||||
bool keepStencil, RefPtr<JS::Stencil>& aStencilDup,
|
RefPtr<JS::Stencil>& aStencilOut,
|
||||||
JS::Handle<JS::Value> aDebuggerPrivateValue,
|
JS::Handle<JS::Value> aDebuggerPrivateValue,
|
||||||
JS::Handle<JSScript*> aDebuggerIntroductionScript, ErrorResult& aRv);
|
JS::Handle<JSScript*> aDebuggerIntroductionScript, ErrorResult& aRv);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user