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

Side by Side Diff: src/zone/zone.h

Issue 2397573007: Added zone tracing (Closed)
Patch Set: Reaction to comments Created 4 years, 2 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 #ifndef V8_ZONE_ZONE_H_ 5 #ifndef V8_ZONE_ZONE_H_
6 #define V8_ZONE_ZONE_H_ 6 #define V8_ZONE_ZONE_H_
7 7
8 #include <limits> 8 #include <limits>
9 9
10 #include "src/base/hashmap.h" 10 #include "src/base/hashmap.h"
(...skipping 13 matching lines...) Expand all
24 // the abstract syntax tree, which is deallocated after compilation. 24 // the abstract syntax tree, which is deallocated after compilation.
25 // 25 //
26 // Note: There is no need to initialize the Zone; the first time an 26 // Note: There is no need to initialize the Zone; the first time an
27 // allocation is attempted, a segment of memory will be requested 27 // allocation is attempted, a segment of memory will be requested
28 // through the allocator. 28 // through the allocator.
29 // 29 //
30 // Note: The implementation is inherently not thread safe. Do not use 30 // Note: The implementation is inherently not thread safe. Do not use
31 // from multi-threaded code. 31 // from multi-threaded code.
32 class V8_EXPORT_PRIVATE Zone final { 32 class V8_EXPORT_PRIVATE Zone final {
33 public: 33 public:
34 explicit Zone(AccountingAllocator* allocator); 34 explicit Zone(AccountingAllocator* allocator, const char* name = "unnamed");
35 ~Zone(); 35 ~Zone();
36 36
37 // Allocate 'size' bytes of memory in the Zone; expands the Zone by 37 // Allocate 'size' bytes of memory in the Zone; expands the Zone by
38 // allocating new segments of memory on demand using malloc(). 38 // allocating new segments of memory on demand using malloc().
39 void* New(size_t size); 39 void* New(size_t size);
40 40
41 template <typename T> 41 template <typename T>
42 T* NewArray(size_t length) { 42 T* NewArray(size_t length) {
43 DCHECK_LT(length, std::numeric_limits<size_t>::max() / sizeof(T)); 43 DCHECK_LT(length, std::numeric_limits<size_t>::max() / sizeof(T));
44 return static_cast<T*>(New(length * sizeof(T))); 44 return static_cast<T*>(New(length * sizeof(T)));
45 } 45 }
46 46
47 // Returns true if more memory has been allocated in zones than 47 // Returns true if more memory has been allocated in zones than
48 // the limit allows. 48 // the limit allows.
49 bool excess_allocation() const { 49 bool excess_allocation() const {
50 return segment_bytes_allocated_ > kExcessLimit; 50 return segment_bytes_allocated_ > kExcessLimit;
51 } 51 }
52 52
53 const char* name() const { return name_; }
54
53 size_t allocation_size() const { return allocation_size_; } 55 size_t allocation_size() const { return allocation_size_; }
54 56
55 AccountingAllocator* allocator() const { return allocator_; } 57 AccountingAllocator* allocator() const { return allocator_; }
56 58
57 private: 59 private:
58 // All pointers returned from New() have this alignment. In addition, if the 60 // All pointers returned from New() have this alignment. In addition, if the
59 // object being allocated has a size that is divisible by 8 then its alignment 61 // object being allocated has a size that is divisible by 8 then its alignment
60 // will be 8. ASan requires 8-byte alignment. 62 // will be 8. ASan requires 8-byte alignment.
61 #ifdef V8_USE_ADDRESS_SANITIZER 63 #ifdef V8_USE_ADDRESS_SANITIZER
62 static const size_t kAlignment = 8; 64 static const size_t kAlignment = 8;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 99
98 // The free region in the current (front) segment is represented as 100 // The free region in the current (front) segment is represented as
99 // the half-open interval [position, limit). The 'position' variable 101 // the half-open interval [position, limit). The 'position' variable
100 // is guaranteed to be aligned as dictated by kAlignment. 102 // is guaranteed to be aligned as dictated by kAlignment.
101 Address position_; 103 Address position_;
102 Address limit_; 104 Address limit_;
103 105
104 AccountingAllocator* allocator_; 106 AccountingAllocator* allocator_;
105 107
106 Segment* segment_head_; 108 Segment* segment_head_;
109 const char* name_;
107 }; 110 };
108 111
109 // ZoneObject is an abstraction that helps define classes of objects 112 // ZoneObject is an abstraction that helps define classes of objects
110 // allocated in the Zone. Use it as a base class; see ast.h. 113 // allocated in the Zone. Use it as a base class; see ast.h.
111 class ZoneObject { 114 class ZoneObject {
112 public: 115 public:
113 // Allocate a new ZoneObject of 'size' bytes in the Zone. 116 // Allocate a new ZoneObject of 'size' bytes in the Zone.
114 void* operator new(size_t size, Zone* zone) { return zone->New(size); } 117 void* operator new(size_t size, Zone* zone) { return zone->New(size); }
115 118
116 // Ideally, the delete operator should be private instead of 119 // Ideally, the delete operator should be private instead of
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 216
214 typedef base::PointerTemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap; 217 typedef base::PointerTemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap;
215 218
216 typedef base::CustomMatcherTemplateHashMapImpl<ZoneAllocationPolicy> 219 typedef base::CustomMatcherTemplateHashMapImpl<ZoneAllocationPolicy>
217 CustomMatcherZoneHashMap; 220 CustomMatcherZoneHashMap;
218 221
219 } // namespace internal 222 } // namespace internal
220 } // namespace v8 223 } // namespace v8
221 224
222 #endif // V8_ZONE_ZONE_H_ 225 #endif // V8_ZONE_ZONE_H_
OLDNEW
« src/isolate.cc ('K') | « src/zone/accounting-allocator.h ('k') | src/zone/zone.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698