| 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 #include "vm/zone.h" | 5 #include "vm/zone.h" |
| 6 | 6 |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
| 9 #include "vm/flags.h" | 9 #include "vm/flags.h" |
| 10 #include "vm/handles_impl.h" | 10 #include "vm/handles_impl.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 #ifdef DEBUG | 65 #ifdef DEBUG |
| 66 // Zap the entire allocated segment (including the header). | 66 // Zap the entire allocated segment (including the header). |
| 67 memset(result, kZapUninitializedByte, size); | 67 memset(result, kZapUninitializedByte, size); |
| 68 #endif | 68 #endif |
| 69 result->next_ = next; | 69 result->next_ = next; |
| 70 result->size_ = size; | 70 result->size_ = size; |
| 71 return result; | 71 return result; |
| 72 } | 72 } |
| 73 | 73 |
| 74 | 74 |
| 75 Zone::Zone() |
| 76 : initial_buffer_(buffer_, kInitialChunkSize), |
| 77 position_(initial_buffer_.start()), |
| 78 limit_(initial_buffer_.end()), |
| 79 head_(NULL), |
| 80 large_segments_(NULL), |
| 81 handles_(), |
| 82 previous_(NULL) { |
| 83 ASSERT(Utils::IsAligned(position_, kAlignment)); |
| 84 #ifdef DEBUG |
| 85 // Zap the entire initial buffer. |
| 86 memset(initial_buffer_.pointer(), kZapUninitializedByte, |
| 87 initial_buffer_.size()); |
| 88 #endif |
| 89 } |
| 90 |
| 91 |
| 92 Zone::~Zone() { |
| 93 if (FLAG_trace_zones) { |
| 94 DumpZoneSizes(); |
| 95 } |
| 96 DeleteAll(); |
| 97 } |
| 98 |
| 99 |
| 75 void Zone::DeleteAll() { | 100 void Zone::DeleteAll() { |
| 76 // Traverse the chained list of segments, zapping (in debug mode) | 101 // Traverse the chained list of segments, zapping (in debug mode) |
| 77 // and freeing every zone segment. | 102 // and freeing every zone segment. |
| 78 if (head_ != NULL) { | 103 if (head_ != NULL) { |
| 79 Segment::DeleteSegmentList(head_); | 104 Segment::DeleteSegmentList(head_); |
| 80 } | 105 } |
| 81 if (large_segments_ != NULL) { | 106 if (large_segments_ != NULL) { |
| 82 Segment::DeleteSegmentList(large_segments_); | 107 Segment::DeleteSegmentList(large_segments_); |
| 83 } | 108 } |
| 84 | 109 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 va_end(args); | 252 va_end(args); |
| 228 return buffer; | 253 return buffer; |
| 229 } | 254 } |
| 230 | 255 |
| 231 | 256 |
| 232 char* Zone::VPrint(const char* format, va_list args) { | 257 char* Zone::VPrint(const char* format, va_list args) { |
| 233 return OS::VSCreate(this, format, args); | 258 return OS::VSCreate(this, format, args); |
| 234 } | 259 } |
| 235 | 260 |
| 236 | 261 |
| 262 StackZone::StackZone(Thread* thread) : StackResource(thread), zone_() { |
| 263 if (FLAG_trace_zones) { |
| 264 OS::PrintErr("*** Starting a new Stack zone 0x%" Px "(0x%" Px ")\n", |
| 265 reinterpret_cast<intptr_t>(this), |
| 266 reinterpret_cast<intptr_t>(&zone_)); |
| 267 } |
| 268 zone_.Link(thread->zone()); |
| 269 thread->set_zone(&zone_); |
| 270 } |
| 271 |
| 272 |
| 273 StackZone::~StackZone() { |
| 274 ASSERT(thread()->zone() == &zone_); |
| 275 thread()->set_zone(zone_.previous_); |
| 276 if (FLAG_trace_zones) { |
| 277 OS::PrintErr("*** Deleting Stack zone 0x%" Px "(0x%" Px ")\n", |
| 278 reinterpret_cast<intptr_t>(this), |
| 279 reinterpret_cast<intptr_t>(&zone_)); |
| 280 } |
| 281 } |
| 282 |
| 237 } // namespace dart | 283 } // namespace dart |
| OLD | NEW |