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

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

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