Bug 1781183 - Part 5: Add BytecodeEmitter::stackLimit. r=bthrall

Depends on D152775

Differential Revision: https://phabricator.services.mozilla.com/D152776
This commit is contained in:
Tooru Fujisawa 2022-07-30 04:45:19 +00:00
Родитель 8520999b66
Коммит 1c30142b79
3 изменённых файлов: 31 добавлений и 18 удалений

Просмотреть файл

@ -83,7 +83,8 @@ class MOZ_RAII AutoAssertReportedException {
static bool EmplaceEmitter(CompilationState& compilationState,
Maybe<BytecodeEmitter>& emitter,
const EitherParser& parser, SharedContext* sc);
uintptr_t stackLimit, const EitherParser& parser,
SharedContext* sc);
template <typename Unit>
class MOZ_STACK_CLASS SourceAwareCompiler {
@ -131,7 +132,7 @@ class MOZ_STACK_CLASS SourceAwareCompiler {
[[nodiscard]] bool emplaceEmitter(Maybe<BytecodeEmitter>& emitter,
SharedContext* sharedContext) {
return EmplaceEmitter(compilationState_, emitter,
return EmplaceEmitter(compilationState_, emitter, stackLimit,
EitherParser(parser.ptr()), sharedContext);
}
@ -624,10 +625,11 @@ bool SourceAwareCompiler<Unit>::createSourceAndParser(JSContext* cx,
static bool EmplaceEmitter(CompilationState& compilationState,
Maybe<BytecodeEmitter>& emitter,
const EitherParser& parser, SharedContext* sc) {
uintptr_t stackLimit, const EitherParser& parser,
SharedContext* sc) {
BytecodeEmitter::EmitterMode emitterMode =
sc->selfHosted() ? BytecodeEmitter::SelfHosting : BytecodeEmitter::Normal;
emitter.emplace(parser, sc, compilationState, emitterMode);
emitter.emplace(stackLimit, parser, sc, compilationState, emitterMode);
return emitter->init();
}
@ -1116,8 +1118,10 @@ static bool CompileLazyFunctionToStencilMaybeInstantiate(
return false;
}
uintptr_t stackLimit = cx->stackLimitForCurrentPrincipal();
Parser<FullParseHandler, Unit> parser(
cx, ec, cx->stackLimitForCurrentPrincipal(), input.options, units, length,
cx, ec, stackLimit, input.options, units, length,
/* foldConstants = */ true, compilationState,
/* syntaxParser = */ nullptr);
if (!parser.checkOptions()) {
@ -1131,7 +1135,7 @@ static bool CompileLazyFunctionToStencilMaybeInstantiate(
return false;
}
BytecodeEmitter bce(&parser, pn->funbox(), compilationState,
BytecodeEmitter bce(stackLimit, &parser, pn->funbox(), compilationState,
BytecodeEmitter::LazyFunction);
if (!bce.init(pn->pn_pos)) {
return false;

Просмотреть файл

@ -132,31 +132,37 @@ static bool ShouldSuppressBreakpointsAndSourceNotes(
return false;
}
BytecodeEmitter::BytecodeEmitter(BytecodeEmitter* parent, SharedContext* sc,
BytecodeEmitter::BytecodeEmitter(BytecodeEmitter* parent, uintptr_t stackLimit,
SharedContext* sc,
CompilationState& compilationState,
EmitterMode emitterMode)
: sc(sc),
cx(sc->cx_),
stackLimit(stackLimit),
parent(parent),
bytecodeSection_(cx, sc->extent().lineno, sc->extent().column),
perScriptData_(cx, compilationState),
compilationState(compilationState),
suppressBreakpointsAndSourceNotes(
ShouldSuppressBreakpointsAndSourceNotes(sc, emitterMode)),
emitterMode(emitterMode) {}
emitterMode(emitterMode) {
MOZ_ASSERT_IF(parent, stackLimit == parent->stackLimit);
}
BytecodeEmitter::BytecodeEmitter(BytecodeEmitter* parent,
BCEParserHandle* handle, SharedContext* sc,
CompilationState& compilationState,
EmitterMode emitterMode)
: BytecodeEmitter(parent, sc, compilationState, emitterMode) {
: BytecodeEmitter(parent, parent->stackLimit, sc, compilationState,
emitterMode) {
parser = handle;
}
BytecodeEmitter::BytecodeEmitter(const EitherParser& parser, SharedContext* sc,
BytecodeEmitter::BytecodeEmitter(uintptr_t stackLimit,
const EitherParser& parser, SharedContext* sc,
CompilationState& compilationState,
EmitterMode emitterMode)
: BytecodeEmitter(nullptr, sc, compilationState, emitterMode) {
: BytecodeEmitter(nullptr, stackLimit, sc, compilationState, emitterMode) {
ep_.emplace(parser);
this->parser = ep_.ptr();
}

Просмотреть файл

@ -205,6 +205,8 @@ struct MOZ_STACK_CLASS BytecodeEmitter {
JSContext* const cx = nullptr;
uintptr_t stackLimit;
// Enclosing function or global context.
BytecodeEmitter* const parent = nullptr;
@ -311,8 +313,9 @@ struct MOZ_STACK_CLASS BytecodeEmitter {
*/
private:
// Internal constructor, for delegation use only.
BytecodeEmitter(BytecodeEmitter* parent, SharedContext* sc,
CompilationState& compilationState, EmitterMode emitterMode);
BytecodeEmitter(BytecodeEmitter* parent, uintptr_t stackLimit,
SharedContext* sc, CompilationState& compilationState,
EmitterMode emitterMode);
BytecodeEmitter(BytecodeEmitter* parent, BCEParserHandle* handle,
SharedContext* sc, CompilationState& compilationState,
@ -329,15 +332,15 @@ struct MOZ_STACK_CLASS BytecodeEmitter {
void reportNeedMoreArgsError(CallNode* callNode, uint32_t requiredArgs);
public:
BytecodeEmitter(const EitherParser& parser, SharedContext* sc,
CompilationState& compilationState,
BytecodeEmitter(uintptr_t stackLimit, const EitherParser& parser,
SharedContext* sc, CompilationState& compilationState,
EmitterMode emitterMode = Normal);
template <typename Unit>
BytecodeEmitter(Parser<FullParseHandler, Unit>* parser, SharedContext* sc,
CompilationState& compilationState,
BytecodeEmitter(uintptr_t stackLimit, Parser<FullParseHandler, Unit>* parser,
SharedContext* sc, CompilationState& compilationState,
EmitterMode emitterMode = Normal)
: BytecodeEmitter(EitherParser(parser), sc, compilationState,
: BytecodeEmitter(stackLimit, EitherParser(parser), sc, compilationState,
emitterMode) {}
[[nodiscard]] bool init();