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" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 Heap::~Heap() { | 50 Heap::~Heap() { |
| 51 delete barrier_; | 51 delete barrier_; |
| 52 delete barrier_done_; | 52 delete barrier_done_; |
| 53 | 53 |
| 54 for (int sel = 0; sel < kNumWeakSelectors; sel++) { | 54 for (int sel = 0; sel < kNumWeakSelectors; sel++) { |
| 55 delete new_weak_tables_[sel]; | 55 delete new_weak_tables_[sel]; |
| 56 delete old_weak_tables_[sel]; | 56 delete old_weak_tables_[sel]; |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 void Heap::AbandonRemainingTLAB(Thread* thread) { | 60 void Heap::FillRemainingTLAB(Thread* thread) { |
| 61 uword start = thread->top(); | 61 uword start = thread->top(); |
| 62 uword end = thread->end(); | 62 uword end = thread->end(); |
| 63 ASSERT(end >= start); | 63 ASSERT(end >= start); |
| 64 intptr_t size = end - start; | 64 intptr_t size = end - start; |
| 65 if (end == new_space_.end()) { | 65 if (end == new_space_.end()) { |
| 66 size = 0; | 66 size = 0; |
| 67 } | 67 } |
| 68 ASSERT(Utils::IsAligned(size, kObjectAlignment)); | 68 ASSERT(Utils::IsAligned(size, kObjectAlignment)); |
| 69 if (size >= kObjectAlignment) { | 69 if (size >= kObjectAlignment) { |
| 70 FreeListElement::AsElement(start, size); | 70 FreeListElement::AsElement(start, size); |
| 71 ASSERT(RawObject::FromAddr(start)->Size() == size); | 71 ASSERT(RawObject::FromAddr(start)->Size() == size); |
| 72 ASSERT((start + size) == new_space_.top()); | |
| 73 } | 72 } |
| 73 } | |
| 74 | |
| 75 void Heap::AbandonRemainingTLAB(Thread* thread) { | |
| 76 FillRemainingTLAB(thread); | |
| 74 thread->set_top(0); | 77 thread->set_top(0); |
| 75 thread->set_end(0); | 78 thread->set_end(0); |
| 76 } | 79 } |
| 77 | 80 |
| 78 intptr_t Heap::CalculateTLABSize() { | 81 intptr_t Heap::CalculateTLABSize() { |
| 79 intptr_t size = new_space_.end() - new_space_.top(); | 82 intptr_t size = new_space_.end() - new_space_.top(); |
| 80 return Utils::RoundDown(size, kObjectAlignment); | 83 return Utils::RoundDown(size, kObjectAlignment); |
| 81 } | 84 } |
| 82 | 85 |
| 83 uword Heap::AllocateNew(intptr_t size) { | 86 uword Heap::AllocateNew(intptr_t size) { |
| 84 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0); | 87 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0); |
| 85 // Currently, only the Dart thread may allocate in new space. | 88 // Currently, only the Dart thread may allocate in new space. |
| 86 isolate()->AssertCurrentThreadIsMutator(); | 89 isolate()->AssertCurrentThreadIsMutator(); |
| 90 ASSERT(Thread::Current()->IsMutatorThread()); | |
|
rmacnak
2017/08/01 21:51:25
Isn't this the same as the line above?
danunez
2017/08/01 23:25:34
Yes it is. I will remove it.
| |
| 87 Thread* thread = Thread::Current(); | 91 Thread* thread = Thread::Current(); |
| 88 uword addr = new_space_.TryAllocateInTLAB(thread, size); | 92 uword addr = new_space_.TryAllocateInTLAB(thread, size); |
| 89 if (addr != 0) { | 93 if (addr != 0) { |
| 90 return addr; | 94 return addr; |
| 91 } | 95 } |
| 92 | 96 |
| 93 intptr_t tlab_size = CalculateTLABSize(); | 97 intptr_t tlab_size = CalculateTLABSize(); |
| 94 if ((tlab_size > 0) && (size > tlab_size)) { | 98 if ((tlab_size > 0) && (size > tlab_size)) { |
| 95 return AllocateOld(size, HeapPage::kData); | 99 return AllocateOld(size, HeapPage::kData); |
| 96 } | 100 } |
| 97 | 101 |
| 98 AbandonRemainingTLAB(thread); | 102 AbandonRemainingTLAB(thread); |
| 103 | |
| 104 // TODO(danunez): Lock for new space here | |
| 99 if (tlab_size > 0) { | 105 if (tlab_size > 0) { |
| 100 uword tlab_top = new_space_.TryAllocateNewTLAB(thread, tlab_size); | 106 uword tlab_top = new_space_.TryAllocateNewTLAB(thread, tlab_size); |
| 101 if (tlab_top != 0) { | 107 if (tlab_top != 0) { |
| 102 addr = new_space_.TryAllocateInTLAB(thread, size); | 108 addr = new_space_.TryAllocateInTLAB(thread, size); |
| 103 ASSERT(addr != 0); | 109 ASSERT(addr != 0); |
| 110 // TODO(danunez): Unlock for new space here | |
| 104 return addr; | 111 return addr; |
| 105 } | 112 } |
| 106 } | 113 } |
| 107 | 114 |
| 108 ASSERT(!thread->HasActiveTLAB()); | 115 ASSERT(!thread->HasActiveTLAB()); |
| 109 | 116 |
| 110 // This call to CollectGarbage might end up "reusing" a collection spawned | 117 // This call to CollectGarbage might end up "reusing" a collection spawned |
| 111 // from a different thread and will be racing to allocate the requested | 118 // from a different thread and will be racing to allocate the requested |
| 112 // memory with other threads being released after the collection. | 119 // memory with other threads being released after the collection. |
| 120 | |
| 121 // TODO(danunez): Ensure that once we start collecting garbage, everything | |
| 122 // stops allocating. | |
| 123 // Safepoint should be dealing with this, but we need to make sure somehow. | |
| 113 CollectGarbage(kNew); | 124 CollectGarbage(kNew); |
| 114 tlab_size = CalculateTLABSize(); | 125 tlab_size = CalculateTLABSize(); |
| 115 uword tlab_top = new_space_.TryAllocateNewTLAB(thread, tlab_size); | 126 uword tlab_top = new_space_.TryAllocateNewTLAB(thread, tlab_size); |
| 127 | |
| 128 // TODO(danunez): Unlock for new space here. Regardless of the outcome, we | |
| 129 // don't need the new space. | |
| 116 if (tlab_top != 0) { | 130 if (tlab_top != 0) { |
| 117 addr = new_space_.TryAllocateInTLAB(thread, size); | 131 addr = new_space_.TryAllocateInTLAB(thread, size); |
| 118 // It is possible a GC doesn't clear enough space. | 132 // It is possible a GC doesn't clear enough space. |
| 119 // In that case, we must fall through and allocate into old space. | 133 // In that case, we must fall through and allocate into old space. |
| 120 if (addr != 0) { | 134 if (addr != 0) { |
| 121 return addr; | 135 return addr; |
| 122 } | 136 } |
| 123 } | 137 } |
| 124 return AllocateOld(size, HeapPage::kData); | 138 return AllocateOld(size, HeapPage::kData); |
| 125 } | 139 } |
| (...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 878 : StackResource(thread) { | 892 : StackResource(thread) { |
| 879 Dart::vm_isolate()->heap()->WriteProtect(false); | 893 Dart::vm_isolate()->heap()->WriteProtect(false); |
| 880 } | 894 } |
| 881 | 895 |
| 882 WritableVMIsolateScope::~WritableVMIsolateScope() { | 896 WritableVMIsolateScope::~WritableVMIsolateScope() { |
| 883 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0); | 897 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0); |
| 884 Dart::vm_isolate()->heap()->WriteProtect(true); | 898 Dart::vm_isolate()->heap()->WriteProtect(true); |
| 885 } | 899 } |
| 886 | 900 |
| 887 } // namespace dart | 901 } // namespace dart |
| OLD | NEW |