Skip to content

Commit

Permalink
Bug 1834483 - Part 2: Use FrontendContext NativeStackLimit field in P…
Browse files Browse the repository at this point in the history
…arseTask and DelazifyTask. r=bthrall

Differential Revision: https://phabricator.services.mozilla.com/D179003
  • Loading branch information
arai-a committed May 31, 2023
1 parent 9f42499 commit 1528634
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
3 changes: 0 additions & 3 deletions js/src/vm/HelperThreadState.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "js/experimental/CompileScript.h" // JS::CompilationStorage
#include "js/experimental/JSStencil.h" // JS::InstantiationStorage
#include "js/HelperThreadAPI.h"
#include "js/Stack.h" // JS::NativeStackLimit
#include "js/TypeDecls.h"
#include "threading/ConditionVariable.h"
#include "vm/HelperThreads.h"
Expand Down Expand Up @@ -503,7 +502,6 @@ struct MOZ_RAII AutoSetContextRuntime {
struct ParseTask : public mozilla::LinkedListElement<ParseTask>,
public JS::OffThreadToken,
public HelperThreadTask {
JS::NativeStackLimit stackLimit;
ParseTaskKind kind;
JS::OwningCompileOptions options;

Expand Down Expand Up @@ -651,7 +649,6 @@ struct LargeFirstDelazification final : public DelazifyStrategy {
// to remove the memory held by the DelazifyTask.
struct DelazifyTask : public mozilla::LinkedListElement<DelazifyTask>,
public HelperThreadTask {
JS::NativeStackLimit stackLimit;
// HelperThreads are shared between all runtimes in the process so explicitly
// track which one we are associated with.
JSRuntime* runtime = nullptr;
Expand Down
19 changes: 7 additions & 12 deletions js/src/vm/HelperThreads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,13 +601,8 @@ void ParseTask::runHelperThreadTask(AutoLockHelperThreadState& locked) {
HelperThreadState().parseFinishedList(locked).insertBack(this);
}

static inline JS::NativeStackLimit GetStackLimit() {
return JS::GetNativeStackLimit(GetNativeStackBase(),
HelperThreadState().stackQuota);
}

void ParseTask::runTask(AutoLockHelperThreadState& lock) {
stackLimit = GetStackLimit();
fc_.setStackQuota(HelperThreadState().stackQuota);

AutoUnlockHelperThreadState unlock(lock);

Expand Down Expand Up @@ -692,8 +687,8 @@ CompileToStencilTask<Unit>::CompileToStencilTask(

template <typename Unit>
void CompileToStencilTask<Unit>::parse(FrontendContext* fc) {
stencil_ = JS::CompileGlobalScriptToStencil(fc, options, stackLimit, data,
compileStorage_);
stencil_ = JS::CompileGlobalScriptToStencil(fc, options, fc->stackLimit(),
data, compileStorage_);
if (!stencil_) {
return;
}
Expand All @@ -715,8 +710,8 @@ CompileModuleToStencilTask<Unit>::CompileModuleToStencilTask(

template <typename Unit>
void CompileModuleToStencilTask<Unit>::parse(FrontendContext* fc) {
stencil_ = JS::CompileModuleScriptToStencil(fc, options, stackLimit, data,
compileStorage_);
stencil_ = JS::CompileModuleScriptToStencil(fc, options, fc->stackLimit(),
data, compileStorage_);
if (!stencil_) {
return;
}
Expand Down Expand Up @@ -1080,7 +1075,7 @@ void DelazifyTask::runHelperThreadTask(AutoLockHelperThreadState& lock) {
}

bool DelazifyTask::runTask(JSContext* cx) {
stackLimit = GetStackLimit();
fc_.setStackQuota(HelperThreadState().stackQuota);

AutoSetContextRuntime ascr(runtime);
AutoSetContextFrontendErrors recordErrors(&this->fc_);
Expand Down Expand Up @@ -1108,7 +1103,7 @@ bool DelazifyTask::runTask(JSContext* cx) {

// Parse and generate bytecode for the inner function.
innerStencil = DelazifyCanonicalScriptedFunction(
cx, &fc_, stackLimit, &scopeCache, borrow, scriptIndex);
cx, &fc_, fc_.stackLimit(), &scopeCache, borrow, scriptIndex);
if (!innerStencil) {
return false;
}
Expand Down
1 change: 1 addition & 0 deletions js/src/vm/JSONParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,7 @@ template class js::JSONSyntaxParser<char16_t>;
template <typename CharT>
static bool IsValidJSONImpl(const CharT* chars, uint32_t len) {
FrontendContext fc;
// NOTE: We don't set stack quota here because JSON parser doesn't use it.

JSONSyntaxParser<CharT> parser(&fc, mozilla::Range(chars, len));
if (!parser.parse()) {
Expand Down

0 comments on commit 1528634

Please sign in to comment.