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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 void Heap::UpdateClassHeapStatsBeforeGC(Heap::Space space) { | 401 void Heap::UpdateClassHeapStatsBeforeGC(Heap::Space space) { |
402 ClassTable* class_table = isolate()->class_table(); | 402 ClassTable* class_table = isolate()->class_table(); |
403 if (space == kNew) { | 403 if (space == kNew) { |
404 class_table->ResetCountersNew(); | 404 class_table->ResetCountersNew(); |
405 } else { | 405 } else { |
406 class_table->ResetCountersOld(); | 406 class_table->ResetCountersOld(); |
407 } | 407 } |
408 } | 408 } |
409 #endif | 409 #endif |
410 | 410 |
| 411 void Heap::NotifyIdle(int64_t deadline) { |
| 412 if (new_space_.ShouldPerformIdleScavenge(deadline)) { |
| 413 Thread* thread = Thread::Current(); |
| 414 TIMELINE_FUNCTION_GC_DURATION(thread, "IdleGC"); |
| 415 int64_t start = OS::GetCurrentMonotonicMicros(); |
| 416 CollectNewSpaceGarbage(thread, kIdle); |
| 417 int64_t end = OS::GetCurrentMonotonicMicros(); |
| 418 OS::Print("idle scavenge duration=%" Pd64 "us headroom=%" Pd64 "us\n", |
| 419 end - start, deadline - end); |
| 420 } |
| 421 } |
| 422 |
411 void Heap::EvacuateNewSpace(Thread* thread, GCReason reason) { | 423 void Heap::EvacuateNewSpace(Thread* thread, GCReason reason) { |
412 ASSERT(reason == kFull); | 424 ASSERT(reason == kFull); |
413 if (BeginNewSpaceGC(thread)) { | 425 if (BeginNewSpaceGC(thread)) { |
414 RecordBeforeGC(kNew, kFull); | 426 RecordBeforeGC(kNew, kFull); |
415 VMTagScope tagScope(thread, VMTag::kGCNewSpaceTagId); | 427 VMTagScope tagScope(thread, VMTag::kGCNewSpaceTagId); |
416 TIMELINE_FUNCTION_GC_DURATION(thread, "EvacuateNewGeneration"); | 428 TIMELINE_FUNCTION_GC_DURATION(thread, "EvacuateNewGeneration"); |
417 NOT_IN_PRODUCT(UpdateClassHeapStatsBeforeGC(kNew)); | 429 NOT_IN_PRODUCT(UpdateClassHeapStatsBeforeGC(kNew)); |
418 new_space_.Evacuate(); | 430 new_space_.Evacuate(); |
419 NOT_IN_PRODUCT(isolate()->class_table()->UpdatePromoted()); | 431 NOT_IN_PRODUCT(isolate()->class_table()->UpdatePromoted()); |
420 RecordAfterGC(kNew); | 432 RecordAfterGC(kNew); |
421 PrintStats(); | 433 PrintStats(); |
422 NOT_IN_PRODUCT(PrintStatsToTimeline(&tds)); | 434 NOT_IN_PRODUCT(PrintStatsToTimeline(&tds)); |
423 EndNewSpaceGC(); | 435 EndNewSpaceGC(); |
424 } | 436 } |
425 } | 437 } |
426 | 438 |
427 void Heap::CollectNewSpaceGarbage(Thread* thread, | 439 void Heap::CollectNewSpaceGarbage(Thread* thread, |
428 GCReason reason) { | 440 GCReason reason) { |
429 ASSERT((reason == kNewSpace) || (reason == kFull)); | 441 ASSERT((reason == kNewSpace) || (reason == kFull) || (reason == kIdle)); |
430 if (BeginNewSpaceGC(thread)) { | 442 if (BeginNewSpaceGC(thread)) { |
431 RecordBeforeGC(kNew, reason); | 443 RecordBeforeGC(kNew, reason); |
432 { | 444 { |
433 VMTagScope tagScope(thread, VMTag::kGCNewSpaceTagId); | 445 VMTagScope tagScope(thread, VMTag::kGCNewSpaceTagId); |
434 TIMELINE_FUNCTION_GC_DURATION(thread, "CollectNewGeneration"); | 446 TIMELINE_FUNCTION_GC_DURATION(thread, "CollectNewGeneration"); |
435 NOT_IN_PRODUCT(UpdateClassHeapStatsBeforeGC(kNew)); | 447 NOT_IN_PRODUCT(UpdateClassHeapStatsBeforeGC(kNew)); |
436 new_space_.Scavenge(); | 448 new_space_.Scavenge(); |
437 NOT_IN_PRODUCT(isolate()->class_table()->UpdatePromoted()); | 449 NOT_IN_PRODUCT(isolate()->class_table()->UpdatePromoted()); |
438 RecordAfterGC(kNew); | 450 RecordAfterGC(kNew); |
439 PrintStats(); | 451 PrintStats(); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 const char* Heap::GCReasonToString(GCReason gc_reason) { | 685 const char* Heap::GCReasonToString(GCReason gc_reason) { |
674 switch (gc_reason) { | 686 switch (gc_reason) { |
675 case kNewSpace: | 687 case kNewSpace: |
676 return "new space"; | 688 return "new space"; |
677 case kPromotion: | 689 case kPromotion: |
678 return "promotion"; | 690 return "promotion"; |
679 case kOldSpace: | 691 case kOldSpace: |
680 return "old space"; | 692 return "old space"; |
681 case kFull: | 693 case kFull: |
682 return "full"; | 694 return "full"; |
| 695 case kIdle: |
| 696 return "idle"; |
683 case kGCAtAlloc: | 697 case kGCAtAlloc: |
684 return "debugging"; | 698 return "debugging"; |
685 case kGCTestCase: | 699 case kGCTestCase: |
686 return "test case"; | 700 return "test case"; |
687 default: | 701 default: |
688 UNREACHABLE(); | 702 UNREACHABLE(); |
689 return ""; | 703 return ""; |
690 } | 704 } |
691 } | 705 } |
692 | 706 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
896 : StackResource(thread) { | 910 : StackResource(thread) { |
897 Dart::vm_isolate()->heap()->WriteProtect(false); | 911 Dart::vm_isolate()->heap()->WriteProtect(false); |
898 } | 912 } |
899 | 913 |
900 WritableVMIsolateScope::~WritableVMIsolateScope() { | 914 WritableVMIsolateScope::~WritableVMIsolateScope() { |
901 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0); | 915 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0); |
902 Dart::vm_isolate()->heap()->WriteProtect(true); | 916 Dart::vm_isolate()->heap()->WriteProtect(true); |
903 } | 917 } |
904 | 918 |
905 } // namespace dart | 919 } // namespace dart |
OLD | NEW |