OLD | NEW |
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 VM_SCAVENGER_H_ | 5 #ifndef VM_SCAVENGER_H_ |
6 #define VM_SCAVENGER_H_ | 6 #define 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 Scavenger(Heap* heap, | 114 Scavenger(Heap* heap, |
115 intptr_t max_semi_capacity_in_words, | 115 intptr_t max_semi_capacity_in_words, |
116 uword object_alignment); | 116 uword object_alignment); |
117 ~Scavenger(); | 117 ~Scavenger(); |
118 | 118 |
119 // Check whether this Scavenger contains this address. | 119 // Check whether this Scavenger contains this address. |
120 // During scavenging both the to and from spaces contain "legal" objects. | 120 // During scavenging both the to and from spaces contain "legal" objects. |
121 // During a scavenge this function only returns true for addresses that will | 121 // During a scavenge this function only returns true for addresses that will |
122 // be part of the surviving objects. | 122 // be part of the surviving objects. |
123 bool Contains(uword addr) const { | 123 bool Contains(uword addr) const { |
124 // No reasonable algorithm should be checking for objects in from space. At | |
125 // least unless it is debugging code. This might need to be relaxed later, | |
126 // but currently it helps prevent dumb bugs. | |
127 ASSERT(from_ == NULL || !from_->Contains(addr)); | |
128 return to_->Contains(addr); | 124 return to_->Contains(addr); |
129 } | 125 } |
130 | 126 |
131 RawObject* FindObject(FindObjectVisitor* visitor) const; | 127 RawObject* FindObject(FindObjectVisitor* visitor) const; |
132 | 128 |
133 uword TryAllocate(intptr_t size) { | 129 uword TryAllocate(intptr_t size) { |
134 ASSERT(Utils::IsAligned(size, kObjectAlignment)); | 130 ASSERT(Utils::IsAligned(size, kObjectAlignment)); |
135 ASSERT(heap_ != Dart::vm_isolate()->heap()); | 131 ASSERT(heap_ != Dart::vm_isolate()->heap()); |
136 #if defined(DEBUG) | 132 #if defined(DEBUG) |
137 if (FLAG_gc_at_alloc && !scavenging_) { | 133 if (FLAG_gc_at_alloc && !scavenging_) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 kProcessToSpace = 2, | 221 kProcessToSpace = 2, |
226 kIterateWeaks = 3, | 222 kIterateWeaks = 3, |
227 // Data | 223 // Data |
228 kStoreBufferEntries = 0, | 224 kStoreBufferEntries = 0, |
229 kDataUnused1 = 1, | 225 kDataUnused1 = 1, |
230 kDataUnused2 = 2, | 226 kDataUnused2 = 2, |
231 kToKBAfterStoreBuffer = 3 | 227 kToKBAfterStoreBuffer = 3 |
232 }; | 228 }; |
233 | 229 |
234 uword FirstObjectStart() const { return to_->start() | object_alignment_; } | 230 uword FirstObjectStart() const { return to_->start() | object_alignment_; } |
235 void Prologue(Isolate* isolate, bool invoke_api_callbacks); | 231 SemiSpace* Prologue(Isolate* isolate, bool invoke_api_callbacks); |
236 void IterateStoreBuffers(Isolate* isolate, ScavengerVisitor* visitor); | 232 void IterateStoreBuffers(Isolate* isolate, ScavengerVisitor* visitor); |
237 void IterateObjectIdTable(Isolate* isolate, ScavengerVisitor* visitor); | 233 void IterateObjectIdTable(Isolate* isolate, ScavengerVisitor* visitor); |
238 void IterateRoots(Isolate* isolate, | 234 void IterateRoots(Isolate* isolate, |
239 ScavengerVisitor* visitor, | 235 ScavengerVisitor* visitor, |
240 bool visit_prologue_weak_persistent_handles); | 236 bool visit_prologue_weak_persistent_handles); |
241 void IterateWeakProperties(Isolate* isolate, ScavengerVisitor* visitor); | 237 void IterateWeakProperties(Isolate* isolate, ScavengerVisitor* visitor); |
242 void IterateWeakReferences(Isolate* isolate, ScavengerVisitor* visitor); | 238 void IterateWeakReferences(Isolate* isolate, ScavengerVisitor* visitor); |
243 void IterateWeakRoots(Isolate* isolate, | 239 void IterateWeakRoots(Isolate* isolate, |
244 HandleVisitor* visitor, | 240 HandleVisitor* visitor, |
245 bool visit_prologue_weak_persistent_handles); | 241 bool visit_prologue_weak_persistent_handles); |
246 void ProcessToSpace(ScavengerVisitor* visitor); | 242 void ProcessToSpace(ScavengerVisitor* visitor); |
247 uword ProcessWeakProperty(RawWeakProperty* raw_weak, | 243 uword ProcessWeakProperty(RawWeakProperty* raw_weak, |
248 ScavengerVisitor* visitor); | 244 ScavengerVisitor* visitor); |
249 void Epilogue(Isolate* isolate, | 245 void Epilogue(Isolate* isolate, SemiSpace* from, bool invoke_api_callbacks); |
250 bool invoke_api_callbacks); | |
251 | 246 |
252 bool IsUnreachable(RawObject** p); | 247 bool IsUnreachable(RawObject** p); |
253 | 248 |
254 // During a scavenge we need to remember the promoted objects. | 249 // During a scavenge we need to remember the promoted objects. |
255 // This is implemented as a stack of objects at the end of the to space. As | 250 // This is implemented as a stack of objects at the end of the to space. As |
256 // object sizes are always greater than sizeof(uword) and promoted objects do | 251 // object sizes are always greater than sizeof(uword) and promoted objects do |
257 // not consume space in the to space they leave enough room for this stack. | 252 // not consume space in the to space they leave enough room for this stack. |
258 void PushToPromotedStack(uword addr) { | 253 void PushToPromotedStack(uword addr) { |
259 ASSERT(scavenging_); | 254 ASSERT(scavenging_); |
260 end_ -= sizeof(addr); | 255 end_ -= sizeof(addr); |
261 ASSERT(end_ > top_); | 256 ASSERT(end_ > top_); |
262 *reinterpret_cast<uword*>(end_) = addr; | 257 *reinterpret_cast<uword*>(end_) = addr; |
263 } | 258 } |
264 uword PopFromPromotedStack() { | 259 uword PopFromPromotedStack() { |
265 ASSERT(scavenging_); | 260 ASSERT(scavenging_); |
266 uword result = *reinterpret_cast<uword*>(end_); | 261 uword result = *reinterpret_cast<uword*>(end_); |
267 end_ += sizeof(result); | 262 end_ += sizeof(result); |
268 ASSERT(end_ <= to_->end()); | 263 ASSERT(end_ <= to_->end()); |
269 return result; | 264 return result; |
270 } | 265 } |
271 bool PromotedStackHasMore() const { | 266 bool PromotedStackHasMore() const { |
272 ASSERT(scavenging_); | 267 ASSERT(scavenging_); |
273 return end_ < to_->end(); | 268 return end_ < to_->end(); |
274 } | 269 } |
275 | 270 |
276 void ProcessWeakTables(); | 271 void ProcessWeakTables(); |
277 | 272 |
278 intptr_t NewSizeInWords(intptr_t old_size_in_words) const; | 273 intptr_t NewSizeInWords(intptr_t old_size_in_words) const; |
279 | 274 |
280 SemiSpace* from_; | |
281 SemiSpace* to_; | 275 SemiSpace* to_; |
282 | 276 |
283 Heap* heap_; | 277 Heap* heap_; |
284 | 278 |
285 // Current allocation top and end. These values are being accessed directly | 279 // Current allocation top and end. These values are being accessed directly |
286 // from generated code. | 280 // from generated code. |
287 uword top_; | 281 uword top_; |
288 uword end_; | 282 uword end_; |
289 | 283 |
290 // A pointer to the first unscanned object. Scanning completes when | 284 // A pointer to the first unscanned object. Scanning completes when |
(...skipping 21 matching lines...) Expand all Loading... |
312 | 306 |
313 friend class ScavengerVisitor; | 307 friend class ScavengerVisitor; |
314 friend class ScavengerWeakVisitor; | 308 friend class ScavengerWeakVisitor; |
315 | 309 |
316 DISALLOW_COPY_AND_ASSIGN(Scavenger); | 310 DISALLOW_COPY_AND_ASSIGN(Scavenger); |
317 }; | 311 }; |
318 | 312 |
319 } // namespace dart | 313 } // namespace dart |
320 | 314 |
321 #endif // VM_SCAVENGER_H_ | 315 #endif // VM_SCAVENGER_H_ |
OLD | NEW |