| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 ASSERT(isolate()->no_gc_scope_depth() == 0); | 82 ASSERT(isolate()->no_gc_scope_depth() == 0); |
| 83 uword addr = old_space_->TryAllocate(size, type); | 83 uword addr = old_space_->TryAllocate(size, type); |
| 84 if (addr != 0) { | 84 if (addr != 0) { |
| 85 return addr; | 85 return addr; |
| 86 } | 86 } |
| 87 // If we are in the process of running a sweep wait for the sweeper to free | 87 // If we are in the process of running a sweep wait for the sweeper to free |
| 88 // memory. | 88 // memory. |
| 89 { | 89 { |
| 90 MonitorLocker ml(old_space_->tasks_lock()); | 90 MonitorLocker ml(old_space_->tasks_lock()); |
| 91 addr = old_space_->TryAllocate(size, type); | 91 addr = old_space_->TryAllocate(size, type); |
| 92 while ((addr == 0) && (old_space_->tasks())) { | 92 while ((addr == 0) && (old_space_->tasks() > 0)) { |
| 93 ml.Wait(); | 93 ml.Wait(); |
| 94 addr = old_space_->TryAllocate(size, type); | 94 addr = old_space_->TryAllocate(size, type); |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 if (addr != 0) { | 97 if (addr != 0) { |
| 98 return addr; | 98 return addr; |
| 99 } | 99 } |
| 100 // All GC tasks finished without allocating successfully. Run a full GC. | 100 // All GC tasks finished without allocating successfully. Run an old GC. |
| 101 CollectAllGarbage(); | 101 CollectGarbage(kOld); |
| 102 addr = old_space_->TryAllocate(size, type, PageSpace::kForceGrowth); | 102 addr = old_space_->TryAllocate(size, type); |
| 103 if (addr != 0) { | 103 if (addr != 0) { |
| 104 return addr; | 104 return addr; |
| 105 } | 105 } |
| 106 // Wait for all of the concurrent tasks to finish before giving up. | 106 // Wait for all of the concurrent tasks to finish before giving up. |
| 107 { | 107 { |
| 108 MonitorLocker ml(old_space_->tasks_lock()); | 108 MonitorLocker ml(old_space_->tasks_lock()); |
| 109 addr = old_space_->TryAllocate(size, type, PageSpace::kForceGrowth); | 109 addr = old_space_->TryAllocate(size, type); |
| 110 while ((addr == 0) && (old_space_->tasks())) { | 110 while ((addr == 0) && (old_space_->tasks() > 0)) { |
| 111 ml.Wait(); | 111 ml.Wait(); |
| 112 addr = old_space_->TryAllocate(size, type, PageSpace::kForceGrowth); | 112 addr = old_space_->TryAllocate(size, type); |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 if (addr != 0) { | 115 if (addr != 0) { |
| 116 return addr; | 116 return addr; |
| 117 } | 117 } |
| 118 // Giving up allocating this object. | 118 // Force growth before attempting a synchronous GC. |
| 119 addr = old_space_->TryAllocate(size, type, PageSpace::kForceGrowth); |
| 120 if (addr != 0) { |
| 121 return addr; |
| 122 } |
| 123 // Before throwing an out-of-memory error try a synchronous GC. |
| 124 CollectAllGarbage(); |
| 125 { |
| 126 MonitorLocker ml(old_space_->tasks_lock()); |
| 127 while (old_space_->tasks() > 0) { |
| 128 ml.Wait(); |
| 129 } |
| 130 } |
| 131 addr = old_space_->TryAllocate(size, type, PageSpace::kForceGrowth); |
| 132 if (addr != 0) { |
| 133 return addr; |
| 134 } |
| 135 // Give up allocating this object. |
| 119 OS::PrintErr( | 136 OS::PrintErr( |
| 120 "Exhausted heap space, trying to allocate %" Pd " bytes.\n", size); | 137 "Exhausted heap space, trying to allocate %" Pd " bytes.\n", size); |
| 121 return 0; | 138 return 0; |
| 122 } | 139 } |
| 123 | 140 |
| 124 void Heap::AllocateExternal(intptr_t size, Space space) { | 141 void Heap::AllocateExternal(intptr_t size, Space space) { |
| 125 ASSERT(isolate()->no_gc_scope_depth() == 0); | 142 ASSERT(isolate()->no_gc_scope_depth() == 0); |
| 126 if (space == kNew) { | 143 if (space == kNew) { |
| 127 new_space_->AllocateExternal(size); | 144 new_space_->AllocateExternal(size); |
| 128 if (new_space_->ExternalInWords() > (FLAG_new_gen_ext_limit * MBInWords)) { | 145 if (new_space_->ExternalInWords() > (FLAG_new_gen_ext_limit * MBInWords)) { |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 heap->DisableGrowthControl(); | 647 heap->DisableGrowthControl(); |
| 631 } | 648 } |
| 632 | 649 |
| 633 | 650 |
| 634 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { | 651 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { |
| 635 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); | 652 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); |
| 636 heap->SetGrowthControlState(current_growth_controller_state_); | 653 heap->SetGrowthControlState(current_growth_controller_state_); |
| 637 } | 654 } |
| 638 | 655 |
| 639 } // namespace dart | 656 } // namespace dart |
| OLD | NEW |