Skip to content

Commit

Permalink
Bug 1716324 part 2 - Rely on default stack size for jsapi-tests, gdb-…
Browse files Browse the repository at this point in the history
…tests, and JS shell main thread. r=tcampbell

Differential Revision: https://phabricator.services.mozilla.com/D117656
  • Loading branch information
jandem committed Jun 17, 2021
1 parent e6bb4ef commit 9f2ed79
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 35 deletions.
1 change: 0 additions & 1 deletion js/src/gdb/gdb-tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ int main(int argc, const char** argv) {
JSContext* cx = checkPtr(JS_NewContext(1024 * 1024));

JS_SetGCParameter(cx, JSGC_MAX_BYTES, 0xffffffff);
JS_SetNativeStackQuota(cx, 5000000);

checkBool(JS::InitSelfHostedCode(cx));
JS::SetWarningReporter(cx, reportWarning);
Expand Down
1 change: 0 additions & 1 deletion js/src/jsapi-tests/testGCOutOfMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ virtual JSContext* createContext() override {
#ifdef JS_GC_ZEAL
JS_UnsetGCZeal(cx, uint8_t(js::gc::ZealMode::GenerationalGC));
#endif
setNativeStackQuota(cx);
return cx;
}

Expand Down
1 change: 0 additions & 1 deletion js/src/jsapi-tests/testOOM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ virtual JSContext* createContext() override {
return nullptr;
}
JS_SetGCParameter(cx, JSGC_MAX_BYTES, (uint32_t)-1);
setNativeStackQuota(cx);
return cx;
}
END_TEST(testOOM)
Expand Down
18 changes: 0 additions & 18 deletions js/src/jsapi-tests/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,30 +346,12 @@ class JSAPITest {

bool definePrint();

static void setNativeStackQuota(JSContext* cx) {
const size_t MAX_STACK_SIZE =
/* Assume we can't use more than 5e5 bytes of C stack by default. */
#if (defined(DEBUG) && defined(__SUNPRO_CC)) || defined(__sparc__)
/*
* Sun compiler uses a larger stack space for js::Interpret() with
* debug. Use a bigger gMaxStackSize to make "make check" happy.
*/
5000000
#else
500000
#endif
;

JS_SetNativeStackQuota(cx, MAX_STACK_SIZE);
}

virtual JSContext* createContext() {
JSContext* cx = JS_NewContext(8L * 1024 * 1024);
if (!cx) {
return nullptr;
}
JS::SetWarningReporter(cx, &reportWarning);
setNativeStackQuota(cx);
return cx;
}

Expand Down
18 changes: 4 additions & 14 deletions js/src/shell/js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,6 @@ enum JSShellExitCode {
EXITCODE_TIMEOUT = 6
};

/*
* Note: This limit should match the stack limit set by the browser in
* js/xpconnect/src/XPCJSContext.cpp
*/
#if defined(MOZ_ASAN) || (defined(DEBUG) && !defined(XP_WIN))
static const size_t gMaxStackSize = 2 * 128 * sizeof(size_t) * 1024;
#else
static const size_t gMaxStackSize = 128 * sizeof(size_t) * 1024;
#endif

/*
* Limit the timeout to 30 minutes to prevent an overflow on platfoms
* that represent the time internally in microseconds using 32-bit int.
Expand Down Expand Up @@ -4749,6 +4739,8 @@ static JSObject* ShellSourceElementCallback(JSContext* cx,
return nullptr;
}

static constexpr size_t gWorkerStackSize = 2 * 128 * sizeof(size_t) * 1024;

static void WorkerMain(WorkerInput* input) {
MOZ_ASSERT(input->parentRuntime);

Expand Down Expand Up @@ -4910,7 +4902,7 @@ static bool EvalInWorker(JSContext* cx, unsigned argc, Value* vp) {
{
AutoEnterOOMUnsafeRegion oomUnsafe;
thread = js_new<Thread>(
Thread::Options().setStackSize(gMaxStackSize + 512 * 1024));
Thread::Options().setStackSize(gWorkerStackSize + 512 * 1024));
if (!thread || !thread->init(WorkerMain, input)) {
oomUnsafe.crash("EvalInWorker");
}
Expand Down Expand Up @@ -11508,7 +11500,7 @@ static void SetWorkerContextOptions(JSContext* cx) {
}
#endif

JS_SetNativeStackQuota(cx, gMaxStackSize);
JS_SetNativeStackQuota(cx, gWorkerStackSize);
}

[[nodiscard]] static bool PrintUnhandledRejection(
Expand Down Expand Up @@ -12489,8 +12481,6 @@ int main(int argc, char** argv) {
JS::SetPromiseRejectionTrackerCallback(
cx, ForwardingPromiseRejectionTrackerCallback);

JS_SetNativeStackQuota(cx, gMaxStackSize);

JS::dbg::SetDebuggerMallocSizeOf(cx, moz_malloc_size_of);

js::UseInternalJobQueues(cx);
Expand Down

0 comments on commit 9f2ed79

Please sign in to comment.