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/lockers.h" | 11 #include "vm/lockers.h" |
12 #include "vm/object.h" | 12 #include "vm/object.h" |
13 #include "vm/object_set.h" | 13 #include "vm/object_set.h" |
14 #include "vm/os.h" | 14 #include "vm/os.h" |
15 #include "vm/pages.h" | 15 #include "vm/pages.h" |
16 #include "vm/raw_object.h" | 16 #include "vm/raw_object.h" |
17 #include "vm/scavenger.h" | 17 #include "vm/scavenger.h" |
18 #include "vm/service.h" | 18 #include "vm/service.h" |
19 #include "vm/service_event.h" | 19 #include "vm/service_event.h" |
20 #include "vm/stack_frame.h" | 20 #include "vm/stack_frame.h" |
21 #include "vm/tags.h" | 21 #include "vm/tags.h" |
| 22 #include "vm/timeline.h" |
22 #include "vm/verifier.h" | 23 #include "vm/verifier.h" |
23 #include "vm/virtual_memory.h" | 24 #include "vm/virtual_memory.h" |
24 #include "vm/weak_table.h" | 25 #include "vm/weak_table.h" |
25 | 26 |
26 namespace dart { | 27 namespace dart { |
27 | 28 |
28 DEFINE_FLAG(bool, disable_alloc_stubs_after_gc, false, "Stress testing flag."); | 29 DEFINE_FLAG(bool, disable_alloc_stubs_after_gc, false, "Stress testing flag."); |
29 DEFINE_FLAG(bool, gc_at_alloc, false, "GC at every allocation."); | 30 DEFINE_FLAG(bool, gc_at_alloc, false, "GC at every allocation."); |
30 DEFINE_FLAG(int, new_gen_ext_limit, 64, | 31 DEFINE_FLAG(int, new_gen_ext_limit, 64, |
31 "maximum total external size (MB) in new gen before triggering GC"); | 32 "maximum total external size (MB) in new gen before triggering GC"); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 | 265 |
265 | 266 |
266 void Heap::CollectGarbage(Space space, | 267 void Heap::CollectGarbage(Space space, |
267 ApiCallbacks api_callbacks, | 268 ApiCallbacks api_callbacks, |
268 GCReason reason) { | 269 GCReason reason) { |
269 TIMERSCOPE(isolate(), time_gc); | 270 TIMERSCOPE(isolate(), time_gc); |
270 bool invoke_api_callbacks = (api_callbacks == kInvokeApiCallbacks); | 271 bool invoke_api_callbacks = (api_callbacks == kInvokeApiCallbacks); |
271 switch (space) { | 272 switch (space) { |
272 case kNew: { | 273 case kNew: { |
273 VMTagScope tagScope(isolate(), VMTag::kGCNewSpaceTagId); | 274 VMTagScope tagScope(isolate(), VMTag::kGCNewSpaceTagId); |
| 275 TimelineDurationScope tds(isolate()->GetGCStream(), |
| 276 "CollectNewGeneration"); |
274 RecordBeforeGC(kNew, reason); | 277 RecordBeforeGC(kNew, reason); |
275 UpdateClassHeapStatsBeforeGC(kNew); | 278 UpdateClassHeapStatsBeforeGC(kNew); |
276 new_space_->Scavenge(invoke_api_callbacks); | 279 new_space_->Scavenge(invoke_api_callbacks); |
277 isolate()->class_table()->UpdatePromoted(); | 280 isolate()->class_table()->UpdatePromoted(); |
278 UpdatePretenurePolicy(); | 281 UpdatePretenurePolicy(); |
279 RecordAfterGC(); | 282 RecordAfterGC(); |
280 PrintStats(); | 283 PrintStats(); |
281 if (old_space_->NeedsGarbageCollection()) { | 284 if (old_space_->NeedsGarbageCollection()) { |
282 // Old collections should call the API callbacks. | 285 // Old collections should call the API callbacks. |
283 CollectGarbage(kOld, kInvokeApiCallbacks, kPromotion); | 286 CollectGarbage(kOld, kInvokeApiCallbacks, kPromotion); |
284 } | 287 } |
285 break; | 288 break; |
286 } | 289 } |
287 case kOld: | 290 case kOld: |
288 case kCode: { | 291 case kCode: { |
289 VMTagScope tagScope(isolate(), VMTag::kGCOldSpaceTagId); | 292 VMTagScope tagScope(isolate(), VMTag::kGCOldSpaceTagId); |
| 293 TimelineDurationScope tds(isolate()->GetGCStream(), |
| 294 "CollectOldGeneration"); |
290 RecordBeforeGC(kOld, reason); | 295 RecordBeforeGC(kOld, reason); |
291 UpdateClassHeapStatsBeforeGC(kOld); | 296 UpdateClassHeapStatsBeforeGC(kOld); |
292 old_space_->MarkSweep(invoke_api_callbacks); | 297 old_space_->MarkSweep(invoke_api_callbacks); |
293 RecordAfterGC(); | 298 RecordAfterGC(); |
294 PrintStats(); | 299 PrintStats(); |
295 break; | 300 break; |
296 } | 301 } |
297 default: | 302 default: |
298 UNREACHABLE(); | 303 UNREACHABLE(); |
299 } | 304 } |
(...skipping 17 matching lines...) Expand all Loading... |
317 ASSERT(space == kNew); | 322 ASSERT(space == kNew); |
318 CollectGarbage(space, kInvokeApiCallbacks, kNewSpace); | 323 CollectGarbage(space, kInvokeApiCallbacks, kNewSpace); |
319 } | 324 } |
320 } | 325 } |
321 | 326 |
322 | 327 |
323 void Heap::CollectAllGarbage() { | 328 void Heap::CollectAllGarbage() { |
324 TIMERSCOPE(isolate(), time_gc); | 329 TIMERSCOPE(isolate(), time_gc); |
325 { | 330 { |
326 VMTagScope tagScope(isolate(), VMTag::kGCNewSpaceTagId); | 331 VMTagScope tagScope(isolate(), VMTag::kGCNewSpaceTagId); |
| 332 TimelineDurationScope tds(isolate()->GetGCStream(), |
| 333 "CollectNewGeneration"); |
327 RecordBeforeGC(kNew, kFull); | 334 RecordBeforeGC(kNew, kFull); |
328 UpdateClassHeapStatsBeforeGC(kNew); | 335 UpdateClassHeapStatsBeforeGC(kNew); |
329 new_space_->Scavenge(kInvokeApiCallbacks); | 336 new_space_->Scavenge(kInvokeApiCallbacks); |
330 isolate()->class_table()->UpdatePromoted(); | 337 isolate()->class_table()->UpdatePromoted(); |
331 UpdatePretenurePolicy(); | 338 UpdatePretenurePolicy(); |
332 RecordAfterGC(); | 339 RecordAfterGC(); |
333 PrintStats(); | 340 PrintStats(); |
334 } | 341 } |
335 { | 342 { |
336 VMTagScope tagScope(isolate(), VMTag::kGCOldSpaceTagId); | 343 VMTagScope tagScope(isolate(), VMTag::kGCOldSpaceTagId); |
| 344 TimelineDurationScope tds(isolate()->GetGCStream(), |
| 345 "CollectOldGeneration"); |
337 RecordBeforeGC(kOld, kFull); | 346 RecordBeforeGC(kOld, kFull); |
338 UpdateClassHeapStatsBeforeGC(kOld); | 347 UpdateClassHeapStatsBeforeGC(kOld); |
339 old_space_->MarkSweep(kInvokeApiCallbacks); | 348 old_space_->MarkSweep(kInvokeApiCallbacks); |
340 RecordAfterGC(); | 349 RecordAfterGC(); |
341 PrintStats(); | 350 PrintStats(); |
342 } | 351 } |
343 } | 352 } |
344 | 353 |
345 | 354 |
346 bool Heap::ShouldPretenure(intptr_t class_id) const { | 355 bool Heap::ShouldPretenure(intptr_t class_id) const { |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 heap->DisableGrowthControl(); | 710 heap->DisableGrowthControl(); |
702 } | 711 } |
703 | 712 |
704 | 713 |
705 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { | 714 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { |
706 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); | 715 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); |
707 heap->SetGrowthControlState(current_growth_controller_state_); | 716 heap->SetGrowthControlState(current_growth_controller_state_); |
708 } | 717 } |
709 | 718 |
710 } // namespace dart | 719 } // namespace dart |
OLD | NEW |