Skip to content

Commit

Permalink
Reland "[wasm] Lazy update instances on a shared Memory.Grow"
Browse files Browse the repository at this point in the history
This is a reland of 80f06d6

Original change's description:
> [wasm] Lazy update instances on a shared Memory.Grow
> 
>  - Introduce a GROW_SHARED_MEMORY interrupt, and handler
>  - Memory objects for isolates are updated on a stack check, add
>    tracking for isolates that hit the stack check
>  - When enough memory is not reserved ahead of time, fail to grow
>  - Add tracking for externalized buffers in the MemoryTracker so
>    that the MemoryTracker will know when backing_stores can be freed.
>  - For shared buffer, do not always allocate a new buffer when
>    growing an externalized buffer
> 
> 
> Change-Id: I9cf1be19f2f165fa6ea4096869f7d6365304c8c4
> Bug: v8:8564
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1472430
> Commit-Queue: Deepti Gandluri <[email protected]>
> Reviewed-by: Ben Smith <[email protected]>
> Reviewed-by: Andreas Haas <[email protected]>
> Cr-Commit-Position: refs/heads/master@{#60064}

Bug: v8:8564
Change-Id: Id0cf8e42a9d54ac702dba351e248a1b92713c98a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1506357
Reviewed-by: Bill Budge <[email protected]>
Commit-Queue: Deepti Gandluri <[email protected]>
Cr-Commit-Position: refs/heads/master@{#60071}
  • Loading branch information
dtig authored and Commit Bot committed Mar 6, 2019
1 parent b22e6cf commit 365b637
Show file tree
Hide file tree
Showing 11 changed files with 873 additions and 77 deletions.
6 changes: 6 additions & 0 deletions src/execution.cc
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,12 @@ Object StackGuard::HandleInterrupts() {
isolate_->heap()->HandleGCRequest();
}

if (CheckAndClearInterrupt(GROW_SHARED_MEMORY)) {
TRACE_INTERRUPT("GROW_SHARED_MEMORY");
isolate_->wasm_engine()->memory_tracker()->UpdateSharedMemoryInstances(
isolate_);
}

if (CheckAndClearInterrupt(TERMINATE_EXECUTION)) {
TRACE_INTERRUPT("TERMINATE_EXECUTION");
return isolate_->TerminateExecution();
Expand Down
13 changes: 7 additions & 6 deletions src/execution.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ class V8_EXPORT_PRIVATE StackGuard final {
// it has been set up.
void ClearThread(const ExecutionAccess& lock);

#define INTERRUPT_LIST(V) \
V(TERMINATE_EXECUTION, TerminateExecution, 0) \
V(GC_REQUEST, GC, 1) \
V(INSTALL_CODE, InstallCode, 2) \
V(API_INTERRUPT, ApiInterrupt, 3) \
V(DEOPT_MARKED_ALLOCATION_SITES, DeoptMarkedAllocationSites, 4)
#define INTERRUPT_LIST(V) \
V(TERMINATE_EXECUTION, TerminateExecution, 0) \
V(GC_REQUEST, GC, 1) \
V(INSTALL_CODE, InstallCode, 2) \
V(API_INTERRUPT, ApiInterrupt, 3) \
V(DEOPT_MARKED_ALLOCATION_SITES, DeoptMarkedAllocationSites, 4) \
V(GROW_SHARED_MEMORY, GrowSharedMemory, 5)

#define V(NAME, Name, id) \
inline bool Check##Name() { return CheckInterrupt(NAME); } \
Expand Down
2 changes: 2 additions & 0 deletions src/isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2922,6 +2922,8 @@ void Isolate::Deinit() {
optimizing_compile_dispatcher_ = nullptr;
}

wasm_engine()->memory_tracker()->DeleteSharedMemoryObjectsOnIsolate(this);

heap_.mark_compact_collector()->EnsureSweepingCompleted();
heap_.memory_allocator()->unmapper()->EnsureUnmappingCompleted();

Expand Down
6 changes: 1 addition & 5 deletions src/objects/js-array-buffer-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,7 @@ void* JSArrayBuffer::allocation_base() const {
}

bool JSArrayBuffer::is_wasm_memory() const {
bool const is_wasm_memory = IsWasmMemoryBit::decode(bit_field());
DCHECK_EQ(is_wasm_memory,
GetIsolate()->wasm_engine()->memory_tracker()->IsWasmMemory(
backing_store()));
return is_wasm_memory;
return IsWasmMemoryBit::decode(bit_field());
}

void JSArrayBuffer::set_is_wasm_memory(bool is_wasm_memory) {
Expand Down
6 changes: 1 addition & 5 deletions src/objects/js-array-buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,7 @@ void JSArrayBuffer::FreeBackingStore(Isolate* isolate, Allocation allocation) {
if (allocation.is_wasm_memory) {
wasm::WasmMemoryTracker* memory_tracker =
isolate->wasm_engine()->memory_tracker();
if (!memory_tracker->FreeMemoryIfIsWasmMemory(isolate,
allocation.backing_store)) {
CHECK(FreePages(GetPlatformPageAllocator(), allocation.allocation_base,
allocation.length));
}
memory_tracker->FreeMemoryIfIsWasmMemory(isolate, allocation.backing_store);
} else {
isolate->array_buffer_allocator()->Free(allocation.allocation_base,
allocation.length);
Expand Down
6 changes: 6 additions & 0 deletions src/value-serializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,9 @@ Maybe<bool> ValueSerializer::WriteWasmMemory(Handle<WasmMemoryObject> object) {
return Nothing<bool>();
}

isolate_->wasm_engine()->memory_tracker()->RegisterWasmMemoryAsShared(
object, isolate_);

WriteTag(SerializationTag::kWasmMemoryTransfer);
WriteZigZag<int32_t>(object->maximum_pages());
return WriteJSReceiver(Handle<JSReceiver>(object->array_buffer(), isolate_));
Expand Down Expand Up @@ -1866,6 +1869,9 @@ MaybeHandle<WasmMemoryObject> ValueDeserializer::ReadWasmMemory() {
Handle<WasmMemoryObject> result =
WasmMemoryObject::New(isolate_, buffer, maximum_pages);

isolate_->wasm_engine()->memory_tracker()->RegisterWasmMemoryAsShared(
result, isolate_);

AddObjectWithID(id, result);
return result;
}
Expand Down
Loading

0 comments on commit 365b637

Please sign in to comment.