| 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/compiler_stats.h" | 9 #include "vm/compiler_stats.h" |
| 10 #include "vm/flags.h" | 10 #include "vm/flags.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 | 50 |
| 51 | 51 |
| 52 uword Heap::AllocateNew(intptr_t size) { | 52 uword Heap::AllocateNew(intptr_t size) { |
| 53 ASSERT(Isolate::Current()->no_gc_scope_depth() == 0); | 53 ASSERT(Isolate::Current()->no_gc_scope_depth() == 0); |
| 54 uword addr = new_space_->TryAllocate(size); | 54 uword addr = new_space_->TryAllocate(size); |
| 55 if (addr != 0) { | 55 if (addr != 0) { |
| 56 return addr; | 56 return addr; |
| 57 } | 57 } |
| 58 CollectGarbage(kNew); | 58 CollectGarbage(kNew); |
| 59 if (FLAG_verbose_gc) { | 59 if (FLAG_verbose_gc) { |
| 60 OS::PrintErr("New space (%dk) Old space (%dk) Code space (%dk)\n", | 60 PrintSizes(); |
| 61 (new_space_->in_use() / KB), | |
| 62 (old_space_->in_use() / KB), | |
| 63 (code_space_->in_use() / KB)); | |
| 64 } | 61 } |
| 65 addr = new_space_->TryAllocate(size); | 62 addr = new_space_->TryAllocate(size); |
| 66 if (addr != 0) { | 63 if (addr != 0) { |
| 67 return addr; | 64 return addr; |
| 68 } | 65 } |
| 69 return AllocateOld(size); | 66 return AllocateOld(size); |
| 70 } | 67 } |
| 71 | 68 |
| 72 | 69 |
| 73 uword Heap::AllocateOld(intptr_t size) { | 70 uword Heap::AllocateOld(intptr_t size) { |
| 74 ASSERT(Isolate::Current()->no_gc_scope_depth() == 0); | 71 ASSERT(Isolate::Current()->no_gc_scope_depth() == 0); |
| 75 uword addr = old_space_->TryAllocate(size); | 72 uword addr = old_space_->TryAllocate(size); |
| 76 if (addr == 0) { | 73 if (addr == 0) { |
| 77 CollectAllGarbage(); | 74 CollectAllGarbage(); |
| 78 if (FLAG_verbose_gc) { | 75 if (FLAG_verbose_gc) { |
| 79 OS::PrintErr("New space (%dk) Old space (%dk) Code space (%dk)\n", | 76 PrintSizes(); |
| 80 (new_space_->in_use() / KB), | |
| 81 (old_space_->in_use() / KB), | |
| 82 (code_space_->in_use() / KB)); | |
| 83 } | 77 } |
| 84 addr = old_space_->TryAllocate(size); | 78 addr = old_space_->TryAllocate(size); |
| 85 if (addr == 0) { | 79 if (addr == 0) { |
| 86 // TODO(cshapiro): Support possible heap growth and OOM exception. | 80 // TODO(cshapiro): Support possible heap growth and OOM exception. |
| 87 FATAL1("Exhausted heap space, trying to allocate %d bytes.", size); | 81 FATAL1("Exhausted heap space, trying to allocate %d bytes.", size); |
| 88 } | 82 } |
| 89 } | 83 } |
| 90 return addr; | 84 return addr; |
| 91 } | 85 } |
| 92 | 86 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 bool Heap::Verify() const { | 195 bool Heap::Verify() const { |
| 202 VerifyPointersVisitor visitor(Isolate::Current()); | 196 VerifyPointersVisitor visitor(Isolate::Current()); |
| 203 new_space_->VisitObjectPointers(&visitor); | 197 new_space_->VisitObjectPointers(&visitor); |
| 204 old_space_->VisitObjectPointers(&visitor); | 198 old_space_->VisitObjectPointers(&visitor); |
| 205 code_space_->VisitObjectPointers(&visitor); | 199 code_space_->VisitObjectPointers(&visitor); |
| 206 // Only returning a value so that Heap::Validate can be called from an ASSERT. | 200 // Only returning a value so that Heap::Validate can be called from an ASSERT. |
| 207 return true; | 201 return true; |
| 208 } | 202 } |
| 209 | 203 |
| 210 | 204 |
| 205 void Heap::PrintSizes() const { |
| 206 OS::PrintErr("New space (%dk) Old space (%dk) Code space (%dk)\n", |
| 207 (new_space_->in_use() / KB), |
| 208 (old_space_->in_use() / KB), |
| 209 (code_space_->in_use() / KB)); |
| 210 } |
| 211 |
| 212 |
| 211 #if defined(DEBUG) | 213 #if defined(DEBUG) |
| 212 NoGCScope::NoGCScope() : StackResource(Isolate::Current()) { | 214 NoGCScope::NoGCScope() : StackResource(Isolate::Current()) { |
| 213 isolate()->IncrementNoGCScopeDepth(); | 215 isolate()->IncrementNoGCScopeDepth(); |
| 214 } | 216 } |
| 215 | 217 |
| 216 | 218 |
| 217 NoGCScope::~NoGCScope() { | 219 NoGCScope::~NoGCScope() { |
| 218 isolate()->DecrementNoGCScopeDepth(); | 220 isolate()->DecrementNoGCScopeDepth(); |
| 219 } | 221 } |
| 220 #endif // defined(DEBUG) | 222 #endif // defined(DEBUG) |
| 221 | 223 |
| 222 } // namespace dart | 224 } // namespace dart |
| OLD | NEW |