| 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 template<typename T, typename B, typename Allocator> | 171 template<typename T, typename B, typename Allocator> |
| 172 friend class BaseGrowableArray; | 172 friend class BaseGrowableArray; |
| 173 DISALLOW_COPY_AND_ASSIGN(Zone); | 173 DISALLOW_COPY_AND_ASSIGN(Zone); |
| 174 }; | 174 }; |
| 175 | 175 |
| 176 | 176 |
| 177 class StackZone : public StackResource { | 177 class StackZone : public StackResource { |
| 178 public: | 178 public: |
| 179 // Create an empty zone and set is at the current zone for the Thread. | 179 // Create an empty zone and set is at the current zone for the Thread. |
| 180 explicit StackZone(Thread* thread) : StackResource(thread), zone_() { | 180 explicit StackZone(Thread* thread) : StackResource(thread), zone_() { |
| 181 Initialize(); | 181 #ifdef DEBUG |
| 182 } | 182 if (FLAG_trace_zones) { |
| 183 | 183 OS::PrintErr("*** Starting a new Stack zone 0x%" Px "(0x%" Px ")\n", |
| 184 // DEPRECATED: Use Thread-based interface. During migration, this defaults | 184 reinterpret_cast<intptr_t>(this), |
| 185 // to using the mutator thread (which must also be the current thread). | 185 reinterpret_cast<intptr_t>(&zone_)); |
| 186 explicit StackZone(Isolate* isolate) : StackResource(isolate), zone_() { | 186 } |
| 187 Initialize(); | 187 #endif |
| 188 zone_.Link(thread->zone()); |
| 189 thread->set_zone(&zone_); |
| 188 } | 190 } |
| 189 | 191 |
| 190 // Delete all memory associated with the zone. | 192 // Delete all memory associated with the zone. |
| 191 ~StackZone() { | 193 ~StackZone() { |
| 192 ASSERT(thread()->zone() == &zone_); | 194 ASSERT(thread()->zone() == &zone_); |
| 193 thread()->set_zone(zone_.previous_); | 195 thread()->set_zone(zone_.previous_); |
| 194 #ifdef DEBUG | 196 #ifdef DEBUG |
| 195 if (FLAG_trace_zones) { | 197 if (FLAG_trace_zones) { |
| 196 OS::PrintErr("*** Deleting Stack zone 0x%" Px "(0x%" Px ")\n", | 198 OS::PrintErr("*** Deleting Stack zone 0x%" Px "(0x%" Px ")\n", |
| 197 reinterpret_cast<intptr_t>(this), | 199 reinterpret_cast<intptr_t>(this), |
| 198 reinterpret_cast<intptr_t>(&zone_)); | 200 reinterpret_cast<intptr_t>(&zone_)); |
| 199 } | 201 } |
| 200 #endif | 202 #endif |
| 201 } | 203 } |
| 202 | 204 |
| 203 // Compute the total size of this zone. This includes wasted space that is | 205 // Compute the total size of this zone. This includes wasted space that is |
| 204 // due to internal fragmentation in the segments. | 206 // due to internal fragmentation in the segments. |
| 205 intptr_t SizeInBytes() const { return zone_.SizeInBytes(); } | 207 intptr_t SizeInBytes() const { return zone_.SizeInBytes(); } |
| 206 | 208 |
| 207 Zone* GetZone() { return &zone_; } | 209 Zone* GetZone() { return &zone_; } |
| 208 | 210 |
| 209 private: | 211 private: |
| 210 Zone zone_; | 212 Zone zone_; |
| 211 | 213 |
| 212 void Initialize() { | |
| 213 #ifdef DEBUG | |
| 214 if (FLAG_trace_zones) { | |
| 215 OS::PrintErr("*** Starting a new Stack zone 0x%" Px "(0x%" Px ")\n", | |
| 216 reinterpret_cast<intptr_t>(this), | |
| 217 reinterpret_cast<intptr_t>(&zone_)); | |
| 218 } | |
| 219 #endif | |
| 220 zone_.Link(thread()->zone()); | |
| 221 thread()->set_zone(&zone_); | |
| 222 } | |
| 223 | |
| 224 template<typename T> friend class GrowableArray; | 214 template<typename T> friend class GrowableArray; |
| 225 template<typename T> friend class ZoneGrowableArray; | 215 template<typename T> friend class ZoneGrowableArray; |
| 226 | 216 |
| 227 DISALLOW_IMPLICIT_CONSTRUCTORS(StackZone); | 217 DISALLOW_IMPLICIT_CONSTRUCTORS(StackZone); |
| 228 }; | 218 }; |
| 229 | 219 |
| 230 inline uword Zone::AllocUnsafe(intptr_t size) { | 220 inline uword Zone::AllocUnsafe(intptr_t size) { |
| 231 ASSERT(size >= 0); | 221 ASSERT(size >= 0); |
| 232 | 222 |
| 233 // Round up the requested size to fit the alignment. | 223 // Round up the requested size to fit the alignment. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 memmove(reinterpret_cast<void*>(new_data), | 283 memmove(reinterpret_cast<void*>(new_data), |
| 294 reinterpret_cast<void*>(old_data), | 284 reinterpret_cast<void*>(old_data), |
| 295 old_len * kElementSize); | 285 old_len * kElementSize); |
| 296 } | 286 } |
| 297 return new_data; | 287 return new_data; |
| 298 } | 288 } |
| 299 | 289 |
| 300 } // namespace dart | 290 } // namespace dart |
| 301 | 291 |
| 302 #endif // VM_ZONE_H_ | 292 #endif // VM_ZONE_H_ |
| OLD | NEW |