OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef RUNTIME_VM_ZONE_H_ | 5 #ifndef RUNTIME_VM_ZONE_H_ |
6 #define RUNTIME_VM_ZONE_H_ | 6 #define RUNTIME_VM_ZONE_H_ |
7 | 7 |
8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
9 #include "vm/allocation.h" | 9 #include "vm/allocation.h" |
10 #include "vm/handles.h" | 10 #include "vm/handles.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 // TODO(zra): Remove these calls and replace them with calls to OS::SCreate | 57 // TODO(zra): Remove these calls and replace them with calls to OS::SCreate |
58 // and OS::VSCreate. | 58 // and OS::VSCreate. |
59 // These calls are deprecated. Do not add further calls to these functions. | 59 // These calls are deprecated. Do not add further calls to these functions. |
60 // instead use OS::SCreate and OS::VSCreate. | 60 // instead use OS::SCreate and OS::VSCreate. |
61 // Make a zone-allocated string based on printf format and args. | 61 // Make a zone-allocated string based on printf format and args. |
62 char* PrintToString(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); | 62 char* PrintToString(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); |
63 char* VPrint(const char* format, va_list args); | 63 char* VPrint(const char* format, va_list args); |
64 | 64 |
65 // Compute the total size of this zone. This includes wasted space that is | 65 // Compute the total size of this zone. This includes wasted space that is |
66 // due to internal fragmentation in the segments. | 66 // due to internal fragmentation in the segments. |
67 intptr_t SizeInBytes() const; | 67 uintptr_t SizeInBytes() const; |
68 | 68 |
69 // Computes the amount of space used in the zone. | 69 // Computes the amount of space used in the zone. |
70 intptr_t CapacityInBytes() const; | 70 uintptr_t CapacityInBytes() const; |
71 | 71 |
72 // Structure for managing handles allocation. | 72 // Structure for managing handles allocation. |
73 VMHandles* handles() { return &handles_; } | 73 VMHandles* handles() { return &handles_; } |
74 | 74 |
75 void VisitObjectPointers(ObjectPointerVisitor* visitor); | 75 void VisitObjectPointers(ObjectPointerVisitor* visitor); |
76 | 76 |
77 Zone* previous() const { return previous_; } | 77 Zone* previous() const { return previous_; } |
78 | 78 |
79 #ifndef PRODUCT | |
80 void PrintJSON(JSONStream* stream) const; | |
81 #endif | |
82 | |
83 private: | 79 private: |
84 Zone(); | 80 Zone(); |
85 ~Zone(); // Delete all memory associated with the zone. | 81 ~Zone(); // Delete all memory associated with the zone. |
86 | 82 |
87 // All pointers returned from AllocateUnsafe() and New() have this alignment. | 83 // All pointers returned from AllocateUnsafe() and New() have this alignment. |
88 static const intptr_t kAlignment = kDoubleSize; | 84 static const intptr_t kAlignment = kDoubleSize; |
89 | 85 |
90 // Default initial chunk size. | 86 // Default initial chunk size. |
91 static const intptr_t kInitialChunkSize = 1 * KB; | 87 static const intptr_t kInitialChunkSize = 1 * KB; |
92 | 88 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 class StackZone : public StackResource { | 169 class StackZone : public StackResource { |
174 public: | 170 public: |
175 // Create an empty zone and set is at the current zone for the Thread. | 171 // Create an empty zone and set is at the current zone for the Thread. |
176 explicit StackZone(Thread* thread); | 172 explicit StackZone(Thread* thread); |
177 | 173 |
178 // Delete all memory associated with the zone. | 174 // Delete all memory associated with the zone. |
179 ~StackZone(); | 175 ~StackZone(); |
180 | 176 |
181 // Compute the total size of this zone. This includes wasted space that is | 177 // Compute the total size of this zone. This includes wasted space that is |
182 // due to internal fragmentation in the segments. | 178 // due to internal fragmentation in the segments. |
183 intptr_t SizeInBytes() const { return zone_.SizeInBytes(); } | 179 uintptr_t SizeInBytes() const { return zone_.SizeInBytes(); } |
184 | 180 |
185 // Computes the used space in the zone. | 181 // Computes the used space in the zone. |
186 intptr_t CapacityInBytes() const { return zone_.CapacityInBytes(); } | 182 intptr_t CapacityInBytes() const { return zone_.CapacityInBytes(); } |
187 | 183 |
188 Zone* GetZone() { return &zone_; } | 184 Zone* GetZone() { return &zone_; } |
189 | 185 |
190 private: | 186 private: |
191 Zone zone_; | 187 Zone zone_; |
192 | 188 |
193 template <typename T> | 189 template <typename T> |
194 friend class GrowableArray; | 190 friend class GrowableArray; |
195 template <typename T> | 191 template <typename T> |
196 friend class ZoneGrowableArray; | 192 friend class ZoneGrowableArray; |
197 | 193 |
198 DISALLOW_IMPLICIT_CONSTRUCTORS(StackZone); | 194 DISALLOW_IMPLICIT_CONSTRUCTORS(StackZone); |
199 }; | 195 }; |
200 | 196 |
201 inline uword Zone::AllocUnsafe(intptr_t size) { | 197 inline uword Zone::AllocUnsafe(intptr_t size) { |
202 ASSERT(size >= 0); | 198 ASSERT(size >= 0); |
203 | |
204 // Round up the requested size to fit the alignment. | 199 // Round up the requested size to fit the alignment. |
205 if (size > (kIntptrMax - kAlignment)) { | 200 if (size > (kIntptrMax - kAlignment)) { |
206 FATAL1("Zone::Alloc: 'size' is too large: size=%" Pd "", size); | 201 FATAL1("Zone::Alloc: 'size' is too large: size=%" Pd "", size); |
207 } | 202 } |
208 size = Utils::RoundUp(size, kAlignment); | 203 size = Utils::RoundUp(size, kAlignment); |
209 | 204 |
210 // Check if the requested size is available without expanding. | 205 // Check if the requested size is available without expanding. |
211 uword result; | 206 uword result; |
212 intptr_t free_size = (limit_ - position_); | 207 intptr_t free_size = (limit_ - position_); |
213 if (free_size >= size) { | 208 if (free_size >= size) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 intptr_t new_len) { | 240 intptr_t new_len) { |
246 CheckLength<ElementType>(new_len); | 241 CheckLength<ElementType>(new_len); |
247 const intptr_t kElementSize = sizeof(ElementType); | 242 const intptr_t kElementSize = sizeof(ElementType); |
248 uword old_end = reinterpret_cast<uword>(old_data) + (old_len * kElementSize); | 243 uword old_end = reinterpret_cast<uword>(old_data) + (old_len * kElementSize); |
249 // Resize existing allocation if nothing was allocated in between... | 244 // Resize existing allocation if nothing was allocated in between... |
250 if (Utils::RoundUp(old_end, kAlignment) == position_) { | 245 if (Utils::RoundUp(old_end, kAlignment) == position_) { |
251 uword new_end = | 246 uword new_end = |
252 reinterpret_cast<uword>(old_data) + (new_len * kElementSize); | 247 reinterpret_cast<uword>(old_data) + (new_len * kElementSize); |
253 // ...and there is sufficient space. | 248 // ...and there is sufficient space. |
254 if (new_end <= limit_) { | 249 if (new_end <= limit_) { |
| 250 ASSERT(new_len >= old_len); |
255 position_ = Utils::RoundUp(new_end, kAlignment); | 251 position_ = Utils::RoundUp(new_end, kAlignment); |
256 return old_data; | 252 return old_data; |
257 } | 253 } |
258 } | 254 } |
259 if (new_len <= old_len) { | 255 if (new_len <= old_len) { |
260 return old_data; | 256 return old_data; |
261 } | 257 } |
262 ElementType* new_data = Alloc<ElementType>(new_len); | 258 ElementType* new_data = Alloc<ElementType>(new_len); |
263 if (old_data != 0) { | 259 if (old_data != 0) { |
264 memmove(reinterpret_cast<void*>(new_data), | 260 memmove(reinterpret_cast<void*>(new_data), |
265 reinterpret_cast<void*>(old_data), old_len * kElementSize); | 261 reinterpret_cast<void*>(old_data), old_len * kElementSize); |
266 } | 262 } |
267 return new_data; | 263 return new_data; |
268 } | 264 } |
269 | 265 |
270 } // namespace dart | 266 } // namespace dart |
271 | 267 |
272 #endif // RUNTIME_VM_ZONE_H_ | 268 #endif // RUNTIME_VM_ZONE_H_ |
OLD | NEW |