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

[cleanup] Make ownership in the ArrayBufferCollector clearer

The allocations vector does not need to be dynamically allocated, we can
just std::move it around instead.

Change-Id: If38af59deeccc06005397f255e18a2fa1bdf4298
Reviewed-on: https://chromium-review.googlesource.com/1099063
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: 's avatarHannes Payer <hpayer@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53727}
parent 83864aa2
......@@ -12,18 +12,18 @@ namespace v8 {
namespace internal {
void ArrayBufferCollector::AddGarbageAllocations(
std::vector<JSArrayBuffer::Allocation>* allocations) {
std::vector<JSArrayBuffer::Allocation> allocations) {
base::LockGuard<base::Mutex> guard(&allocations_mutex_);
allocations_.push_back(allocations);
allocations_.push_back(std::move(allocations));
}
void ArrayBufferCollector::FreeAllocations() {
base::LockGuard<base::Mutex> guard(&allocations_mutex_);
for (std::vector<JSArrayBuffer::Allocation>* allocations : allocations_) {
for (auto alloc : *allocations) {
for (const std::vector<JSArrayBuffer::Allocation>& allocations :
allocations_) {
for (JSArrayBuffer::Allocation alloc : allocations) {
JSArrayBuffer::FreeBackingStore(heap_->isolate(), alloc);
}
delete allocations;
}
allocations_.clear();
}
......
......@@ -28,7 +28,7 @@ class ArrayBufferCollector {
// These allocations will begin to be freed once FreeAllocations() is called,
// or on TearDown.
void AddGarbageAllocations(
std::vector<JSArrayBuffer::Allocation>* allocations);
std::vector<JSArrayBuffer::Allocation> allocations);
// Calls FreeAllocations() on a background thread.
void FreeAllocationsOnBackgroundThread();
......@@ -42,7 +42,7 @@ class ArrayBufferCollector {
Heap* heap_;
base::Mutex allocations_mutex_;
std::vector<std::vector<JSArrayBuffer::Allocation>*> allocations_;
std::vector<std::vector<JSArrayBuffer::Allocation>> allocations_;
};
} // namespace internal
......
......@@ -20,8 +20,7 @@ LocalArrayBufferTracker::~LocalArrayBufferTracker() {
template <typename Callback>
void LocalArrayBufferTracker::Process(Callback callback) {
std::vector<JSArrayBuffer::Allocation>* backing_stores_to_free =
new std::vector<JSArrayBuffer::Allocation>();
std::vector<JSArrayBuffer::Allocation> backing_stores_to_free;
JSArrayBuffer* new_buffer = nullptr;
JSArrayBuffer* old_buffer = nullptr;
......@@ -54,7 +53,7 @@ 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(
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);
......@@ -73,9 +72,8 @@ void LocalArrayBufferTracker::Process(Callback callback) {
// Pass the backing stores that need to be freed to the main thread for later
// distribution.
// ArrayBufferCollector takes ownership of this pointer.
space_->heap()->array_buffer_collector()->AddGarbageAllocations(
backing_stores_to_free);
std::move(backing_stores_to_free));
}
void ArrayBufferTracker::PrepareToFreeDeadInNewSpace(Heap* heap) {
......
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