diff --git a/src/heap/array-buffer-tracker-inl.h b/src/heap/array-buffer-tracker-inl.h index 7bfdca351f..697d4405d8 100644 --- a/src/heap/array-buffer-tracker-inl.h +++ b/src/heap/array-buffer-tracker-inl.h @@ -65,9 +65,7 @@ void LocalArrayBufferTracker::Free(Callback should_free) { const size_t length = it->second.length; if (should_free(buffer)) { - JSArrayBuffer::FreeBackingStore( - isolate, {it->second.backing_store, length, it->second.backing_store, - buffer->is_wasm_memory()}); + JSArrayBuffer::FreeBackingStore(isolate, it->second); it = array_buffers_.erase(it); freed_memory += length; } else { @@ -101,7 +99,10 @@ void LocalArrayBufferTracker::Add(JSArrayBuffer* buffer, size_t length) { page_->IncrementExternalBackingStoreBytes( ExternalBackingStoreType::kArrayBuffer, length); - auto ret = array_buffers_.insert({buffer, {buffer->backing_store(), length}}); + auto ret = array_buffers_.insert( + {buffer, + {buffer->backing_store(), length, buffer->backing_store(), + buffer->is_wasm_memory()}}); USE(ret); // Check that we indeed inserted a new value and did not overwrite an existing // one (which would be a bug). diff --git a/src/heap/array-buffer-tracker.cc b/src/heap/array-buffer-tracker.cc index f2dc085b92..4f92e7e17c 100644 --- a/src/heap/array-buffer-tracker.cc +++ b/src/heap/array-buffer-tracker.cc @@ -29,7 +29,7 @@ void LocalArrayBufferTracker::Process(Callback callback) { size_t moved_memory = 0; for (TrackingData::iterator it = array_buffers_.begin(); it != array_buffers_.end(); ++it) { - old_buffer = reinterpret_cast(it->first); + old_buffer = it->first; Page* old_page = Page::FromAddress(old_buffer->address()); const CallbackResult result = callback(old_buffer, &new_buffer); if (result == kKeepEntry) { @@ -48,6 +48,7 @@ void LocalArrayBufferTracker::Process(Callback callback) { const size_t size = NumberToSize(new_buffer->byte_length()); // We should decrement before adding to avoid potential overflows in // the external memory counters. + DCHECK_EQ(it->first->is_wasm_memory(), it->second.is_wasm_memory); old_page->DecrementExternalBackingStoreBytes( ExternalBackingStoreType::kArrayBuffer, it->second.length); tracker->Add(new_buffer, size); @@ -59,12 +60,9 @@ void LocalArrayBufferTracker::Process(Callback callback) { // We pass backing_store() and stored length to the collector for freeing // the backing store. Wasm allocations will go through their own tracker // based on the backing store. - backing_stores_to_free.emplace_back( - it->second.backing_store, it->second.length, it->second.backing_store, - old_buffer->is_wasm_memory()); + backing_stores_to_free.push_back(it->second); old_page->DecrementExternalBackingStoreBytes( ExternalBackingStoreType::kArrayBuffer, it->second.length); - } else { UNREACHABLE(); } diff --git a/src/heap/array-buffer-tracker.h b/src/heap/array-buffer-tracker.h index 40de8d962b..347260dde0 100644 --- a/src/heap/array-buffer-tracker.h +++ b/src/heap/array-buffer-tracker.h @@ -10,11 +10,11 @@ #include "src/allocation.h" #include "src/base/platform/mutex.h" #include "src/globals.h" +#include "src/objects/js-array.h" namespace v8 { namespace internal { -class JSArrayBuffer; class MarkingState; class Page; class Space; @@ -105,17 +105,12 @@ class LocalArrayBufferTracker { } }; - struct BackingStoreAndLength { - void* backing_store; - size_t length; - }; - // Keep track of the backing store and the corresponding length at time of // registering. The length is accessed from JavaScript and can be a // HeapNumber. The reason for tracking the length is that in the case of // length being a HeapNumber, the buffer and its length may be stored on // different memory pages, making it impossible to guarantee order of freeing. - typedef std::unordered_map + typedef std::unordered_map TrackingData; inline Space* space(); diff --git a/src/objects/js-array.h b/src/objects/js-array.h index 34b4f1f523..28cfe71f5d 100644 --- a/src/objects/js-array.h +++ b/src/objects/js-array.h @@ -174,8 +174,6 @@ class JSArrayBuffer : public JSObject { void Neuter(); struct Allocation { - using AllocationMode = ArrayBuffer::Allocator::AllocationMode; - Allocation(void* allocation_base, size_t length, void* backing_store, bool is_wasm_memory) : allocation_base(allocation_base),