| 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 |
| 11 #include "vm/dart.h" | 11 #include "vm/dart.h" |
| 12 #include "vm/dart_api_state.h" | 12 #include "vm/dart_api_state.h" |
| 13 #include "vm/isolate.h" | 13 #include "vm/isolate.h" |
| 14 #include "vm/lockers.h" | 14 #include "vm/lockers.h" |
| 15 #include "vm/object.h" | 15 #include "vm/object.h" |
| 16 #include "vm/object_id_ring.h" | 16 #include "vm/object_id_ring.h" |
| 17 #include "vm/safepoint.h" |
| 17 #include "vm/stack_frame.h" | 18 #include "vm/stack_frame.h" |
| 18 #include "vm/store_buffer.h" | 19 #include "vm/store_buffer.h" |
| 19 #include "vm/thread_registry.h" | 20 #include "vm/thread_registry.h" |
| 20 #include "vm/verified_memory.h" | 21 #include "vm/verified_memory.h" |
| 21 #include "vm/verifier.h" | 22 #include "vm/verifier.h" |
| 22 #include "vm/visitor.h" | 23 #include "vm/visitor.h" |
| 23 #include "vm/weak_table.h" | 24 #include "vm/weak_table.h" |
| 24 | 25 |
| 25 namespace dart { | 26 namespace dart { |
| 26 | 27 |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 } else { | 443 } else { |
| 443 return old_size_in_words; | 444 return old_size_in_words; |
| 444 } | 445 } |
| 445 } | 446 } |
| 446 | 447 |
| 447 | 448 |
| 448 SemiSpace* Scavenger::Prologue(Isolate* isolate, bool invoke_api_callbacks) { | 449 SemiSpace* Scavenger::Prologue(Isolate* isolate, bool invoke_api_callbacks) { |
| 449 if (invoke_api_callbacks && (isolate->gc_prologue_callback() != NULL)) { | 450 if (invoke_api_callbacks && (isolate->gc_prologue_callback() != NULL)) { |
| 450 (isolate->gc_prologue_callback())(); | 451 (isolate->gc_prologue_callback())(); |
| 451 } | 452 } |
| 452 isolate->thread_registry()->PrepareForGC(); | 453 isolate->PrepareForGC(); |
| 453 // Flip the two semi-spaces so that to_ is always the space for allocating | 454 // Flip the two semi-spaces so that to_ is always the space for allocating |
| 454 // objects. | 455 // objects. |
| 455 SemiSpace* from = to_; | 456 SemiSpace* from = to_; |
| 456 to_ = SemiSpace::New(NewSizeInWords(from->size_in_words())); | 457 to_ = SemiSpace::New(NewSizeInWords(from->size_in_words())); |
| 457 if (to_ == NULL) { | 458 if (to_ == NULL) { |
| 458 // TODO(koda): We could try to recover (collect old space, wait for another | 459 // TODO(koda): We could try to recover (collect old space, wait for another |
| 459 // isolate to finish scavenge, etc.). | 460 // isolate to finish scavenge, etc.). |
| 460 FATAL("Out of memory.\n"); | 461 FATAL("Out of memory.\n"); |
| 461 } | 462 } |
| 462 UpdateMaxHeapCapacity(); | 463 UpdateMaxHeapCapacity(); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 } | 757 } |
| 757 | 758 |
| 758 | 759 |
| 759 void Scavenger::Scavenge(bool invoke_api_callbacks) { | 760 void Scavenger::Scavenge(bool invoke_api_callbacks) { |
| 760 Isolate* isolate = heap_->isolate(); | 761 Isolate* isolate = heap_->isolate(); |
| 761 // Ensure that all threads for this isolate are at a safepoint (either stopped | 762 // Ensure that all threads for this isolate are at a safepoint (either stopped |
| 762 // or in native code). If two threads are racing at this point, the loser | 763 // or in native code). If two threads are racing at this point, the loser |
| 763 // will continue with its scavenge after waiting for the winner to complete. | 764 // will continue with its scavenge after waiting for the winner to complete. |
| 764 // TODO(koda): Consider moving SafepointThreads into allocation failure/retry | 765 // TODO(koda): Consider moving SafepointThreads into allocation failure/retry |
| 765 // logic to avoid needless collections. | 766 // logic to avoid needless collections. |
| 766 isolate->thread_registry()->SafepointThreads(); | 767 SafepointOperationScope safepoint_scope(Thread::Current()); |
| 767 | 768 |
| 768 // Scavenging is not reentrant. Make sure that is the case. | 769 // Scavenging is not reentrant. Make sure that is the case. |
| 769 ASSERT(!scavenging_); | 770 ASSERT(!scavenging_); |
| 770 scavenging_ = true; | 771 scavenging_ = true; |
| 771 | 772 |
| 772 PageSpace* page_space = heap_->old_space(); | 773 PageSpace* page_space = heap_->old_space(); |
| 773 NoSafepointScope no_safepoints; | 774 NoSafepointScope no_safepoints; |
| 774 | 775 |
| 775 // TODO(koda): Make verification more compatible with concurrent sweep. | 776 // TODO(koda): Make verification more compatible with concurrent sweep. |
| 776 if (FLAG_verify_before_gc && !FLAG_concurrent_sweep) { | 777 if (FLAG_verify_before_gc && !FLAG_concurrent_sweep) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 // TODO(koda): Make verification more compatible with concurrent sweep. | 817 // TODO(koda): Make verification more compatible with concurrent sweep. |
| 817 if (FLAG_verify_after_gc && !FLAG_concurrent_sweep) { | 818 if (FLAG_verify_after_gc && !FLAG_concurrent_sweep) { |
| 818 OS::PrintErr("Verifying after Scavenge..."); | 819 OS::PrintErr("Verifying after Scavenge..."); |
| 819 heap_->Verify(kForbidMarked); | 820 heap_->Verify(kForbidMarked); |
| 820 OS::PrintErr(" done.\n"); | 821 OS::PrintErr(" done.\n"); |
| 821 } | 822 } |
| 822 | 823 |
| 823 // Done scavenging. Reset the marker. | 824 // Done scavenging. Reset the marker. |
| 824 ASSERT(scavenging_); | 825 ASSERT(scavenging_); |
| 825 scavenging_ = false; | 826 scavenging_ = false; |
| 826 | |
| 827 isolate->thread_registry()->ResumeAllThreads(); | |
| 828 } | 827 } |
| 829 | 828 |
| 830 | 829 |
| 831 void Scavenger::WriteProtect(bool read_only) { | 830 void Scavenger::WriteProtect(bool read_only) { |
| 832 ASSERT(!scavenging_); | 831 ASSERT(!scavenging_); |
| 833 to_->WriteProtect(read_only); | 832 to_->WriteProtect(read_only); |
| 834 } | 833 } |
| 835 | 834 |
| 836 | 835 |
| 837 void Scavenger::PrintToJSONObject(JSONObject* object) const { | 836 void Scavenger::PrintToJSONObject(JSONObject* object) const { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 866 } | 865 } |
| 867 | 866 |
| 868 | 867 |
| 869 void Scavenger::FreeExternal(intptr_t size) { | 868 void Scavenger::FreeExternal(intptr_t size) { |
| 870 ASSERT(size >= 0); | 869 ASSERT(size >= 0); |
| 871 external_size_ -= size; | 870 external_size_ -= size; |
| 872 ASSERT(external_size_ >= 0); | 871 ASSERT(external_size_ >= 0); |
| 873 } | 872 } |
| 874 | 873 |
| 875 } // namespace dart | 874 } // namespace dart |
| OLD | NEW |