| 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/heap_profiler.h" | 10 #include "vm/heap_profiler.h" |
| 11 #include "vm/heap_trace.h" | |
| 12 #include "vm/isolate.h" | 11 #include "vm/isolate.h" |
| 13 #include "vm/object.h" | 12 #include "vm/object.h" |
| 14 #include "vm/object_set.h" | 13 #include "vm/object_set.h" |
| 15 #include "vm/os.h" | 14 #include "vm/os.h" |
| 16 #include "vm/pages.h" | 15 #include "vm/pages.h" |
| 17 #include "vm/raw_object.h" | 16 #include "vm/raw_object.h" |
| 18 #include "vm/scavenger.h" | 17 #include "vm/scavenger.h" |
| 19 #include "vm/stack_frame.h" | 18 #include "vm/stack_frame.h" |
| 20 #include "vm/verifier.h" | 19 #include "vm/verifier.h" |
| 21 #include "vm/virtual_memory.h" | 20 #include "vm/virtual_memory.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 34 DEFINE_FLAG(int, old_gen_heap_size, Heap::kHeapSizeInMB, | 33 DEFINE_FLAG(int, old_gen_heap_size, Heap::kHeapSizeInMB, |
| 35 "old gen heap size in MB," | 34 "old gen heap size in MB," |
| 36 "e.g: --old_gen_heap_size=1024 allocates a 1024MB old gen heap"); | 35 "e.g: --old_gen_heap_size=1024 allocates a 1024MB old gen heap"); |
| 37 | 36 |
| 38 Heap::Heap() : read_only_(false), gc_in_progress_(false) { | 37 Heap::Heap() : read_only_(false), gc_in_progress_(false) { |
| 39 new_space_ = new Scavenger(this, | 38 new_space_ = new Scavenger(this, |
| 40 (FLAG_new_gen_heap_size * MB), | 39 (FLAG_new_gen_heap_size * MB), |
| 41 kNewObjectAlignmentOffset); | 40 kNewObjectAlignmentOffset); |
| 42 old_space_ = new PageSpace(this, (FLAG_old_gen_heap_size * MB)); | 41 old_space_ = new PageSpace(this, (FLAG_old_gen_heap_size * MB)); |
| 43 stats_.num_ = 0; | 42 stats_.num_ = 0; |
| 44 heap_trace_ = new HeapTrace; | |
| 45 } | 43 } |
| 46 | 44 |
| 47 | 45 |
| 48 Heap::~Heap() { | 46 Heap::~Heap() { |
| 49 delete new_space_; | 47 delete new_space_; |
| 50 delete old_space_; | 48 delete old_space_; |
| 51 } | 49 } |
| 52 | 50 |
| 53 | 51 |
| 54 uword Heap::AllocateNew(intptr_t size) { | 52 uword Heap::AllocateNew(intptr_t size) { |
| 55 ASSERT(Isolate::Current()->no_gc_scope_depth() == 0); | 53 ASSERT(Isolate::Current()->no_gc_scope_depth() == 0); |
| 56 uword addr = new_space_->TryAllocate(size); | 54 uword addr = new_space_->TryAllocate(size); |
| 57 if (addr == 0) { | 55 if (addr == 0) { |
| 58 CollectGarbage(kNew); | 56 CollectGarbage(kNew); |
| 59 addr = new_space_->TryAllocate(size); | 57 addr = new_space_->TryAllocate(size); |
| 60 if (addr == 0) { | 58 if (addr == 0) { |
| 61 return AllocateOld(size, HeapPage::kData); | 59 return AllocateOld(size, HeapPage::kData); |
| 62 } | 60 } |
| 63 } | 61 } |
| 64 if (HeapTrace::is_enabled()) { | |
| 65 heap_trace_->TraceAllocation(addr, size); | |
| 66 } | |
| 67 return addr; | 62 return addr; |
| 68 } | 63 } |
| 69 | 64 |
| 70 | 65 |
| 71 uword Heap::AllocateOld(intptr_t size, HeapPage::PageType type) { | 66 uword Heap::AllocateOld(intptr_t size, HeapPage::PageType type) { |
| 72 ASSERT(Isolate::Current()->no_gc_scope_depth() == 0); | 67 ASSERT(Isolate::Current()->no_gc_scope_depth() == 0); |
| 73 uword addr = old_space_->TryAllocate(size, type); | 68 uword addr = old_space_->TryAllocate(size, type); |
| 74 if (addr == 0) { | 69 if (addr == 0) { |
| 75 CollectAllGarbage(); | 70 CollectAllGarbage(); |
| 76 addr = old_space_->TryAllocate(size, type, PageSpace::kForceGrowth); | 71 addr = old_space_->TryAllocate(size, type, PageSpace::kForceGrowth); |
| 77 if (addr == 0) { | 72 if (addr == 0) { |
| 78 OS::PrintErr("Exhausted heap space, trying to allocate %"Pd" bytes.\n", | 73 OS::PrintErr("Exhausted heap space, trying to allocate %"Pd" bytes.\n", |
| 79 size); | 74 size); |
| 80 return 0; | 75 return 0; |
| 81 } | 76 } |
| 82 } | 77 } |
| 83 if (HeapTrace::is_enabled()) { | |
| 84 heap_trace_->TraceAllocation(addr, size); | |
| 85 } | |
| 86 return addr; | 78 return addr; |
| 87 } | 79 } |
| 88 | 80 |
| 89 | 81 |
| 90 bool Heap::Contains(uword addr) const { | 82 bool Heap::Contains(uword addr) const { |
| 91 return new_space_->Contains(addr) || | 83 return new_space_->Contains(addr) || |
| 92 old_space_->Contains(addr); | 84 old_space_->Contains(addr); |
| 93 } | 85 } |
| 94 | 86 |
| 95 | 87 |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 heap->DisableGrowthControl(); | 487 heap->DisableGrowthControl(); |
| 496 } | 488 } |
| 497 | 489 |
| 498 | 490 |
| 499 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { | 491 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { |
| 500 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); | 492 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); |
| 501 heap->SetGrowthControlState(current_growth_controller_state_); | 493 heap->SetGrowthControlState(current_growth_controller_state_); |
| 502 } | 494 } |
| 503 | 495 |
| 504 } // namespace dart | 496 } // namespace dart |
| OLD | NEW |