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

[wasm] Move JumpBuffer inside StackMemory

The stack memory will be accessed through a global list later, so the
stack pointer should be accessible without the containing
WasmContinuationObject. This also saves some unnecessary allocations and
indirections already.

R=ahaas@chromium.org

Bug: v8:12191
Change-Id: Ic3d71ecadbb13b18f0440049527ba71d657589b4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3312486
Commit-Queue: Thibaud Michaud <thibaudm@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78215}
parent 35563db2
......@@ -1853,8 +1853,7 @@ void WasmContinuationObject::WasmContinuationObjectPrint(std::ostream& os) {
PrintHeader(os, "WasmContinuationObject");
os << "\n - parent: " << parent();
os << "\n - jmpbuf: " << jmpbuf();
os << "\n - managed_stack: " << managed_stack();
os << "\n - managed_jmpbuf: " << managed_jmpbuf();
os << "\n - stack: " << stack();
os << "\n";
}
......
......@@ -706,9 +706,8 @@ void SyncStackLimit(Isolate* isolate) {
DisallowGarbageCollection no_gc;
auto continuation = WasmContinuationObject::cast(
*isolate->roots_table().slot(RootIndex::kActiveContinuation));
auto jmpbuf =
Managed<wasm::JumpBuffer>::cast(continuation.managed_jmpbuf()).get();
uintptr_t limit = reinterpret_cast<uintptr_t>(jmpbuf->stack_limit);
auto stack = Managed<wasm::StackMemory>::cast(continuation.stack()).get();
uintptr_t limit = reinterpret_cast<uintptr_t>(stack->jmpbuf()->stack_limit);
isolate->stack_guard()->SetStackLimit(limit);
}
} // namespace
......
......@@ -45,6 +45,7 @@ class StackMemory {
void* jslimit() { return limit_ + kJSLimitOffsetKB; }
void* base() { return limit_ + size_; }
JumpBuffer* jmpbuf() { return &jmpbuf_; }
// Track external memory usage for Managed<StackMemory> objects.
size_t owned_size() { return sizeof(StackMemory) + (owned_ ? size_ : 0); }
......@@ -68,6 +69,7 @@ class StackMemory {
byte* limit_;
size_t size_;
bool owned_;
JumpBuffer jmpbuf_;
};
} // namespace wasm
......
......@@ -1747,18 +1747,14 @@ Handle<WasmContinuationObject> WasmContinuationObject::New(
HeapObject parent) {
Handle<WasmContinuationObject> result = Handle<WasmContinuationObject>::cast(
isolate->factory()->NewStruct(WASM_CONTINUATION_OBJECT_TYPE));
auto jmpbuf = std::make_unique<wasm::JumpBuffer>();
jmpbuf->stack_limit = stack->jslimit();
jmpbuf->sp = stack->base();
result->set_jmpbuf(
*isolate->factory()->NewForeign(reinterpret_cast<Address>(jmpbuf.get())));
stack->jmpbuf()->stack_limit = stack->jslimit();
stack->jmpbuf()->sp = stack->base();
result->set_jmpbuf(*isolate->factory()->NewForeign(
reinterpret_cast<Address>(stack->jmpbuf())));
size_t external_size = stack->owned_size();
Handle<Foreign> managed_stack = Managed<wasm::StackMemory>::FromUniquePtr(
isolate, external_size, std::move(stack));
Handle<Foreign> managed_jmpbuf = Managed<wasm::JumpBuffer>::FromUniquePtr(
isolate, sizeof(wasm::JumpBuffer), std::move(jmpbuf));
result->set_managed_stack(*managed_stack);
result->set_managed_jmpbuf(*managed_jmpbuf);
result->set_stack(*managed_stack);
result->set_parent(parent);
return result;
}
......
......@@ -90,9 +90,8 @@ extern class WasmIndirectFunctionTable extends Struct {
}
extern class WasmContinuationObject extends Struct {
managed_stack: Foreign;
managed_jmpbuf: Foreign;
jmpbuf: Foreign; // Direct access to managed_jmpbuf's underlying pointer.
stack: Foreign;
jmpbuf: Foreign; // Direct access to the stack's jump buffer.
parent: WasmContinuationObject|Undefined;
}
......
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