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 "vm/dart.h" | 7 #include "vm/dart.h" |
8 #include "vm/dart_api_state.h" | 8 #include "vm/dart_api_state.h" |
9 #include "vm/isolate.h" | 9 #include "vm/isolate.h" |
10 #include "vm/lockers.h" | 10 #include "vm/lockers.h" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 RawObject* visiting_old_object_; | 190 RawObject* visiting_old_object_; |
191 | 191 |
192 friend class Scavenger; | 192 friend class Scavenger; |
193 | 193 |
194 DISALLOW_COPY_AND_ASSIGN(ScavengerVisitor); | 194 DISALLOW_COPY_AND_ASSIGN(ScavengerVisitor); |
195 }; | 195 }; |
196 | 196 |
197 | 197 |
198 class ScavengerWeakVisitor : public HandleVisitor { | 198 class ScavengerWeakVisitor : public HandleVisitor { |
199 public: | 199 public: |
200 ScavengerWeakVisitor(Thread* thread, | 200 ScavengerWeakVisitor(Thread* thread, Scavenger* scavenger) |
201 Scavenger* scavenger, | 201 : HandleVisitor(thread), scavenger_(scavenger) { |
202 FinalizationQueue* finalization_queue) | |
203 : HandleVisitor(thread), | |
204 scavenger_(scavenger), | |
205 queue_(finalization_queue) { | |
206 ASSERT(scavenger->heap_->isolate() == thread->isolate()); | 202 ASSERT(scavenger->heap_->isolate() == thread->isolate()); |
207 } | 203 } |
208 | 204 |
209 void VisitHandle(uword addr) { | 205 void VisitHandle(uword addr) { |
210 FinalizablePersistentHandle* handle = | 206 FinalizablePersistentHandle* handle = |
211 reinterpret_cast<FinalizablePersistentHandle*>(addr); | 207 reinterpret_cast<FinalizablePersistentHandle*>(addr); |
212 RawObject** p = handle->raw_addr(); | 208 RawObject** p = handle->raw_addr(); |
213 if (scavenger_->IsUnreachable(p)) { | 209 if (scavenger_->IsUnreachable(p)) { |
214 handle->UpdateUnreachable(thread()->isolate(), queue_); | 210 handle->UpdateUnreachable(thread()->isolate()); |
215 } else { | 211 } else { |
216 handle->UpdateRelocated(thread()->isolate()); | 212 handle->UpdateRelocated(thread()->isolate()); |
217 } | 213 } |
218 } | 214 } |
219 | 215 |
220 private: | 216 private: |
221 Scavenger* scavenger_; | 217 Scavenger* scavenger_; |
222 FinalizationQueue* queue_; | |
223 | 218 |
224 DISALLOW_COPY_AND_ASSIGN(ScavengerWeakVisitor); | 219 DISALLOW_COPY_AND_ASSIGN(ScavengerWeakVisitor); |
225 }; | 220 }; |
226 | 221 |
227 | 222 |
228 // Visitor used to verify that all old->new references have been added to the | 223 // Visitor used to verify that all old->new references have been added to the |
229 // StoreBuffers. | 224 // StoreBuffers. |
230 class VerifyStoreBufferPointerVisitor : public ObjectPointerVisitor { | 225 class VerifyStoreBufferPointerVisitor : public ObjectPointerVisitor { |
231 public: | 226 public: |
232 VerifyStoreBufferPointerVisitor(Isolate* isolate, const SemiSpace* to) | 227 VerifyStoreBufferPointerVisitor(Isolate* isolate, const SemiSpace* to) |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 StackZone zone(thread); | 811 StackZone zone(thread); |
817 // Setup the visitor and run the scavenge. | 812 // Setup the visitor and run the scavenge. |
818 ScavengerVisitor visitor(isolate, this, from); | 813 ScavengerVisitor visitor(isolate, this, from); |
819 page_space->AcquireDataLock(); | 814 page_space->AcquireDataLock(); |
820 IterateRoots(isolate, &visitor); | 815 IterateRoots(isolate, &visitor); |
821 int64_t start = OS::GetCurrentMonotonicMicros(); | 816 int64_t start = OS::GetCurrentMonotonicMicros(); |
822 ProcessToSpace(&visitor); | 817 ProcessToSpace(&visitor); |
823 int64_t middle = OS::GetCurrentMonotonicMicros(); | 818 int64_t middle = OS::GetCurrentMonotonicMicros(); |
824 { | 819 { |
825 TIMELINE_FUNCTION_GC_DURATION(thread, "WeakHandleProcessing"); | 820 TIMELINE_FUNCTION_GC_DURATION(thread, "WeakHandleProcessing"); |
826 if (FLAG_background_finalization) { | 821 ScavengerWeakVisitor weak_visitor(thread, this); |
827 FinalizationQueue* queue = new FinalizationQueue(); | 822 IterateWeakRoots(isolate, &weak_visitor); |
828 ScavengerWeakVisitor weak_visitor(thread, this, queue); | |
829 IterateWeakRoots(isolate, &weak_visitor); | |
830 if (queue->length() > 0) { | |
831 Dart::thread_pool()->Run(new BackgroundFinalizer(isolate, queue)); | |
832 } else { | |
833 delete queue; | |
834 } | |
835 } else { | |
836 ScavengerWeakVisitor weak_visitor(thread, this, NULL); | |
837 IterateWeakRoots(isolate, &weak_visitor); | |
838 } | |
839 } | 823 } |
840 ProcessWeakReferences(); | 824 ProcessWeakReferences(); |
841 page_space->ReleaseDataLock(); | 825 page_space->ReleaseDataLock(); |
842 | 826 |
843 // Scavenge finished. Run accounting. | 827 // Scavenge finished. Run accounting. |
844 int64_t end = OS::GetCurrentMonotonicMicros(); | 828 int64_t end = OS::GetCurrentMonotonicMicros(); |
845 heap_->RecordTime(kProcessToSpace, middle - start); | 829 heap_->RecordTime(kProcessToSpace, middle - start); |
846 heap_->RecordTime(kIterateWeaks, end - middle); | 830 heap_->RecordTime(kIterateWeaks, end - middle); |
847 stats_history_.Add(ScavengeStats( | 831 stats_history_.Add(ScavengeStats( |
848 start, end, usage_before, GetCurrentUsage(), promo_candidate_words, | 832 start, end, usage_before, GetCurrentUsage(), promo_candidate_words, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 } | 890 } |
907 | 891 |
908 | 892 |
909 void Scavenger::FreeExternal(intptr_t size) { | 893 void Scavenger::FreeExternal(intptr_t size) { |
910 ASSERT(size >= 0); | 894 ASSERT(size >= 0); |
911 external_size_ -= size; | 895 external_size_ -= size; |
912 ASSERT(external_size_ >= 0); | 896 ASSERT(external_size_ >= 0); |
913 } | 897 } |
914 | 898 |
915 } // namespace dart | 899 } // namespace dart |
OLD | NEW |