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::MakeTLABIterable(uword start, uword end) { | |
|
rmacnak
2017/07/25 21:02:44
Consider recasting as Scavenger::AbandonRemainingT
danunez
2017/07/26 20:19:20
Good call.
| |
| 61 ASSERT(end >= start); | |
| 62 intptr_t size = end - start; | |
|
rmacnak
2017/07/25 21:02:44
Assert size is a multiple of kObjectAlignment
danunez
2017/07/26 20:19:20
Done.
| |
| 63 if (end == new_space_.end()) { | |
| 64 size = 0; | |
| 65 } | |
| 66 if (size > kObjectAlignment) { | |
|
rmacnak
2017/07/25 21:02:44
Create a FreeListElement for size == kObjectAlignm
danunez
2017/07/26 20:19:20
Done.
| |
| 67 FreeListElement::AsElement(start, size); | |
| 68 ASSERT(RawObject::FromAddr(start)->Size() == size); | |
| 69 ASSERT(start + size == new_space_.top()); | |
| 70 } | |
| 71 } | |
| 72 | |
| 73 intptr_t Heap::CalculateTLABSize() { | |
| 74 intptr_t size = new_space_.end() - new_space_.top(); | |
| 75 return Utils::RoundDown(size, kObjectAlignment); | |
| 76 } | |
| 77 | |
| 60 uword Heap::AllocateNew(intptr_t size) { | 78 uword Heap::AllocateNew(intptr_t size) { |
| 61 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0); | 79 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0); |
| 62 // Currently, only the Dart thread may allocate in new space. | 80 // Currently, only the Dart thread may allocate in new space. |
| 63 isolate()->AssertCurrentThreadIsMutator(); | 81 isolate()->AssertCurrentThreadIsMutator(); |
| 64 Thread* thread = Thread::Current(); | 82 Thread* thread = Thread::Current(); |
| 65 uword addr = new_space_.TryAllocateInTLAB(thread, size); | 83 uword addr = new_space_.TryAllocateInTLAB(thread, size); |
| 84 | |
| 85 if (addr != 0) { | |
| 86 return addr; | |
| 87 } | |
| 88 | |
| 89 intptr_t tlab_size = CalculateTLABSize(); | |
| 90 | |
| 91 if (tlab_size > 0 && size > tlab_size) { | |
| 92 return AllocateOld(size, HeapPage::kData); | |
| 93 } | |
| 94 | |
| 95 MakeTLABIterable(thread->top(), thread->end()); | |
| 96 | |
| 97 if (tlab_size > 0) { | |
| 98 uword tlab_top = new_space_.TryAllocateNewTLAB(tlab_size); | |
| 99 | |
| 100 if (tlab_top != 0) { | |
| 101 // Set TLS to tlab_top and tlab_top+tlab_size | |
| 102 thread->set_top(tlab_top); | |
| 103 thread->set_end(new_space_.top()); | |
|
rmacnak
2017/07/25 21:02:44
tlab_top + tlab_size
(Thinking forward, new_space
danunez
2017/07/26 20:19:20
That is a very good point, especially since that s
| |
| 104 ASSERT(thread->top() < new_space_.top()); | |
| 105 addr = new_space_.TryAllocateInTLAB(thread, size); | |
| 106 ASSERT(addr != 0); | |
| 107 return addr; | |
| 108 } | |
| 109 } | |
| 110 | |
| 66 if (addr == 0) { | 111 if (addr == 0) { |
|
rmacnak
2017/07/25 21:02:45
addr must be 0 if we reach here, right?
danunez
2017/07/26 20:19:20
Correct. Consider that removed.
| |
| 67 // This call to CollectGarbage might end up "reusing" a collection spawned | 112 // This call to CollectGarbage might end up "reusing" a collection spawned |
| 68 // from a different thread and will be racing to allocate the requested | 113 // from a different thread and will be racing to allocate the requested |
| 69 // memory with other threads being released after the collection. | 114 // memory with other threads being released after the collection. |
| 70 CollectGarbage(kNew); | 115 CollectGarbage(kNew); |
| 71 addr = new_space_.TryAllocateInTLAB(thread, size); | 116 |
| 72 if (addr == 0) { | 117 intptr_t tlab_size = CalculateTLABSize(); |
| 73 return AllocateOld(size, HeapPage::kData); | 118 uword tlab_top = new_space_.TryAllocateNewTLAB(tlab_size); |
| 119 | |
| 120 if (tlab_top != 0) { | |
| 121 // Set TLS to tlab_top and tlab_top+tlab_size | |
| 122 thread->set_top(tlab_top); | |
| 123 thread->set_end(new_space_.top()); | |
|
rmacnak
2017/07/25 21:02:44
tlab_top + tlab_size
This thread setup seems like
danunez
2017/07/26 20:19:20
Done.
| |
| 124 ASSERT(thread->top() < new_space_.top()); | |
| 125 addr = new_space_.TryAllocateInTLAB(thread, size); | |
| 126 // It is possible a GC doesn't clear enough space. | |
| 127 // In that case, we must fail through and allocate into old space. | |
|
rmacnak
2017/07/25 21:02:44
fall through
danunez
2017/07/26 20:19:20
Done.
| |
| 128 if (addr != 0) { | |
| 129 return addr; | |
| 130 } | |
| 74 } | 131 } |
| 132 | |
| 133 return AllocateOld(size, HeapPage::kData); | |
| 75 } | 134 } |
| 76 return addr; | 135 return addr; |
| 77 } | 136 } |
| 78 | 137 |
| 79 uword Heap::AllocateOld(intptr_t size, HeapPage::PageType type) { | 138 uword Heap::AllocateOld(intptr_t size, HeapPage::PageType type) { |
| 80 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0); | 139 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0); |
| 81 uword addr = old_space_.TryAllocate(size, type); | 140 uword addr = old_space_.TryAllocate(size, type); |
| 82 if (addr != 0) { | 141 if (addr != 0) { |
| 83 return addr; | 142 return addr; |
| 84 } | 143 } |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 539 | 598 |
| 540 bool Heap::Verify(MarkExpectation mark_expectation) const { | 599 bool Heap::Verify(MarkExpectation mark_expectation) const { |
| 541 HeapIterationScope heap_iteration_scope; | 600 HeapIterationScope heap_iteration_scope; |
| 542 return VerifyGC(mark_expectation); | 601 return VerifyGC(mark_expectation); |
| 543 } | 602 } |
| 544 | 603 |
| 545 bool Heap::VerifyGC(MarkExpectation mark_expectation) const { | 604 bool Heap::VerifyGC(MarkExpectation mark_expectation) const { |
| 546 StackZone stack_zone(Thread::Current()); | 605 StackZone stack_zone(Thread::Current()); |
| 547 | 606 |
| 548 // Change the new space's top_ with the more up-to-date thread's view of top_ | 607 // Change the new space's top_ with the more up-to-date thread's view of top_ |
| 549 new_space_.FlushTLS(); | 608 uword top_bk = new_space_.FlushTLS(); |
|
rmacnak
2017/07/25 21:02:44
Consider saved_top since saved_x is the commonly u
danunez
2017/07/26 20:19:20
Done.
| |
| 550 | 609 |
| 551 ObjectSet* allocated_set = | 610 ObjectSet* allocated_set = |
| 552 CreateAllocatedObjectSet(stack_zone.GetZone(), mark_expectation); | 611 CreateAllocatedObjectSet(stack_zone.GetZone(), mark_expectation); |
| 553 VerifyPointersVisitor visitor(isolate(), allocated_set); | 612 VerifyPointersVisitor visitor(isolate(), allocated_set); |
| 554 VisitObjectPointers(&visitor); | 613 VisitObjectPointers(&visitor); |
| 555 | 614 |
| 615 new_space_.UnflushTLS(top_bk); | |
| 556 // Only returning a value so that Heap::Validate can be called from an ASSERT. | 616 // Only returning a value so that Heap::Validate can be called from an ASSERT. |
| 557 return true; | 617 return true; |
| 558 } | 618 } |
| 559 | 619 |
| 560 void Heap::PrintSizes() const { | 620 void Heap::PrintSizes() const { |
| 561 OS::PrintErr( | 621 OS::PrintErr( |
| 562 "New space (%" Pd64 "k of %" Pd64 | 622 "New space (%" Pd64 "k of %" Pd64 |
| 563 "k) " | 623 "k) " |
| 564 "Old space (%" Pd64 "k of %" Pd64 "k)\n", | 624 "Old space (%" Pd64 "k of %" Pd64 "k)\n", |
| 565 (UsedInWords(kNew) / KBInWords), (CapacityInWords(kNew) / KBInWords), | 625 (UsedInWords(kNew) / KBInWords), (CapacityInWords(kNew) / KBInWords), |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 818 : StackResource(thread) { | 878 : StackResource(thread) { |
| 819 Dart::vm_isolate()->heap()->WriteProtect(false); | 879 Dart::vm_isolate()->heap()->WriteProtect(false); |
| 820 } | 880 } |
| 821 | 881 |
| 822 WritableVMIsolateScope::~WritableVMIsolateScope() { | 882 WritableVMIsolateScope::~WritableVMIsolateScope() { |
| 823 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0); | 883 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0); |
| 824 Dart::vm_isolate()->heap()->WriteProtect(true); | 884 Dart::vm_isolate()->heap()->WriteProtect(true); |
| 825 } | 885 } |
| 826 | 886 |
| 827 } // namespace dart | 887 } // namespace dart |
| OLD | NEW |