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

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

Issue 238063011: Modify the Weak Reference Set creation API to make it easier to create (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 8 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
« no previous file with comments | « runtime/vm/dart_api_state.h ('k') | runtime/vm/scavenger.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <map> 7 #include <map>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 while (true) { 358 while (true) {
359 WeakReferenceSet* queue = state->delayed_weak_reference_sets(); 359 WeakReferenceSet* queue = state->delayed_weak_reference_sets();
360 if (queue == NULL) { 360 if (queue == NULL) {
361 // The delay queue is empty therefore no clean-up is required. 361 // The delay queue is empty therefore no clean-up is required.
362 return; 362 return;
363 } 363 }
364 state->set_delayed_weak_reference_sets(NULL); 364 state->set_delayed_weak_reference_sets(NULL);
365 while (queue != NULL) { 365 while (queue != NULL) {
366 WeakReferenceSet* reference_set = WeakReferenceSet::Pop(&queue); 366 WeakReferenceSet* reference_set = WeakReferenceSet::Pop(&queue);
367 ASSERT(reference_set != NULL); 367 ASSERT(reference_set != NULL);
368 intptr_t num_keys = reference_set->num_keys();
369 intptr_t num_values = reference_set->num_values();
370 if ((num_keys == 1) && (num_values == 1) &&
371 reference_set->SingletonKeyEqualsValue()) {
372 // We do not have to process sets that have just one key/value pair
373 // and the key and value are identical.
374 continue;
375 }
368 bool is_unreachable = true; 376 bool is_unreachable = true;
369 // Test each key object for reachability. If a key object is 377 // Test each key object for reachability. If a key object is
370 // reachable, all value objects should be marked. 378 // reachable, all value objects should be marked.
371 for (intptr_t k = 0; k < reference_set->num_keys(); ++k) { 379 for (intptr_t k = 0; k < num_keys; ++k) {
372 if (!IsUnreachable(*reference_set->get_key(k))) { 380 if (!IsUnreachable(*reference_set->get_key(k))) {
373 for (intptr_t v = 0; v < reference_set->num_values(); ++v) { 381 for (intptr_t v = 0; v < num_values; ++v) {
374 visitor->VisitPointer(reference_set->get_value(v)); 382 visitor->VisitPointer(reference_set->get_value(v));
375 } 383 }
376 is_unreachable = false; 384 is_unreachable = false;
377 delete reference_set; 385 // Since we have found a key object that is reachable and all
386 // value objects have been marked we can break out of iterating
387 // this set and move on to the next set.
378 break; 388 break;
379 } 389 }
380 } 390 }
381 // If all key objects are unreachable put the reference on a 391 // If all key objects are unreachable put the reference on a
382 // delay queue. This reference will be revisited if another 392 // delay queue. This reference will be revisited if another
383 // reference is marked. 393 // reference is marked.
384 if (is_unreachable) { 394 if (is_unreachable) {
385 state->DelayWeakReferenceSet(reference_set); 395 state->DelayWeakReferenceSet(reference_set);
386 } 396 }
387 } 397 }
388 if (!visitor->marking_stack()->IsEmpty()) { 398 if (!visitor->marking_stack()->IsEmpty()) {
389 DrainMarkingStack(isolate, visitor); 399 DrainMarkingStack(isolate, visitor);
390 } else { 400 } else {
391 // Break out of the loop if there has been no forward process. 401 // Break out of the loop if there has been no forward process.
402 // All key objects in the weak reference sets are unreachable
403 // so we reset the weak reference sets queue.
404 state->set_delayed_weak_reference_sets(NULL);
392 break; 405 break;
393 } 406 }
394 } 407 }
395 // Deallocate any unmarked references on the delay queue. 408 ASSERT(state->delayed_weak_reference_sets() == NULL);
396 if (state->delayed_weak_reference_sets() != NULL) { 409 // All weak reference sets are zone allocated and unmarked references which
397 WeakReferenceSet* queue = state->delayed_weak_reference_sets(); 410 // were on the delay queue will be freed when the zone is released in the
398 state->set_delayed_weak_reference_sets(NULL); 411 // epilog callback.
399 while (queue != NULL) {
400 delete WeakReferenceSet::Pop(&queue);
401 }
402 }
403 } 412 }
404 413
405 414
406 void GCMarker::DrainMarkingStack(Isolate* isolate, 415 void GCMarker::DrainMarkingStack(Isolate* isolate,
407 MarkingVisitor* visitor) { 416 MarkingVisitor* visitor) {
408 while (!visitor->marking_stack()->IsEmpty()) { 417 while (!visitor->marking_stack()->IsEmpty()) {
409 RawObject* raw_obj = visitor->marking_stack()->Pop(); 418 RawObject* raw_obj = visitor->marking_stack()->Pop();
410 visitor->VisitingOldObject(raw_obj); 419 visitor->VisitingOldObject(raw_obj);
411 if (raw_obj->GetClassId() != kWeakPropertyCid) { 420 if (raw_obj->GetClassId() != kWeakPropertyCid) {
412 raw_obj->VisitPointers(visitor); 421 raw_obj->VisitPointers(visitor);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 MarkingWeakVisitor mark_weak; 506 MarkingWeakVisitor mark_weak;
498 IterateWeakRoots(isolate, &mark_weak, invoke_api_callbacks); 507 IterateWeakRoots(isolate, &mark_weak, invoke_api_callbacks);
499 mark.Finalize(); 508 mark.Finalize();
500 ProcessWeakTables(page_space); 509 ProcessWeakTables(page_space);
501 ProcessObjectIdTable(isolate); 510 ProcessObjectIdTable(isolate);
502 511
503 Epilogue(isolate, invoke_api_callbacks); 512 Epilogue(isolate, invoke_api_callbacks);
504 } 513 }
505 514
506 } // namespace dart 515 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_state.h ('k') | runtime/vm/scavenger.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698