Skip to content

Commit

Permalink
Bug 1671912 - Reuse CompilationGCOutput across delazifications in Com…
Browse files Browse the repository at this point in the history
…pilationInfoVector::instantiateStencils. r=tcampbell

Differential Revision: https://phabricator.services.mozilla.com/D97114
  • Loading branch information
arai-a committed Dec 12, 2020
1 parent 0712077 commit 53800b5
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 34 deletions.
4 changes: 3 additions & 1 deletion js/src/builtin/TestingFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5084,7 +5084,9 @@ static bool EvalStencilXDR(JSContext* cx, uint32_t argc, Value* vp) {

/* Instantiate the stencil. */
Rooted<frontend::CompilationGCOutput> output(cx);
if (!compilationInfos.get().instantiateStencils(cx, output.get())) {
Rooted<frontend::CompilationGCOutput> outputForDelazification(cx);
if (!compilationInfos.get().instantiateStencils(
cx, output.get(), outputForDelazification.get())) {
return false;
}

Expand Down
10 changes: 6 additions & 4 deletions js/src/frontend/BytecodeCompilation.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,18 @@ extern UniquePtr<CompilationInfo> CompileGlobalScriptToStencil(
extern bool PrepareForInstantiate(JSContext* cx,
CompilationInfo& compilationInfo,
CompilationGCOutput& gcOutput);
extern bool PrepareForInstantiate(JSContext* cx,
CompilationInfoVector& compilationInfos,
CompilationGCOutput& gcOutput);
extern bool PrepareForInstantiate(
JSContext* cx, CompilationInfoVector& compilationInfos,
CompilationGCOutput& gcOutput,
CompilationGCOutput& gcOutputForDelazification);

extern bool InstantiateStencils(JSContext* cx, CompilationInfo& compilationInfo,
CompilationGCOutput& gcOutput);

extern bool InstantiateStencils(JSContext* cx,
CompilationInfoVector& compilationInfos,
CompilationGCOutput& gcOutput);
CompilationGCOutput& gcOutput,
CompilationGCOutput& gcOutputForDelazification);

extern JSScript* CompileGlobalScript(JSContext* cx,
const JS::ReadOnlyCompileOptions& options,
Expand Down
20 changes: 12 additions & 8 deletions js/src/frontend/BytecodeCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,16 @@ bool frontend::InstantiateStencils(JSContext* cx,
return true;
}

bool frontend::InstantiateStencils(JSContext* cx,
CompilationInfoVector& compilationInfos,
CompilationGCOutput& gcOutput) {
bool frontend::InstantiateStencils(
JSContext* cx, CompilationInfoVector& compilationInfos,
CompilationGCOutput& gcOutput,
CompilationGCOutput& gcOutputForDelazification_) {
{
AutoGeckoProfilerEntry pseudoFrame(cx, "stencil instantiate",
JS::ProfilingCategoryPair::JS_Parsing);

if (!compilationInfos.instantiateStencils(cx, gcOutput)) {
if (!compilationInfos.instantiateStencils(cx, gcOutput,
gcOutputForDelazification_)) {
return false;
}
}
Expand Down Expand Up @@ -385,13 +387,15 @@ bool frontend::PrepareForInstantiate(JSContext* cx,
return compilationInfo.prepareForInstantiate(cx, gcOutput);
}

bool frontend::PrepareForInstantiate(JSContext* cx,
CompilationInfoVector& compilationInfos,
CompilationGCOutput& gcOutput) {
bool frontend::PrepareForInstantiate(
JSContext* cx, CompilationInfoVector& compilationInfos,
CompilationGCOutput& gcOutput,
CompilationGCOutput& gcOutputForDelazification_) {
AutoGeckoProfilerEntry pseudoFrame(cx, "stencil instantiate",
JS::ProfilingCategoryPair::JS_Parsing);

return compilationInfos.prepareForInstantiate(cx, gcOutput);
return compilationInfos.prepareForInstantiate(cx, gcOutput,
gcOutputForDelazification_);
}

template <typename Unit>
Expand Down
13 changes: 8 additions & 5 deletions js/src/frontend/CompilationInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -495,12 +495,15 @@ struct CompilationInfoVector {
CompilationInfoVector& operator=(const CompilationInfoVector&) = delete;
CompilationInfoVector& operator=(CompilationInfoVector&&) = delete;

MOZ_MUST_USE bool prepareForInstantiate(JSContext* cx,
CompilationGCOutput& gcOutput);
MOZ_MUST_USE bool instantiateStencils(JSContext* cx,
CompilationGCOutput& gcOutput);
MOZ_MUST_USE bool prepareForInstantiate(
JSContext* cx, CompilationGCOutput& gcOutput,
CompilationGCOutput& gcOutputForDelazification);
MOZ_MUST_USE bool instantiateStencils(
JSContext* cx, CompilationGCOutput& gcOutput,
CompilationGCOutput& gcOutputForDelazification);
MOZ_MUST_USE bool instantiateStencilsAfterPreparation(
JSContext* cx, CompilationGCOutput& gcOutput);
JSContext* cx, CompilationGCOutput& gcOutput,
CompilationGCOutput& gcOutputForDelazification);

MOZ_MUST_USE bool deserializeStencils(JSContext* cx,
const JS::TranscodeRange& range,
Expand Down
42 changes: 33 additions & 9 deletions js/src/frontend/Stencil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,17 +717,20 @@ bool CompilationInfoVector::buildDelazificationIndices(JSContext* cx) {
return true;
}

bool CompilationInfoVector::instantiateStencils(JSContext* cx,
CompilationGCOutput& gcOutput) {
if (!prepareForInstantiate(cx, gcOutput)) {
bool CompilationInfoVector::instantiateStencils(
JSContext* cx, CompilationGCOutput& gcOutput,
CompilationGCOutput& gcOutputForDelazification) {
if (!prepareForInstantiate(cx, gcOutput, gcOutputForDelazification)) {
return false;
}

return instantiateStencilsAfterPreparation(cx, gcOutput);
return instantiateStencilsAfterPreparation(cx, gcOutput,
gcOutputForDelazification);
}

bool CompilationInfoVector::instantiateStencilsAfterPreparation(
JSContext* cx, CompilationGCOutput& gcOutput) {
JSContext* cx, CompilationGCOutput& gcOutput,
CompilationGCOutput& gcOutputForDelazification) {
if (!initial.instantiateStencilsAfterPreparation(cx, gcOutput)) {
return false;
}
Expand All @@ -746,15 +749,18 @@ bool CompilationInfoVector::instantiateStencilsAfterPreparation(
// decoding.
delazification.input.initFromLazy(lazy);

Rooted<CompilationGCOutput> gcOutputForDelazification(cx);
if (!delazification.prepareGCOutputForInstantiate(
cx, gcOutputForDelazification.get())) {
cx, gcOutputForDelazification)) {
return false;
}
if (!delazification.instantiateStencilsAfterPreparation(
cx, gcOutputForDelazification.get())) {
cx, gcOutputForDelazification)) {
return false;
}

// Destroy elements, without unreserving.
gcOutputForDelazification.functions.shrinkTo(0);
gcOutputForDelazification.scopes.shrinkTo(0);
}

return true;
Expand Down Expand Up @@ -796,15 +802,33 @@ bool CompilationInfo::prepareForInstantiate(JSContext* cx,
}

bool CompilationInfoVector::prepareForInstantiate(
JSContext* cx, CompilationGCOutput& gcOutput) {
JSContext* cx, CompilationGCOutput& gcOutput,
CompilationGCOutput& gcOutputForDelazification) {
if (!initial.prepareForInstantiate(cx, gcOutput)) {
return false;
}

size_t maxScriptDataLength = 0;
size_t maxScopeDataLength = 0;
for (auto& delazification : delazifications) {
if (!delazification.prepareInputAndStencilForInstantiate(cx)) {
return false;
}
if (maxScriptDataLength < delazification.stencil.scriptData.length()) {
maxScriptDataLength = delazification.stencil.scriptData.length();
}
if (maxScopeDataLength < delazification.stencil.scopeData.length()) {
maxScopeDataLength = delazification.stencil.scopeData.length();
}
}

if (!gcOutput.functions.reserve(maxScriptDataLength)) {
ReportOutOfMemory(cx);
return false;
}
if (!gcOutput.scopes.reserve(maxScopeDataLength)) {
ReportOutOfMemory(cx);
return false;
}

if (!buildDelazificationIndices(cx)) {
Expand Down
12 changes: 7 additions & 5 deletions js/src/jsapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ JS_PUBLIC_API JSErrorInterceptor* JS_GetErrorInterceptorCallback(
JSRuntime* rt) {
#if defined(NIGHTLY_BUILD)
return rt->errorInterception.interceptor;
#else // !NIGHTLY_BUILD
#else // !NIGHTLY_BUILD
return nullptr;
#endif // defined(NIGHTLY_BUILD)
}
Expand Down Expand Up @@ -5771,8 +5771,9 @@ JS_PUBLIC_API JS::TranscodeResult JS::DecodeScriptMaybeStencil(
}

Rooted<frontend::CompilationGCOutput> gcOutput(cx);
if (!frontend::InstantiateStencils(cx, compilationInfos.get(),
gcOutput.get())) {
Rooted<frontend::CompilationGCOutput> gcOutputForDelazification(cx);
if (!frontend::InstantiateStencils(cx, compilationInfos.get(), gcOutput.get(),
gcOutputForDelazification.get())) {
return JS::TranscodeResult_Throw;
}

Expand Down Expand Up @@ -5833,8 +5834,9 @@ JS_PUBLIC_API JS::TranscodeResult JS::DecodeScriptAndStartIncrementalEncoding(
}

Rooted<frontend::CompilationGCOutput> gcOutput(cx);
if (!frontend::InstantiateStencils(cx, compilationInfos.get(),
gcOutput.get())) {
Rooted<frontend::CompilationGCOutput> gcOutputForDelazification(cx);
if (!frontend::InstantiateStencils(cx, compilationInfos.get(), gcOutput.get(),
gcOutputForDelazification.get())) {
return JS::TranscodeResult_Throw;
}

Expand Down
2 changes: 2 additions & 0 deletions js/src/vm/HelperThreadState.h
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,8 @@ struct ParseTask : public mozilla::LinkedListElement<ParseTask>,

frontend::CompilationGCOutput gcOutput_;

frontend::CompilationGCOutput gcOutputForDelazification_;

// Any errors or warnings produced during compilation. These are reported
// when finishing the script.
Vector<UniquePtr<CompileError>, 0, SystemAllocPolicy> errors;
Expand Down
7 changes: 5 additions & 2 deletions js/src/vm/HelperThreads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ void ParseTask::trace(JSTracer* trc) {
compilationInfos_->trace(trc);
}
gcOutput_.trace(trc);
gcOutputForDelazification_.trace(trc);
}

size_t ParseTask::sizeOfExcludingThis(
Expand Down Expand Up @@ -701,7 +702,8 @@ bool ParseTask::instantiateStencils(JSContext* cx) {
if (compilationInfo_) {
result = frontend::InstantiateStencils(cx, *compilationInfo_, gcOutput_);
} else {
result = frontend::InstantiateStencils(cx, *compilationInfos_, gcOutput_);
result = frontend::InstantiateStencils(cx, *compilationInfos_, gcOutput_,
gcOutputForDelazification_);
}

// Whatever happens to the top-level script compilation (even if it fails),
Expand Down Expand Up @@ -794,7 +796,8 @@ void ScriptDecodeTask::parse(JSContext* cx) {
compilationInfos_ = std::move(compilationInfos.get());

if (compilationInfos_) {
if (!frontend::PrepareForInstantiate(cx, *compilationInfos_, gcOutput_)) {
if (!frontend::PrepareForInstantiate(cx, *compilationInfos_, gcOutput_,
gcOutputForDelazification_)) {
compilationInfos_ = nullptr;
}
}
Expand Down

0 comments on commit 53800b5

Please sign in to comment.