Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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/heap.h" | 5 #include "vm/heap.h" |
| 6 | 6 |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
| 9 #include "vm/flags.h" | 9 #include "vm/flags.h" |
| 10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 | 22 |
| 23 namespace dart { | 23 namespace dart { |
| 24 | 24 |
| 25 DEFINE_FLAG(bool, verbose_gc, false, "Enables verbose GC."); | 25 DEFINE_FLAG(bool, verbose_gc, false, "Enables verbose GC."); |
| 26 DEFINE_FLAG(int, verbose_gc_hdr, 40, "Print verbose GC header interval."); | 26 DEFINE_FLAG(int, verbose_gc_hdr, 40, "Print verbose GC header interval."); |
| 27 DEFINE_FLAG(bool, verify_before_gc, false, | 27 DEFINE_FLAG(bool, verify_before_gc, false, |
| 28 "Enables heap verification before GC."); | 28 "Enables heap verification before GC."); |
| 29 DEFINE_FLAG(bool, verify_after_gc, false, | 29 DEFINE_FLAG(bool, verify_after_gc, false, |
| 30 "Enables heap verification after GC."); | 30 "Enables heap verification after GC."); |
| 31 DEFINE_FLAG(bool, gc_at_alloc, false, "GC at every allocation."); | 31 DEFINE_FLAG(bool, gc_at_alloc, false, "GC at every allocation."); |
| 32 DEFINE_FLAG(int, new_gen_heap_size, 32, "new gen heap size in MB," | |
| 33 "e.g: --new_gen_heap_size=64 allocates a 64MB new gen heap"); | |
| 34 DEFINE_FLAG(int, old_gen_heap_size, Heap::kHeapSizeInMB, | |
| 35 "old gen heap size in MB," | |
| 36 "e.g: --old_gen_heap_size=1024 allocates a 1024MB old gen heap"); | |
| 37 DEFINE_FLAG(int, new_gen_ext_limit, 64, | 32 DEFINE_FLAG(int, new_gen_ext_limit, 64, |
| 38 "maximum total external size (MB) in new gen before triggering GC"); | 33 "maximum total external size (MB) in new gen before triggering GC"); |
| 39 | 34 |
| 40 Heap::Heap() : read_only_(false), gc_in_progress_(false) { | 35 Heap::Heap(intptr_t max_new_gen_words, |
|
Ivan Posva
2014/04/24 17:12:44
Thanks! This is also a good step towards being abl
| |
| 36 intptr_t max_old_gen_words) | |
| 37 : read_only_(false), gc_in_progress_(false) { | |
| 41 for (int sel = 0; | 38 for (int sel = 0; |
| 42 sel < kNumWeakSelectors; | 39 sel < kNumWeakSelectors; |
| 43 sel++) { | 40 sel++) { |
| 44 new_weak_tables_[sel] = new WeakTable(); | 41 new_weak_tables_[sel] = new WeakTable(); |
| 45 old_weak_tables_[sel] = new WeakTable(); | 42 old_weak_tables_[sel] = new WeakTable(); |
| 46 } | 43 } |
| 47 new_space_ = new Scavenger(this, | 44 new_space_ = new Scavenger(this, |
| 48 (FLAG_new_gen_heap_size * MBInWords), | 45 max_new_gen_words, |
| 49 kNewObjectAlignmentOffset); | 46 kNewObjectAlignmentOffset); |
| 50 old_space_ = new PageSpace(this, (FLAG_old_gen_heap_size * MBInWords)); | 47 old_space_ = new PageSpace(this, max_old_gen_words); |
| 51 stats_.num_ = 0; | 48 stats_.num_ = 0; |
| 52 } | 49 } |
| 53 | 50 |
| 54 | 51 |
| 55 Heap::~Heap() { | 52 Heap::~Heap() { |
| 56 delete new_space_; | 53 delete new_space_; |
| 57 delete old_space_; | 54 delete old_space_; |
| 58 for (int sel = 0; | 55 for (int sel = 0; |
| 59 sel < kNumWeakSelectors; | 56 sel < kNumWeakSelectors; |
| 60 sel++) { | 57 sel++) { |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 uword Heap::TopAddress() { | 307 uword Heap::TopAddress() { |
| 311 return reinterpret_cast<uword>(new_space_->TopAddress()); | 308 return reinterpret_cast<uword>(new_space_->TopAddress()); |
| 312 } | 309 } |
| 313 | 310 |
| 314 | 311 |
| 315 uword Heap::EndAddress() { | 312 uword Heap::EndAddress() { |
| 316 return reinterpret_cast<uword>(new_space_->EndAddress()); | 313 return reinterpret_cast<uword>(new_space_->EndAddress()); |
| 317 } | 314 } |
| 318 | 315 |
| 319 | 316 |
| 320 void Heap::Init(Isolate* isolate) { | 317 void Heap::Init(Isolate* isolate, |
| 318 intptr_t max_new_gen_words, | |
| 319 intptr_t max_old_gen_words) { | |
| 321 ASSERT(isolate->heap() == NULL); | 320 ASSERT(isolate->heap() == NULL); |
| 322 Heap* heap = new Heap(); | 321 Heap* heap = new Heap(max_new_gen_words, max_old_gen_words); |
| 323 isolate->set_heap(heap); | 322 isolate->set_heap(heap); |
| 324 } | 323 } |
| 325 | 324 |
| 326 | 325 |
| 327 void Heap::StartEndAddress(uword* start, uword* end) const { | 326 void Heap::GetMergedAddressRange(uword* start, uword* end) const { |
| 328 ASSERT(new_space_->CapacityInWords() != 0); | 327 if (new_space_->CapacityInWords() != 0) { |
| 329 new_space_->StartEndAddress(start, end); | 328 uword new_start; |
| 329 uword new_end; | |
| 330 new_space_->StartEndAddress(&new_start, &new_end); | |
| 331 *start = Utils::Minimum(new_start, *start); | |
| 332 *end = Utils::Maximum(new_end, *end); | |
| 333 } | |
| 330 if (old_space_->CapacityInWords() != 0) { | 334 if (old_space_->CapacityInWords() != 0) { |
| 331 uword old_start; | 335 uword old_start; |
| 332 uword old_end; | 336 uword old_end; |
| 333 old_space_->StartEndAddress(&old_start, &old_end); | 337 old_space_->StartEndAddress(&old_start, &old_end); |
| 334 *start = Utils::Minimum(old_start, *start); | 338 *start = Utils::Minimum(old_start, *start); |
| 335 *end = Utils::Maximum(old_end, *end); | 339 *end = Utils::Maximum(old_end, *end); |
| 336 } | 340 } |
| 337 ASSERT(*start <= *end); | 341 ASSERT(*start <= *end); |
| 338 } | 342 } |
| 339 | 343 |
| 340 | 344 |
| 341 ObjectSet* Heap::CreateAllocatedObjectSet() const { | 345 ObjectSet* Heap::CreateAllocatedObjectSet() const { |
| 346 uword start = static_cast<uword>(-1); | |
| 347 uword end = 0; | |
| 348 Isolate* vm_isolate = Dart::vm_isolate(); | |
| 349 vm_isolate->heap()->GetMergedAddressRange(&start, &end); | |
| 342 Isolate* isolate = Isolate::Current(); | 350 Isolate* isolate = Isolate::Current(); |
| 343 uword start, end; | 351 isolate->heap()->GetMergedAddressRange(&start, &end); |
|
koda
2014/04/24 00:24:48
Actually, why do we get explicitly get Isolate::Cu
Ivan Posva
2014/04/24 17:12:44
Please use this.
koda
2014/04/24 17:52:54
Actually, there was a reason. We need the isolate
| |
| 344 isolate->heap()->StartEndAddress(&start, &end); | |
| 345 | 352 |
| 346 Isolate* vm_isolate = Dart::vm_isolate(); | 353 ObjectSet* allocated_set = new ObjectSet(start, end); |
| 347 uword vm_start, vm_end; | |
| 348 vm_isolate->heap()->StartEndAddress(&vm_start, &vm_end); | |
| 349 | |
| 350 ObjectSet* allocated_set = new ObjectSet(Utils::Minimum(start, vm_start), | |
| 351 Utils::Maximum(end, vm_end)); | |
| 352 | 354 |
| 353 VerifyObjectVisitor object_visitor(isolate, allocated_set); | 355 VerifyObjectVisitor object_visitor(isolate, allocated_set); |
| 354 isolate->heap()->IterateObjects(&object_visitor); | 356 isolate->heap()->IterateObjects(&object_visitor); |
| 355 vm_isolate->heap()->IterateObjects(&object_visitor); | 357 vm_isolate->heap()->IterateObjects(&object_visitor); |
| 356 | 358 |
| 357 return allocated_set; | 359 return allocated_set; |
| 358 } | 360 } |
| 359 | 361 |
| 360 | 362 |
| 361 bool Heap::Verify() const { | 363 bool Heap::Verify() const { |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 581 heap->DisableGrowthControl(); | 583 heap->DisableGrowthControl(); |
| 582 } | 584 } |
| 583 | 585 |
| 584 | 586 |
| 585 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { | 587 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { |
| 586 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); | 588 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); |
| 587 heap->SetGrowthControlState(current_growth_controller_state_); | 589 heap->SetGrowthControlState(current_growth_controller_state_); |
| 588 } | 590 } |
| 589 | 591 |
| 590 } // namespace dart | 592 } // namespace dart |
| OLD | NEW |