Skip to content

Commit

Permalink
Bug 1341326 - Set stack limit and stack size properly for helper thre…
Browse files Browse the repository at this point in the history
…ads, r=jandem.

--HG--
extra : rebase_source : 31566501efe68ba25f88c50813f36d05c3bf2ab3
  • Loading branch information
bhackett1024 committed Feb 22, 2017
1 parent 334243e commit 1938ed4
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
15 changes: 15 additions & 0 deletions js/src/jit-test/tests/basic/bug1341326.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
if (helperThreadCount() == 0)
quit();
function eval(source) {
offThreadCompileModule(source);
}
var N = 10000;
var left = repeat_str('(1&', N);
var right = repeat_str(')', N);
var str = 'actual = '.concat(left, '1', right, ';');
eval(str);
function repeat_str(str, repeat_count) {
var arr = new Array(--repeat_count);
while (repeat_count != 0) arr[--repeat_count] = str;
return str.concat.apply(str, arr);
}
3 changes: 2 additions & 1 deletion js/src/jsapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1546,7 +1546,8 @@ JS_SetNativeStackQuota(JSContext* cx, size_t systemCodeStackSize, size_t trusted
SetNativeStackQuotaAndLimit(cx, JS::StackForTrustedScript, trustedScriptStackSize);
SetNativeStackQuotaAndLimit(cx, JS::StackForUntrustedScript, untrustedScriptStackSize);

cx->initJitStackLimit();
if (cx->isCooperativelyScheduled())
cx->initJitStackLimit();
}

/************************************************************************/
Expand Down
2 changes: 2 additions & 0 deletions js/src/threading/posix/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ js::Thread::Thread(Thread&& aOther)
{
id_ = aOther.id_;
aOther.id_ = Id();
options_ = aOther.options_;
}

js::Thread&
Expand All @@ -86,6 +87,7 @@ js::Thread::operator=(Thread&& aOther)
MOZ_RELEASE_ASSERT(!joinable());
id_ = aOther.id_;
aOther.id_ = Id();
options_ = aOther.options_;
return *this;
}

Expand Down
2 changes: 2 additions & 0 deletions js/src/threading/windows/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ js::Thread::Thread(Thread&& aOther)
{
id_ = aOther.id_;
aOther.id_ = Id();
options_ = aOther.options_;
}

js::Thread&
Expand All @@ -67,6 +68,7 @@ js::Thread::operator=(Thread&& aOther)
MOZ_RELEASE_ASSERT(!joinable());
id_ = aOther.id_;
aOther.id_ = Id();
options_ = aOther.options_;
return *this;
}

Expand Down
13 changes: 3 additions & 10 deletions js/src/vm/HelperThreads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1663,7 +1663,7 @@ JSContext::addPendingOutOfMemory()
}

void
HelperThread::handleParseWorkload(AutoLockHelperThreadState& locked, uintptr_t stackLimit)
HelperThread::handleParseWorkload(AutoLockHelperThreadState& locked)
{
MOZ_ASSERT(HelperThreadState().canStartParseTask(locked));
MOZ_ASSERT(idle());
Expand Down Expand Up @@ -1903,14 +1903,7 @@ HelperThread::threadLoop()
oomUnsafe.crash("HelperThread cx.init()");
}
cx.setHelperThread(this);

// Compute the thread's stack limit, for over-recursed checks.
uintptr_t stackLimit = GetNativeStackBase();
#if JS_STACK_GROWTH_DIRECTION > 0
stackLimit += HELPER_STACK_QUOTA;
#else
stackLimit -= HELPER_STACK_QUOTA;
#endif
JS_SetNativeStackQuota(&cx, HELPER_STACK_QUOTA);

while (true) {
MOZ_ASSERT(idle());
Expand Down Expand Up @@ -1946,7 +1939,7 @@ HelperThread::threadLoop()
handlePromiseTaskWorkload(lock);
} else if (HelperThreadState().canStartParseTask(lock)) {
js::oom::SetThreadType(js::oom::THREAD_TYPE_PARSE);
handleParseWorkload(lock, stackLimit);
handleParseWorkload(lock);
} else if (HelperThreadState().canStartCompressionTask(lock)) {
js::oom::SetThreadType(js::oom::THREAD_TYPE_COMPRESS);
handleCompressionWorkload(lock);
Expand Down
2 changes: 1 addition & 1 deletion js/src/vm/HelperThreads.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ struct HelperThread
void handleWasmWorkload(AutoLockHelperThreadState& locked);
void handlePromiseTaskWorkload(AutoLockHelperThreadState& locked);
void handleIonWorkload(AutoLockHelperThreadState& locked);
void handleParseWorkload(AutoLockHelperThreadState& locked, uintptr_t stackLimit);
void handleParseWorkload(AutoLockHelperThreadState& locked);
void handleCompressionWorkload(AutoLockHelperThreadState& locked);
void handleGCHelperWorkload(AutoLockHelperThreadState& locked);
void handleGCParallelWorkload(AutoLockHelperThreadState& locked);
Expand Down

0 comments on commit 1938ed4

Please sign in to comment.