5 #include "src/heap/array-buffer-collector.h" 7 #include "src/base/template-utils.h" 8 #include "src/cancelable-task.h" 9 #include "src/heap/array-buffer-tracker.h" 10 #include "src/heap/gc-tracer.h" 11 #include "src/heap/heap-inl.h" 12 #include "src/task-utils.h" 19 void FreeAllocationsHelper(
20 Heap* heap,
const std::vector<JSArrayBuffer::Allocation>& allocations) {
21 for (JSArrayBuffer::Allocation alloc : allocations) {
22 JSArrayBuffer::FreeBackingStore(heap->isolate(), alloc);
28 void ArrayBufferCollector::QueueOrFreeGarbageAllocations(
29 std::vector<JSArrayBuffer::Allocation> allocations) {
30 if (heap_->ShouldReduceMemory()) {
31 FreeAllocationsHelper(heap_, allocations);
33 base::MutexGuard guard(&allocations_mutex_);
34 allocations_.push_back(std::move(allocations));
38 void ArrayBufferCollector::PerformFreeAllocations() {
39 base::MutexGuard guard(&allocations_mutex_);
40 for (
const std::vector<JSArrayBuffer::Allocation>& allocations :
42 FreeAllocationsHelper(heap_, allocations);
47 void ArrayBufferCollector::FreeAllocations() {
49 heap_->account_external_memory_concurrently_freed();
50 if (!heap_->IsTearingDown() && !heap_->ShouldReduceMemory() &&
51 FLAG_concurrent_array_buffer_freeing) {
52 V8::GetCurrentPlatform()->CallOnWorkerThread(
53 MakeCancelableTask(heap_->isolate(), [
this] {
56 GCTracer::BackgroundScope::BACKGROUND_ARRAY_BUFFER_FREE);
57 PerformFreeAllocations();
64 PerformFreeAllocations();