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

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

Issue 8984006: Implement weak persistent handles in the Dart API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix whitespace. Created 9 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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/gc_marker.h" 5 #include "vm/gc_marker.h"
6 6
7 #include "vm/allocation.h" 7 #include "vm/allocation.h"
8 #include "vm/isolate.h" 8 #include "vm/isolate.h"
9 #include "vm/pages.h" 9 #include "vm/pages.h"
10 #include "vm/raw_object.h" 10 #include "vm/raw_object.h"
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 180
181 Heap* heap_; 181 Heap* heap_;
182 Heap* vm_heap_; 182 Heap* vm_heap_;
183 PageSpace* page_space_; 183 PageSpace* page_space_;
184 MarkingStack* marking_stack_; 184 MarkingStack* marking_stack_;
185 185
186 DISALLOW_IMPLICIT_CONSTRUCTORS(MarkingVisitor); 186 DISALLOW_IMPLICIT_CONSTRUCTORS(MarkingVisitor);
187 }; 187 };
188 188
189 189
190 class MarkingWeakVisitor : public ObjectPointerVisitor {
191 public:
192 MarkingWeakVisitor() {
193 }
194
195 void VisitPointers(RawObject** first, RawObject** last) {
196 for (RawObject** current = first; current <= last; current++) {
197 RawObject* raw_obj = *current;
198 ASSERT(raw_obj->IsHeapObject());
199 if (!raw_obj->IsMarked() && raw_obj->IsOldObject()) {
200 *current = Object::null();
201 }
202 }
203 }
204
205 private:
206 DISALLOW_COPY_AND_ASSIGN(MarkingWeakVisitor);
207 };
208
209
190 void GCMarker::Prologue(Isolate* isolate) { 210 void GCMarker::Prologue(Isolate* isolate) {
191 // Nothing to do at the moment. 211 // Nothing to do at the moment.
192 } 212 }
193 213
194 214
195 void GCMarker::IterateRoots(Isolate* isolate, MarkingVisitor* visitor) { 215 void GCMarker::IterateRoots(Isolate* isolate, ObjectPointerVisitor* visitor) {
196 isolate->VisitObjectPointers(visitor, 216 isolate->VisitStrongObjectPointers(visitor,
197 StackFrameIterator::kDontValidateFrames); 217 StackFrameIterator::kDontValidateFrames);
198 heap_->IterateNewPointers(visitor); 218 heap_->IterateNewPointers(visitor);
199 heap_->IterateCodePointers(visitor); 219 heap_->IterateCodePointers(visitor);
200 } 220 }
201 221
202 222
203 void GCMarker::DrainMarkingStack(Isolate* isolate, MarkingVisitor* visitor) { 223 void GCMarker::IterateWeakRoots(Isolate* isolate,
224 ObjectPointerVisitor* visitor) {
225 isolate->VisitWeakObjectPointers(visitor);
226 }
227
228
229 void GCMarker::DrainMarkingStack(Isolate* isolate,
230 MarkingVisitor* visitor) {
204 while (!visitor->marking_stack()->IsEmpty()) { 231 while (!visitor->marking_stack()->IsEmpty()) {
205 RawObject* raw_obj = visitor->marking_stack()->Pop(); 232 RawObject* raw_obj = visitor->marking_stack()->Pop();
206 raw_obj->VisitPointers(visitor); 233 raw_obj->VisitPointers(visitor);
207 } 234 }
208 } 235 }
209 236
210 237
211 void GCMarker::MarkObjects(Isolate* isolate, PageSpace* page_space) { 238 void GCMarker::MarkObjects(Isolate* isolate, PageSpace* page_space) {
212 MarkingStack marking_stack; 239 MarkingStack marking_stack;
213 Prologue(isolate); 240 Prologue(isolate);
214 MarkingVisitor mark(heap_, page_space, &marking_stack); 241 MarkingVisitor mark(heap_, page_space, &marking_stack);
215 IterateRoots(isolate, &mark); 242 IterateRoots(isolate, &mark);
216 DrainMarkingStack(isolate, &mark); 243 DrainMarkingStack(isolate, &mark);
244 MarkingWeakVisitor mark_weak;
245 IterateWeakRoots(isolate, &mark_weak);
217 } 246 }
218 247
219 } // namespace dart 248 } // namespace dart
OLDNEW
« runtime/vm/dart_api_state.h ('K') | « runtime/vm/gc_marker.h ('k') | runtime/vm/handles.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698