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

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

Issue 2992753002: Prepares allocation for proper sync with mutator and bg threads. (Closed)
Patch Set: Adds locking when creating new TLABs 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 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) { 61 void Heap::MakeTLABIterable(Thread* thread) {
62 uword start = thread->top(); 62 uword start = thread->top();
63 uword end = thread->end(); 63 uword end = thread->end();
64 ASSERT(end >= start); 64 ASSERT(end >= start);
65 intptr_t size = end - start; 65 intptr_t size = end - start;
66 ASSERT(Utils::IsAligned(size, kObjectAlignment)); 66 ASSERT(Utils::IsAligned(size, kObjectAlignment));
67 if (size >= kObjectAlignment) { 67 if (size >= kObjectAlignment) {
68 FreeListElement::AsElement(start, size); 68 FreeListElement::AsElement(start, size);
69 ASSERT(RawObject::FromAddr(start)->Size() == size); 69 ASSERT(RawObject::FromAddr(start)->Size() == size);
70 ASSERT((start + size) == new_space_.top());
71 } 70 }
72 } 71 }
73 72
74 void Heap::AbandonRemainingTLAB(Thread* thread) { 73 void Heap::AbandonRemainingTLAB(Thread* thread) {
75 FillRemainingTLAB(thread); 74 MakeTLABIterable(thread);
76 thread->set_top(0); 75 thread->set_top(0);
77 thread->set_end(0); 76 thread->set_end(0);
78 } 77 }
79 78
80 intptr_t Heap::CalculateTLABSize() { 79 intptr_t Heap::CalculateTLABSize() {
81 intptr_t size = new_space_.end() - new_space_.top(); 80 intptr_t size = new_space_.end() - new_space_.top();
82 return Utils::RoundDown(size, kObjectAlignment); 81 return Utils::RoundDown(size, kObjectAlignment);
83 } 82 }
84 83
85 uword Heap::AllocateNew(intptr_t size) { 84 uword Heap::AllocateNew(intptr_t size) {
(...skipping 19 matching lines...) Expand all
105 ASSERT(addr != 0); 104 ASSERT(addr != 0);
106 return addr; 105 return addr;
107 } 106 }
108 } 107 }
109 108
110 ASSERT(!thread->HasActiveTLAB()); 109 ASSERT(!thread->HasActiveTLAB());
111 110
112 // This call to CollectGarbage might end up "reusing" a collection spawned 111 // This call to CollectGarbage might end up "reusing" a collection spawned
113 // from a different thread and will be racing to allocate the requested 112 // from a different thread and will be racing to allocate the requested
114 // memory with other threads being released after the collection. 113 // memory with other threads being released after the collection.
114 // TODO(danunez): Ensure that once we start collecting garbage, everything
115 // stops allocating.
116 // Safepoint should be dealing with this, but we need to make sure somehow.
115 CollectGarbage(kNew); 117 CollectGarbage(kNew);
116 tlab_size = CalculateTLABSize(); 118 tlab_size = CalculateTLABSize();
117 uword tlab_top = new_space_.TryAllocateNewTLAB(thread, tlab_size); 119 uword tlab_top = new_space_.TryAllocateNewTLAB(thread, tlab_size);
118 if (tlab_top != 0) { 120 if (tlab_top != 0) {
119 addr = new_space_.TryAllocateInTLAB(thread, size); 121 addr = new_space_.TryAllocateInTLAB(thread, size);
120 // It is possible a GC doesn't clear enough space. 122 // It is possible a GC doesn't clear enough space.
121 // In that case, we must fall through and allocate into old space. 123 // In that case, we must fall through and allocate into old space.
122 if (addr != 0) { 124 if (addr != 0) {
123 return addr; 125 return addr;
124 } 126 }
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 625
624 bool Heap::VerifyGC(MarkExpectation mark_expectation) const { 626 bool Heap::VerifyGC(MarkExpectation mark_expectation) const {
625 StackZone stack_zone(Thread::Current()); 627 StackZone stack_zone(Thread::Current());
626 628
627 // Change the new space's top_ with the more up-to-date thread's view of top_ 629 // Change the new space's top_ with the more up-to-date thread's view of top_
628 new_space_.MakeNewSpaceIterable(); 630 new_space_.MakeNewSpaceIterable();
629 631
630 ObjectSet* allocated_set = 632 ObjectSet* allocated_set =
631 CreateAllocatedObjectSet(stack_zone.GetZone(), mark_expectation); 633 CreateAllocatedObjectSet(stack_zone.GetZone(), mark_expectation);
632 VerifyPointersVisitor visitor(isolate(), allocated_set); 634 VerifyPointersVisitor visitor(isolate(), allocated_set);
635 // TODO(danunez): Need to lock and unlock for new space here.
rmacnak 2017/08/10 18:37:06 This function should already be always running dur
danunez 2017/08/10 20:36:46 Done.
633 VisitObjectPointers(&visitor); 636 VisitObjectPointers(&visitor);
634 637
635 // Only returning a value so that Heap::Validate can be called from an ASSERT. 638 // Only returning a value so that Heap::Validate can be called from an ASSERT.
636 return true; 639 return true;
637 } 640 }
638 641
639 void Heap::PrintSizes() const { 642 void Heap::PrintSizes() const {
640 OS::PrintErr( 643 OS::PrintErr(
641 "New space (%" Pd64 "k of %" Pd64 644 "New space (%" Pd64 "k of %" Pd64
642 "k) " 645 "k) "
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 : StackResource(thread) { 902 : StackResource(thread) {
900 Dart::vm_isolate()->heap()->WriteProtect(false); 903 Dart::vm_isolate()->heap()->WriteProtect(false);
901 } 904 }
902 905
903 WritableVMIsolateScope::~WritableVMIsolateScope() { 906 WritableVMIsolateScope::~WritableVMIsolateScope() {
904 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0); 907 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0);
905 Dart::vm_isolate()->heap()->WriteProtect(true); 908 Dart::vm_isolate()->heap()->WriteProtect(true);
906 } 909 }
907 910
908 } // namespace dart 911 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/heap.h ('k') | runtime/vm/scavenger.h » ('j') | runtime/vm/scavenger.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698