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/dart_api_state.h" | |
9 #include "vm/flags.h" | 10 #include "vm/flags.h" |
10 #include "vm/handles_impl.h" | 11 #include "vm/handles_impl.h" |
11 #include "vm/heap.h" | 12 #include "vm/heap.h" |
12 #include "vm/os.h" | 13 #include "vm/os.h" |
13 | 14 |
14 namespace dart { | 15 namespace dart { |
15 | 16 |
16 // Zone segments represent chunks of memory: They have starting | 17 // Zone segments represent chunks of memory: They have starting |
17 // address encoded in the this pointer and a size in bytes. They are | 18 // address encoded in the this pointer and a size in bytes. They are |
18 // chained together to form the backing storage for an expanding zone. | 19 // chained together to form the backing storage for an expanding zone. |
(...skipping 20 matching lines...) Expand all Loading... | |
39 | 40 |
40 DISALLOW_IMPLICIT_CONSTRUCTORS(Segment); | 41 DISALLOW_IMPLICIT_CONSTRUCTORS(Segment); |
41 }; | 42 }; |
42 | 43 |
43 | 44 |
44 void Zone::Segment::DeleteSegmentList(Segment* head) { | 45 void Zone::Segment::DeleteSegmentList(Segment* head) { |
45 Segment* current = head; | 46 Segment* current = head; |
46 Thread* current_thread = Thread::Current(); | 47 Thread* current_thread = Thread::Current(); |
47 while (current != NULL) { | 48 while (current != NULL) { |
48 if (current_thread != NULL) { | 49 if (current_thread != NULL) { |
49 // TODO(bkonyi) Handle special case of segment deletion within native | |
50 // isolate. | |
51 current_thread->DecrementMemoryUsage(current->size()); | 50 current_thread->DecrementMemoryUsage(current->size()); |
51 } else if (ApiNativeScope::Current() != NULL) { | |
52 // If there is no current thread, we might be iniside of a native scope. | |
siva
2017/01/26 03:02:05
iniside => inside
bkonyi
2017/01/26 22:34:27
Done.
| |
53 ApiNativeScope::DecrementNativeScopeMemoryUsage(current->size()); | |
52 } | 54 } |
53 Segment* next = current->next(); | 55 Segment* next = current->next(); |
54 #ifdef DEBUG | 56 #ifdef DEBUG |
55 // Zap the entire current segment (including the header). | 57 // Zap the entire current segment (including the header). |
56 memset(current, kZapDeletedByte, current->size()); | 58 memset(current, kZapDeletedByte, current->size()); |
57 #endif | 59 #endif |
58 Segment::Delete(current); | 60 Segment::Delete(current); |
59 current = next; | 61 current = next; |
60 } | 62 } |
61 } | 63 } |
62 | 64 |
63 | 65 |
64 Zone::Segment* Zone::Segment::New(intptr_t size, Zone::Segment* next) { | 66 Zone::Segment* Zone::Segment::New(intptr_t size, Zone::Segment* next) { |
65 ASSERT(size >= 0); | 67 ASSERT(size >= 0); |
66 Segment* result = reinterpret_cast<Segment*>(malloc(size)); | 68 Segment* result = reinterpret_cast<Segment*>(malloc(size)); |
67 if (result == NULL) { | 69 if (result == NULL) { |
68 OUT_OF_MEMORY(); | 70 OUT_OF_MEMORY(); |
69 } | 71 } |
70 ASSERT(Utils::IsAligned(result->start(), Zone::kAlignment)); | 72 ASSERT(Utils::IsAligned(result->start(), Zone::kAlignment)); |
71 #ifdef DEBUG | 73 #ifdef DEBUG |
72 // Zap the entire allocated segment (including the header). | 74 // Zap the entire allocated segment (including the header). |
73 memset(result, kZapUninitializedByte, size); | 75 memset(result, kZapUninitializedByte, size); |
74 #endif | 76 #endif |
75 result->next_ = next; | 77 result->next_ = next; |
76 result->size_ = size; | 78 result->size_ = size; |
77 if (Thread::Current() != NULL) { | 79 Thread* current = Thread::Current(); |
78 // TODO(bkonyi) Handle special case of segment creation within native | 80 if (current != NULL) { |
79 // isolate. | 81 current->IncrementMemoryUsage(size); |
80 Thread::Current()->IncrementMemoryUsage(size); | 82 } else if (ApiNativeScope::Current() != NULL) { |
83 // If there is no current thread, we might be inside of a native scope. | |
84 ApiNativeScope::IncrementNativeScopeMemoryUsage(size); | |
81 } | 85 } |
82 return result; | 86 return result; |
83 } | 87 } |
84 | 88 |
85 | 89 |
86 Zone::Zone() | 90 Zone::Zone() |
87 : initial_buffer_(buffer_, kInitialChunkSize), | 91 : initial_buffer_(buffer_, kInitialChunkSize), |
88 position_(initial_buffer_.start()), | 92 position_(initial_buffer_.start()), |
89 limit_(initial_buffer_.end()), | 93 limit_(initial_buffer_.end()), |
90 head_(NULL), | 94 head_(NULL), |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 ASSERT(thread()->zone() == &zone_); | 318 ASSERT(thread()->zone() == &zone_); |
315 thread()->set_zone(zone_.previous_); | 319 thread()->set_zone(zone_.previous_); |
316 if (FLAG_trace_zones) { | 320 if (FLAG_trace_zones) { |
317 OS::PrintErr("*** Deleting Stack zone 0x%" Px "(0x%" Px ")\n", | 321 OS::PrintErr("*** Deleting Stack zone 0x%" Px "(0x%" Px ")\n", |
318 reinterpret_cast<intptr_t>(this), | 322 reinterpret_cast<intptr_t>(this), |
319 reinterpret_cast<intptr_t>(&zone_)); | 323 reinterpret_cast<intptr_t>(&zone_)); |
320 } | 324 } |
321 } | 325 } |
322 | 326 |
323 } // namespace dart | 327 } // namespace dart |
OLD | NEW |