| 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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 bool invoke_api_callbacks = (api_callbacks == kInvokeApiCallbacks); | 374 bool invoke_api_callbacks = (api_callbacks == kInvokeApiCallbacks); |
| 375 RecordBeforeGC(kNew, reason); | 375 RecordBeforeGC(kNew, reason); |
| 376 VMTagScope tagScope(thread, VMTag::kGCNewSpaceTagId); | 376 VMTagScope tagScope(thread, VMTag::kGCNewSpaceTagId); |
| 377 TIMELINE_FUNCTION_GC_DURATION(thread, "CollectNewGeneration"); | 377 TIMELINE_FUNCTION_GC_DURATION(thread, "CollectNewGeneration"); |
| 378 UpdateClassHeapStatsBeforeGC(kNew); | 378 UpdateClassHeapStatsBeforeGC(kNew); |
| 379 new_space_.Scavenge(invoke_api_callbacks); | 379 new_space_.Scavenge(invoke_api_callbacks); |
| 380 isolate()->class_table()->UpdatePromoted(); | 380 isolate()->class_table()->UpdatePromoted(); |
| 381 UpdatePretenurePolicy(); | 381 UpdatePretenurePolicy(); |
| 382 RecordAfterGC(kNew); | 382 RecordAfterGC(kNew); |
| 383 PrintStats(); | 383 PrintStats(); |
| 384 NOT_IN_PRODUCT(PrintStatsToTimeline(&tds)); |
| 384 EndNewSpaceGC(); | 385 EndNewSpaceGC(); |
| 385 if ((reason == kNewSpace) && old_space_.NeedsGarbageCollection()) { | 386 if ((reason == kNewSpace) && old_space_.NeedsGarbageCollection()) { |
| 386 // Old collections should call the API callbacks. | 387 // Old collections should call the API callbacks. |
| 387 CollectOldSpaceGarbage(thread, kInvokeApiCallbacks, kPromotion); | 388 CollectOldSpaceGarbage(thread, kInvokeApiCallbacks, kPromotion); |
| 388 } | 389 } |
| 389 } | 390 } |
| 390 } | 391 } |
| 391 | 392 |
| 392 | 393 |
| 393 void Heap::CollectOldSpaceGarbage(Thread* thread, | 394 void Heap::CollectOldSpaceGarbage(Thread* thread, |
| 394 ApiCallbacks api_callbacks, | 395 ApiCallbacks api_callbacks, |
| 395 GCReason reason) { | 396 GCReason reason) { |
| 396 ASSERT((reason != kNewSpace)); | 397 ASSERT((reason != kNewSpace)); |
| 397 if (BeginOldSpaceGC(thread)) { | 398 if (BeginOldSpaceGC(thread)) { |
| 398 bool invoke_api_callbacks = (api_callbacks == kInvokeApiCallbacks); | 399 bool invoke_api_callbacks = (api_callbacks == kInvokeApiCallbacks); |
| 399 RecordBeforeGC(kOld, reason); | 400 RecordBeforeGC(kOld, reason); |
| 400 VMTagScope tagScope(thread, VMTag::kGCOldSpaceTagId); | 401 VMTagScope tagScope(thread, VMTag::kGCOldSpaceTagId); |
| 401 TIMELINE_FUNCTION_GC_DURATION(thread, "CollectOldGeneration"); | 402 TIMELINE_FUNCTION_GC_DURATION(thread, "CollectOldGeneration"); |
| 402 UpdateClassHeapStatsBeforeGC(kOld); | 403 UpdateClassHeapStatsBeforeGC(kOld); |
| 403 old_space_.MarkSweep(invoke_api_callbacks); | 404 old_space_.MarkSweep(invoke_api_callbacks); |
| 404 RecordAfterGC(kOld); | 405 RecordAfterGC(kOld); |
| 405 PrintStats(); | 406 PrintStats(); |
| 407 NOT_IN_PRODUCT(PrintStatsToTimeline(&tds)); |
| 406 EndOldSpaceGC(); | 408 EndOldSpaceGC(); |
| 407 } | 409 } |
| 408 } | 410 } |
| 409 | 411 |
| 410 | 412 |
| 411 void Heap::CollectGarbage(Space space, | 413 void Heap::CollectGarbage(Space space, |
| 412 ApiCallbacks api_callbacks, | 414 ApiCallbacks api_callbacks, |
| 413 GCReason reason) { | 415 GCReason reason) { |
| 414 Thread* thread = Thread::Current(); | 416 Thread* thread = Thread::Current(); |
| 415 switch (space) { | 417 switch (space) { |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 MicrosecondsToMilliseconds(stats_.times_[1]), | 829 MicrosecondsToMilliseconds(stats_.times_[1]), |
| 828 MicrosecondsToMilliseconds(stats_.times_[2]), | 830 MicrosecondsToMilliseconds(stats_.times_[2]), |
| 829 MicrosecondsToMilliseconds(stats_.times_[3]), | 831 MicrosecondsToMilliseconds(stats_.times_[3]), |
| 830 stats_.data_[0], | 832 stats_.data_[0], |
| 831 stats_.data_[1], | 833 stats_.data_[1], |
| 832 stats_.data_[2], | 834 stats_.data_[2], |
| 833 stats_.data_[3]); | 835 stats_.data_[3]); |
| 834 } | 836 } |
| 835 | 837 |
| 836 | 838 |
| 839 void Heap::PrintStatsToTimeline(TimelineEventScope* event) { |
| 840 if ((event == NULL) || !event->enabled()) { |
| 841 return; |
| 842 } |
| 843 event->SetNumArguments(12); |
| 844 event->FormatArgument(0, |
| 845 "Before.New.Used (kB)", |
| 846 "%" Pd "", |
| 847 RoundWordsToKB(stats_.before_.new_.used_in_words)); |
| 848 event->FormatArgument(1, |
| 849 "After.New.Used (kB)", |
| 850 "%" Pd "", |
| 851 RoundWordsToKB(stats_.after_.new_.used_in_words)); |
| 852 event->FormatArgument(2, |
| 853 "Before.Old.Used (kB)", |
| 854 "%" Pd "", |
| 855 RoundWordsToKB(stats_.before_.old_.used_in_words)); |
| 856 event->FormatArgument(3, |
| 857 "After.Old.Used (kB)", |
| 858 "%" Pd "", |
| 859 RoundWordsToKB(stats_.after_.old_.used_in_words)); |
| 860 |
| 861 event->FormatArgument(4, |
| 862 "Before.New.Capacity (kB)", |
| 863 "%" Pd "", |
| 864 RoundWordsToKB(stats_.before_.new_.capacity_in_words)); |
| 865 event->FormatArgument(5, |
| 866 "After.New.Capacity (kB)", |
| 867 "%" Pd "", |
| 868 RoundWordsToKB(stats_.after_.new_.capacity_in_words)); |
| 869 event->FormatArgument(6, |
| 870 "Before.Old.Capacity (kB)", |
| 871 "%" Pd "", |
| 872 RoundWordsToKB(stats_.before_.old_.capacity_in_words)); |
| 873 event->FormatArgument(7, |
| 874 "After.Old.Capacity (kB)", |
| 875 "%" Pd "", |
| 876 RoundWordsToKB(stats_.after_.old_.capacity_in_words)); |
| 877 |
| 878 event->FormatArgument(8, |
| 879 "Before.New.External (kB)", |
| 880 "%" Pd "", |
| 881 RoundWordsToKB(stats_.before_.new_.external_in_words)); |
| 882 event->FormatArgument(9, |
| 883 "After.New.External (kB)", |
| 884 "%" Pd "", |
| 885 RoundWordsToKB(stats_.after_.new_.external_in_words)); |
| 886 event->FormatArgument(10, |
| 887 "Before.Old.External (kB)", |
| 888 "%" Pd "", |
| 889 RoundWordsToKB(stats_.before_.old_.external_in_words)); |
| 890 event->FormatArgument(11, |
| 891 "After.Old.External (kB)", |
| 892 "%" Pd "", |
| 893 RoundWordsToKB(stats_.after_.old_.external_in_words)); |
| 894 } |
| 895 |
| 896 |
| 837 NoHeapGrowthControlScope::NoHeapGrowthControlScope() | 897 NoHeapGrowthControlScope::NoHeapGrowthControlScope() |
| 838 : StackResource(Thread::Current()) { | 898 : StackResource(Thread::Current()) { |
| 839 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); | 899 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); |
| 840 current_growth_controller_state_ = heap->GrowthControlState(); | 900 current_growth_controller_state_ = heap->GrowthControlState(); |
| 841 heap->DisableGrowthControl(); | 901 heap->DisableGrowthControl(); |
| 842 } | 902 } |
| 843 | 903 |
| 844 | 904 |
| 845 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { | 905 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { |
| 846 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); | 906 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); |
| 847 heap->SetGrowthControlState(current_growth_controller_state_); | 907 heap->SetGrowthControlState(current_growth_controller_state_); |
| 848 } | 908 } |
| 849 | 909 |
| 850 | 910 |
| 851 WritableVMIsolateScope::WritableVMIsolateScope(Thread* thread) | 911 WritableVMIsolateScope::WritableVMIsolateScope(Thread* thread) |
| 852 : StackResource(thread) { | 912 : StackResource(thread) { |
| 853 Dart::vm_isolate()->heap()->WriteProtect(false); | 913 Dart::vm_isolate()->heap()->WriteProtect(false); |
| 854 } | 914 } |
| 855 | 915 |
| 856 | 916 |
| 857 WritableVMIsolateScope::~WritableVMIsolateScope() { | 917 WritableVMIsolateScope::~WritableVMIsolateScope() { |
| 858 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0); | 918 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0); |
| 859 Dart::vm_isolate()->heap()->WriteProtect(true); | 919 Dart::vm_isolate()->heap()->WriteProtect(true); |
| 860 } | 920 } |
| 861 | 921 |
| 862 } // namespace dart | 922 } // namespace dart |
| OLD | NEW |