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 25 matching lines...) Expand all Loading... |
36 uword address(int n) { return reinterpret_cast<uword>(this) + n; } | 36 uword address(int n) { return reinterpret_cast<uword>(this) + n; } |
37 | 37 |
38 static void Delete(Segment* segment) { free(segment); } | 38 static void Delete(Segment* segment) { free(segment); } |
39 | 39 |
40 DISALLOW_IMPLICIT_CONSTRUCTORS(Segment); | 40 DISALLOW_IMPLICIT_CONSTRUCTORS(Segment); |
41 }; | 41 }; |
42 | 42 |
43 | 43 |
44 void Zone::Segment::DeleteSegmentList(Segment* head) { | 44 void Zone::Segment::DeleteSegmentList(Segment* head) { |
45 Segment* current = head; | 45 Segment* current = head; |
| 46 Thread* current_thread = Thread::Current(); |
46 while (current != NULL) { | 47 while (current != NULL) { |
| 48 if (current_thread != NULL) { |
| 49 // TODO(bkonyi) Handle special case of segment deletion within native |
| 50 // isolate. |
| 51 current_thread->DecrementMemoryUsage(current->size()); |
| 52 } |
47 Segment* next = current->next(); | 53 Segment* next = current->next(); |
48 #ifdef DEBUG | 54 #ifdef DEBUG |
49 // Zap the entire current segment (including the header). | 55 // Zap the entire current segment (including the header). |
50 memset(current, kZapDeletedByte, current->size()); | 56 memset(current, kZapDeletedByte, current->size()); |
51 #endif | 57 #endif |
52 Segment::Delete(current); | 58 Segment::Delete(current); |
53 current = next; | 59 current = next; |
54 } | 60 } |
55 } | 61 } |
56 | 62 |
57 | 63 |
58 Zone::Segment* Zone::Segment::New(intptr_t size, Zone::Segment* next) { | 64 Zone::Segment* Zone::Segment::New(intptr_t size, Zone::Segment* next) { |
59 ASSERT(size >= 0); | 65 ASSERT(size >= 0); |
60 Segment* result = reinterpret_cast<Segment*>(malloc(size)); | 66 Segment* result = reinterpret_cast<Segment*>(malloc(size)); |
61 if (result == NULL) { | 67 if (result == NULL) { |
62 OUT_OF_MEMORY(); | 68 OUT_OF_MEMORY(); |
63 } | 69 } |
64 ASSERT(Utils::IsAligned(result->start(), Zone::kAlignment)); | 70 ASSERT(Utils::IsAligned(result->start(), Zone::kAlignment)); |
65 #ifdef DEBUG | 71 #ifdef DEBUG |
66 // Zap the entire allocated segment (including the header). | 72 // Zap the entire allocated segment (including the header). |
67 memset(result, kZapUninitializedByte, size); | 73 memset(result, kZapUninitializedByte, size); |
68 #endif | 74 #endif |
69 result->next_ = next; | 75 result->next_ = next; |
70 result->size_ = size; | 76 result->size_ = size; |
| 77 if (Thread::Current() != NULL) { |
| 78 // TODO(bkonyi) Handle special case of segment creation within native |
| 79 // isolate. |
| 80 Thread::Current()->IncrementMemoryUsage(size); |
| 81 } |
71 return result; | 82 return result; |
72 } | 83 } |
73 | 84 |
74 | 85 |
75 Zone::Zone() | 86 Zone::Zone() |
76 : initial_buffer_(buffer_, kInitialChunkSize), | 87 : initial_buffer_(buffer_, kInitialChunkSize), |
77 position_(initial_buffer_.start()), | 88 position_(initial_buffer_.start()), |
78 limit_(initial_buffer_.end()), | 89 limit_(initial_buffer_.end()), |
79 head_(NULL), | 90 head_(NULL), |
80 large_segments_(NULL), | 91 large_segments_(NULL), |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 ASSERT(thread()->zone() == &zone_); | 314 ASSERT(thread()->zone() == &zone_); |
304 thread()->set_zone(zone_.previous_); | 315 thread()->set_zone(zone_.previous_); |
305 if (FLAG_trace_zones) { | 316 if (FLAG_trace_zones) { |
306 OS::PrintErr("*** Deleting Stack zone 0x%" Px "(0x%" Px ")\n", | 317 OS::PrintErr("*** Deleting Stack zone 0x%" Px "(0x%" Px ")\n", |
307 reinterpret_cast<intptr_t>(this), | 318 reinterpret_cast<intptr_t>(this), |
308 reinterpret_cast<intptr_t>(&zone_)); | 319 reinterpret_cast<intptr_t>(&zone_)); |
309 } | 320 } |
310 } | 321 } |
311 | 322 |
312 } // namespace dart | 323 } // namespace dart |
OLD | NEW |