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" |
| 11 #include "vm/lockers.h" | |
| 11 #include "vm/object.h" | 12 #include "vm/object.h" |
| 12 #include "vm/object_set.h" | 13 #include "vm/object_set.h" |
| 13 #include "vm/os.h" | 14 #include "vm/os.h" |
| 14 #include "vm/pages.h" | 15 #include "vm/pages.h" |
| 15 #include "vm/raw_object.h" | 16 #include "vm/raw_object.h" |
| 16 #include "vm/scavenger.h" | 17 #include "vm/scavenger.h" |
| 17 #include "vm/service.h" | 18 #include "vm/service.h" |
| 18 #include "vm/stack_frame.h" | 19 #include "vm/stack_frame.h" |
| 19 #include "vm/tags.h" | 20 #include "vm/tags.h" |
| 20 #include "vm/verifier.h" | 21 #include "vm/verifier.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 return AllocateOld(size, HeapPage::kData); | 74 return AllocateOld(size, HeapPage::kData); |
| 74 } | 75 } |
| 75 } | 76 } |
| 76 return addr; | 77 return addr; |
| 77 } | 78 } |
| 78 | 79 |
| 79 | 80 |
| 80 uword Heap::AllocateOld(intptr_t size, HeapPage::PageType type) { | 81 uword Heap::AllocateOld(intptr_t size, HeapPage::PageType type) { |
| 81 ASSERT(isolate()->no_gc_scope_depth() == 0); | 82 ASSERT(isolate()->no_gc_scope_depth() == 0); |
| 82 uword addr = old_space_->TryAllocate(size, type); | 83 uword addr = old_space_->TryAllocate(size, type); |
| 83 if (addr == 0) { | 84 if (addr != 0) { |
| 84 CollectAllGarbage(); | 85 return addr; |
| 85 addr = old_space_->TryAllocate(size, type, PageSpace::kForceGrowth); | 86 } |
| 86 if (addr == 0) { | 87 // If we are in the process of running a sweep wait for the sweeper to free |
| 87 OS::PrintErr("Exhausted heap space, trying to allocate %" Pd " bytes.\n", | 88 // memory. |
| 88 size); | 89 { |
| 89 return 0; | 90 MonitorLocker ml(old_space_->tasks_lock()); |
| 91 addr = old_space_->TryAllocate(size, type); | |
| 92 while ((addr == 0) && (old_space_->tasks())) { | |
| 93 ml.Wait(); | |
| 94 addr = old_space_->TryAllocate(size, type); | |
| 90 } | 95 } |
| 91 } | 96 } |
| 92 return addr; | 97 if (addr != 0) { |
| 98 return addr; | |
| 99 } | |
| 100 // All GC tasks finished without allocating successfully. Run a full GC. | |
| 101 CollectAllGarbage(); | |
| 102 addr = old_space_->TryAllocate(size, type, PageSpace::kForceGrowth); | |
| 103 if (addr != 0) { | |
| 104 return addr; | |
| 105 } | |
| 106 // Wait for all of the concurrent tasks to finish before giving up. | |
| 107 { | |
| 108 MonitorLocker ml(old_space_->tasks_lock()); | |
| 109 addr = old_space_->TryAllocate(size, type); | |
| 110 while ((addr == 0) && (old_space_->tasks())) { | |
| 111 ml.Wait(); | |
| 112 addr = old_space_->TryAllocate(size, type); | |
|
koda
2014/08/27 05:42:20
Shouldn't this have kForceGrowth?
| |
| 113 } | |
| 114 } | |
| 115 if (addr != 0) { | |
| 116 return addr; | |
| 117 } | |
| 118 // Giving up allocating this object. | |
| 119 OS::PrintErr( | |
| 120 "Exhausted heap space, trying to allocate %" Pd " bytes.\n", size); | |
| 121 return 0; | |
| 93 } | 122 } |
| 94 | 123 |
| 95 void Heap::AllocateExternal(intptr_t size, Space space) { | 124 void Heap::AllocateExternal(intptr_t size, Space space) { |
| 96 ASSERT(isolate()->no_gc_scope_depth() == 0); | 125 ASSERT(isolate()->no_gc_scope_depth() == 0); |
| 97 if (space == kNew) { | 126 if (space == kNew) { |
| 98 new_space_->AllocateExternal(size); | 127 new_space_->AllocateExternal(size); |
| 99 if (new_space_->ExternalInWords() > (FLAG_new_gen_ext_limit * MBInWords)) { | 128 if (new_space_->ExternalInWords() > (FLAG_new_gen_ext_limit * MBInWords)) { |
| 100 // Attempt to free some external allocation by a scavenge. (If the total | 129 // Attempt to free some external allocation by a scavenge. (If the total |
| 101 // remains above the limit, next external alloc will trigger another.) | 130 // remains above the limit, next external alloc will trigger another.) |
| 102 CollectGarbage(kNew); | 131 CollectGarbage(kNew); |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 601 heap->DisableGrowthControl(); | 630 heap->DisableGrowthControl(); |
| 602 } | 631 } |
| 603 | 632 |
| 604 | 633 |
| 605 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { | 634 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { |
| 606 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); | 635 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); |
| 607 heap->SetGrowthControlState(current_growth_controller_state_); | 636 heap->SetGrowthControlState(current_growth_controller_state_); |
| 608 } | 637 } |
| 609 | 638 |
| 610 } // namespace dart | 639 } // namespace dart |
| OLD | NEW |