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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 // Zap value used to indicate uninitialized zone area (debug purposes). | 91 // Zap value used to indicate uninitialized zone area (debug purposes). |
92 static const unsigned char kZapUninitializedByte = 0xab; | 92 static const unsigned char kZapUninitializedByte = 0xab; |
93 | 93 |
94 // Expand the zone to accommodate an allocation of 'size' bytes. | 94 // Expand the zone to accommodate an allocation of 'size' bytes. |
95 uword AllocateExpand(intptr_t size); | 95 uword AllocateExpand(intptr_t size); |
96 | 96 |
97 // Allocate a large segment. | 97 // Allocate a large segment. |
98 uword AllocateLargeSegment(intptr_t size); | 98 uword AllocateLargeSegment(intptr_t size); |
99 | 99 |
100 // Insert zone into zone chain, after current_zone. | 100 // Insert zone into zone chain, after current_zone. |
101 void Link(Zone* current_zone) { | 101 void Link(Zone* current_zone) { previous_ = current_zone; } |
102 previous_ = current_zone; | |
103 } | |
104 | 102 |
105 // Delete all objects and free all memory allocated in the zone. | 103 // Delete all objects and free all memory allocated in the zone. |
106 void DeleteAll(); | 104 void DeleteAll(); |
107 | 105 |
108 // Does not actually free any memory. Enables templated containers like | 106 // Does not actually free any memory. Enables templated containers like |
109 // BaseGrowableArray to use different allocators. | 107 // BaseGrowableArray to use different allocators. |
110 template <class ElementType> | 108 template <class ElementType> |
111 void Free(ElementType* old_array, intptr_t len) { | 109 void Free(ElementType* old_array, intptr_t len) { |
112 #ifdef DEBUG | 110 #ifdef DEBUG |
113 if (len > 0) { | 111 if (len > 0) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 Segment* large_segments_; | 147 Segment* large_segments_; |
150 | 148 |
151 // Structure for managing handles allocation. | 149 // Structure for managing handles allocation. |
152 VMHandles handles_; | 150 VMHandles handles_; |
153 | 151 |
154 // Used for chaining zones in order to allow unwinding of stacks. | 152 // Used for chaining zones in order to allow unwinding of stacks. |
155 Zone* previous_; | 153 Zone* previous_; |
156 | 154 |
157 friend class StackZone; | 155 friend class StackZone; |
158 friend class ApiZone; | 156 friend class ApiZone; |
159 template<typename T, typename B, typename Allocator> | 157 template <typename T, typename B, typename Allocator> |
160 friend class BaseGrowableArray; | 158 friend class BaseGrowableArray; |
161 template<typename T, typename B, typename Allocator> | 159 template <typename T, typename B, typename Allocator> |
162 friend class BaseDirectChainedHashMap; | 160 friend class BaseDirectChainedHashMap; |
163 DISALLOW_COPY_AND_ASSIGN(Zone); | 161 DISALLOW_COPY_AND_ASSIGN(Zone); |
164 }; | 162 }; |
165 | 163 |
166 | 164 |
167 class StackZone : public StackResource { | 165 class StackZone : public StackResource { |
168 public: | 166 public: |
169 // Create an empty zone and set is at the current zone for the Thread. | 167 // Create an empty zone and set is at the current zone for the Thread. |
170 explicit StackZone(Thread* thread); | 168 explicit StackZone(Thread* thread); |
171 | 169 |
172 // Delete all memory associated with the zone. | 170 // Delete all memory associated with the zone. |
173 ~StackZone(); | 171 ~StackZone(); |
174 | 172 |
175 // Compute the total size of this zone. This includes wasted space that is | 173 // Compute the total size of this zone. This includes wasted space that is |
176 // due to internal fragmentation in the segments. | 174 // due to internal fragmentation in the segments. |
177 intptr_t SizeInBytes() const { return zone_.SizeInBytes(); } | 175 intptr_t SizeInBytes() const { return zone_.SizeInBytes(); } |
178 | 176 |
179 Zone* GetZone() { return &zone_; } | 177 Zone* GetZone() { return &zone_; } |
180 | 178 |
181 private: | 179 private: |
182 Zone zone_; | 180 Zone zone_; |
183 | 181 |
184 template<typename T> friend class GrowableArray; | 182 template <typename T> |
185 template<typename T> friend class ZoneGrowableArray; | 183 friend class GrowableArray; |
| 184 template <typename T> |
| 185 friend class ZoneGrowableArray; |
186 | 186 |
187 DISALLOW_IMPLICIT_CONSTRUCTORS(StackZone); | 187 DISALLOW_IMPLICIT_CONSTRUCTORS(StackZone); |
188 }; | 188 }; |
189 | 189 |
190 inline uword Zone::AllocUnsafe(intptr_t size) { | 190 inline uword Zone::AllocUnsafe(intptr_t size) { |
191 ASSERT(size >= 0); | 191 ASSERT(size >= 0); |
192 | 192 |
193 // Round up the requested size to fit the alignment. | 193 // Round up the requested size to fit the alignment. |
194 if (size > (kIntptrMax - kAlignment)) { | 194 if (size > (kIntptrMax - kAlignment)) { |
195 FATAL1("Zone::Alloc: 'size' is too large: size=%" Pd "", size); | 195 FATAL1("Zone::Alloc: 'size' is too large: size=%" Pd "", size); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 position_ = Utils::RoundUp(new_end, kAlignment); | 244 position_ = Utils::RoundUp(new_end, kAlignment); |
245 return old_data; | 245 return old_data; |
246 } | 246 } |
247 } | 247 } |
248 if (new_len <= old_len) { | 248 if (new_len <= old_len) { |
249 return old_data; | 249 return old_data; |
250 } | 250 } |
251 ElementType* new_data = Alloc<ElementType>(new_len); | 251 ElementType* new_data = Alloc<ElementType>(new_len); |
252 if (old_data != 0) { | 252 if (old_data != 0) { |
253 memmove(reinterpret_cast<void*>(new_data), | 253 memmove(reinterpret_cast<void*>(new_data), |
254 reinterpret_cast<void*>(old_data), | 254 reinterpret_cast<void*>(old_data), old_len * kElementSize); |
255 old_len * kElementSize); | |
256 } | 255 } |
257 return new_data; | 256 return new_data; |
258 } | 257 } |
259 | 258 |
260 } // namespace dart | 259 } // namespace dart |
261 | 260 |
262 #endif // RUNTIME_VM_ZONE_H_ | 261 #endif // RUNTIME_VM_ZONE_H_ |
OLD | NEW |