LCOV - code coverage report
Current view: top level - src/heap - array-buffer-collector.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 27 27 100.0 %
Date: 2019-04-18 Functions: 6 6 100.0 %

          Line data    Source code
       1             : // Copyright 2017 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #include "src/heap/array-buffer-collector.h"
       6             : 
       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"
      13             : 
      14             : namespace v8 {
      15             : namespace internal {
      16             : 
      17             : namespace {
      18             : 
      19      355922 : void FreeAllocationsHelper(
      20             :     Heap* heap, const std::vector<JSArrayBuffer::Allocation>& allocations) {
      21      612418 :   for (JSArrayBuffer::Allocation alloc : allocations) {
      22      256484 :     JSArrayBuffer::FreeBackingStore(heap->isolate(), alloc);
      23             :   }
      24      355934 : }
      25             : 
      26             : }  // namespace
      27             : 
      28      355857 : void ArrayBufferCollector::QueueOrFreeGarbageAllocations(
      29             :     std::vector<JSArrayBuffer::Allocation> allocations) {
      30      711714 :   if (heap_->ShouldReduceMemory()) {
      31        7448 :     FreeAllocationsHelper(heap_, allocations);
      32             :   } else {
      33      348409 :     base::MutexGuard guard(&allocations_mutex_);
      34      348482 :     allocations_.push_back(std::move(allocations));
      35             :   }
      36      355932 : }
      37             : 
      38      159225 : void ArrayBufferCollector::PerformFreeAllocations() {
      39      159225 :   base::MutexGuard guard(&allocations_mutex_);
      40      507709 :   for (const std::vector<JSArrayBuffer::Allocation>& allocations :
      41             :        allocations_) {
      42      348482 :     FreeAllocationsHelper(heap_, allocations);
      43             :   }
      44      159227 :   allocations_.clear();
      45      159227 : }
      46             : 
      47       97861 : void ArrayBufferCollector::FreeAllocations() {
      48             :   // TODO(wez): Remove backing-store from external memory accounting.
      49       97861 :   heap_->account_external_memory_concurrently_freed();
      50      195722 :   if (!heap_->IsTearingDown() && !heap_->ShouldReduceMemory() &&
      51             :       FLAG_concurrent_array_buffer_freeing) {
      52      181912 :     V8::GetCurrentPlatform()->CallOnWorkerThread(
      53      543612 :         MakeCancelableTask(heap_->isolate(), [this] {
      54      449471 :           TRACE_BACKGROUND_GC(
      55             :               heap_->tracer(),
      56             :               GCTracer::BackgroundScope::BACKGROUND_ARRAY_BUFFER_FREE);
      57       89893 :           PerformFreeAllocations();
      58      271807 :         }));
      59             :   } else {
      60             :     // Fallback for when concurrency is disabled/restricted. This is e.g. the
      61             :     // case when the GC should reduce memory. For such GCs the
      62             :     // QueueOrFreeGarbageAllocations() call would immediately free the
      63             :     // allocations and this call would free already queued ones.
      64        6905 :     PerformFreeAllocations();
      65             :   }
      66       97861 : }
      67             : 
      68             : }  // namespace internal
      69      122036 : }  // namespace v8

Generated by: LCOV version 1.10