OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 current->state_ = Node::PENDING; | 365 current->state_ = Node::PENDING; |
366 LOG(HandleEvent("GlobalHandle::Pending", current->handle().location())); | 366 LOG(HandleEvent("GlobalHandle::Pending", current->handle().location())); |
367 } | 367 } |
368 } | 368 } |
369 } | 369 } |
370 } | 370 } |
371 | 371 |
372 | 372 |
373 int post_gc_processing_count = 0; | 373 int post_gc_processing_count = 0; |
374 | 374 |
375 void GlobalHandles::PostGarbageCollectionProcessing() { | 375 bool GlobalHandles::PostGarbageCollectionProcessing() { |
376 // Process weak global handle callbacks. This must be done after the | 376 // Process weak global handle callbacks. This must be done after the |
377 // GC is completely done, because the callbacks may invoke arbitrary | 377 // GC is completely done, because the callbacks may invoke arbitrary |
378 // API functions. | 378 // API functions. |
379 // At the same time deallocate all DESTROYED nodes. | 379 // At the same time deallocate all DESTROYED nodes. |
380 ASSERT(Heap::gc_state() == Heap::NOT_IN_GC); | 380 ASSERT(Heap::gc_state() == Heap::NOT_IN_GC); |
381 const int initial_post_gc_processing_count = ++post_gc_processing_count; | 381 const int initial_post_gc_processing_count = ++post_gc_processing_count; |
| 382 bool weak_callback_invoked = false; |
382 Node** p = &head_; | 383 Node** p = &head_; |
383 while (*p != NULL) { | 384 while (*p != NULL) { |
384 if ((*p)->PostGarbageCollectionProcessing()) { | 385 if ((*p)->PostGarbageCollectionProcessing()) { |
385 if (initial_post_gc_processing_count != post_gc_processing_count) { | 386 if (initial_post_gc_processing_count != post_gc_processing_count) { |
386 // Weak callback triggered another GC and another round of | 387 // Weak callback triggered another GC and another round of |
387 // PostGarbageCollection processing. The current node might | 388 // PostGarbageCollection processing. The current node might |
388 // have been deleted in that round, so we need to bail out (or | 389 // have been deleted in that round, so we need to bail out (or |
389 // restart the processing). | 390 // restart the processing). |
390 break; | 391 break; |
391 } | 392 } |
| 393 weak_callback_invoked = true; |
392 } | 394 } |
393 if ((*p)->state_ == Node::DESTROYED) { | 395 if ((*p)->state_ == Node::DESTROYED) { |
394 // Delete the link. | 396 // Delete the link. |
395 Node* node = *p; | 397 Node* node = *p; |
396 *p = node->next(); // Update the link. | 398 *p = node->next(); // Update the link. |
397 if (first_deallocated()) { | 399 if (first_deallocated()) { |
398 first_deallocated()->set_next(node); | 400 first_deallocated()->set_next(node); |
399 } | 401 } |
400 node->set_next_free(first_deallocated()); | 402 node->set_next_free(first_deallocated()); |
401 set_first_deallocated(node); | 403 set_first_deallocated(node); |
402 } else { | 404 } else { |
403 p = (*p)->next_addr(); | 405 p = (*p)->next_addr(); |
404 } | 406 } |
405 } | 407 } |
406 set_first_free(NULL); | 408 set_first_free(NULL); |
407 if (first_deallocated()) { | 409 if (first_deallocated()) { |
408 first_deallocated()->set_next(head()); | 410 first_deallocated()->set_next(head()); |
409 } | 411 } |
| 412 return weak_callback_invoked; |
410 } | 413 } |
411 | 414 |
412 | 415 |
413 void GlobalHandles::IterateStrongRoots(ObjectVisitor* v) { | 416 void GlobalHandles::IterateStrongRoots(ObjectVisitor* v) { |
414 // Traversal of global handles marked as NORMAL. | 417 // Traversal of global handles marked as NORMAL. |
415 for (Node* current = head_; current != NULL; current = current->next()) { | 418 for (Node* current = head_; current != NULL; current = current->next()) { |
416 if (current->state_ == Node::NORMAL) { | 419 if (current->state_ == Node::NORMAL) { |
417 v->VisitPointer(¤t->object_); | 420 v->VisitPointer(¤t->object_); |
418 } | 421 } |
419 } | 422 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 | 520 |
518 void GlobalHandles::RemoveObjectGroups() { | 521 void GlobalHandles::RemoveObjectGroups() { |
519 List<ObjectGroup*>* object_groups = ObjectGroups(); | 522 List<ObjectGroup*>* object_groups = ObjectGroups(); |
520 for (int i = 0; i< object_groups->length(); i++) { | 523 for (int i = 0; i< object_groups->length(); i++) { |
521 delete object_groups->at(i); | 524 delete object_groups->at(i); |
522 } | 525 } |
523 object_groups->Clear(); | 526 object_groups->Clear(); |
524 } | 527 } |
525 | 528 |
526 } } // namespace v8::internal | 529 } } // namespace v8::internal |
OLD | NEW |