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

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

Issue 9148051: Provide API support for weak handles and post-mortem finalization. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: a better strategy for protected handle checks Created 8 years, 11 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 | 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/dart_api_state.h"
8 #include "vm/isolate.h" 9 #include "vm/isolate.h"
9 #include "vm/pages.h" 10 #include "vm/pages.h"
10 #include "vm/raw_object.h" 11 #include "vm/raw_object.h"
11 #include "vm/stack_frame.h" 12 #include "vm/stack_frame.h"
12 #include "vm/visitor.h" 13 #include "vm/visitor.h"
13 14
14 namespace dart { 15 namespace dart {
15 16
16 // A simple chunked marking stack. 17 // A simple chunked marking stack.
17 class MarkingStack : public ValueObject { 18 class MarkingStack : public ValueObject {
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 181
181 Heap* heap_; 182 Heap* heap_;
182 Heap* vm_heap_; 183 Heap* vm_heap_;
183 PageSpace* page_space_; 184 PageSpace* page_space_;
184 MarkingStack* marking_stack_; 185 MarkingStack* marking_stack_;
185 186
186 DISALLOW_IMPLICIT_CONSTRUCTORS(MarkingVisitor); 187 DISALLOW_IMPLICIT_CONSTRUCTORS(MarkingVisitor);
187 }; 188 };
188 189
189 190
190 class MarkingWeakVisitor : public ObjectPointerVisitor { 191 class MarkingWeakVisitor : public HandleVisitor {
191 public: 192 public:
192 MarkingWeakVisitor() { 193 MarkingWeakVisitor() {
193 } 194 }
194 195
195 void VisitPointers(RawObject** first, RawObject** last) { 196 void VisitHandle(uword* addr) {
196 for (RawObject** current = first; current <= last; current++) { 197 WeakPersistentHandle* handle =
197 RawObject* raw_obj = *current; 198 reinterpret_cast<WeakPersistentHandle*>(addr);
198 ASSERT(raw_obj->IsHeapObject()); 199 RawObject* raw_obj = handle->raw();
199 if (!raw_obj->IsMarked() && raw_obj->IsOldObject()) { 200 ASSERT(raw_obj->IsHeapObject());
200 *current = Object::null(); 201 if (!raw_obj->IsMarked() && raw_obj->IsOldObject()) {
201 } 202 handle->Finalize();
Anton Muhin 2012/01/12 13:40:26 there might be unpleasant problem: naively impleme
cshapiro 2012/01/12 18:15:38 Correct. There is one case we consider to be safe
Anton Muhin 2012/01/13 14:20:58 Carl, sorry, I wasn't clear enough regarding #2.
cshapiro 2012/01/13 22:56:46 Thanks for the clarification. I discussed your co
202 } 203 }
203 } 204 }
204 205
205 private: 206 private:
206 DISALLOW_COPY_AND_ASSIGN(MarkingWeakVisitor); 207 DISALLOW_COPY_AND_ASSIGN(MarkingWeakVisitor);
207 }; 208 };
208 209
209 210
210 void GCMarker::Prologue(Isolate* isolate) { 211 void GCMarker::Prologue(Isolate* isolate) {
211 // Nothing to do at the moment. 212 // Nothing to do at the moment.
212 } 213 }
213 214
214 215
215 void GCMarker::IterateRoots(Isolate* isolate, ObjectPointerVisitor* visitor) { 216 void GCMarker::IterateRoots(Isolate* isolate, ObjectPointerVisitor* visitor) {
216 isolate->VisitStrongObjectPointers(visitor, 217 isolate->VisitObjectPointers(visitor,
217 StackFrameIterator::kDontValidateFrames); 218 StackFrameIterator::kDontValidateFrames);
218 heap_->IterateNewPointers(visitor); 219 heap_->IterateNewPointers(visitor);
219 heap_->IterateCodePointers(visitor); 220 heap_->IterateCodePointers(visitor);
220 } 221 }
221 222
222 223
223 void GCMarker::IterateWeakRoots(Isolate* isolate, 224 void GCMarker::IterateWeakRoots(Isolate* isolate, HandleVisitor* visitor) {
224 ObjectPointerVisitor* visitor) { 225 isolate->VisitWeakPersistentHandles(visitor);
225 isolate->VisitWeakObjectPointers(visitor);
226 } 226 }
227 227
228 228
229 void GCMarker::DrainMarkingStack(Isolate* isolate, 229 void GCMarker::DrainMarkingStack(Isolate* isolate,
230 MarkingVisitor* visitor) { 230 MarkingVisitor* visitor) {
231 while (!visitor->marking_stack()->IsEmpty()) { 231 while (!visitor->marking_stack()->IsEmpty()) {
232 RawObject* raw_obj = visitor->marking_stack()->Pop(); 232 RawObject* raw_obj = visitor->marking_stack()->Pop();
233 raw_obj->VisitPointers(visitor); 233 raw_obj->VisitPointers(visitor);
234 } 234 }
235 } 235 }
236 236
237 237
238 void GCMarker::MarkObjects(Isolate* isolate, PageSpace* page_space) { 238 void GCMarker::MarkObjects(Isolate* isolate, PageSpace* page_space) {
239 MarkingStack marking_stack; 239 MarkingStack marking_stack;
240 Prologue(isolate); 240 Prologue(isolate);
241 MarkingVisitor mark(heap_, page_space, &marking_stack); 241 MarkingVisitor mark(heap_, page_space, &marking_stack);
242 IterateRoots(isolate, &mark); 242 IterateRoots(isolate, &mark);
243 DrainMarkingStack(isolate, &mark); 243 DrainMarkingStack(isolate, &mark);
244 MarkingWeakVisitor mark_weak; 244 MarkingWeakVisitor mark_weak;
245 IterateWeakRoots(isolate, &mark_weak); 245 IterateWeakRoots(isolate, &mark_weak);
246 } 246 }
247 247
248 } // namespace dart 248 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698