| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 // Zap the entire allocated segment (including the header). | 68 // Zap the entire allocated segment (including the header). |
| 69 memset(result, kZapUninitializedByte, size); | 69 memset(result, kZapUninitializedByte, size); |
| 70 #endif | 70 #endif |
| 71 result->next_ = next; | 71 result->next_ = next; |
| 72 result->size_ = size; | 72 result->size_ = size; |
| 73 } | 73 } |
| 74 return result; | 74 return result; |
| 75 } | 75 } |
| 76 | 76 |
| 77 | 77 |
| 78 Zone::Zone() | |
| 79 : initial_buffer_(buffer_, kInitialChunkSize), | |
| 80 position_(initial_buffer_.start()), | |
| 81 limit_(initial_buffer_.end()), | |
| 82 head_(NULL), | |
| 83 large_segments_(NULL), | |
| 84 handles_(), | |
| 85 previous_(NULL) { | |
| 86 #ifdef DEBUG | |
| 87 // Zap the entire initial buffer. | |
| 88 memset(initial_buffer_.pointer(), kZapUninitializedByte, | |
| 89 initial_buffer_.size()); | |
| 90 #endif | |
| 91 } | |
| 92 | |
| 93 | |
| 94 Zone::~Zone() { | |
| 95 #if defined(DEBUG) | |
| 96 if (FLAG_trace_zones) { | |
| 97 DumpZoneSizes(); | |
| 98 } | |
| 99 #endif | |
| 100 DeleteAll(); | |
| 101 } | |
| 102 | |
| 103 | |
| 104 void Zone::DeleteAll() { | 78 void Zone::DeleteAll() { |
| 105 // Traverse the chained list of segments, zapping (in debug mode) | 79 // Traverse the chained list of segments, zapping (in debug mode) |
| 106 // and freeing every zone segment. | 80 // and freeing every zone segment. |
| 107 Segment::DeleteSegmentList(head_); | 81 Segment::DeleteSegmentList(head_); |
| 108 Segment::DeleteSegmentList(large_segments_); | 82 Segment::DeleteSegmentList(large_segments_); |
| 109 | 83 |
| 110 // Reset zone state. | 84 // Reset zone state. |
| 111 #ifdef DEBUG | 85 #ifdef DEBUG |
| 112 memset(initial_buffer_.pointer(), kZapDeletedByte, initial_buffer_.size()); | 86 memset(initial_buffer_.pointer(), kZapDeletedByte, initial_buffer_.size()); |
| 113 #endif | 87 #endif |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 for (Segment* s = large_segments_; s != NULL; s = s->next()) { | 179 for (Segment* s = large_segments_; s != NULL; s = s->next()) { |
| 206 size += s->size(); | 180 size += s->size(); |
| 207 } | 181 } |
| 208 OS::PrintErr("*** Zone(0x%"Px") size in bytes," | 182 OS::PrintErr("*** Zone(0x%"Px") size in bytes," |
| 209 " Total = %"Pd" Large Segments = %"Pd"\n", | 183 " Total = %"Pd" Large Segments = %"Pd"\n", |
| 210 reinterpret_cast<intptr_t>(this), SizeInBytes(), size); | 184 reinterpret_cast<intptr_t>(this), SizeInBytes(), size); |
| 211 } | 185 } |
| 212 #endif | 186 #endif |
| 213 | 187 |
| 214 | 188 |
| 215 StackZone::StackZone(BaseIsolate* isolate) | |
| 216 : StackResource(isolate), | |
| 217 zone_() { | |
| 218 #ifdef DEBUG | |
| 219 if (FLAG_trace_zones) { | |
| 220 OS::PrintErr("*** Starting a new Stack zone 0x%"Px"(0x%"Px")\n", | |
| 221 reinterpret_cast<intptr_t>(this), | |
| 222 reinterpret_cast<intptr_t>(&zone_)); | |
| 223 } | |
| 224 #endif | |
| 225 zone_.Link(isolate->current_zone()); | |
| 226 isolate->set_current_zone(&zone_); | |
| 227 } | |
| 228 | |
| 229 | |
| 230 StackZone::~StackZone() { | |
| 231 ASSERT(isolate()->current_zone() == &zone_); | |
| 232 isolate()->set_current_zone(zone_.previous_); | |
| 233 #ifdef DEBUG | |
| 234 if (FLAG_trace_zones) { | |
| 235 OS::PrintErr("*** Deleting Stack zone 0x%"Px"(0x%"Px")\n", | |
| 236 reinterpret_cast<intptr_t>(this), | |
| 237 reinterpret_cast<intptr_t>(&zone_)); | |
| 238 } | |
| 239 #endif | |
| 240 } | |
| 241 | |
| 242 | |
| 243 void Zone::VisitObjectPointers(ObjectPointerVisitor* visitor) { | 189 void Zone::VisitObjectPointers(ObjectPointerVisitor* visitor) { |
| 244 Zone* zone = this; | 190 Zone* zone = this; |
| 245 while (zone != NULL) { | 191 while (zone != NULL) { |
| 246 zone->handles()->VisitObjectPointers(visitor); | 192 zone->handles()->VisitObjectPointers(visitor); |
| 247 zone = zone->previous_; | 193 zone = zone->previous_; |
| 248 } | 194 } |
| 249 } | 195 } |
| 250 | 196 |
| 251 | 197 |
| 252 char* Zone::PrintToString(const char* format, ...) { | 198 char* Zone::PrintToString(const char* format, ...) { |
| 253 va_list args; | 199 va_list args; |
| 254 va_start(args, format); | 200 va_start(args, format); |
| 255 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 201 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 256 va_end(args); | 202 va_end(args); |
| 257 | 203 |
| 258 char* buffer = Alloc<char>(len + 1); | 204 char* buffer = Alloc<char>(len + 1); |
| 259 va_list args2; | 205 va_list args2; |
| 260 va_start(args2, format); | 206 va_start(args2, format); |
| 261 OS::VSNPrint(buffer, (len + 1), format, args2); | 207 OS::VSNPrint(buffer, (len + 1), format, args2); |
| 262 va_end(args2); | 208 va_end(args2); |
| 263 | 209 |
| 264 return buffer; | 210 return buffer; |
| 265 } | 211 } |
| 266 | 212 |
| 267 | 213 |
| 268 } // namespace dart | 214 } // namespace dart |
| OLD | NEW |