Skip to content

Commit

Permalink
Bug 1675962 - Part 1: Make CompilationInfo methods static. r=tcampbell
Browse files Browse the repository at this point in the history
These methods will be modified to take CompilationInput and CompilationStencil
separately in later patch.

Differential Revision: https://phabricator.services.mozilla.com/D97115
  • Loading branch information
arai-a committed Dec 12, 2020
1 parent 53800b5 commit 5d55356
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 42 deletions.
9 changes: 5 additions & 4 deletions js/src/frontend/BytecodeCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ bool frontend::InstantiateStencils(JSContext* cx,
AutoGeckoProfilerEntry pseudoFrame(cx, "stencil instantiate",
JS::ProfilingCategoryPair::JS_Parsing);

if (!compilationInfo.instantiateStencils(cx, gcOutput)) {
if (!CompilationInfo::instantiateStencils(cx, compilationInfo, gcOutput)) {
return false;
}
}
Expand Down Expand Up @@ -384,7 +384,7 @@ bool frontend::PrepareForInstantiate(JSContext* cx,
AutoGeckoProfilerEntry pseudoFrame(cx, "stencil instantiate",
JS::ProfilingCategoryPair::JS_Parsing);

return compilationInfo.prepareForInstantiate(cx, gcOutput);
return CompilationInfo::prepareForInstantiate(cx, compilationInfo, gcOutput);
}

bool frontend::PrepareForInstantiate(
Expand Down Expand Up @@ -868,7 +868,7 @@ bool frontend::StandaloneFunctionCompiler<Unit>::compile(
.functionFlags.isAsmJSNative());
}

if (!compilationInfo.instantiateStencils(cx, gcOutput)) {
if (!CompilationInfo::instantiateStencils(cx, compilationInfo, gcOutput)) {
return false;
}

Expand Down Expand Up @@ -1089,7 +1089,8 @@ bool frontend::InstantiateStencilsForDelazify(
static_cast<uint32_t>(compilationInfo.input.lazy->immutableFlags());

Rooted<CompilationGCOutput> gcOutput(cx);
if (!compilationInfo.instantiateStencils(cx, gcOutput.get())) {
if (!CompilationInfo::instantiateStencils(cx, compilationInfo,
gcOutput.get())) {
return false;
}

Expand Down
25 changes: 15 additions & 10 deletions js/src/frontend/CompilationInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -436,16 +436,21 @@ struct CompilationInfo {
CompilationInfo(JSContext* cx, const JS::ReadOnlyCompileOptions& options)
: input(options) {}

MOZ_MUST_USE bool prepareInputAndStencilForInstantiate(JSContext* cx);
MOZ_MUST_USE bool prepareGCOutputForInstantiate(
JSContext* cx, CompilationGCOutput& gcOutput);

MOZ_MUST_USE bool prepareForInstantiate(JSContext* cx,
CompilationGCOutput& gcOutput);
MOZ_MUST_USE bool instantiateStencils(JSContext* cx,
CompilationGCOutput& gcOutput);
MOZ_MUST_USE bool instantiateStencilsAfterPreparation(
JSContext* cx, CompilationGCOutput& gcOutput);
static MOZ_MUST_USE bool prepareInputAndStencilForInstantiate(
JSContext* cx, CompilationInfo& compilationInfo);
static MOZ_MUST_USE bool prepareGCOutputForInstantiate(
JSContext* cx, CompilationInfo& compilationInfo,
CompilationGCOutput& gcOutput);

static MOZ_MUST_USE bool prepareForInstantiate(
JSContext* cx, CompilationInfo& compilationInfo,
CompilationGCOutput& gcOutput);
static MOZ_MUST_USE bool instantiateStencils(JSContext* cx,
CompilationInfo& compilationInfo,
CompilationGCOutput& gcOutput);
static MOZ_MUST_USE bool instantiateStencilsAfterPreparation(
JSContext* cx, CompilationInfo& compilationInfo,
CompilationGCOutput& gcOutput);

MOZ_MUST_USE bool serializeStencils(JSContext* cx, JS::TranscodeBuffer& buf,
bool* succeededOut = nullptr);
Expand Down
2 changes: 1 addition & 1 deletion js/src/frontend/Frontend2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ bool Smoosh::compileGlobalScript(JSContext* cx,
return false;
}

if (!compilationInfo.instantiateStencils(cx, gcOutput)) {
if (!CompilationInfo::instantiateStencils(cx, compilationInfo, gcOutput)) {
return false;
}

Expand Down
74 changes: 47 additions & 27 deletions js/src/frontend/Stencil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,35 +602,42 @@ static void FunctionsFromExistingLazy(CompilationInfo& compilationInfo,
MOZ_ASSERT(idx == gcOutput.functions.length());
}

/* static */
bool CompilationInfo::instantiateStencils(JSContext* cx,
CompilationInfo& compilationInfo,
CompilationGCOutput& gcOutput) {
if (!preparationIsPerformed) {
if (!prepareForInstantiate(cx, gcOutput)) {
if (!compilationInfo.preparationIsPerformed) {
if (!prepareForInstantiate(cx, compilationInfo, gcOutput)) {
return false;
}
}

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

/* static */
bool CompilationInfo::instantiateStencilsAfterPreparation(
JSContext* cx, CompilationGCOutput& gcOutput) {
JSContext* cx, CompilationInfo& compilationInfo,
CompilationGCOutput& gcOutput) {
auto& input = compilationInfo.input;
auto& stencil = compilationInfo.stencil;

if (!gcOutput.functions.resize(stencil.scriptData.length())) {
ReportOutOfMemory(cx);
return false;
}

if (!InstantiateAtoms(cx, *this)) {
if (!InstantiateAtoms(cx, compilationInfo)) {
return false;
}

if (input.lazy) {
MOZ_ASSERT(!stencil.scriptData[CompilationInfo::TopLevelIndex].isModule());

FunctionsFromExistingLazy(*this, gcOutput);
FunctionsFromExistingLazy(compilationInfo, gcOutput);

#ifdef DEBUG
AssertDelazificationFieldsMatch(*this, gcOutput);
AssertDelazificationFieldsMatch(compilationInfo, gcOutput);
#endif
} else {
if (stencil.scriptData[CompilationInfo::TopLevelIndex].isModule()) {
Expand All @@ -640,39 +647,39 @@ bool CompilationInfo::instantiateStencilsAfterPreparation(
ModuleScope::EnclosingEnvironmentChainLength);
}

if (!InstantiateScriptSourceObject(cx, *this, gcOutput)) {
if (!InstantiateScriptSourceObject(cx, compilationInfo, gcOutput)) {
return false;
}

if (!MaybeInstantiateModule(cx, *this, gcOutput)) {
if (!MaybeInstantiateModule(cx, compilationInfo, gcOutput)) {
return false;
}

if (!InstantiateFunctions(cx, *this, gcOutput)) {
if (!InstantiateFunctions(cx, compilationInfo, gcOutput)) {
return false;
}
}

if (!InstantiateScopes(cx, *this, gcOutput)) {
if (!InstantiateScopes(cx, compilationInfo, gcOutput)) {
return false;
}

if (!input.lazy) {
if (!InstantiateScriptStencils(cx, *this, gcOutput)) {
if (!InstantiateScriptStencils(cx, compilationInfo, gcOutput)) {
return false;
}
}

if (!InstantiateTopLevel(cx, *this, gcOutput)) {
if (!InstantiateTopLevel(cx, compilationInfo, gcOutput)) {
return false;
}

// Must be infallible from here forward.

UpdateEmittedInnerFunctions(cx, *this, gcOutput);
UpdateEmittedInnerFunctions(cx, compilationInfo, gcOutput);

if (!input.lazy) {
LinkEnclosingLazyScript(*this, gcOutput);
LinkEnclosingLazyScript(compilationInfo, gcOutput);
}

return true;
Expand Down Expand Up @@ -731,7 +738,8 @@ bool CompilationInfoVector::instantiateStencils(
bool CompilationInfoVector::instantiateStencilsAfterPreparation(
JSContext* cx, CompilationGCOutput& gcOutput,
CompilationGCOutput& gcOutputForDelazification) {
if (!initial.instantiateStencilsAfterPreparation(cx, gcOutput)) {
if (!CompilationInfo::instantiateStencilsAfterPreparation(cx, initial,
gcOutput)) {
return false;
}

Expand All @@ -749,12 +757,12 @@ bool CompilationInfoVector::instantiateStencilsAfterPreparation(
// decoding.
delazification.input.initFromLazy(lazy);

if (!delazification.prepareGCOutputForInstantiate(
cx, gcOutputForDelazification)) {
if (!CompilationInfo::prepareGCOutputForInstantiate(
cx, delazification, gcOutputForDelazification)) {
return false;
}
if (!delazification.instantiateStencilsAfterPreparation(
cx, gcOutputForDelazification)) {
if (!CompilationInfo::instantiateStencilsAfterPreparation(
cx, delazification, gcOutputForDelazification)) {
return false;
}

Expand All @@ -766,18 +774,27 @@ bool CompilationInfoVector::instantiateStencilsAfterPreparation(
return true;
}

bool CompilationInfo::prepareInputAndStencilForInstantiate(JSContext* cx) {
/* static */
bool CompilationInfo::prepareInputAndStencilForInstantiate(
JSContext* cx, CompilationInfo& compilationInfo) {
auto& input = compilationInfo.input;
auto& stencil = compilationInfo.stencil;

if (!input.atomCache.allocate(cx, stencil.parserAtomData.length())) {
return false;
}

preparationIsPerformed = true;
compilationInfo.preparationIsPerformed = true;

return true;
}

/* static */
bool CompilationInfo::prepareGCOutputForInstantiate(
JSContext* cx, CompilationGCOutput& gcOutput) {
JSContext* cx, CompilationInfo& compilationInfo,
CompilationGCOutput& gcOutput) {
auto& stencil = compilationInfo.stencil;

if (!gcOutput.functions.reserve(stencil.scriptData.length())) {
ReportOutOfMemory(cx);
return false;
Expand All @@ -790,12 +807,14 @@ bool CompilationInfo::prepareGCOutputForInstantiate(
return true;
}

/* static */
bool CompilationInfo::prepareForInstantiate(JSContext* cx,
CompilationInfo& compilationInfo,
CompilationGCOutput& gcOutput) {
if (!prepareInputAndStencilForInstantiate(cx)) {
if (!prepareInputAndStencilForInstantiate(cx, compilationInfo)) {
return false;
}
if (!prepareGCOutputForInstantiate(cx, gcOutput)) {
if (!prepareGCOutputForInstantiate(cx, compilationInfo, gcOutput)) {
return false;
}
return true;
Expand All @@ -804,14 +823,15 @@ bool CompilationInfo::prepareForInstantiate(JSContext* cx,
bool CompilationInfoVector::prepareForInstantiate(
JSContext* cx, CompilationGCOutput& gcOutput,
CompilationGCOutput& gcOutputForDelazification) {
if (!initial.prepareForInstantiate(cx, gcOutput)) {
if (!CompilationInfo::prepareForInstantiate(cx, initial, gcOutput)) {
return false;
}

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

0 comments on commit 5d55356

Please sign in to comment.