| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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/scavenger.h" | 5 #include "vm/scavenger.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 // isolate to finish scavenge, etc.). | 468 // isolate to finish scavenge, etc.). |
| 469 FATAL("Out of memory.\n"); | 469 FATAL("Out of memory.\n"); |
| 470 } | 470 } |
| 471 top_ = FirstObjectStart(); | 471 top_ = FirstObjectStart(); |
| 472 resolved_top_ = top_; | 472 resolved_top_ = top_; |
| 473 end_ = to_->end(); | 473 end_ = to_->end(); |
| 474 } | 474 } |
| 475 | 475 |
| 476 | 476 |
| 477 void Scavenger::Epilogue(Isolate* isolate, | 477 void Scavenger::Epilogue(Isolate* isolate, |
| 478 ScavengerVisitor* visitor, | |
| 479 bool invoke_api_callbacks) { | 478 bool invoke_api_callbacks) { |
| 480 // All objects in the to space have been copied from the from space at this | 479 // All objects in the to space have been copied from the from space at this |
| 481 // moment. | 480 // moment. |
| 482 double avg_frac = stats_history_.Get(0).PromoCandidatesSuccessFraction(); | 481 double avg_frac = stats_history_.Get(0).PromoCandidatesSuccessFraction(); |
| 483 if (stats_history_.Size() >= 2) { | 482 if (stats_history_.Size() >= 2) { |
| 484 // Previous scavenge is only given half as much weight. | 483 // Previous scavenge is only given half as much weight. |
| 485 avg_frac += 0.5 * stats_history_.Get(1).PromoCandidatesSuccessFraction(); | 484 avg_frac += 0.5 * stats_history_.Get(1).PromoCandidatesSuccessFraction(); |
| 486 avg_frac /= 1.0 + 0.5; // Normalize. | 485 avg_frac /= 1.0 + 0.5; // Normalize. |
| 487 } | 486 } |
| 488 if (avg_frac < (FLAG_early_tenuring_threshold / 100.0)) { | 487 if (avg_frac < (FLAG_early_tenuring_threshold / 100.0)) { |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 OS::PrintErr("Verifying before Scavenge..."); | 810 OS::PrintErr("Verifying before Scavenge..."); |
| 812 heap_->Verify(kForbidMarked); | 811 heap_->Verify(kForbidMarked); |
| 813 OS::PrintErr(" done.\n"); | 812 OS::PrintErr(" done.\n"); |
| 814 } | 813 } |
| 815 | 814 |
| 816 // Prepare for a scavenge. | 815 // Prepare for a scavenge. |
| 817 SpaceUsage usage_before = GetCurrentUsage(); | 816 SpaceUsage usage_before = GetCurrentUsage(); |
| 818 intptr_t promo_candidate_words = | 817 intptr_t promo_candidate_words = |
| 819 (survivor_end_ - FirstObjectStart()) / kWordSize; | 818 (survivor_end_ - FirstObjectStart()) / kWordSize; |
| 820 Prologue(isolate, invoke_api_callbacks); | 819 Prologue(isolate, invoke_api_callbacks); |
| 821 const bool prologue_weak_are_strong = !invoke_api_callbacks; | 820 // The API prologue/epilogue may create/destroy zones, so we must not |
| 821 // depend on zone allocations surviving beyond the epilogue callback. |
| 822 { |
| 823 StackZone zone(isolate); |
| 824 // Setup the visitor and run the scavenge. |
| 825 ScavengerVisitor visitor(isolate, this); |
| 826 page_space->AcquireDataLock(); |
| 827 const bool prologue_weak_are_strong = !invoke_api_callbacks; |
| 828 IterateRoots(isolate, &visitor, prologue_weak_are_strong); |
| 829 int64_t start = OS::GetCurrentTimeMicros(); |
| 830 ProcessToSpace(&visitor); |
| 831 int64_t middle = OS::GetCurrentTimeMicros(); |
| 832 IterateWeakReferences(isolate, &visitor); |
| 833 ScavengerWeakVisitor weak_visitor(this, prologue_weak_are_strong); |
| 834 // Include the prologue weak handles, since we must process any promotion. |
| 835 const bool visit_prologue_weak_handles = true; |
| 836 IterateWeakRoots(isolate, &weak_visitor, visit_prologue_weak_handles); |
| 837 visitor.Finalize(); |
| 838 ProcessWeakTables(); |
| 839 page_space->ReleaseDataLock(); |
| 822 | 840 |
| 823 // Setup the visitor and run the scavenge. | 841 // Scavenge finished. Run accounting. |
| 824 ScavengerVisitor visitor(isolate, this); | 842 int64_t end = OS::GetCurrentTimeMicros(); |
| 825 page_space->AcquireDataLock(); | 843 heap_->RecordTime(kProcessToSpace, middle - start); |
| 826 IterateRoots(isolate, &visitor, prologue_weak_are_strong); | 844 heap_->RecordTime(kIterateWeaks, end - middle); |
| 827 int64_t start = OS::GetCurrentTimeMicros(); | 845 stats_history_.Add( |
| 828 ProcessToSpace(&visitor); | 846 ScavengeStats(start, end, |
| 829 int64_t middle = OS::GetCurrentTimeMicros(); | 847 usage_before, GetCurrentUsage(), |
| 830 IterateWeakReferences(isolate, &visitor); | 848 promo_candidate_words, |
| 831 ScavengerWeakVisitor weak_visitor(this, prologue_weak_are_strong); | 849 visitor.bytes_promoted() >> kWordSizeLog2)); |
| 832 // Include the prologue weak handles, since we must process any promotion. | 850 } |
| 833 const bool visit_prologue_weak_handles = true; | 851 Epilogue(isolate, invoke_api_callbacks); |
| 834 IterateWeakRoots(isolate, &weak_visitor, visit_prologue_weak_handles); | |
| 835 visitor.Finalize(); | |
| 836 ProcessWeakTables(); | |
| 837 page_space->ReleaseDataLock(); | |
| 838 | |
| 839 // Scavenge finished. Run accounting and epilogue. | |
| 840 int64_t end = OS::GetCurrentTimeMicros(); | |
| 841 heap_->RecordTime(kProcessToSpace, middle - start); | |
| 842 heap_->RecordTime(kIterateWeaks, end - middle); | |
| 843 stats_history_.Add(ScavengeStats(start, end, | |
| 844 usage_before, GetCurrentUsage(), | |
| 845 promo_candidate_words, | |
| 846 visitor.bytes_promoted() >> kWordSizeLog2)); | |
| 847 Epilogue(isolate, &visitor, invoke_api_callbacks); | |
| 848 | 852 |
| 849 // TODO(koda): Make verification more compatible with concurrent sweep. | 853 // TODO(koda): Make verification more compatible with concurrent sweep. |
| 850 if (FLAG_verify_after_gc && !FLAG_concurrent_sweep) { | 854 if (FLAG_verify_after_gc && !FLAG_concurrent_sweep) { |
| 851 OS::PrintErr("Verifying after Scavenge..."); | 855 OS::PrintErr("Verifying after Scavenge..."); |
| 852 heap_->Verify(kForbidMarked); | 856 heap_->Verify(kForbidMarked); |
| 853 OS::PrintErr(" done.\n"); | 857 OS::PrintErr(" done.\n"); |
| 854 } | 858 } |
| 855 | 859 |
| 856 // Done scavenging. Reset the marker. | 860 // Done scavenging. Reset the marker. |
| 857 ASSERT(scavenging_); | 861 ASSERT(scavenging_); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 } | 903 } |
| 900 | 904 |
| 901 | 905 |
| 902 void Scavenger::FreeExternal(intptr_t size) { | 906 void Scavenger::FreeExternal(intptr_t size) { |
| 903 ASSERT(size >= 0); | 907 ASSERT(size >= 0); |
| 904 external_size_ -= size; | 908 external_size_ -= size; |
| 905 ASSERT(external_size_ >= 0); | 909 ASSERT(external_size_ >= 0); |
| 906 } | 910 } |
| 907 | 911 |
| 908 } // namespace dart | 912 } // namespace dart |
| OLD | NEW |