| 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 <map> | 7 #include <map> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "vm/dart.h" | 10 #include "vm/dart.h" |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 void Scavenger::VisitObjects(ObjectVisitor* visitor) const { | 523 void Scavenger::VisitObjects(ObjectVisitor* visitor) const { |
| 524 uword cur = FirstObjectStart(); | 524 uword cur = FirstObjectStart(); |
| 525 while (cur < top_) { | 525 while (cur < top_) { |
| 526 RawObject* raw_obj = RawObject::FromAddr(cur); | 526 RawObject* raw_obj = RawObject::FromAddr(cur); |
| 527 visitor->VisitObject(raw_obj); | 527 visitor->VisitObject(raw_obj); |
| 528 cur += raw_obj->Size(); | 528 cur += raw_obj->Size(); |
| 529 } | 529 } |
| 530 } | 530 } |
| 531 | 531 |
| 532 | 532 |
| 533 void Scavenger::Scavenge() { | 533 void Scavenger::Scavenge(const char* gc_reason) { |
| 534 // TODO(cshapiro): Add a decision procedure for determining when the | 534 // TODO(cshapiro): Add a decision procedure for determining when the |
| 535 // the API callbacks should be invoked. | 535 // the API callbacks should be invoked. |
| 536 Scavenge(false); | 536 Scavenge(false, gc_reason); |
| 537 } | 537 } |
| 538 | 538 |
| 539 | 539 |
| 540 void Scavenger::Scavenge(bool invoke_api_callbacks) { | 540 void Scavenger::Scavenge(bool invoke_api_callbacks, const char* gc_reason) { |
| 541 // Scavenging is not reentrant. Make sure that is the case. | 541 // Scavenging is not reentrant. Make sure that is the case. |
| 542 ASSERT(!scavenging_); | 542 ASSERT(!scavenging_); |
| 543 scavenging_ = true; | 543 scavenging_ = true; |
| 544 had_promotion_failure_ = false; | 544 had_promotion_failure_ = false; |
| 545 Isolate* isolate = Isolate::Current(); | 545 Isolate* isolate = Isolate::Current(); |
| 546 NoHandleScope no_handles(isolate); | 546 NoHandleScope no_handles(isolate); |
| 547 | 547 |
| 548 if (FLAG_verify_before_gc) { | 548 if (FLAG_verify_before_gc) { |
| 549 OS::PrintErr("Verifying before Scavenge..."); | 549 OS::PrintErr("Verifying before Scavenge..."); |
| 550 heap_->Verify(); | 550 heap_->Verify(); |
| 551 OS::PrintErr(" done.\n"); | 551 OS::PrintErr(" done.\n"); |
| 552 } | 552 } |
| 553 | 553 |
| 554 if (FLAG_verbose_gc) { | 554 if (FLAG_verbose_gc) { |
| 555 OS::PrintErr("Start scavenge\n"); | 555 OS::PrintErr("Start scavenge for %s collection\n", gc_reason); |
| 556 } | 556 } |
| 557 Timer timer(FLAG_verbose_gc, "Scavenge"); | 557 Timer timer(FLAG_verbose_gc, "Scavenge"); |
| 558 timer.Start(); | 558 timer.Start(); |
| 559 // Setup the visitor and run a scavenge. | 559 // Setup the visitor and run a scavenge. |
| 560 ScavengerVisitor visitor(isolate, this); | 560 ScavengerVisitor visitor(isolate, this); |
| 561 Prologue(isolate, invoke_api_callbacks); | 561 Prologue(isolate, invoke_api_callbacks); |
| 562 IterateRoots(isolate, &visitor, !invoke_api_callbacks); | 562 IterateRoots(isolate, &visitor, !invoke_api_callbacks); |
| 563 ProcessToSpace(&visitor); | 563 ProcessToSpace(&visitor); |
| 564 IterateWeakReferences(isolate, &visitor); | 564 IterateWeakReferences(isolate, &visitor); |
| 565 ScavengerWeakVisitor weak_visitor(this); | 565 ScavengerWeakVisitor weak_visitor(this); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 583 scavenging_ = false; | 583 scavenging_ = false; |
| 584 } | 584 } |
| 585 | 585 |
| 586 | 586 |
| 587 void Scavenger::WriteProtect(bool read_only) { | 587 void Scavenger::WriteProtect(bool read_only) { |
| 588 space_->Protect( | 588 space_->Protect( |
| 589 read_only ? VirtualMemory::kReadOnly : VirtualMemory::kReadWrite); | 589 read_only ? VirtualMemory::kReadOnly : VirtualMemory::kReadWrite); |
| 590 } | 590 } |
| 591 | 591 |
| 592 } // namespace dart | 592 } // namespace dart |
| OLD | NEW |