diff options
Diffstat (limited to 'deps/v8/src/heap/array-buffer-collector.cc')
-rw-r--r-- | deps/v8/src/heap/array-buffer-collector.cc | 64 |
1 files changed, 34 insertions, 30 deletions
diff --git a/deps/v8/src/heap/array-buffer-collector.cc b/deps/v8/src/heap/array-buffer-collector.cc index 2c28f46a85..0cf4ae945d 100644 --- a/deps/v8/src/heap/array-buffer-collector.cc +++ b/deps/v8/src/heap/array-buffer-collector.cc @@ -12,50 +12,54 @@ namespace v8 { namespace internal { -void ArrayBufferCollector::AddGarbageAllocations( +namespace { + +void FreeAllocationsHelper( + Heap* heap, const std::vector<JSArrayBuffer::Allocation>& allocations) { + for (JSArrayBuffer::Allocation alloc : allocations) { + JSArrayBuffer::FreeBackingStore(heap->isolate(), alloc); + } +} + +} // namespace + +void ArrayBufferCollector::QueueOrFreeGarbageAllocations( std::vector<JSArrayBuffer::Allocation> allocations) { - base::LockGuard<base::Mutex> guard(&allocations_mutex_); - allocations_.push_back(std::move(allocations)); + if (heap_->ShouldReduceMemory()) { + FreeAllocationsHelper(heap_, allocations); + } else { + base::LockGuard<base::Mutex> guard(&allocations_mutex_); + allocations_.push_back(std::move(allocations)); + } } -void ArrayBufferCollector::FreeAllocations() { +void ArrayBufferCollector::PerformFreeAllocations() { base::LockGuard<base::Mutex> guard(&allocations_mutex_); for (const std::vector<JSArrayBuffer::Allocation>& allocations : allocations_) { - for (JSArrayBuffer::Allocation alloc : allocations) { - JSArrayBuffer::FreeBackingStore(heap_->isolate(), alloc); - } + FreeAllocationsHelper(heap_, allocations); } allocations_.clear(); } -class ArrayBufferCollector::FreeingTask final : public CancelableTask { - public: - explicit FreeingTask(Heap* heap) - : CancelableTask(heap->isolate()), heap_(heap) {} - - virtual ~FreeingTask() {} - - private: - void RunInternal() final { - TRACE_BACKGROUND_GC( - heap_->tracer(), - GCTracer::BackgroundScope::BACKGROUND_ARRAY_BUFFER_FREE); - heap_->array_buffer_collector()->FreeAllocations(); - } - - Heap* heap_; -}; - -void ArrayBufferCollector::FreeAllocationsOnBackgroundThread() { +void ArrayBufferCollector::FreeAllocations() { // TODO(wez): Remove backing-store from external memory accounting. heap_->account_external_memory_concurrently_freed(); - if (!heap_->IsTearingDown() && FLAG_concurrent_array_buffer_freeing) { + if (!heap_->IsTearingDown() && !heap_->ShouldReduceMemory() && + FLAG_concurrent_array_buffer_freeing) { V8::GetCurrentPlatform()->CallOnWorkerThread( - base::make_unique<FreeingTask>(heap_)); + MakeCancelableLambdaTask(heap_->isolate(), [this] { + TRACE_BACKGROUND_GC( + heap_->tracer(), + GCTracer::BackgroundScope::BACKGROUND_ARRAY_BUFFER_FREE); + PerformFreeAllocations(); + })); } else { - // Fallback for when concurrency is disabled/restricted. - FreeAllocations(); + // Fallback for when concurrency is disabled/restricted. This is e.g. the + // case when the GC should reduce memory. For such GCs the + // QueueOrFreeGarbageAllocations() call would immediately free the + // allocations and this call would free already queued ones. + PerformFreeAllocations(); } } |