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

Side by Side Diff: runtime/vm/scavenger.h

Issue 2951333002: Moves the top_ and end_ words of the Scavenger into mutator thread. (Closed)
Patch Set: Created 3 years, 6 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 #ifndef RUNTIME_VM_SCAVENGER_H_ 5 #ifndef RUNTIME_VM_SCAVENGER_H_
6 #define RUNTIME_VM_SCAVENGER_H_ 6 #define RUNTIME_VM_SCAVENGER_H_
7 7
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "platform/utils.h" 9 #include "platform/utils.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 // During scavenging both the to and from spaces contain "legal" objects. 117 // During scavenging both the to and from spaces contain "legal" objects.
118 // During a scavenge this function only returns true for addresses that will 118 // During a scavenge this function only returns true for addresses that will
119 // be part of the surviving objects. 119 // be part of the surviving objects.
120 bool Contains(uword addr) const { return to_->Contains(addr); } 120 bool Contains(uword addr) const { return to_->Contains(addr); }
121 121
122 RawObject* FindObject(FindObjectVisitor* visitor) const; 122 RawObject* FindObject(FindObjectVisitor* visitor) const;
123 123
124 uword TryAllocate(intptr_t size) { 124 uword TryAllocate(intptr_t size) {
125 ASSERT(Utils::IsAligned(size, kObjectAlignment)); 125 ASSERT(Utils::IsAligned(size, kObjectAlignment));
126 ASSERT(heap_ != Dart::vm_isolate()->heap()); 126 ASSERT(heap_ != Dart::vm_isolate()->heap());
127
127 #if defined(DEBUG) 128 #if defined(DEBUG)
128 if (FLAG_gc_at_alloc && !scavenging_) { 129 if (FLAG_gc_at_alloc && !scavenging_) {
129 Scavenge(); 130 Scavenge();
131 ASSERT(Isolate::Current()->mutator_thread()->top() == top_);
rmacnak 2017/06/22 22:31:51 Thread::Current() should be the mutator
danunez 2017/06/30 20:35:57 Done.
130 } 132 }
131 #endif 133 #endif
134
135 top_ = Isolate::Current()->mutator_thread()->top();
136 ASSERT(Isolate::Current()->mutator_thread()->end() == end_);
137
132 uword result = top_; 138 uword result = top_;
133 intptr_t remaining = end_ - top_; 139 intptr_t remaining = end_ - top_;
134 if (remaining < size) { 140 if (remaining < size) {
135 return 0; 141 return 0;
136 } 142 }
137 ASSERT(to_->Contains(result)); 143 ASSERT(to_->Contains(result));
138 ASSERT((result & kObjectAlignmentMask) == object_alignment_); 144 ASSERT((result & kObjectAlignmentMask) == object_alignment_);
139 145
140 top_ += size; 146 top_ += size;
141 ASSERT(to_->Contains(top_) || (top_ == to_->end())); 147 ASSERT(to_->Contains(top_) || (top_ == to_->end()));
148 Isolate::Current()->mutator_thread()->set_top_offset(top_);
142 return result; 149 return result;
143 } 150 }
144 151
145 // Collect the garbage in this scavenger. 152 // Collect the garbage in this scavenger.
146 void Scavenge(); 153 void Scavenge();
147 void Scavenge(bool invoke_api_callbacks); 154 void Scavenge(bool invoke_api_callbacks);
148 155
149 // Promote all live objects. 156 // Promote all live objects.
150 void Evacuate() { 157 void Evacuate() {
151 Scavenge(); 158 Scavenge();
152 Scavenge(); 159 Scavenge();
153 ASSERT(UsedInWords() == 0); 160 ASSERT(UsedInWords() == 0);
154 } 161 }
155 162
156 // Accessors to generate code for inlined allocation. 163 // Accessors to generate code for inlined allocation.
rmacnak 2017/06/22 22:31:50 Remove to check these are all unused now.
danunez 2017/06/30 20:35:57 TopAddress() and EndAddress() are used, but only t
157 uword* TopAddress() { return &top_; } 164 uword* TopAddress() { return &top_; }
158 uword* EndAddress() { return &end_; } 165 uword* EndAddress() { return &end_; }
159 static intptr_t top_offset() { return OFFSET_OF(Scavenger, top_); } 166 static intptr_t top_offset() { return OFFSET_OF(Scavenger, top_); }
160 static intptr_t end_offset() { return OFFSET_OF(Scavenger, end_); } 167 static intptr_t end_offset() { return OFFSET_OF(Scavenger, end_); }
161 168
162 int64_t UsedInWords() const { 169 int64_t UsedInWords() const {
163 return (top_ - FirstObjectStart()) >> kWordSizeLog2; 170 return (top_ - FirstObjectStart()) >> kWordSizeLog2;
164 } 171 }
165 int64_t CapacityInWords() const { return to_->size_in_words(); } 172 int64_t CapacityInWords() const { return to_->size_in_words(); }
166 int64_t ExternalInWords() const { return external_size_ >> kWordSizeLog2; } 173 int64_t ExternalInWords() const { return external_size_ >> kWordSizeLog2; }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 234
228 bool IsUnreachable(RawObject** p); 235 bool IsUnreachable(RawObject** p);
229 236
230 // During a scavenge we need to remember the promoted objects. 237 // During a scavenge we need to remember the promoted objects.
231 // This is implemented as a stack of objects at the end of the to space. As 238 // This is implemented as a stack of objects at the end of the to space. As
232 // object sizes are always greater than sizeof(uword) and promoted objects do 239 // object sizes are always greater than sizeof(uword) and promoted objects do
233 // not consume space in the to space they leave enough room for this stack. 240 // not consume space in the to space they leave enough room for this stack.
234 void PushToPromotedStack(uword addr) { 241 void PushToPromotedStack(uword addr) {
235 ASSERT(scavenging_); 242 ASSERT(scavenging_);
236 end_ -= sizeof(addr); 243 end_ -= sizeof(addr);
244 Isolate::Current()->mutator_thread()->set_end_offset(end_);
237 ASSERT(end_ > top_); 245 ASSERT(end_ > top_);
238 *reinterpret_cast<uword*>(end_) = addr; 246 *reinterpret_cast<uword*>(end_) = addr;
239 } 247 }
240 uword PopFromPromotedStack() { 248 uword PopFromPromotedStack() {
241 ASSERT(scavenging_); 249 ASSERT(scavenging_);
242 uword result = *reinterpret_cast<uword*>(end_); 250 uword result = *reinterpret_cast<uword*>(end_);
243 end_ += sizeof(result); 251 end_ += sizeof(result);
252 Isolate::Current()->mutator_thread()->set_end_offset(end_);
244 ASSERT(end_ <= to_->end()); 253 ASSERT(end_ <= to_->end());
245 return result; 254 return result;
246 } 255 }
247 bool PromotedStackHasMore() const { 256 bool PromotedStackHasMore() const {
248 ASSERT(scavenging_); 257 ASSERT(scavenging_);
249 return end_ < to_->end(); 258 return end_ < to_->end();
250 } 259 }
251 260
252 void UpdateMaxHeapCapacity(); 261 void UpdateMaxHeapCapacity();
253 void UpdateMaxHeapUsage(); 262 void UpdateMaxHeapUsage();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 RawWeakProperty* delayed_weak_properties_; 297 RawWeakProperty* delayed_weak_properties_;
289 298
290 int64_t gc_time_micros_; 299 int64_t gc_time_micros_;
291 intptr_t collections_; 300 intptr_t collections_;
292 static const int kStatsHistoryCapacity = 2; 301 static const int kStatsHistoryCapacity = 2;
293 RingBuffer<ScavengeStats, kStatsHistoryCapacity> stats_history_; 302 RingBuffer<ScavengeStats, kStatsHistoryCapacity> stats_history_;
294 303
295 // The total size of external data associated with objects in this scavenger. 304 // The total size of external data associated with objects in this scavenger.
296 intptr_t external_size_; 305 intptr_t external_size_;
297 306
307 Mutex* space_lock_;
308
298 friend class ScavengerVisitor; 309 friend class ScavengerVisitor;
299 friend class ScavengerWeakVisitor; 310 friend class ScavengerWeakVisitor;
300 311
301 DISALLOW_COPY_AND_ASSIGN(Scavenger); 312 DISALLOW_COPY_AND_ASSIGN(Scavenger);
302 }; 313 };
303 314
304 } // namespace dart 315 } // namespace dart
305 316
306 #endif // RUNTIME_VM_SCAVENGER_H_ 317 #endif // RUNTIME_VM_SCAVENGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698