[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: Hannes Payer <hpayer@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53727}
This commit is contained in:
Peter Marshall 2018-06-14 10:03:34 +02:00 committed by Commit Bot
parent 83864aa236
commit 919114211c
3 changed files with 10 additions and 12 deletions

View File

@ -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();
}

View File

@ -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

View File

@ -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) {