| 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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 : heap_(heap), | 310 : heap_(heap), |
| 311 object_alignment_(object_alignment), | 311 object_alignment_(object_alignment), |
| 312 scavenging_(false), | 312 scavenging_(false), |
| 313 gc_time_micros_(0), | 313 gc_time_micros_(0), |
| 314 collections_(0), | 314 collections_(0), |
| 315 external_size_(0) { | 315 external_size_(0) { |
| 316 // Verify assumptions about the first word in objects which the scavenger is | 316 // Verify assumptions about the first word in objects which the scavenger is |
| 317 // going to use for forwarding pointers. | 317 // going to use for forwarding pointers. |
| 318 ASSERT(Object::tags_offset() == 0); | 318 ASSERT(Object::tags_offset() == 0); |
| 319 | 319 |
| 320 // Allocate the virtual memory for this scavenge heap. | 320 if (max_capacity_in_words == 0) { |
| 321 space_ = VirtualMemory::Reserve(max_capacity_in_words << kWordSizeLog2); | 321 space_ = NULL; |
| 322 if (space_ == NULL) { | 322 to_ = new MemoryRegion(NULL, 0); |
| 323 FATAL("Out of memory.\n"); | 323 from_ = new MemoryRegion(NULL, 0); |
| 324 } else { |
| 325 // Allocate the virtual memory for this scavenge heap. |
| 326 space_ = VirtualMemory::Reserve(max_capacity_in_words << kWordSizeLog2); |
| 327 if (space_ == NULL) { |
| 328 FATAL("Out of memory.\n"); |
| 329 } |
| 330 |
| 331 // Allocate the entire space at the beginning. |
| 332 space_->Commit(false); |
| 333 |
| 334 // Setup the semi spaces. |
| 335 uword semi_space_size = space_->size() / 2; |
| 336 ASSERT((semi_space_size & (VirtualMemory::PageSize() - 1)) == 0); |
| 337 to_ = new MemoryRegion(space_->address(), semi_space_size); |
| 338 uword middle = space_->start() + semi_space_size; |
| 339 from_ = new MemoryRegion(reinterpret_cast<void*>(middle), semi_space_size); |
| 324 } | 340 } |
| 325 | 341 |
| 326 // Allocate the entire space at the beginning. | |
| 327 space_->Commit(false); | |
| 328 | |
| 329 // Setup the semi spaces. | |
| 330 uword semi_space_size = space_->size() / 2; | |
| 331 ASSERT((semi_space_size & (VirtualMemory::PageSize() - 1)) == 0); | |
| 332 to_ = new MemoryRegion(space_->address(), semi_space_size); | |
| 333 uword middle = space_->start() + semi_space_size; | |
| 334 from_ = new MemoryRegion(reinterpret_cast<void*>(middle), semi_space_size); | |
| 335 | |
| 336 // Make sure that the two semi-spaces are aligned properly. | 342 // Make sure that the two semi-spaces are aligned properly. |
| 337 ASSERT(Utils::IsAligned(to_->start(), kObjectAlignment)); | 343 ASSERT(Utils::IsAligned(to_->start(), kObjectAlignment)); |
| 338 ASSERT(Utils::IsAligned(from_->start(), kObjectAlignment)); | 344 ASSERT(Utils::IsAligned(from_->start(), kObjectAlignment)); |
| 339 | 345 |
| 340 // Setup local fields. | 346 // Setup local fields. |
| 341 top_ = FirstObjectStart(); | 347 top_ = FirstObjectStart(); |
| 342 resolved_top_ = top_; | 348 resolved_top_ = top_; |
| 343 end_ = to_->end(); | 349 end_ = to_->end(); |
| 344 | 350 |
| 345 survivor_end_ = FirstObjectStart(); | 351 survivor_end_ = FirstObjectStart(); |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 OS::PrintErr(" done.\n"); | 732 OS::PrintErr(" done.\n"); |
| 727 } | 733 } |
| 728 | 734 |
| 729 // Done scavenging. Reset the marker. | 735 // Done scavenging. Reset the marker. |
| 730 ASSERT(scavenging_); | 736 ASSERT(scavenging_); |
| 731 scavenging_ = false; | 737 scavenging_ = false; |
| 732 } | 738 } |
| 733 | 739 |
| 734 | 740 |
| 735 void Scavenger::WriteProtect(bool read_only) { | 741 void Scavenger::WriteProtect(bool read_only) { |
| 736 space_->Protect( | 742 if (space_ != NULL) { |
| 737 read_only ? VirtualMemory::kReadOnly : VirtualMemory::kReadWrite); | 743 space_->Protect( |
| 744 read_only ? VirtualMemory::kReadOnly : VirtualMemory::kReadWrite); |
| 745 } |
| 738 } | 746 } |
| 739 | 747 |
| 740 | 748 |
| 741 void Scavenger::PrintToJSONObject(JSONObject* object) { | 749 void Scavenger::PrintToJSONObject(JSONObject* object) { |
| 742 JSONObject space(object, "new"); | 750 JSONObject space(object, "new"); |
| 743 space.AddProperty("type", "@Scavenger"); | 751 space.AddProperty("type", "@Scavenger"); |
| 744 space.AddProperty("id", "heaps/new"); | 752 space.AddProperty("id", "heaps/new"); |
| 745 space.AddProperty("name", "Scavenger"); | 753 space.AddProperty("name", "Scavenger"); |
| 746 space.AddProperty("user_name", "new"); | 754 space.AddProperty("user_name", "new"); |
| 747 space.AddProperty("collections", collections()); | 755 space.AddProperty("collections", collections()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 758 } | 766 } |
| 759 | 767 |
| 760 | 768 |
| 761 void Scavenger::FreeExternal(intptr_t size) { | 769 void Scavenger::FreeExternal(intptr_t size) { |
| 762 ASSERT(size >= 0); | 770 ASSERT(size >= 0); |
| 763 external_size_ -= size; | 771 external_size_ -= size; |
| 764 ASSERT(external_size_ >= 0); | 772 ASSERT(external_size_ >= 0); |
| 765 } | 773 } |
| 766 | 774 |
| 767 } // namespace dart | 775 } // namespace dart |
| OLD | NEW |