| 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 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 // going to use for forwarding pointers. | 408 // going to use for forwarding pointers. |
| 409 ASSERT(Object::tags_offset() == 0); | 409 ASSERT(Object::tags_offset() == 0); |
| 410 | 410 |
| 411 // Set initial size resulting in a total of three different levels. | 411 // Set initial size resulting in a total of three different levels. |
| 412 const intptr_t initial_semi_capacity_in_words = max_semi_capacity_in_words / | 412 const intptr_t initial_semi_capacity_in_words = max_semi_capacity_in_words / |
| 413 (FLAG_new_gen_growth_factor * FLAG_new_gen_growth_factor); | 413 (FLAG_new_gen_growth_factor * FLAG_new_gen_growth_factor); |
| 414 to_ = SemiSpace::New(initial_semi_capacity_in_words); | 414 to_ = SemiSpace::New(initial_semi_capacity_in_words); |
| 415 if (to_ == NULL) { | 415 if (to_ == NULL) { |
| 416 FATAL("Out of memory.\n"); | 416 FATAL("Out of memory.\n"); |
| 417 } | 417 } |
| 418 | 418 UpdateMaxHeapCapacity(); |
| 419 // Setup local fields. | 419 // Setup local fields. |
| 420 top_ = FirstObjectStart(); | 420 top_ = FirstObjectStart(); |
| 421 resolved_top_ = top_; | 421 resolved_top_ = top_; |
| 422 end_ = to_->end(); | 422 end_ = to_->end(); |
| 423 | 423 |
| 424 survivor_end_ = FirstObjectStart(); | 424 survivor_end_ = FirstObjectStart(); |
| 425 } | 425 } |
| 426 | 426 |
| 427 | 427 |
| 428 Scavenger::~Scavenger() { | 428 Scavenger::~Scavenger() { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 452 Thread::PrepareForGC(); | 452 Thread::PrepareForGC(); |
| 453 // Flip the two semi-spaces so that to_ is always the space for allocating | 453 // Flip the two semi-spaces so that to_ is always the space for allocating |
| 454 // objects. | 454 // objects. |
| 455 SemiSpace* from = to_; | 455 SemiSpace* from = to_; |
| 456 to_ = SemiSpace::New(NewSizeInWords(from->size_in_words())); | 456 to_ = SemiSpace::New(NewSizeInWords(from->size_in_words())); |
| 457 if (to_ == NULL) { | 457 if (to_ == NULL) { |
| 458 // TODO(koda): We could try to recover (collect old space, wait for another | 458 // TODO(koda): We could try to recover (collect old space, wait for another |
| 459 // isolate to finish scavenge, etc.). | 459 // isolate to finish scavenge, etc.). |
| 460 FATAL("Out of memory.\n"); | 460 FATAL("Out of memory.\n"); |
| 461 } | 461 } |
| 462 UpdateMaxHeapCapacity(); |
| 462 top_ = FirstObjectStart(); | 463 top_ = FirstObjectStart(); |
| 463 resolved_top_ = top_; | 464 resolved_top_ = top_; |
| 464 end_ = to_->end(); | 465 end_ = to_->end(); |
| 465 return from; | 466 return from; |
| 466 } | 467 } |
| 467 | 468 |
| 468 | 469 |
| 469 void Scavenger::Epilogue(Isolate* isolate, | 470 void Scavenger::Epilogue(Isolate* isolate, |
| 470 SemiSpace* from, | 471 SemiSpace* from, |
| 471 bool invoke_api_callbacks) { | 472 bool invoke_api_callbacks) { |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 } | 699 } |
| 699 while (!delayed_weak_stack->is_empty()) { | 700 while (!delayed_weak_stack->is_empty()) { |
| 700 // Pop the delayed weak object from the stack and visit its pointers. | 701 // Pop the delayed weak object from the stack and visit its pointers. |
| 701 RawObject* weak_property = delayed_weak_stack->RemoveLast(); | 702 RawObject* weak_property = delayed_weak_stack->RemoveLast(); |
| 702 weak_property->VisitPointers(visitor); | 703 weak_property->VisitPointers(visitor); |
| 703 } | 704 } |
| 704 } | 705 } |
| 705 } | 706 } |
| 706 | 707 |
| 707 | 708 |
| 709 void Scavenger::UpdateMaxHeapCapacity() { |
| 710 if (heap_ == NULL) { |
| 711 // Some unit tests. |
| 712 return; |
| 713 } |
| 714 ASSERT(to_ != NULL); |
| 715 ASSERT(heap_ != NULL); |
| 716 Isolate* isolate = heap_->isolate(); |
| 717 ASSERT(isolate != NULL); |
| 718 isolate->GetHeapNewCapacityMaxMetric()->SetValue( |
| 719 to_->size_in_words() * kWordSize); |
| 720 } |
| 721 |
| 722 |
| 708 uword Scavenger::ProcessWeakProperty(RawWeakProperty* raw_weak, | 723 uword Scavenger::ProcessWeakProperty(RawWeakProperty* raw_weak, |
| 709 ScavengerVisitor* visitor) { | 724 ScavengerVisitor* visitor) { |
| 710 // The fate of the weak property is determined by its key. | 725 // The fate of the weak property is determined by its key. |
| 711 RawObject* raw_key = raw_weak->ptr()->key_; | 726 RawObject* raw_key = raw_weak->ptr()->key_; |
| 712 if (raw_key->IsHeapObject() && raw_key->IsNewObject()) { | 727 if (raw_key->IsHeapObject() && raw_key->IsNewObject()) { |
| 713 uword raw_addr = RawObject::ToAddr(raw_key); | 728 uword raw_addr = RawObject::ToAddr(raw_key); |
| 714 uword header = *reinterpret_cast<uword*>(raw_addr); | 729 uword header = *reinterpret_cast<uword*>(raw_addr); |
| 715 if (!IsForwarding(header)) { | 730 if (!IsForwarding(header)) { |
| 716 // Key is white. Delay the weak property. | 731 // Key is white. Delay the weak property. |
| 717 visitor->DelayWeakProperty(raw_weak); | 732 visitor->DelayWeakProperty(raw_weak); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 } | 929 } |
| 915 | 930 |
| 916 | 931 |
| 917 void Scavenger::FreeExternal(intptr_t size) { | 932 void Scavenger::FreeExternal(intptr_t size) { |
| 918 ASSERT(size >= 0); | 933 ASSERT(size >= 0); |
| 919 external_size_ -= size; | 934 external_size_ -= size; |
| 920 ASSERT(external_size_ >= 0); | 935 ASSERT(external_size_ >= 0); |
| 921 } | 936 } |
| 922 | 937 |
| 923 } // namespace dart | 938 } // namespace dart |
| OLD | NEW |