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

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

Issue 2992343002: Attempts to fix bugs introduced in 8b6fcf50e85d. (Closed)
Patch Set: Removes UnflushTLS() and renames FlushTLS to something appropriate 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 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 ASSERT(Utils::IsAligned(size, kObjectAlignment));
66 if (size >= kObjectAlignment) {
67 FreeListElement::AsElement(start, size);
68 ASSERT(RawObject::FromAddr(start)->Size() == size);
69 ASSERT((start + size) == new_space_.top());
70 }
71 }
72
73 void Heap::AbandonRemainingTLAB(Thread* thread) {
74 FillRemainingTLAB(thread);
75 thread->set_top(0);
76 thread->set_end(0);
77 }
78
79 intptr_t Heap::CalculateTLABSize() {
80 intptr_t size = new_space_.end() - new_space_.top();
81 return Utils::RoundDown(size, kObjectAlignment);
82 }
83
60 uword Heap::AllocateNew(intptr_t size) { 84 uword Heap::AllocateNew(intptr_t size) {
61 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0); 85 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0);
62 // Currently, only the Dart thread may allocate in new space. 86 // Currently, only the Dart thread may allocate in new space.
63 isolate()->AssertCurrentThreadIsMutator(); 87 isolate()->AssertCurrentThreadIsMutator();
64 Thread* thread = Thread::Current(); 88 Thread* thread = Thread::Current();
65 uword addr = new_space_.TryAllocateInTLAB(thread, size); 89 uword addr = new_space_.TryAllocateInTLAB(thread, size);
66 if (addr == 0) { 90 if (addr != 0) {
67 // This call to CollectGarbage might end up "reusing" a collection spawned 91 return addr;
68 // from a different thread and will be racing to allocate the requested 92 }
69 // memory with other threads being released after the collection. 93
70 CollectGarbage(kNew); 94 intptr_t tlab_size = CalculateTLABSize();
71 addr = new_space_.TryAllocateInTLAB(thread, size); 95 if ((tlab_size > 0) && (size > tlab_size)) {
72 if (addr == 0) { 96 return AllocateOld(size, HeapPage::kData);
73 return AllocateOld(size, HeapPage::kData); 97 }
98
99 AbandonRemainingTLAB(thread);
100 if (tlab_size > 0) {
101 uword tlab_top = new_space_.TryAllocateNewTLAB(thread, tlab_size);
102 if (tlab_top != 0) {
103 addr = new_space_.TryAllocateInTLAB(thread, size);
104 ASSERT(addr != 0);
105 return addr;
74 } 106 }
75 } 107 }
76 return addr; 108
109 ASSERT(!thread->HasActiveTLAB());
110
111 // This call to CollectGarbage might end up "reusing" a collection spawned
112 // from a different thread and will be racing to allocate the requested
113 // memory with other threads being released after the collection.
114 CollectGarbage(kNew);
115 tlab_size = CalculateTLABSize();
116 uword tlab_top = new_space_.TryAllocateNewTLAB(thread, tlab_size);
117 if (tlab_top != 0) {
118 addr = new_space_.TryAllocateInTLAB(thread, size);
119 // It is possible a GC doesn't clear enough space.
120 // In that case, we must fall through and allocate into old space.
121 if (addr != 0) {
122 return addr;
123 }
124 }
125 return AllocateOld(size, HeapPage::kData);
77 } 126 }
78 127
79 uword Heap::AllocateOld(intptr_t size, HeapPage::PageType type) { 128 uword Heap::AllocateOld(intptr_t size, HeapPage::PageType type) {
80 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0); 129 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0);
81 uword addr = old_space_.TryAllocate(size, type); 130 uword addr = old_space_.TryAllocate(size, type);
82 if (addr != 0) { 131 if (addr != 0) {
83 return addr; 132 return addr;
84 } 133 }
85 // If we are in the process of running a sweep, wait for the sweeper to free 134 // If we are in the process of running a sweep, wait for the sweeper to free
86 // memory. 135 // memory.
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 597
549 bool Heap::Verify(MarkExpectation mark_expectation) const { 598 bool Heap::Verify(MarkExpectation mark_expectation) const {
550 HeapIterationScope heap_iteration_scope; 599 HeapIterationScope heap_iteration_scope;
551 return VerifyGC(mark_expectation); 600 return VerifyGC(mark_expectation);
552 } 601 }
553 602
554 bool Heap::VerifyGC(MarkExpectation mark_expectation) const { 603 bool Heap::VerifyGC(MarkExpectation mark_expectation) const {
555 StackZone stack_zone(Thread::Current()); 604 StackZone stack_zone(Thread::Current());
556 605
557 // Change the new space's top_ with the more up-to-date thread's view of top_ 606 // Change the new space's top_ with the more up-to-date thread's view of top_
558 new_space_.FlushTLS(); 607 new_space_.MakeNewSpaceIterable();
559 608
560 ObjectSet* allocated_set = 609 ObjectSet* allocated_set =
561 CreateAllocatedObjectSet(stack_zone.GetZone(), mark_expectation); 610 CreateAllocatedObjectSet(stack_zone.GetZone(), mark_expectation);
562 VerifyPointersVisitor visitor(isolate(), allocated_set); 611 VerifyPointersVisitor visitor(isolate(), allocated_set);
563 VisitObjectPointers(&visitor); 612 VisitObjectPointers(&visitor);
564 613
565 // Only returning a value so that Heap::Validate can be called from an ASSERT. 614 // Only returning a value so that Heap::Validate can be called from an ASSERT.
566 return true; 615 return true;
567 } 616 }
568 617
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 : StackResource(thread) { 878 : StackResource(thread) {
830 Dart::vm_isolate()->heap()->WriteProtect(false); 879 Dart::vm_isolate()->heap()->WriteProtect(false);
831 } 880 }
832 881
833 WritableVMIsolateScope::~WritableVMIsolateScope() { 882 WritableVMIsolateScope::~WritableVMIsolateScope() {
834 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0); 883 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0);
835 Dart::vm_isolate()->heap()->WriteProtect(true); 884 Dart::vm_isolate()->heap()->WriteProtect(true);
836 } 885 }
837 886
838 } // namespace dart 887 } // 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