Chromium Code Reviews| 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" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 intptr_t max_new_gen_semi_words, | 31 intptr_t max_new_gen_semi_words, |
| 32 intptr_t max_old_gen_words, | 32 intptr_t max_old_gen_words, |
| 33 intptr_t max_external_words) | 33 intptr_t max_external_words) |
| 34 : isolate_(isolate), | 34 : isolate_(isolate), |
| 35 new_space_(this, max_new_gen_semi_words, kNewObjectAlignmentOffset), | 35 new_space_(this, max_new_gen_semi_words, kNewObjectAlignmentOffset), |
| 36 old_space_(this, max_old_gen_words, max_external_words), | 36 old_space_(this, max_old_gen_words, max_external_words), |
| 37 barrier_(new Monitor()), | 37 barrier_(new Monitor()), |
| 38 barrier_done_(new Monitor()), | 38 barrier_done_(new Monitor()), |
| 39 read_only_(false), | 39 read_only_(false), |
| 40 gc_new_space_in_progress_(false), | 40 gc_new_space_in_progress_(false), |
| 41 gc_old_space_in_progress_(false) { | 41 gc_old_space_in_progress_(false), |
| 42 debug_gc_in_progress_(false) { | |
| 42 UpdateGlobalMaxUsed(); | 43 UpdateGlobalMaxUsed(); |
| 43 for (int sel = 0; sel < kNumWeakSelectors; sel++) { | 44 for (int sel = 0; sel < kNumWeakSelectors; sel++) { |
| 44 new_weak_tables_[sel] = new WeakTable(); | 45 new_weak_tables_[sel] = new WeakTable(); |
| 45 old_weak_tables_[sel] = new WeakTable(); | 46 old_weak_tables_[sel] = new WeakTable(); |
| 46 } | 47 } |
| 47 stats_.num_ = 0; | 48 stats_.num_ = 0; |
| 48 } | 49 } |
| 49 | 50 |
| 50 | 51 |
| 51 Heap::~Heap() { | 52 Heap::~Heap() { |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 368 void Heap::CollectNewSpaceGarbage(Thread* thread, | 369 void Heap::CollectNewSpaceGarbage(Thread* thread, |
| 369 ApiCallbacks api_callbacks, | 370 ApiCallbacks api_callbacks, |
| 370 GCReason reason) { | 371 GCReason reason) { |
| 371 ASSERT((reason == kNewSpace) || (reason == kFull)); | 372 ASSERT((reason == kNewSpace) || (reason == kFull)); |
| 372 if (BeginNewSpaceGC(thread)) { | 373 if (BeginNewSpaceGC(thread)) { |
| 373 bool invoke_api_callbacks = (api_callbacks == kInvokeApiCallbacks); | 374 bool invoke_api_callbacks = (api_callbacks == kInvokeApiCallbacks); |
| 374 RecordBeforeGC(kNew, reason); | 375 RecordBeforeGC(kNew, reason); |
| 375 VMTagScope tagScope(thread, VMTag::kGCNewSpaceTagId); | 376 VMTagScope tagScope(thread, VMTag::kGCNewSpaceTagId); |
| 376 TIMELINE_FUNCTION_GC_DURATION(thread, "CollectNewGeneration"); | 377 TIMELINE_FUNCTION_GC_DURATION(thread, "CollectNewGeneration"); |
| 377 NOT_IN_PRODUCT(UpdateClassHeapStatsBeforeGC(kNew)); | 378 NOT_IN_PRODUCT(UpdateClassHeapStatsBeforeGC(kNew)); |
| 378 new_space_.Scavenge(invoke_api_callbacks); | 379 if (debug_gc_in_progress_) { |
| 380 new_space_.Evacuate(); | |
| 381 } else { | |
| 382 new_space_.Scavenge(invoke_api_callbacks); | |
| 383 } | |
| 379 NOT_IN_PRODUCT(isolate()->class_table()->UpdatePromoted()); | 384 NOT_IN_PRODUCT(isolate()->class_table()->UpdatePromoted()); |
| 380 RecordAfterGC(kNew); | 385 RecordAfterGC(kNew); |
| 381 PrintStats(); | 386 PrintStats(); |
| 382 NOT_IN_PRODUCT(PrintStatsToTimeline(&tds)); | 387 NOT_IN_PRODUCT(PrintStatsToTimeline(&tds)); |
| 383 EndNewSpaceGC(); | 388 EndNewSpaceGC(); |
| 384 if ((reason == kNewSpace) && old_space_.NeedsGarbageCollection()) { | 389 if ((reason == kNewSpace) && old_space_.NeedsGarbageCollection()) { |
| 385 // Old collections should call the API callbacks. | 390 // Old collections should call the API callbacks. |
| 386 CollectOldSpaceGarbage(thread, kInvokeApiCallbacks, kPromotion); | 391 CollectOldSpaceGarbage(thread, kInvokeApiCallbacks, kPromotion); |
| 387 } | 392 } |
| 388 } | 393 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 CollectOldSpaceGarbage(thread, kInvokeApiCallbacks, kOldSpace); | 442 CollectOldSpaceGarbage(thread, kInvokeApiCallbacks, kOldSpace); |
| 438 } else { | 443 } else { |
| 439 ASSERT(space == kNew); | 444 ASSERT(space == kNew); |
| 440 CollectNewSpaceGarbage(thread, kInvokeApiCallbacks, kNewSpace); | 445 CollectNewSpaceGarbage(thread, kInvokeApiCallbacks, kNewSpace); |
| 441 } | 446 } |
| 442 } | 447 } |
| 443 | 448 |
| 444 | 449 |
| 445 void Heap::CollectAllGarbage() { | 450 void Heap::CollectAllGarbage() { |
| 446 Thread* thread = Thread::Current(); | 451 Thread* thread = Thread::Current(); |
| 452 debug_gc_in_progress_ = true; | |
|
rmacnak
2017/06/19 19:29:00
Can this be
new_space_.Evacuate();
CollectOldSpac
| |
| 447 CollectNewSpaceGarbage(thread, kInvokeApiCallbacks, kFull); | 453 CollectNewSpaceGarbage(thread, kInvokeApiCallbacks, kFull); |
| 448 CollectOldSpaceGarbage(thread, kInvokeApiCallbacks, kFull); | 454 CollectOldSpaceGarbage(thread, kInvokeApiCallbacks, kFull); |
| 455 debug_gc_in_progress_ = false; | |
| 449 } | 456 } |
| 450 | 457 |
| 451 | 458 |
| 452 void Heap::WaitForSweeperTasks(Thread* thread) { | 459 void Heap::WaitForSweeperTasks(Thread* thread) { |
| 453 MonitorLocker ml(old_space_.tasks_lock()); | 460 MonitorLocker ml(old_space_.tasks_lock()); |
| 454 while (old_space_.tasks() > 0) { | 461 while (old_space_.tasks() > 0) { |
| 455 ml.WaitWithSafepointCheck(thread); | 462 ml.WaitWithSafepointCheck(thread); |
| 456 } | 463 } |
| 457 } | 464 } |
| 458 | 465 |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 854 Dart::vm_isolate()->heap()->WriteProtect(false); | 861 Dart::vm_isolate()->heap()->WriteProtect(false); |
| 855 } | 862 } |
| 856 | 863 |
| 857 | 864 |
| 858 WritableVMIsolateScope::~WritableVMIsolateScope() { | 865 WritableVMIsolateScope::~WritableVMIsolateScope() { |
| 859 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0); | 866 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0); |
| 860 Dart::vm_isolate()->heap()->WriteProtect(true); | 867 Dart::vm_isolate()->heap()->WriteProtect(true); |
| 861 } | 868 } |
| 862 | 869 |
| 863 } // namespace dart | 870 } // namespace dart |
| OLD | NEW |