Commit bae176e4 authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

[gc] Only track potentially live buffers in ABT processing step.

For kUpdateEntry and kRemoveEntry, the ArrayBuffer is no longer present
on the current page. These are the two most common cases; kKeepEntry is
only used for aborted old-page evacuation candidates. Currently we pay
the cost of removing the entry from the array_buffers_ map, even though
the page itself will be cleared (for new space) or only aborted
evacuation candidates will be kept on the page (for old space).

Change-Id: Ib442109d444973a72e378d9072206f404d1c5183
Reviewed-on: https://chromium-review.googlesource.com/1102332Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53757}
parent 23b8d2fd
......@@ -21,17 +21,18 @@ LocalArrayBufferTracker::~LocalArrayBufferTracker() {
template <typename Callback>
void LocalArrayBufferTracker::Process(Callback callback) {
std::vector<JSArrayBuffer::Allocation> backing_stores_to_free;
TrackingData kept_array_buffers;
JSArrayBuffer* new_buffer = nullptr;
JSArrayBuffer* old_buffer = nullptr;
size_t freed_memory = 0;
size_t moved_memory = 0;
for (TrackingData::iterator it = array_buffers_.begin();
it != array_buffers_.end();) {
it != array_buffers_.end(); ++it) {
old_buffer = reinterpret_cast<JSArrayBuffer*>(it->first);
const CallbackResult result = callback(old_buffer, &new_buffer);
if (result == kKeepEntry) {
++it;
kept_array_buffers.insert(*it);
} else if (result == kUpdateEntry) {
DCHECK_NOT_NULL(new_buffer);
Page* target_page = Page::FromAddress(new_buffer->address());
......@@ -47,7 +48,6 @@ void LocalArrayBufferTracker::Process(Callback callback) {
tracker->Add(new_buffer, size);
}
moved_memory += it->second;
it = array_buffers_.erase(it);
} else if (result == kRemoveEntry) {
freed_memory += it->second;
// We pass backing_store() and stored length to the collector for freeing
......@@ -56,7 +56,6 @@ void LocalArrayBufferTracker::Process(Callback callback) {
backing_stores_to_free.emplace_back(
old_buffer->backing_store(), it->second, old_buffer->backing_store(),
old_buffer->allocation_mode(), old_buffer->is_wasm_memory());
it = array_buffers_.erase(it);
} else {
UNREACHABLE();
}
......@@ -70,6 +69,8 @@ void LocalArrayBufferTracker::Process(Callback callback) {
static_cast<intptr_t>(freed_memory));
}
array_buffers_.swap(kept_array_buffers);
// Pass the backing stores that need to be freed to the main thread for later
// distribution.
space_->heap()->array_buffer_collector()->AddGarbageAllocations(
......
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