LCOV - code coverage report
Current view: top level - src/zone - accounting-allocator.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 12 12 100.0 %
Date: 2019-03-21 Functions: 3 3 100.0 %

          Line data    Source code
       1             : // Copyright 2016 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/zone/accounting-allocator.h"
       6             : 
       7             : #include "src/allocation.h"
       8             : #include "src/base/logging.h"
       9             : #include "src/zone/zone-segment.h"
      10             : 
      11             : namespace v8 {
      12             : namespace internal {
      13             : 
      14             : AccountingAllocator::~AccountingAllocator() = default;
      15             : 
      16    56995641 : Segment* AccountingAllocator::AllocateSegment(size_t bytes) {
      17    56995641 :   void* memory = AllocWithRetry(bytes);
      18    57037555 :   if (memory == nullptr) return nullptr;
      19             : 
      20             :   size_t current =
      21             :       current_memory_usage_.fetch_add(bytes, std::memory_order_relaxed);
      22    57039456 :   size_t max = max_memory_usage_.load(std::memory_order_relaxed);
      23    57795752 :   while (current > max && !max_memory_usage_.compare_exchange_weak(
      24             :                               max, current, std::memory_order_relaxed)) {
      25             :     // {max} was updated by {compare_exchange_weak}; retry.
      26             :   }
      27             :   DCHECK_LE(sizeof(Segment), bytes);
      28    57039456 :   return new (memory) Segment(bytes);
      29             : }
      30             : 
      31    56994783 : void AccountingAllocator::ReturnSegment(Segment* segment) {
      32    56994783 :   segment->ZapContents();
      33             :   current_memory_usage_.fetch_sub(segment->total_size(),
      34             :                                   std::memory_order_relaxed);
      35    56995363 :   segment->ZapHeader();
      36    57013984 :   free(segment);
      37    57013984 : }
      38             : 
      39             : }  // namespace internal
      40      120216 : }  // namespace v8

Generated by: LCOV version 1.10