OLD | NEW |
(Empty) | |
| 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 <cstdlib> |
| 8 |
| 9 #if V8_LIBC_BIONIC |
| 10 #include <malloc.h> // NOLINT |
| 11 #endif |
| 12 |
| 13 namespace v8 { |
| 14 namespace internal { |
| 15 |
| 16 Segment* AccountingAllocator::AllocateSegment(size_t bytes) { |
| 17 void* memory = malloc(bytes); |
| 18 if (memory) { |
| 19 base::AtomicWord current = |
| 20 base::NoBarrier_AtomicIncrement(¤t_memory_usage_, bytes); |
| 21 base::AtomicWord max = base::NoBarrier_Load(&max_memory_usage_); |
| 22 while (current > max) { |
| 23 max = base::NoBarrier_CompareAndSwap(&max_memory_usage_, max, current); |
| 24 } |
| 25 } |
| 26 return reinterpret_cast<Segment*>(memory); |
| 27 } |
| 28 |
| 29 void AccountingAllocator::FreeSegment(Segment* memory) { |
| 30 base::NoBarrier_AtomicIncrement( |
| 31 ¤t_memory_usage_, -static_cast<base::AtomicWord>(memory->size())); |
| 32 free(memory); |
| 33 } |
| 34 |
| 35 size_t AccountingAllocator::GetCurrentMemoryUsage() const { |
| 36 return base::NoBarrier_Load(¤t_memory_usage_); |
| 37 } |
| 38 |
| 39 size_t AccountingAllocator::GetMaxMemoryUsage() const { |
| 40 return base::NoBarrier_Load(&max_memory_usage_); |
| 41 } |
| 42 |
| 43 } // namespace internal |
| 44 } // namespace v8 |
OLD | NEW |