Commit 721ae440 authored by Thibaud Michaud's avatar Thibaud Michaud Committed by V8 LUCI CQ

[wasm] Fix stack-switching JS limit offset

Add the missing KB multiplier. Also add a flag to set the fixed stack
size.

R=clemensb@chromium.org

Bug: v8:12191
Change-Id: I9782192d2eef1986286f726a05444a4bec49fc66
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3875902Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Commit-Queue: Thibaud Michaud <thibaudm@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83065}
parent 924cf85e
......@@ -1026,6 +1026,8 @@ DEFINE_DEBUG_BOOL(trace_wasm_streaming, false,
"trace streaming compilation of wasm code")
DEFINE_DEBUG_BOOL(trace_wasm_stack_switching, false,
"trace wasm stack switching")
DEFINE_INT(wasm_stack_switching_stack_size, V8_DEFAULT_STACK_SIZE_KB,
"default size of stacks for wasm stack-switching (in kB)")
DEFINE_BOOL(liftoff, true,
"enable Liftoff, the baseline compiler for WebAssembly")
DEFINE_BOOL(liftoff_only, false,
......
......@@ -37,7 +37,7 @@ StackMemory::StackMemory(Isolate* isolate) : isolate_(isolate), owned_(true) {
static std::atomic<int> next_id(1);
id_ = next_id.fetch_add(1);
PageAllocator* allocator = GetPlatformPageAllocator();
int kJsStackSizeKB = 4;
int kJsStackSizeKB = v8_flags.wasm_stack_switching_stack_size;
size_ = (kJsStackSizeKB + kJSLimitOffsetKB) * KB;
size_ = RoundUp(size_, allocator->AllocatePageSize());
limit_ = static_cast<byte*>(
......
......@@ -38,7 +38,7 @@ class StackMemory {
static StackMemory* GetCurrentStackView(Isolate* isolate);
~StackMemory();
void* jslimit() const { return limit_ + kJSLimitOffsetKB; }
void* jslimit() const { return limit_ + kJSLimitOffsetKB * KB; }
Address base() const { return reinterpret_cast<Address>(limit_ + size_); }
JumpBuffer* jmpbuf() { return &jmpbuf_; }
int id() { return id_; }
......
......@@ -4,6 +4,10 @@
// Flags: --allow-natives-syntax --experimental-wasm-stack-switching
// Flags: --experimental-wasm-type-reflection --expose-gc
// Flags: --wasm-stack-switching-stack-size=100
// We pick a small stack size to run the stack overflow test quickly, but big
// enough to run all the tests.
load("test/mjsunit/wasm/wasm-module-builder.js");
......@@ -478,3 +482,16 @@ function TestNestedSuspenders(suspend) {
assertEquals([], export_sig.parameters);
assertEquals(['externref'], export_sig.results);
})();
(function TestStackOverflow() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
builder.addFunction("test", kSig_i_r)
.addBody([
kExprLocalGet, 0,
kExprCallFunction, 0
]).exportFunc();
let instance = builder.instantiate();
let wrapper = ToPromising(instance.exports.test);
assertThrows(wrapper, RangeError, /Maximum call stack size exceeded/);
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment