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) { ...@@ -1853,8 +1853,7 @@ void WasmContinuationObject::WasmContinuationObjectPrint(std::ostream& os) {
PrintHeader(os, "WasmContinuationObject"); PrintHeader(os, "WasmContinuationObject");
os << "\n - parent: " << parent(); os << "\n - parent: " << parent();
os << "\n - jmpbuf: " << jmpbuf(); os << "\n - jmpbuf: " << jmpbuf();
os << "\n - managed_stack: " << managed_stack(); os << "\n - stack: " << stack();
os << "\n - managed_jmpbuf: " << managed_jmpbuf();
os << "\n"; os << "\n";
} }
......
...@@ -706,9 +706,8 @@ void SyncStackLimit(Isolate* isolate) { ...@@ -706,9 +706,8 @@ void SyncStackLimit(Isolate* isolate) {
DisallowGarbageCollection no_gc; DisallowGarbageCollection no_gc;
auto continuation = WasmContinuationObject::cast( auto continuation = WasmContinuationObject::cast(
*isolate->roots_table().slot(RootIndex::kActiveContinuation)); *isolate->roots_table().slot(RootIndex::kActiveContinuation));
auto jmpbuf = auto stack = Managed<wasm::StackMemory>::cast(continuation.stack()).get();
Managed<wasm::JumpBuffer>::cast(continuation.managed_jmpbuf()).get(); uintptr_t limit = reinterpret_cast<uintptr_t>(stack->jmpbuf()->stack_limit);
uintptr_t limit = reinterpret_cast<uintptr_t>(jmpbuf->stack_limit);
isolate->stack_guard()->SetStackLimit(limit); isolate->stack_guard()->SetStackLimit(limit);
} }
} // namespace } // namespace
......
...@@ -45,6 +45,7 @@ class StackMemory { ...@@ -45,6 +45,7 @@ class StackMemory {
void* jslimit() { return limit_ + kJSLimitOffsetKB; } void* jslimit() { return limit_ + kJSLimitOffsetKB; }
void* base() { return limit_ + size_; } void* base() { return limit_ + size_; }
JumpBuffer* jmpbuf() { return &jmpbuf_; }
// Track external memory usage for Managed<StackMemory> objects. // Track external memory usage for Managed<StackMemory> objects.
size_t owned_size() { return sizeof(StackMemory) + (owned_ ? size_ : 0); } size_t owned_size() { return sizeof(StackMemory) + (owned_ ? size_ : 0); }
...@@ -68,6 +69,7 @@ class StackMemory { ...@@ -68,6 +69,7 @@ class StackMemory {
byte* limit_; byte* limit_;
size_t size_; size_t size_;
bool owned_; bool owned_;
JumpBuffer jmpbuf_;
}; };
} // namespace wasm } // namespace wasm
......
...@@ -1747,18 +1747,14 @@ Handle<WasmContinuationObject> WasmContinuationObject::New( ...@@ -1747,18 +1747,14 @@ Handle<WasmContinuationObject> WasmContinuationObject::New(
HeapObject parent) { HeapObject parent) {
Handle<WasmContinuationObject> result = Handle<WasmContinuationObject>::cast( Handle<WasmContinuationObject> result = Handle<WasmContinuationObject>::cast(
isolate->factory()->NewStruct(WASM_CONTINUATION_OBJECT_TYPE)); isolate->factory()->NewStruct(WASM_CONTINUATION_OBJECT_TYPE));
auto jmpbuf = std::make_unique<wasm::JumpBuffer>(); stack->jmpbuf()->stack_limit = stack->jslimit();
jmpbuf->stack_limit = stack->jslimit(); stack->jmpbuf()->sp = stack->base();
jmpbuf->sp = stack->base(); result->set_jmpbuf(*isolate->factory()->NewForeign(
result->set_jmpbuf( reinterpret_cast<Address>(stack->jmpbuf())));
*isolate->factory()->NewForeign(reinterpret_cast<Address>(jmpbuf.get())));
size_t external_size = stack->owned_size(); size_t external_size = stack->owned_size();
Handle<Foreign> managed_stack = Managed<wasm::StackMemory>::FromUniquePtr( Handle<Foreign> managed_stack = Managed<wasm::StackMemory>::FromUniquePtr(
isolate, external_size, std::move(stack)); isolate, external_size, std::move(stack));
Handle<Foreign> managed_jmpbuf = Managed<wasm::JumpBuffer>::FromUniquePtr( result->set_stack(*managed_stack);
isolate, sizeof(wasm::JumpBuffer), std::move(jmpbuf));
result->set_managed_stack(*managed_stack);
result->set_managed_jmpbuf(*managed_jmpbuf);
result->set_parent(parent); result->set_parent(parent);
return result; return result;
} }
......
...@@ -90,9 +90,8 @@ extern class WasmIndirectFunctionTable extends Struct { ...@@ -90,9 +90,8 @@ extern class WasmIndirectFunctionTable extends Struct {
} }
extern class WasmContinuationObject extends Struct { extern class WasmContinuationObject extends Struct {
managed_stack: Foreign; stack: Foreign;
managed_jmpbuf: Foreign; jmpbuf: Foreign; // Direct access to the stack's jump buffer.
jmpbuf: Foreign; // Direct access to managed_jmpbuf's underlying pointer.
parent: WasmContinuationObject|Undefined; 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