Commit 423c10d5 authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

[gc] Use Allocation instead of custom struct in the ArrayBufferTracker

We convert this {ptr, size} pair to an ArrayBuffer::Allocation when we
need to free it anyway, so we can get rid of this intermediate step to
make things simpler.

Change-Id: I6e82949ec02acb5794f4d668afb2313ebdcb9d52
Reviewed-on: https://chromium-review.googlesource.com/1136309
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54457}
parent ed8a119f
......@@ -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).
......
......@@ -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<JSArrayBuffer*>(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();
}
......
......@@ -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<JSArrayBuffer*, BackingStoreAndLength, Hasher>
typedef std::unordered_map<JSArrayBuffer*, JSArrayBuffer::Allocation, Hasher>
TrackingData;
inline Space* space();
......
......@@ -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),
......
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