| 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 16 matching lines...) Expand all Loading... |
| 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," | 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"); | 33 "e.g: --new_gen_heap_size=64 allocates a 64MB new gen heap"); |
| 34 DEFINE_FLAG(int, old_gen_heap_size, Heap::kHeapSizeInMB, | 34 DEFINE_FLAG(int, old_gen_heap_size, Heap::kHeapSizeInMB, |
| 35 "old gen heap size in MB," | 35 "old gen heap size in MB," |
| 36 "e.g: --old_gen_heap_size=1024 allocates a 1024MB old gen heap"); | 36 "e.g: --old_gen_heap_size=1024 allocates a 1024MB old gen heap"); |
| 37 DEFINE_FLAG(int, new_gen_ext_limit, 64, |
| 38 "maximum total external size (MB) in new gen before triggering GC"); |
| 37 | 39 |
| 38 Heap::Heap() : read_only_(false), gc_in_progress_(false) { | 40 Heap::Heap() : read_only_(false), gc_in_progress_(false) { |
| 39 for (int sel = 0; | 41 for (int sel = 0; |
| 40 sel < kNumWeakSelectors; | 42 sel < kNumWeakSelectors; |
| 41 sel++) { | 43 sel++) { |
| 42 new_weak_tables_[sel] = new WeakTable(); | 44 new_weak_tables_[sel] = new WeakTable(); |
| 43 old_weak_tables_[sel] = new WeakTable(); | 45 old_weak_tables_[sel] = new WeakTable(); |
| 44 } | 46 } |
| 45 new_space_ = new Scavenger(this, | 47 new_space_ = new Scavenger(this, |
| 46 (FLAG_new_gen_heap_size * MBInWords), | 48 (FLAG_new_gen_heap_size * MBInWords), |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 size); | 89 size); |
| 88 return 0; | 90 return 0; |
| 89 } | 91 } |
| 90 } | 92 } |
| 91 return addr; | 93 return addr; |
| 92 } | 94 } |
| 93 | 95 |
| 94 void Heap::AllocateExternal(intptr_t size, Space space) { | 96 void Heap::AllocateExternal(intptr_t size, Space space) { |
| 95 if (space == kNew) { | 97 if (space == kNew) { |
| 96 new_space_->AllocateExternal(size); | 98 new_space_->AllocateExternal(size); |
| 99 if (new_space_->ExternalInWords() > (FLAG_new_gen_ext_limit * MBInWords)) { |
| 100 // Attempt to free some external allocation by a scavenge. (If the total |
| 101 // remains above the limit, next external alloc will trigger another.) |
| 102 CollectGarbage(kNew); |
| 103 } |
| 97 } else { | 104 } else { |
| 98 ASSERT(space == kOld); | 105 ASSERT(space == kOld); |
| 99 old_space_->AllocateExternal(size); | 106 old_space_->AllocateExternal(size); |
| 100 } | 107 } |
| 101 } | 108 } |
| 102 | 109 |
| 103 void Heap::FreeExternal(intptr_t size, Space space) { | 110 void Heap::FreeExternal(intptr_t size, Space space) { |
| 104 if (space == kNew) { | 111 if (space == kNew) { |
| 105 new_space_->FreeExternal(size); | 112 new_space_->FreeExternal(size); |
| 106 } else { | 113 } else { |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 heap->DisableGrowthControl(); | 579 heap->DisableGrowthControl(); |
| 573 } | 580 } |
| 574 | 581 |
| 575 | 582 |
| 576 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { | 583 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { |
| 577 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); | 584 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); |
| 578 heap->SetGrowthControlState(current_growth_controller_state_); | 585 heap->SetGrowthControlState(current_growth_controller_state_); |
| 579 } | 586 } |
| 580 | 587 |
| 581 } // namespace dart | 588 } // namespace dart |
| OLD | NEW |