Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(429)

Side by Side Diff: src/base/accounting-allocator.cc

Issue 2299753002: Made zone segments aligned in memory and included a pointer to the zone in the header. Larger objec…
Patch Set: Added a zone segment pool for small segments to avoid frequent sys calls Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/base/accounting-allocator.h ('k') | src/base/platform/platform.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/base/accounting-allocator.h" 5 #include "src/base/accounting-allocator.h"
6 6
7 #include <cstdlib> 7 #include <cstdlib>
8 8
9 #if V8_LIBC_BIONIC 9 #if V8_LIBC_BIONIC
10 #include <malloc.h> // NOLINT 10 #include <malloc.h> // NOLINT
11 #endif 11 #endif
12 12
13 namespace v8 { 13 namespace v8 {
14 namespace base { 14 namespace base {
15 15
16 void* AccountingAllocator::Allocate(size_t bytes) { 16 void* AccountingAllocator::Allocate(size_t bytes) {
17 void* memory = malloc(bytes); 17 void* memory = malloc(bytes);
18 if (memory) { 18 if (memory) {
19 AtomicWord current = 19 ChangeCurrentMemoryUsage(bytes);
20 NoBarrier_AtomicIncrement(&current_memory_usage_, bytes);
21 AtomicWord max = NoBarrier_Load(&max_memory_usage_);
22 while (current > max) {
23 max = NoBarrier_CompareAndSwap(&max_memory_usage_, max, current);
24 }
25 } 20 }
26 return memory; 21 return memory;
27 } 22 }
28 23
29 void AccountingAllocator::Free(void* memory, size_t bytes) { 24 void AccountingAllocator::Free(void* memory, size_t bytes) {
30 free(memory); 25 free(memory);
31 NoBarrier_AtomicIncrement(&current_memory_usage_, 26 ChangeCurrentMemoryUsage(-static_cast<int64_t>(bytes));
32 -static_cast<AtomicWord>(bytes)); 27 }
28
29 void AccountingAllocator::ChangeCurrentMemoryUsage(const int64_t bytes) {
30 AtomicWord current = NoBarrier_AtomicIncrement(&current_memory_usage_, bytes);
31 AtomicWord max = NoBarrier_Load(&max_memory_usage_);
32 if (bytes > 0) {
33 while (current > max) {
34 max = NoBarrier_CompareAndSwap(&max_memory_usage_, max, current);
35 }
36 }
33 } 37 }
34 38
35 size_t AccountingAllocator::GetCurrentMemoryUsage() const { 39 size_t AccountingAllocator::GetCurrentMemoryUsage() const {
36 return NoBarrier_Load(&current_memory_usage_); 40 return NoBarrier_Load(&current_memory_usage_);
37 } 41 }
38 42
39 size_t AccountingAllocator::GetMaxMemoryUsage() const { 43 size_t AccountingAllocator::GetMaxMemoryUsage() const {
40 return NoBarrier_Load(&max_memory_usage_); 44 return NoBarrier_Load(&max_memory_usage_);
41 } 45 }
42 46
43 } // namespace base 47 } // namespace base
44 } // namespace v8 48 } // namespace v8
OLDNEW
« no previous file with comments | « src/base/accounting-allocator.h ('k') | src/base/platform/platform.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698