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/heap.h" | 5 #include "vm/heap.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/isolate.h" | 10 #include "vm/isolate.h" |
11 #include "vm/object.h" | 11 #include "vm/object.h" |
12 #include "vm/object_set.h" | 12 #include "vm/object_set.h" |
13 #include "vm/os.h" | 13 #include "vm/os.h" |
14 #include "vm/pages.h" | 14 #include "vm/pages.h" |
15 #include "vm/raw_object.h" | 15 #include "vm/raw_object.h" |
16 #include "vm/scavenger.h" | 16 #include "vm/scavenger.h" |
17 #include "vm/stack_frame.h" | 17 #include "vm/stack_frame.h" |
| 18 #include "vm/tags.h" |
18 #include "vm/verifier.h" | 19 #include "vm/verifier.h" |
19 #include "vm/virtual_memory.h" | 20 #include "vm/virtual_memory.h" |
20 #include "vm/weak_table.h" | 21 #include "vm/weak_table.h" |
21 | 22 |
22 namespace dart { | 23 namespace dart { |
23 | 24 |
24 DEFINE_FLAG(bool, verbose_gc, false, "Enables verbose GC."); | 25 DEFINE_FLAG(bool, verbose_gc, false, "Enables verbose GC."); |
25 DEFINE_FLAG(int, verbose_gc_hdr, 40, "Print verbose GC header interval."); | 26 DEFINE_FLAG(int, verbose_gc_hdr, 40, "Print verbose GC header interval."); |
26 DEFINE_FLAG(bool, verify_before_gc, false, | 27 DEFINE_FLAG(bool, verify_before_gc, false, |
27 "Enables heap verification before GC."); | 28 "Enables heap verification before GC."); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 return reinterpret_cast<RawInstructions*>(raw_obj); | 170 return reinterpret_cast<RawInstructions*>(raw_obj); |
170 } | 171 } |
171 | 172 |
172 | 173 |
173 RawObject* Heap::FindOldObject(FindObjectVisitor* visitor) const { | 174 RawObject* Heap::FindOldObject(FindObjectVisitor* visitor) const { |
174 return old_space_->FindObject(visitor, HeapPage::kData); | 175 return old_space_->FindObject(visitor, HeapPage::kData); |
175 } | 176 } |
176 | 177 |
177 | 178 |
178 void Heap::CollectGarbage(Space space, ApiCallbacks api_callbacks) { | 179 void Heap::CollectGarbage(Space space, ApiCallbacks api_callbacks) { |
| 180 Isolate* isolate = Isolate::Current(); |
179 bool invoke_api_callbacks = (api_callbacks == kInvokeApiCallbacks); | 181 bool invoke_api_callbacks = (api_callbacks == kInvokeApiCallbacks); |
180 switch (space) { | 182 switch (space) { |
181 case kNew: { | 183 case kNew: { |
| 184 VMTagScope tagScope(isolate, VMTag::kGCNewSpaceTagId); |
182 RecordBeforeGC(kNew, kNewSpace); | 185 RecordBeforeGC(kNew, kNewSpace); |
183 UpdateClassHeapStatsBeforeGC(kNew); | 186 UpdateClassHeapStatsBeforeGC(kNew); |
184 new_space_->Scavenge(invoke_api_callbacks); | 187 new_space_->Scavenge(invoke_api_callbacks); |
185 RecordAfterGC(); | 188 RecordAfterGC(); |
186 PrintStats(); | 189 PrintStats(); |
187 if (new_space_->HadPromotionFailure()) { | 190 if (new_space_->HadPromotionFailure()) { |
188 // Old collections should call the API callbacks. | 191 // Old collections should call the API callbacks. |
189 CollectGarbage(kOld, kInvokeApiCallbacks); | 192 CollectGarbage(kOld, kInvokeApiCallbacks); |
190 } | 193 } |
191 break; | 194 break; |
192 } | 195 } |
193 case kOld: | 196 case kOld: |
194 case kCode: { | 197 case kCode: { |
| 198 VMTagScope tagScope(isolate, VMTag::kGCOldSpaceTagId); |
195 bool promotion_failure = new_space_->HadPromotionFailure(); | 199 bool promotion_failure = new_space_->HadPromotionFailure(); |
196 RecordBeforeGC(kOld, promotion_failure ? kPromotionFailure : kOldSpace); | 200 RecordBeforeGC(kOld, promotion_failure ? kPromotionFailure : kOldSpace); |
197 UpdateClassHeapStatsBeforeGC(kOld); | 201 UpdateClassHeapStatsBeforeGC(kOld); |
198 old_space_->MarkSweep(invoke_api_callbacks); | 202 old_space_->MarkSweep(invoke_api_callbacks); |
199 RecordAfterGC(); | 203 RecordAfterGC(); |
200 PrintStats(); | 204 PrintStats(); |
201 break; | 205 break; |
202 } | 206 } |
203 default: | 207 default: |
204 UNREACHABLE(); | 208 UNREACHABLE(); |
(...skipping 17 matching lines...) Expand all Loading... |
222 if (space == kOld) { | 226 if (space == kOld) { |
223 api_callbacks = kInvokeApiCallbacks; | 227 api_callbacks = kInvokeApiCallbacks; |
224 } else { | 228 } else { |
225 api_callbacks = kIgnoreApiCallbacks; | 229 api_callbacks = kIgnoreApiCallbacks; |
226 } | 230 } |
227 CollectGarbage(space, api_callbacks); | 231 CollectGarbage(space, api_callbacks); |
228 } | 232 } |
229 | 233 |
230 | 234 |
231 void Heap::CollectAllGarbage() { | 235 void Heap::CollectAllGarbage() { |
232 RecordBeforeGC(kNew, kFull); | 236 Isolate* isolate = Isolate::Current(); |
233 UpdateClassHeapStatsBeforeGC(kNew); | 237 { |
234 new_space_->Scavenge(kInvokeApiCallbacks); | 238 VMTagScope tagScope(isolate, VMTag::kGCNewSpaceTagId); |
235 RecordAfterGC(); | 239 RecordBeforeGC(kNew, kFull); |
236 PrintStats(); | 240 UpdateClassHeapStatsBeforeGC(kNew); |
237 RecordBeforeGC(kOld, kFull); | 241 new_space_->Scavenge(kInvokeApiCallbacks); |
238 UpdateClassHeapStatsBeforeGC(kOld); | 242 RecordAfterGC(); |
239 old_space_->MarkSweep(kInvokeApiCallbacks); | 243 PrintStats(); |
240 RecordAfterGC(); | 244 } |
241 PrintStats(); | 245 { |
| 246 VMTagScope tagScope(isolate, VMTag::kGCOldSpaceTagId); |
| 247 RecordBeforeGC(kOld, kFull); |
| 248 UpdateClassHeapStatsBeforeGC(kOld); |
| 249 old_space_->MarkSweep(kInvokeApiCallbacks); |
| 250 RecordAfterGC(); |
| 251 PrintStats(); |
| 252 } |
242 } | 253 } |
243 | 254 |
244 | 255 |
245 void Heap::SetGrowthControlState(bool state) { | 256 void Heap::SetGrowthControlState(bool state) { |
246 old_space_->SetGrowthControlState(state); | 257 old_space_->SetGrowthControlState(state); |
247 } | 258 } |
248 | 259 |
249 | 260 |
250 bool Heap::GrowthControlState() { | 261 bool Heap::GrowthControlState() { |
251 return old_space_->GrowthControlState(); | 262 return old_space_->GrowthControlState(); |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 heap->DisableGrowthControl(); | 552 heap->DisableGrowthControl(); |
542 } | 553 } |
543 | 554 |
544 | 555 |
545 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { | 556 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { |
546 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); | 557 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); |
547 heap->SetGrowthControlState(current_growth_controller_state_); | 558 heap->SetGrowthControlState(current_growth_controller_state_); |
548 } | 559 } |
549 | 560 |
550 } // namespace dart | 561 } // namespace dart |
OLD | NEW |