OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/global-handles.h" | 5 #include "src/global-handles.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 #include "src/vm-state-inl.h" | 9 #include "src/vm-state-inl.h" |
10 | 10 |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 // Handle specific callback - might be a weak reference in disguise. | 373 // Handle specific callback - might be a weak reference in disguise. |
374 WeakCallbackInfo<void>::Callback weak_callback_; | 374 WeakCallbackInfo<void>::Callback weak_callback_; |
375 | 375 |
376 // Provided data for callback. In FREE state, this is used for | 376 // Provided data for callback. In FREE state, this is used for |
377 // the free list link. | 377 // the free list link. |
378 union { | 378 union { |
379 void* parameter; | 379 void* parameter; |
380 Node* next_free; | 380 Node* next_free; |
381 } parameter_or_next_free_; | 381 } parameter_or_next_free_; |
382 | 382 |
| 383 #ifdef VERIFY_HEAP |
| 384 friend std::vector<std::pair<void*, uint8_t>> |
| 385 GlobalHandles::GetNewSpaceNodeStates(); |
| 386 friend void GlobalHandles::RestoreNewSpaceNodeStates( |
| 387 const std::vector<std::pair<void*, uint8_t>>& states); |
| 388 #endif // VERIFY_HEAP |
| 389 |
383 DISALLOW_COPY_AND_ASSIGN(Node); | 390 DISALLOW_COPY_AND_ASSIGN(Node); |
384 }; | 391 }; |
385 | 392 |
386 | 393 |
387 class GlobalHandles::NodeBlock { | 394 class GlobalHandles::NodeBlock { |
388 public: | 395 public: |
389 static const int kSize = 256; | 396 static const int kSize = 256; |
390 | 397 |
391 explicit NodeBlock(GlobalHandles* global_handles, NodeBlock* next) | 398 explicit NodeBlock(GlobalHandles* global_handles, NodeBlock* next) |
392 : next_(next), | 399 : next_(next), |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 for (int i = 0; i < new_space_nodes_.length(); ++i) { | 719 for (int i = 0; i < new_space_nodes_.length(); ++i) { |
713 Node* node = new_space_nodes_[i]; | 720 Node* node = new_space_nodes_[i]; |
714 DCHECK(node->is_in_new_space_list()); | 721 DCHECK(node->is_in_new_space_list()); |
715 if ((node->is_independent() || !node->is_active()) && node->IsWeak() && | 722 if ((node->is_independent() || !node->is_active()) && node->IsWeak() && |
716 is_unscavenged(isolate_->heap(), node->location())) { | 723 is_unscavenged(isolate_->heap(), node->location())) { |
717 node->MarkPending(); | 724 node->MarkPending(); |
718 } | 725 } |
719 } | 726 } |
720 } | 727 } |
721 | 728 |
722 | 729 template <GlobalHandles::IterationMode mode> |
723 void GlobalHandles::IterateNewSpaceWeakUnmodifiedRoots(ObjectVisitor* v) { | 730 void GlobalHandles::IterateNewSpaceWeakUnmodifiedRoots(ObjectVisitor* v) { |
724 for (int i = 0; i < new_space_nodes_.length(); ++i) { | 731 for (int i = 0; i < new_space_nodes_.length(); ++i) { |
725 Node* node = new_space_nodes_[i]; | 732 Node* node = new_space_nodes_[i]; |
726 DCHECK(node->is_in_new_space_list()); | 733 DCHECK(node->is_in_new_space_list()); |
727 if ((node->is_independent() || !node->is_active()) && | 734 if ((node->is_independent() || !node->is_active()) && |
728 node->IsWeakRetainer()) { | 735 node->IsWeakRetainer()) { |
729 // Pending weak phantom handles die immediately. Everything else survives. | 736 // Pending weak phantom handles die immediately. Everything else survives. |
730 if (node->IsPendingPhantomResetHandle()) { | 737 if (node->IsPendingPhantomResetHandle()) { |
731 node->ResetPhantomHandle(); | 738 if (mode == IterationMode::HANDLE_PHANTOM_NODES) { |
732 ++number_of_phantom_handle_resets_; | 739 node->ResetPhantomHandle(); |
| 740 ++number_of_phantom_handle_resets_; |
| 741 } |
733 } else if (node->IsPendingPhantomCallback()) { | 742 } else if (node->IsPendingPhantomCallback()) { |
734 node->CollectPhantomCallbackData(isolate(), | 743 if (mode == IterationMode::HANDLE_PHANTOM_NODES) { |
735 &pending_phantom_callbacks_); | 744 node->CollectPhantomCallbackData(isolate(), |
| 745 &pending_phantom_callbacks_); |
| 746 } |
736 } else { | 747 } else { |
737 v->VisitPointer(node->location()); | 748 v->VisitPointer(node->location()); |
738 } | 749 } |
739 } | 750 } |
740 } | 751 } |
741 } | 752 } |
742 | 753 |
| 754 template void GlobalHandles::IterateNewSpaceWeakUnmodifiedRoots< |
| 755 GlobalHandles::HANDLE_PHANTOM_NODES>(ObjectVisitor* v); |
| 756 |
| 757 template void GlobalHandles::IterateNewSpaceWeakUnmodifiedRoots< |
| 758 GlobalHandles::DONT_HANDLE_PHANTOM_NODES>(ObjectVisitor* v); |
| 759 |
| 760 #ifdef VERIFY_HEAP |
| 761 |
| 762 std::vector<std::pair<void*, uint8_t>> GlobalHandles::GetNewSpaceNodeStates() { |
| 763 std::vector<std::pair<void*, uint8_t>> states; |
| 764 for (int i = 0; i < new_space_nodes_.length(); ++i) { |
| 765 Node* node = new_space_nodes_[i]; |
| 766 DCHECK(node->is_in_new_space_list()); |
| 767 states.push_back(std::make_pair(static_cast<void*>(node), node->flags_)); |
| 768 } |
| 769 return states; |
| 770 } |
| 771 |
| 772 void GlobalHandles::RestoreNewSpaceNodeStates( |
| 773 const std::vector<std::pair<void*, uint8_t>>& states) { |
| 774 for (auto pair : states) { |
| 775 static_cast<Node*>(pair.first)->flags_ = pair.second; |
| 776 } |
| 777 } |
| 778 |
| 779 #endif // VERIFY_HEAP |
743 | 780 |
744 DISABLE_CFI_PERF | 781 DISABLE_CFI_PERF |
745 bool GlobalHandles::IterateObjectGroups(ObjectVisitor* v, | 782 bool GlobalHandles::IterateObjectGroups(ObjectVisitor* v, |
746 WeakSlotCallbackWithHeap can_skip) { | 783 WeakSlotCallbackWithHeap can_skip) { |
747 ComputeObjectGroupsAndImplicitReferences(); | 784 ComputeObjectGroupsAndImplicitReferences(); |
748 int last = 0; | 785 int last = 0; |
749 bool any_group_was_visited = false; | 786 bool any_group_was_visited = false; |
750 for (int i = 0; i < object_groups_.length(); i++) { | 787 for (int i = 0; i < object_groups_.length(); i++) { |
751 ObjectGroup* entry = object_groups_.at(i); | 788 ObjectGroup* entry = object_groups_.at(i); |
752 DCHECK(entry != NULL); | 789 DCHECK(entry != NULL); |
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1451 blocks_[block][offset] = object; | 1488 blocks_[block][offset] = object; |
1452 if (isolate->heap()->InNewSpace(object)) { | 1489 if (isolate->heap()->InNewSpace(object)) { |
1453 new_space_indices_.Add(size_); | 1490 new_space_indices_.Add(size_); |
1454 } | 1491 } |
1455 *index = size_++; | 1492 *index = size_++; |
1456 } | 1493 } |
1457 | 1494 |
1458 | 1495 |
1459 } // namespace internal | 1496 } // namespace internal |
1460 } // namespace v8 | 1497 } // namespace v8 |
OLD | NEW |