Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(339)

Side by Side Diff: runtime/vm/scavenger.cc

Issue 2012973002: Background finalization. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/profiler.h ('k') | runtime/vm/thread.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 RawObject* visiting_old_object_; 186 RawObject* visiting_old_object_;
187 187
188 friend class Scavenger; 188 friend class Scavenger;
189 189
190 DISALLOW_COPY_AND_ASSIGN(ScavengerVisitor); 190 DISALLOW_COPY_AND_ASSIGN(ScavengerVisitor);
191 }; 191 };
192 192
193 193
194 class ScavengerWeakVisitor : public HandleVisitor { 194 class ScavengerWeakVisitor : public HandleVisitor {
195 public: 195 public:
196 explicit ScavengerWeakVisitor(Scavenger* scavenger) 196 ScavengerWeakVisitor(Thread* thread,
197 : HandleVisitor(Thread::Current()), 197 Scavenger* scavenger,
198 scavenger_(scavenger) { 198 FinalizationQueue* finalization_queue) :
199 ASSERT(scavenger->heap_->isolate() == Thread::Current()->isolate()); 199 HandleVisitor(thread),
200 scavenger_(scavenger),
201 queue_(finalization_queue) {
202 ASSERT(scavenger->heap_->isolate() == thread->isolate());
200 } 203 }
201 204
202 void VisitHandle(uword addr) { 205 void VisitHandle(uword addr) {
203 FinalizablePersistentHandle* handle = 206 FinalizablePersistentHandle* handle =
204 reinterpret_cast<FinalizablePersistentHandle*>(addr); 207 reinterpret_cast<FinalizablePersistentHandle*>(addr);
205 RawObject** p = handle->raw_addr(); 208 RawObject** p = handle->raw_addr();
206 if (scavenger_->IsUnreachable(p)) { 209 if (scavenger_->IsUnreachable(p)) {
207 handle->UpdateUnreachable(thread()->isolate()); 210 handle->UpdateUnreachable(thread()->isolate(), queue_);
208 } else { 211 } else {
209 handle->UpdateRelocated(thread()->isolate()); 212 handle->UpdateRelocated(thread()->isolate());
210 } 213 }
211 } 214 }
212 215
213 private: 216 private:
214 Scavenger* scavenger_; 217 Scavenger* scavenger_;
218 FinalizationQueue* queue_;
215 219
216 DISALLOW_COPY_AND_ASSIGN(ScavengerWeakVisitor); 220 DISALLOW_COPY_AND_ASSIGN(ScavengerWeakVisitor);
217 }; 221 };
218 222
219 223
220 // Visitor used to verify that all old->new references have been added to the 224 // Visitor used to verify that all old->new references have been added to the
221 // StoreBuffers. 225 // StoreBuffers.
222 class VerifyStoreBufferPointerVisitor : public ObjectPointerVisitor { 226 class VerifyStoreBufferPointerVisitor : public ObjectPointerVisitor {
223 public: 227 public:
224 VerifyStoreBufferPointerVisitor(Isolate* isolate, 228 VerifyStoreBufferPointerVisitor(Isolate* isolate,
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 StackZone zone(thread); 809 StackZone zone(thread);
806 // Setup the visitor and run the scavenge. 810 // Setup the visitor and run the scavenge.
807 ScavengerVisitor visitor(isolate, this, from); 811 ScavengerVisitor visitor(isolate, this, from);
808 page_space->AcquireDataLock(); 812 page_space->AcquireDataLock();
809 IterateRoots(isolate, &visitor); 813 IterateRoots(isolate, &visitor);
810 int64_t start = OS::GetCurrentTimeMicros(); 814 int64_t start = OS::GetCurrentTimeMicros();
811 ProcessToSpace(&visitor); 815 ProcessToSpace(&visitor);
812 int64_t middle = OS::GetCurrentTimeMicros(); 816 int64_t middle = OS::GetCurrentTimeMicros();
813 { 817 {
814 TIMELINE_FUNCTION_GC_DURATION(thread, "WeakHandleProcessing"); 818 TIMELINE_FUNCTION_GC_DURATION(thread, "WeakHandleProcessing");
815 ScavengerWeakVisitor weak_visitor(this); 819 FinalizationQueue* queue = new FinalizationQueue();
820 ScavengerWeakVisitor weak_visitor(thread, this, queue);
816 IterateWeakRoots(isolate, &weak_visitor); 821 IterateWeakRoots(isolate, &weak_visitor);
822 if (queue->length() > 0) {
823 Dart::thread_pool()->Run(new BackgroundFinalizer(isolate, queue));
824 } else {
825 delete queue;
826 }
817 } 827 }
818 ProcessWeakReferences(); 828 ProcessWeakReferences();
819 page_space->ReleaseDataLock(); 829 page_space->ReleaseDataLock();
820 830
821 // Scavenge finished. Run accounting. 831 // Scavenge finished. Run accounting.
822 int64_t end = OS::GetCurrentTimeMicros(); 832 int64_t end = OS::GetCurrentTimeMicros();
823 heap_->RecordTime(kProcessToSpace, middle - start); 833 heap_->RecordTime(kProcessToSpace, middle - start);
824 heap_->RecordTime(kIterateWeaks, end - middle); 834 heap_->RecordTime(kIterateWeaks, end - middle);
825 stats_history_.Add( 835 stats_history_.Add(
826 ScavengeStats(start, end, 836 ScavengeStats(start, end,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 } 894 }
885 895
886 896
887 void Scavenger::FreeExternal(intptr_t size) { 897 void Scavenger::FreeExternal(intptr_t size) {
888 ASSERT(size >= 0); 898 ASSERT(size >= 0);
889 external_size_ -= size; 899 external_size_ -= size;
890 ASSERT(external_size_ >= 0); 900 ASSERT(external_size_ >= 0);
891 } 901 }
892 902
893 } // namespace dart 903 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/profiler.h ('k') | runtime/vm/thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698