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

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

Issue 2995693002: Puts TLABs back into the build and fixes assert failure. (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
« no previous file with comments | « runtime/vm/heap.h ('k') | runtime/vm/isolate.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 Heap::~Heap() { 51 Heap::~Heap() {
52 delete barrier_; 52 delete barrier_;
53 delete barrier_done_; 53 delete barrier_done_;
54 54
55 for (int sel = 0; sel < kNumWeakSelectors; sel++) { 55 for (int sel = 0; sel < kNumWeakSelectors; sel++) {
56 delete new_weak_tables_[sel]; 56 delete new_weak_tables_[sel];
57 delete old_weak_tables_[sel]; 57 delete old_weak_tables_[sel];
58 } 58 }
59 } 59 }
60 60
61 void Heap::FillRemainingTLAB(Thread* thread) {
62 uword start = thread->top();
63 uword end = thread->end();
64 ASSERT(end >= start);
65 intptr_t size = end - start;
66 ASSERT(Utils::IsAligned(size, kObjectAlignment));
67 if (size >= kObjectAlignment) {
68 FreeListElement::AsElement(start, size);
69 ASSERT(RawObject::FromAddr(start)->Size() == size);
70 ASSERT((start + size) == new_space_.top());
71 }
72 }
73
74 void Heap::AbandonRemainingTLAB(Thread* thread) {
75 FillRemainingTLAB(thread);
76 thread->set_top(0);
77 thread->set_end(0);
78 }
79
80 intptr_t Heap::CalculateTLABSize() {
81 intptr_t size = new_space_.end() - new_space_.top();
82 return Utils::RoundDown(size, kObjectAlignment);
83 }
84
61 uword Heap::AllocateNew(intptr_t size) { 85 uword Heap::AllocateNew(intptr_t size) {
62 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0); 86 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0);
63 // Currently, only the Dart thread may allocate in new space. 87 // Currently, only the Dart thread may allocate in new space.
64 isolate()->AssertCurrentThreadIsMutator(); 88 isolate()->AssertCurrentThreadIsMutator();
65 Thread* thread = Thread::Current(); 89 Thread* thread = Thread::Current();
66 uword addr = new_space_.TryAllocateInTLAB(thread, size); 90 uword addr = new_space_.TryAllocateInTLAB(thread, size);
67 if (addr == 0) { 91 if (addr != 0) {
68 // This call to CollectGarbage might end up "reusing" a collection spawned 92 return addr;
69 // from a different thread and will be racing to allocate the requested 93 }
70 // memory with other threads being released after the collection. 94
71 CollectGarbage(kNew); 95 intptr_t tlab_size = CalculateTLABSize();
72 addr = new_space_.TryAllocateInTLAB(thread, size); 96 if ((tlab_size > 0) && (size > tlab_size)) {
73 if (addr == 0) { 97 return AllocateOld(size, HeapPage::kData);
74 return AllocateOld(size, HeapPage::kData); 98 }
99
100 AbandonRemainingTLAB(thread);
101 if (tlab_size > 0) {
102 uword tlab_top = new_space_.TryAllocateNewTLAB(thread, tlab_size);
103 if (tlab_top != 0) {
104 addr = new_space_.TryAllocateInTLAB(thread, size);
105 ASSERT(addr != 0);
106 return addr;
75 } 107 }
76 } 108 }
77 return addr; 109
110 ASSERT(!thread->HasActiveTLAB());
111
112 // This call to CollectGarbage might end up "reusing" a collection spawned
113 // from a different thread and will be racing to allocate the requested
114 // memory with other threads being released after the collection.
115 CollectGarbage(kNew);
116 tlab_size = CalculateTLABSize();
117 uword tlab_top = new_space_.TryAllocateNewTLAB(thread, tlab_size);
118 if (tlab_top != 0) {
119 addr = new_space_.TryAllocateInTLAB(thread, size);
120 // It is possible a GC doesn't clear enough space.
121 // In that case, we must fall through and allocate into old space.
122 if (addr != 0) {
123 return addr;
124 }
125 }
126 return AllocateOld(size, HeapPage::kData);
78 } 127 }
79 128
80 uword Heap::AllocateOld(intptr_t size, HeapPage::PageType type) { 129 uword Heap::AllocateOld(intptr_t size, HeapPage::PageType type) {
81 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0); 130 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0);
82 uword addr = old_space_.TryAllocate(size, type); 131 uword addr = old_space_.TryAllocate(size, type);
83 if (addr != 0) { 132 if (addr != 0) {
84 return addr; 133 return addr;
85 } 134 }
86 // If we are in the process of running a sweep, wait for the sweeper to free 135 // If we are in the process of running a sweep, wait for the sweeper to free
87 // memory. 136 // memory.
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 618
570 bool Heap::Verify(MarkExpectation mark_expectation) const { 619 bool Heap::Verify(MarkExpectation mark_expectation) const {
571 HeapIterationScope heap_iteration_scope(Thread::Current()); 620 HeapIterationScope heap_iteration_scope(Thread::Current());
572 return VerifyGC(mark_expectation); 621 return VerifyGC(mark_expectation);
573 } 622 }
574 623
575 bool Heap::VerifyGC(MarkExpectation mark_expectation) const { 624 bool Heap::VerifyGC(MarkExpectation mark_expectation) const {
576 StackZone stack_zone(Thread::Current()); 625 StackZone stack_zone(Thread::Current());
577 626
578 // Change the new space's top_ with the more up-to-date thread's view of top_ 627 // Change the new space's top_ with the more up-to-date thread's view of top_
579 new_space_.FlushTLS(); 628 new_space_.MakeNewSpaceIterable();
580 629
581 ObjectSet* allocated_set = 630 ObjectSet* allocated_set =
582 CreateAllocatedObjectSet(stack_zone.GetZone(), mark_expectation); 631 CreateAllocatedObjectSet(stack_zone.GetZone(), mark_expectation);
583 VerifyPointersVisitor visitor(isolate(), allocated_set); 632 VerifyPointersVisitor visitor(isolate(), allocated_set);
584 VisitObjectPointers(&visitor); 633 VisitObjectPointers(&visitor);
585 634
586 // Only returning a value so that Heap::Validate can be called from an ASSERT. 635 // Only returning a value so that Heap::Validate can be called from an ASSERT.
587 return true; 636 return true;
588 } 637 }
589 638
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 : StackResource(thread) { 899 : StackResource(thread) {
851 Dart::vm_isolate()->heap()->WriteProtect(false); 900 Dart::vm_isolate()->heap()->WriteProtect(false);
852 } 901 }
853 902
854 WritableVMIsolateScope::~WritableVMIsolateScope() { 903 WritableVMIsolateScope::~WritableVMIsolateScope() {
855 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0); 904 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0);
856 Dart::vm_isolate()->heap()->WriteProtect(true); 905 Dart::vm_isolate()->heap()->WriteProtect(true);
857 } 906 }
858 907
859 } // namespace dart 908 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/heap.h ('k') | runtime/vm/isolate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698