Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: runtime/vm/heap.cc

Issue 2991343003: Makes new space iterable by filling up the mutator's TLAB (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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::FillRemainingTLAB(Thread* thread) {
61 uword start = thread->top();
62 uword end = thread->end();
63 ASSERT(end >= start);
64 intptr_t size = end - start;
65 if (end == new_space_.end()) {
rmacnak 2017/08/03 20:31:40 Do we need this check? Won't this only happen if t
danunez 2017/08/03 20:39:21 As discussed, the TLAB may not be full. This check
66 size = 0;
67 }
68 ASSERT(Utils::IsAligned(size, kObjectAlignment));
69 if (size >= kObjectAlignment) {
70 FreeListElement::AsElement(start, size);
71 ASSERT(RawObject::FromAddr(start)->Size() == size);
72 ASSERT((start + size) == new_space_.top());
73 }
74 }
75
76 void Heap::AbandonRemainingTLAB(Thread* thread) {
77 FillRemainingTLAB(thread);
78 thread->set_top(0);
79 thread->set_end(0);
80 }
81
82 intptr_t Heap::CalculateTLABSize() {
83 intptr_t size = new_space_.end() - new_space_.top();
84 return Utils::RoundDown(size, kObjectAlignment);
85 }
86
60 uword Heap::AllocateNew(intptr_t size) { 87 uword Heap::AllocateNew(intptr_t size) {
61 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0); 88 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0);
62 // Currently, only the Dart thread may allocate in new space. 89 // Currently, only the Dart thread may allocate in new space.
63 isolate()->AssertCurrentThreadIsMutator(); 90 isolate()->AssertCurrentThreadIsMutator();
64 Thread* thread = Thread::Current(); 91 Thread* thread = Thread::Current();
65 uword addr = new_space_.TryAllocateInTLAB(thread, size); 92 uword addr = new_space_.TryAllocateInTLAB(thread, size);
66 if (addr == 0) { 93 if (addr != 0) {
67 // This call to CollectGarbage might end up "reusing" a collection spawned 94 return addr;
68 // from a different thread and will be racing to allocate the requested 95 }
69 // memory with other threads being released after the collection. 96
70 CollectGarbage(kNew); 97 intptr_t tlab_size = CalculateTLABSize();
71 addr = new_space_.TryAllocateInTLAB(thread, size); 98 if ((tlab_size > 0) && (size > tlab_size)) {
72 if (addr == 0) { 99 return AllocateOld(size, HeapPage::kData);
73 return AllocateOld(size, HeapPage::kData); 100 }
101
102 AbandonRemainingTLAB(thread);
103 if (tlab_size > 0) {
104 uword tlab_top = new_space_.TryAllocateNewTLAB(thread, tlab_size);
105 if (tlab_top != 0) {
106 addr = new_space_.TryAllocateInTLAB(thread, size);
107 ASSERT(addr != 0);
108 return addr;
74 } 109 }
75 } 110 }
76 return addr; 111
112 ASSERT(!thread->HasActiveTLAB());
113
114 // This call to CollectGarbage might end up "reusing" a collection spawned
115 // from a different thread and will be racing to allocate the requested
116 // memory with other threads being released after the collection.
117 CollectGarbage(kNew);
118 tlab_size = CalculateTLABSize();
119 uword tlab_top = new_space_.TryAllocateNewTLAB(thread, tlab_size);
120 if (tlab_top != 0) {
121 addr = new_space_.TryAllocateInTLAB(thread, size);
122 // It is possible a GC doesn't clear enough space.
123 // In that case, we must fall through and allocate into old space.
124 if (addr != 0) {
125 return addr;
126 }
127 }
128 return AllocateOld(size, HeapPage::kData);
77 } 129 }
78 130
79 uword Heap::AllocateOld(intptr_t size, HeapPage::PageType type) { 131 uword Heap::AllocateOld(intptr_t size, HeapPage::PageType type) {
80 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0); 132 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0);
81 uword addr = old_space_.TryAllocate(size, type); 133 uword addr = old_space_.TryAllocate(size, type);
82 if (addr != 0) { 134 if (addr != 0) {
83 return addr; 135 return addr;
84 } 136 }
85 // If we are in the process of running a sweep, wait for the sweeper to free 137 // If we are in the process of running a sweep, wait for the sweeper to free
86 // memory. 138 // memory.
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 600
549 bool Heap::Verify(MarkExpectation mark_expectation) const { 601 bool Heap::Verify(MarkExpectation mark_expectation) const {
550 HeapIterationScope heap_iteration_scope; 602 HeapIterationScope heap_iteration_scope;
551 return VerifyGC(mark_expectation); 603 return VerifyGC(mark_expectation);
552 } 604 }
553 605
554 bool Heap::VerifyGC(MarkExpectation mark_expectation) const { 606 bool Heap::VerifyGC(MarkExpectation mark_expectation) const {
555 StackZone stack_zone(Thread::Current()); 607 StackZone stack_zone(Thread::Current());
556 608
557 // Change the new space's top_ with the more up-to-date thread's view of top_ 609 // Change the new space's top_ with the more up-to-date thread's view of top_
558 new_space_.FlushTLS(); 610 uword saved_top = new_space_.FlushTLS();
559 611
560 ObjectSet* allocated_set = 612 ObjectSet* allocated_set =
561 CreateAllocatedObjectSet(stack_zone.GetZone(), mark_expectation); 613 CreateAllocatedObjectSet(stack_zone.GetZone(), mark_expectation);
562 VerifyPointersVisitor visitor(isolate(), allocated_set); 614 VerifyPointersVisitor visitor(isolate(), allocated_set);
563 VisitObjectPointers(&visitor); 615 VisitObjectPointers(&visitor);
564 616
617 new_space_.UnflushTLS(saved_top);
565 // Only returning a value so that Heap::Validate can be called from an ASSERT. 618 // Only returning a value so that Heap::Validate can be called from an ASSERT.
566 return true; 619 return true;
567 } 620 }
568 621
569 void Heap::PrintSizes() const { 622 void Heap::PrintSizes() const {
570 OS::PrintErr( 623 OS::PrintErr(
571 "New space (%" Pd64 "k of %" Pd64 624 "New space (%" Pd64 "k of %" Pd64
572 "k) " 625 "k) "
573 "Old space (%" Pd64 "k of %" Pd64 "k)\n", 626 "Old space (%" Pd64 "k of %" Pd64 "k)\n",
574 (UsedInWords(kNew) / KBInWords), (CapacityInWords(kNew) / KBInWords), 627 (UsedInWords(kNew) / KBInWords), (CapacityInWords(kNew) / KBInWords),
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 : StackResource(thread) { 882 : StackResource(thread) {
830 Dart::vm_isolate()->heap()->WriteProtect(false); 883 Dart::vm_isolate()->heap()->WriteProtect(false);
831 } 884 }
832 885
833 WritableVMIsolateScope::~WritableVMIsolateScope() { 886 WritableVMIsolateScope::~WritableVMIsolateScope() {
834 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0); 887 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0);
835 Dart::vm_isolate()->heap()->WriteProtect(true); 888 Dart::vm_isolate()->heap()->WriteProtect(true);
836 } 889 }
837 890
838 } // namespace dart 891 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/heap.h ('k') | runtime/vm/isolate.cc » ('j') | runtime/vm/scavenger.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698