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

Side by Side Diff: src/zone.h

Issue 18635003: Reintroduce runtime zone to Isolate. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « src/runtime.cc ('k') | src/zone.cc » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 public: 59 public:
60 explicit Zone(Isolate* isolate); 60 explicit Zone(Isolate* isolate);
61 ~Zone(); 61 ~Zone();
62 // Allocate 'size' bytes of memory in the Zone; expands the Zone by 62 // Allocate 'size' bytes of memory in the Zone; expands the Zone by
63 // allocating new segments of memory on demand using malloc(). 63 // allocating new segments of memory on demand using malloc().
64 inline void* New(int size); 64 inline void* New(int size);
65 65
66 template <typename T> 66 template <typename T>
67 inline T* NewArray(int length); 67 inline T* NewArray(int length);
68 68
69 // Deletes all objects and free all memory allocated in the Zone. Keeps one
70 // small (size <= kMaximumKeptSegmentSize) segment around if it finds one.
71 void DeleteAll();
72
73 // Deletes the last small segment kept around by DeleteAll(). You
74 // may no longer allocate in the Zone after a call to this method.
75 void DeleteKeptSegment();
76
69 // Returns true if more memory has been allocated in zones than 77 // Returns true if more memory has been allocated in zones than
70 // the limit allows. 78 // the limit allows.
71 inline bool excess_allocation(); 79 inline bool excess_allocation();
72 80
73 inline void adjust_segment_bytes_allocated(int delta); 81 inline void adjust_segment_bytes_allocated(int delta);
74 82
75 inline unsigned allocation_size() { return allocation_size_; } 83 inline unsigned allocation_size() { return allocation_size_; }
76 84
77 inline Isolate* isolate() { return isolate_; } 85 inline Isolate* isolate() { return isolate_; }
78 86
79 private: 87 private:
80 friend class Isolate; 88 friend class Isolate;
81 89
82 // All pointers returned from New() have this alignment. In addition, if the 90 // All pointers returned from New() have this alignment. In addition, if the
83 // object being allocated has a size that is divisible by 8 then its alignment 91 // object being allocated has a size that is divisible by 8 then its alignment
84 // will be 8. 92 // will be 8.
85 static const int kAlignment = kPointerSize; 93 static const int kAlignment = kPointerSize;
86 94
87 // Never allocate segments smaller than this size in bytes. 95 // Never allocate segments smaller than this size in bytes.
88 static const int kMinimumSegmentSize = 8 * KB; 96 static const int kMinimumSegmentSize = 8 * KB;
89 97
90 // Never allocate segments larger than this size in bytes. 98 // Never allocate segments larger than this size in bytes.
91 static const int kMaximumSegmentSize = 1 * MB; 99 static const int kMaximumSegmentSize = 1 * MB;
92 100
101 // Never keep segments larger than this size in bytes around.
102 static const int kMaximumKeptSegmentSize = 64 * KB;
103
93 // Report zone excess when allocation exceeds this limit. 104 // Report zone excess when allocation exceeds this limit.
94 static const int kExcessLimit = 256 * MB; 105 static const int kExcessLimit = 256 * MB;
95 106
96 // The number of bytes allocated in this zone so far. 107 // The number of bytes allocated in this zone so far.
97 unsigned allocation_size_; 108 unsigned allocation_size_;
98 109
99 // The number of bytes allocated in segments. Note that this number 110 // The number of bytes allocated in segments. Note that this number
100 // includes memory allocated from the OS but not yet allocated from 111 // includes memory allocated from the OS but not yet allocated from
101 // the zone. 112 // the zone.
102 int segment_bytes_allocated_; 113 int segment_bytes_allocated_;
103 114
104 // Expand the Zone to hold at least 'size' more bytes and allocate 115 // Expand the Zone to hold at least 'size' more bytes and allocate
105 // the bytes. Returns the address of the newly allocated chunk of 116 // the bytes. Returns the address of the newly allocated chunk of
106 // memory in the Zone. Should only be called if there isn't enough 117 // memory in the Zone. Should only be called if there isn't enough
107 // room in the Zone already. 118 // room in the Zone already.
108 Address NewExpand(int size); 119 Address NewExpand(int size);
109 120
110 // Creates a new segment, sets it size, and pushes it to the front 121 // Creates a new segment, sets it size, and pushes it to the front
111 // of the segment chain. Returns the new segment. 122 // of the segment chain. Returns the new segment.
112 Segment* NewSegment(int size); 123 INLINE(Segment* NewSegment(int size));
113 124
114 // Deletes the given segment. Does not touch the segment chain. 125 // Deletes the given segment. Does not touch the segment chain.
115 void DeleteSegment(Segment* segment, int size); 126 INLINE(void DeleteSegment(Segment* segment, int size));
116 127
117 // The free region in the current (front) segment is represented as 128 // The free region in the current (front) segment is represented as
118 // the half-open interval [position, limit). The 'position' variable 129 // the half-open interval [position, limit). The 'position' variable
119 // is guaranteed to be aligned as dictated by kAlignment. 130 // is guaranteed to be aligned as dictated by kAlignment.
120 Address position_; 131 Address position_;
121 Address limit_; 132 Address limit_;
122 133
123 Segment* segment_head_; 134 Segment* segment_head_;
124 Isolate* isolate_; 135 Isolate* isolate_;
125 }; 136 };
(...skipping 12 matching lines...) Expand all
138 // require the operator to be visible. MSVC requires the delete 149 // require the operator to be visible. MSVC requires the delete
139 // operator to be public. 150 // operator to be public.
140 151
141 // ZoneObjects should never be deleted individually; use 152 // ZoneObjects should never be deleted individually; use
142 // Zone::DeleteAll() to delete all zone objects in one go. 153 // Zone::DeleteAll() to delete all zone objects in one go.
143 void operator delete(void*, size_t) { UNREACHABLE(); } 154 void operator delete(void*, size_t) { UNREACHABLE(); }
144 void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); } 155 void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); }
145 }; 156 };
146 157
147 158
159 // The ZoneScope is used to automatically call DeleteAll() on a
160 // Zone when the ZoneScope is destroyed (i.e. goes out of scope)
161 struct ZoneScope {
162 public:
163 explicit ZoneScope(Zone* zone) : zone_(zone) { }
164 ~ZoneScope() { zone_->DeleteAll(); }
165
166 Zone* zone() { return zone_; }
167
168 private:
169 Zone* zone_;
170 };
171
172
148 // The ZoneAllocationPolicy is used to specialize generic data 173 // The ZoneAllocationPolicy is used to specialize generic data
149 // structures to allocate themselves and their elements in the Zone. 174 // structures to allocate themselves and their elements in the Zone.
150 struct ZoneAllocationPolicy { 175 struct ZoneAllocationPolicy {
151 public: 176 public:
152 explicit ZoneAllocationPolicy(Zone* zone) : zone_(zone) { } 177 explicit ZoneAllocationPolicy(Zone* zone) : zone_(zone) { }
153 INLINE(void* New(size_t size)); 178 INLINE(void* New(size_t size));
154 INLINE(static void Delete(void *pointer)) { } 179 INLINE(static void Delete(void *pointer)) { }
155 180
156 private: 181 private:
157 Zone* zone_; 182 Zone* zone_;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 : SplayTree<Config, ZoneAllocationPolicy>(ZoneAllocationPolicy(zone)) {} 247 : SplayTree<Config, ZoneAllocationPolicy>(ZoneAllocationPolicy(zone)) {}
223 ~ZoneSplayTree(); 248 ~ZoneSplayTree();
224 }; 249 };
225 250
226 251
227 typedef TemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap; 252 typedef TemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap;
228 253
229 } } // namespace v8::internal 254 } } // namespace v8::internal
230 255
231 #endif // V8_ZONE_H_ 256 #endif // V8_ZONE_H_
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | src/zone.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698