| 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 |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 } | 396 } |
| 397 delete pending; | 397 delete pending; |
| 398 pending = next; | 398 pending = next; |
| 399 } | 399 } |
| 400 heap_->RecordData(kStoreBufferEntries, entries); | 400 heap_->RecordData(kStoreBufferEntries, entries); |
| 401 // Done iterating through old objects remembered in the store buffers. | 401 // Done iterating through old objects remembered in the store buffers. |
| 402 visitor->VisitingOldObject(NULL); | 402 visitor->VisitingOldObject(NULL); |
| 403 } | 403 } |
| 404 | 404 |
| 405 | 405 |
| 406 void Scavenger::IterateObjectIdTable(Isolate* isolate, |
| 407 ScavengerVisitor* visitor) { |
| 408 RawObject** table = heap_->get_object_id_ring_table(); |
| 409 const intptr_t table_size = heap_->get_object_id_ring_table_size(); |
| 410 if ((table == NULL) || (table_size <= 0)) { |
| 411 return; |
| 412 } |
| 413 visitor->VisitPointers(&table[0], &table[table_size]); |
| 414 } |
| 415 |
| 416 |
| 406 void Scavenger::IterateRoots(Isolate* isolate, | 417 void Scavenger::IterateRoots(Isolate* isolate, |
| 407 ScavengerVisitor* visitor, | 418 ScavengerVisitor* visitor, |
| 408 bool visit_prologue_weak_persistent_handles) { | 419 bool visit_prologue_weak_persistent_handles) { |
| 409 int64_t start = OS::GetCurrentTimeMicros(); | 420 int64_t start = OS::GetCurrentTimeMicros(); |
| 410 isolate->VisitObjectPointers(visitor, | 421 isolate->VisitObjectPointers(visitor, |
| 411 visit_prologue_weak_persistent_handles, | 422 visit_prologue_weak_persistent_handles, |
| 412 StackFrameIterator::kDontValidateFrames); | 423 StackFrameIterator::kDontValidateFrames); |
| 413 int64_t middle = OS::GetCurrentTimeMicros(); | 424 int64_t middle = OS::GetCurrentTimeMicros(); |
| 414 IterateStoreBuffers(isolate, visitor); | 425 IterateStoreBuffers(isolate, visitor); |
| 426 IterateObjectIdTable(isolate, visitor); |
| 415 int64_t end = OS::GetCurrentTimeMicros(); | 427 int64_t end = OS::GetCurrentTimeMicros(); |
| 416 heap_->RecordTime(kVisitIsolateRoots, middle - start); | 428 heap_->RecordTime(kVisitIsolateRoots, middle - start); |
| 417 heap_->RecordTime(kIterateStoreBuffers, end - middle); | 429 heap_->RecordTime(kIterateStoreBuffers, end - middle); |
| 418 } | 430 } |
| 419 | 431 |
| 420 | 432 |
| 421 bool Scavenger::IsUnreachable(RawObject** p) { | 433 bool Scavenger::IsUnreachable(RawObject** p) { |
| 422 RawObject* raw_obj = *p; | 434 RawObject* raw_obj = *p; |
| 423 if (!raw_obj->IsHeapObject()) { | 435 if (!raw_obj->IsHeapObject()) { |
| 424 return false; | 436 return false; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 if (IsForwarding(header)) { | 579 if (IsForwarding(header)) { |
| 568 // The object has survived. Preserve its record. | 580 // The object has survived. Preserve its record. |
| 569 uword new_addr = ForwardedAddr(header); | 581 uword new_addr = ForwardedAddr(header); |
| 570 raw_obj = RawObject::FromAddr(new_addr); | 582 raw_obj = RawObject::FromAddr(new_addr); |
| 571 heap_->SetPeer(raw_obj, it->second); | 583 heap_->SetPeer(raw_obj, it->second); |
| 572 } | 584 } |
| 573 } | 585 } |
| 574 } | 586 } |
| 575 | 587 |
| 576 | 588 |
| 589 void Scavenger::ProcessObjectIdTable() { |
| 590 RawObject** table = heap_->get_object_id_ring_table(); |
| 591 const intptr_t table_size = heap_->get_object_id_ring_table_size(); |
| 592 if ((table == NULL) || (table_size <= 0)) { |
| 593 return; |
| 594 } |
| 595 for (intptr_t i = 0; i < table_size; i++) { |
| 596 RawObject* raw_obj = table[i]; |
| 597 ASSERT(raw_obj->IsHeapObject()); |
| 598 if (raw_obj->IsOldObject()) { |
| 599 // SKip old objects. |
| 600 continue; |
| 601 } |
| 602 uword raw_addr = RawObject::ToAddr(raw_obj); |
| 603 uword header = *reinterpret_cast<uword*>(raw_addr); |
| 604 if (IsForwarding(header)) { |
| 605 // The object has survived. Update its address in the table. |
| 606 uword new_addr = ForwardedAddr(header); |
| 607 raw_obj = RawObject::FromAddr(new_addr); |
| 608 table[i] = raw_obj; |
| 609 } |
| 610 } |
| 611 } |
| 612 |
| 613 |
| 577 void Scavenger::VisitObjectPointers(ObjectPointerVisitor* visitor) const { | 614 void Scavenger::VisitObjectPointers(ObjectPointerVisitor* visitor) const { |
| 578 uword cur = FirstObjectStart(); | 615 uword cur = FirstObjectStart(); |
| 579 while (cur < top_) { | 616 while (cur < top_) { |
| 580 RawObject* raw_obj = RawObject::FromAddr(cur); | 617 RawObject* raw_obj = RawObject::FromAddr(cur); |
| 581 cur += raw_obj->VisitPointers(visitor); | 618 cur += raw_obj->VisitPointers(visitor); |
| 582 } | 619 } |
| 583 } | 620 } |
| 584 | 621 |
| 585 | 622 |
| 586 void Scavenger::VisitObjects(ObjectVisitor* visitor) const { | 623 void Scavenger::VisitObjects(ObjectVisitor* visitor) const { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 Prologue(isolate, invoke_api_callbacks); | 656 Prologue(isolate, invoke_api_callbacks); |
| 620 IterateRoots(isolate, &visitor, !invoke_api_callbacks); | 657 IterateRoots(isolate, &visitor, !invoke_api_callbacks); |
| 621 int64_t start = OS::GetCurrentTimeMicros(); | 658 int64_t start = OS::GetCurrentTimeMicros(); |
| 622 ProcessToSpace(&visitor); | 659 ProcessToSpace(&visitor); |
| 623 int64_t middle = OS::GetCurrentTimeMicros(); | 660 int64_t middle = OS::GetCurrentTimeMicros(); |
| 624 IterateWeakReferences(isolate, &visitor); | 661 IterateWeakReferences(isolate, &visitor); |
| 625 ScavengerWeakVisitor weak_visitor(this); | 662 ScavengerWeakVisitor weak_visitor(this); |
| 626 IterateWeakRoots(isolate, &weak_visitor, invoke_api_callbacks); | 663 IterateWeakRoots(isolate, &weak_visitor, invoke_api_callbacks); |
| 627 visitor.Finalize(); | 664 visitor.Finalize(); |
| 628 ProcessPeerReferents(); | 665 ProcessPeerReferents(); |
| 666 ProcessObjectIdTable(); |
| 629 int64_t end = OS::GetCurrentTimeMicros(); | 667 int64_t end = OS::GetCurrentTimeMicros(); |
| 630 heap_->RecordTime(kProcessToSpace, middle - start); | 668 heap_->RecordTime(kProcessToSpace, middle - start); |
| 631 heap_->RecordTime(kIterateWeaks, end - middle); | 669 heap_->RecordTime(kIterateWeaks, end - middle); |
| 632 Epilogue(isolate, invoke_api_callbacks); | 670 Epilogue(isolate, invoke_api_callbacks); |
| 633 | 671 |
| 634 if (FLAG_verify_after_gc) { | 672 if (FLAG_verify_after_gc) { |
| 635 OS::PrintErr("Verifying after Scavenge..."); | 673 OS::PrintErr("Verifying after Scavenge..."); |
| 636 heap_->Verify(); | 674 heap_->Verify(); |
| 637 OS::PrintErr(" done.\n"); | 675 OS::PrintErr(" done.\n"); |
| 638 } | 676 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 662 PeerTable::iterator it = peer_table_.find(raw_obj); | 700 PeerTable::iterator it = peer_table_.find(raw_obj); |
| 663 return (it == peer_table_.end()) ? NULL : it->second; | 701 return (it == peer_table_.end()) ? NULL : it->second; |
| 664 } | 702 } |
| 665 | 703 |
| 666 | 704 |
| 667 int64_t Scavenger::PeerCount() const { | 705 int64_t Scavenger::PeerCount() const { |
| 668 return static_cast<int64_t>(peer_table_.size()); | 706 return static_cast<int64_t>(peer_table_.size()); |
| 669 } | 707 } |
| 670 | 708 |
| 671 } // namespace dart | 709 } // namespace dart |
| OLD | NEW |