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/object.h" | 10 #include "vm/object.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 static inline void ForwardTo(uword orignal, uword target) { | 37 static inline void ForwardTo(uword orignal, uword target) { |
38 // Make sure forwarding can be encoded. | 38 // Make sure forwarding can be encoded. |
39 ASSERT((target & kForwardingMask) == 0); | 39 ASSERT((target & kForwardingMask) == 0); |
40 *reinterpret_cast<uword*>(orignal) = target | kForwarded; | 40 *reinterpret_cast<uword*>(orignal) = target | kForwarded; |
41 } | 41 } |
42 | 42 |
43 | 43 |
44 class ScavengerVisitor : public ObjectPointerVisitor { | 44 class ScavengerVisitor : public ObjectPointerVisitor { |
45 public: | 45 public: |
46 explicit ScavengerVisitor(Scavenger* scavenger) | 46 explicit ScavengerVisitor(Isolate* isolate, Scavenger* scavenger) |
47 : scavenger_(scavenger), | 47 : ObjectPointerVisitor(isolate), |
| 48 scavenger_(scavenger), |
48 heap_(scavenger->heap_), | 49 heap_(scavenger->heap_), |
49 vm_heap_(Dart::vm_isolate()->heap()) {} | 50 vm_heap_(Dart::vm_isolate()->heap()) {} |
50 | 51 |
51 void VisitPointers(RawObject** first, RawObject** last) { | 52 void VisitPointers(RawObject** first, RawObject** last) { |
52 for (RawObject** current = first; current <= last; current++) { | 53 for (RawObject** current = first; current <= last; current++) { |
53 ScavengePointer(current); | 54 ScavengePointer(current); |
54 } | 55 } |
55 } | 56 } |
56 | 57 |
57 private: | 58 private: |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 | 362 |
362 if (FLAG_verify_before_gc) { | 363 if (FLAG_verify_before_gc) { |
363 OS::PrintErr("Verifying before Scavenge... "); | 364 OS::PrintErr("Verifying before Scavenge... "); |
364 heap_->Verify(); | 365 heap_->Verify(); |
365 OS::PrintErr(" done.\n"); | 366 OS::PrintErr(" done.\n"); |
366 } | 367 } |
367 | 368 |
368 Timer timer(FLAG_verbose_gc, "Scavenge"); | 369 Timer timer(FLAG_verbose_gc, "Scavenge"); |
369 timer.Start(); | 370 timer.Start(); |
370 // Setup the visitor and run a scavenge. | 371 // Setup the visitor and run a scavenge. |
371 ScavengerVisitor visitor(this); | 372 ScavengerVisitor visitor(isolate, this); |
372 Prologue(isolate, invoke_api_callbacks); | 373 Prologue(isolate, invoke_api_callbacks); |
373 IterateRoots(isolate, &visitor, !invoke_api_callbacks); | 374 IterateRoots(isolate, &visitor, !invoke_api_callbacks); |
374 ProcessToSpace(&visitor); | 375 ProcessToSpace(&visitor); |
375 IterateWeakReferences(isolate, &visitor); | 376 IterateWeakReferences(isolate, &visitor); |
376 ScavengerWeakVisitor weak_visitor(this); | 377 ScavengerWeakVisitor weak_visitor(this); |
377 IterateWeakRoots(isolate, &weak_visitor, invoke_api_callbacks); | 378 IterateWeakRoots(isolate, &weak_visitor, invoke_api_callbacks); |
378 Epilogue(isolate, invoke_api_callbacks); | 379 Epilogue(isolate, invoke_api_callbacks); |
379 timer.Stop(); | 380 timer.Stop(); |
380 if (FLAG_verbose_gc) { | 381 if (FLAG_verbose_gc) { |
381 OS::PrintErr("Scavenge[%d]: %dus\n", count_, timer.TotalElapsedTime()); | 382 OS::PrintErr("Scavenge[%d]: %dus\n", count_, timer.TotalElapsedTime()); |
382 } | 383 } |
383 | 384 |
384 if (FLAG_verify_after_gc) { | 385 if (FLAG_verify_after_gc) { |
385 OS::PrintErr("Verifying after Scavenge... "); | 386 OS::PrintErr("Verifying after Scavenge... "); |
386 heap_->Verify(); | 387 heap_->Verify(); |
387 OS::PrintErr(" done.\n"); | 388 OS::PrintErr(" done.\n"); |
388 } | 389 } |
389 | 390 |
390 count_++; | 391 count_++; |
391 // Done scavenging. Reset the marker. | 392 // Done scavenging. Reset the marker. |
392 ASSERT(scavenging_); | 393 ASSERT(scavenging_); |
393 scavenging_ = false; | 394 scavenging_ = false; |
394 } | 395 } |
395 | 396 |
396 } // namespace dart | 397 } // namespace dart |
OLD | NEW |