| 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 VM_ZONE_H_ | 5 #ifndef VM_ZONE_H_ |
| 6 #define VM_ZONE_H_ | 6 #define 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 uword AllocateLargeSegment(intptr_t size); | 105 uword AllocateLargeSegment(intptr_t size); |
| 106 | 106 |
| 107 // Insert zone into zone chain, after current_zone. | 107 // Insert zone into zone chain, after current_zone. |
| 108 void Link(Zone* current_zone) { | 108 void Link(Zone* current_zone) { |
| 109 previous_ = current_zone; | 109 previous_ = current_zone; |
| 110 } | 110 } |
| 111 | 111 |
| 112 // Delete all objects and free all memory allocated in the zone. | 112 // Delete all objects and free all memory allocated in the zone. |
| 113 void DeleteAll(); | 113 void DeleteAll(); |
| 114 | 114 |
| 115 // Does not actually free any memory. Enables templated containers like |
| 116 // BaseGrowableArray to use different allocators. |
| 117 template <class ElementType> |
| 118 void Free(ElementType* old_array, intptr_t len) { |
| 119 #ifdef DEBUG |
| 120 memset(old_array, kZapUninitializedByte, len * sizeof(ElementType)); |
| 121 #endif |
| 122 } |
| 123 |
| 115 #if defined(DEBUG) | 124 #if defined(DEBUG) |
| 116 // Dump the current allocated sizes in the zone object. | 125 // Dump the current allocated sizes in the zone object. |
| 117 void DumpZoneSizes(); | 126 void DumpZoneSizes(); |
| 118 #endif | 127 #endif |
| 119 | 128 |
| 120 // This buffer is used for allocation before any segments. | 129 // This buffer is used for allocation before any segments. |
| 121 // This would act as the initial stack allocated chunk so that we don't | 130 // This would act as the initial stack allocated chunk so that we don't |
| 122 // end up calling malloc/free on zone scopes that allocate less than | 131 // end up calling malloc/free on zone scopes that allocate less than |
| 123 // kChunkSize | 132 // kChunkSize |
| 124 uint8_t buffer_[kInitialChunkSize]; | 133 uint8_t buffer_[kInitialChunkSize]; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 142 Segment* large_segments_; | 151 Segment* large_segments_; |
| 143 | 152 |
| 144 // Structure for managing handles allocation. | 153 // Structure for managing handles allocation. |
| 145 VMHandles handles_; | 154 VMHandles handles_; |
| 146 | 155 |
| 147 // Used for chaining zones in order to allow unwinding of stacks. | 156 // Used for chaining zones in order to allow unwinding of stacks. |
| 148 Zone* previous_; | 157 Zone* previous_; |
| 149 | 158 |
| 150 friend class StackZone; | 159 friend class StackZone; |
| 151 friend class ApiZone; | 160 friend class ApiZone; |
| 152 template<typename T, typename B> friend class BaseGrowableArray; | 161 template<typename T, typename B, typename Allocator> |
| 162 friend class BaseGrowableArray; |
| 153 DISALLOW_COPY_AND_ASSIGN(Zone); | 163 DISALLOW_COPY_AND_ASSIGN(Zone); |
| 154 }; | 164 }; |
| 155 | 165 |
| 156 | 166 |
| 157 class StackZone : public StackResource { | 167 class StackZone : public StackResource { |
| 158 public: | 168 public: |
| 159 // Create an empty zone and set is at the current zone for the Isolate. | 169 // Create an empty zone and set is at the current zone for the Isolate. |
| 160 explicit StackZone(Isolate* isolate) | 170 explicit StackZone(Isolate* isolate) |
| 161 : StackResource(isolate), | 171 : StackResource(isolate), |
| 162 zone_() { | 172 zone_() { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 reinterpret_cast<void*>(old_data), | 255 reinterpret_cast<void*>(old_data), |
| 246 Utils::Minimum(old_len * sizeof(ElementType), | 256 Utils::Minimum(old_len * sizeof(ElementType), |
| 247 new_len * sizeof(ElementType))); | 257 new_len * sizeof(ElementType))); |
| 248 } | 258 } |
| 249 return new_data; | 259 return new_data; |
| 250 } | 260 } |
| 251 | 261 |
| 252 } // namespace dart | 262 } // namespace dart |
| 253 | 263 |
| 254 #endif // VM_ZONE_H_ | 264 #endif // VM_ZONE_H_ |
| OLD | NEW |