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

Side by Side Diff: src/global-handles.cc

Issue 1410593005: Adds a scavenge GC pass to collect unmodified references (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Forgot a fix in the last patch Created 5 years, 1 month 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
« no previous file with comments | « src/global-handles.h ('k') | src/heap/heap.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 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 DCHECK(offsetof(Node, flags_) == Internals::kNodeFlagsOffset); 47 DCHECK(offsetof(Node, flags_) == Internals::kNodeFlagsOffset);
48 STATIC_ASSERT(static_cast<int>(NodeState::kMask) == 48 STATIC_ASSERT(static_cast<int>(NodeState::kMask) ==
49 Internals::kNodeStateMask); 49 Internals::kNodeStateMask);
50 STATIC_ASSERT(WEAK == Internals::kNodeStateIsWeakValue); 50 STATIC_ASSERT(WEAK == Internals::kNodeStateIsWeakValue);
51 STATIC_ASSERT(PENDING == Internals::kNodeStateIsPendingValue); 51 STATIC_ASSERT(PENDING == Internals::kNodeStateIsPendingValue);
52 STATIC_ASSERT(NEAR_DEATH == Internals::kNodeStateIsNearDeathValue); 52 STATIC_ASSERT(NEAR_DEATH == Internals::kNodeStateIsNearDeathValue);
53 STATIC_ASSERT(static_cast<int>(IsIndependent::kShift) == 53 STATIC_ASSERT(static_cast<int>(IsIndependent::kShift) ==
54 Internals::kNodeIsIndependentShift); 54 Internals::kNodeIsIndependentShift);
55 STATIC_ASSERT(static_cast<int>(IsPartiallyDependent::kShift) == 55 STATIC_ASSERT(static_cast<int>(IsPartiallyDependent::kShift) ==
56 Internals::kNodeIsPartiallyDependentShift); 56 Internals::kNodeIsPartiallyDependentShift);
57 STATIC_ASSERT(static_cast<int>(IsActive::kShift) ==
58 Internals::kNodeIsActiveShift);
57 } 59 }
58 60
59 #ifdef ENABLE_HANDLE_ZAPPING 61 #ifdef ENABLE_HANDLE_ZAPPING
60 ~Node() { 62 ~Node() {
61 // TODO(1428): if it's a weak handle we should have invoked its callback. 63 // TODO(1428): if it's a weak handle we should have invoked its callback.
62 // Zap the values for eager trapping. 64 // Zap the values for eager trapping.
63 object_ = reinterpret_cast<Object*>(kGlobalHandleZapValue); 65 object_ = reinterpret_cast<Object*>(kGlobalHandleZapValue);
64 class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId; 66 class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId;
65 index_ = 0; 67 index_ = 0;
66 set_independent(false); 68 set_independent(false);
67 set_partially_dependent(false); 69 if (FLAG_scavenge_reclaim_unmodified_objects) {
70 set_active(false);
71 } else {
72 set_partially_dependent(false);
73 }
68 set_in_new_space_list(false); 74 set_in_new_space_list(false);
69 parameter_or_next_free_.next_free = NULL; 75 parameter_or_next_free_.next_free = NULL;
70 weak_callback_ = NULL; 76 weak_callback_ = NULL;
71 } 77 }
72 #endif 78 #endif
73 79
74 void Initialize(int index, Node** first_free) { 80 void Initialize(int index, Node** first_free) {
75 index_ = static_cast<uint8_t>(index); 81 index_ = static_cast<uint8_t>(index);
76 DCHECK(static_cast<int>(index_) == index); 82 DCHECK(static_cast<int>(index_) == index);
77 set_state(FREE); 83 set_state(FREE);
78 set_weakness_type(NORMAL_WEAK); 84 set_weakness_type(NORMAL_WEAK);
79 set_in_new_space_list(false); 85 set_in_new_space_list(false);
80 parameter_or_next_free_.next_free = *first_free; 86 parameter_or_next_free_.next_free = *first_free;
81 *first_free = this; 87 *first_free = this;
82 } 88 }
83 89
84 void Acquire(Object* object) { 90 void Acquire(Object* object) {
85 DCHECK(state() == FREE); 91 DCHECK(state() == FREE);
86 object_ = object; 92 object_ = object;
87 class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId; 93 class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId;
88 set_independent(false); 94 set_independent(false);
89 set_partially_dependent(false); 95 if (FLAG_scavenge_reclaim_unmodified_objects) {
96 set_active(false);
97 } else {
98 set_partially_dependent(false);
99 }
90 set_state(NORMAL); 100 set_state(NORMAL);
91 parameter_or_next_free_.parameter = NULL; 101 parameter_or_next_free_.parameter = NULL;
92 weak_callback_ = NULL; 102 weak_callback_ = NULL;
93 IncreaseBlockUses(); 103 IncreaseBlockUses();
94 } 104 }
95 105
96 void Zap() { 106 void Zap() {
97 DCHECK(IsInUse()); 107 DCHECK(IsInUse());
98 // Zap the values for eager trapping. 108 // Zap the values for eager trapping.
99 object_ = reinterpret_cast<Object*>(kGlobalHandleZapValue); 109 object_ = reinterpret_cast<Object*>(kGlobalHandleZapValue);
100 } 110 }
101 111
102 void Release() { 112 void Release() {
103 DCHECK(IsInUse()); 113 DCHECK(IsInUse());
104 set_state(FREE); 114 set_state(FREE);
105 // Zap the values for eager trapping. 115 // Zap the values for eager trapping.
106 object_ = reinterpret_cast<Object*>(kGlobalHandleZapValue); 116 object_ = reinterpret_cast<Object*>(kGlobalHandleZapValue);
107 class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId; 117 class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId;
108 set_independent(false); 118 set_independent(false);
109 set_partially_dependent(false); 119 if (FLAG_scavenge_reclaim_unmodified_objects) {
120 set_active(false);
121 } else {
122 set_partially_dependent(false);
123 }
110 weak_callback_ = NULL; 124 weak_callback_ = NULL;
111 DecreaseBlockUses(); 125 DecreaseBlockUses();
112 } 126 }
113 127
114 // Object slot accessors. 128 // Object slot accessors.
115 Object* object() const { return object_; } 129 Object* object() const { return object_; }
116 Object** location() { return &object_; } 130 Object** location() { return &object_; }
117 Handle<Object> handle() { return Handle<Object>(location()); } 131 Handle<Object> handle() { return Handle<Object>(location()); }
118 132
119 // Wrapper class ID accessors. 133 // Wrapper class ID accessors.
(...skipping 13 matching lines...) Expand all
133 } 147 }
134 148
135 bool is_independent() { 149 bool is_independent() {
136 return IsIndependent::decode(flags_); 150 return IsIndependent::decode(flags_);
137 } 151 }
138 void set_independent(bool v) { 152 void set_independent(bool v) {
139 flags_ = IsIndependent::update(flags_, v); 153 flags_ = IsIndependent::update(flags_, v);
140 } 154 }
141 155
142 bool is_partially_dependent() { 156 bool is_partially_dependent() {
157 CHECK(!FLAG_scavenge_reclaim_unmodified_objects);
143 return IsPartiallyDependent::decode(flags_); 158 return IsPartiallyDependent::decode(flags_);
144 } 159 }
145 void set_partially_dependent(bool v) { 160 void set_partially_dependent(bool v) {
161 CHECK(!FLAG_scavenge_reclaim_unmodified_objects);
146 flags_ = IsPartiallyDependent::update(flags_, v); 162 flags_ = IsPartiallyDependent::update(flags_, v);
147 } 163 }
148 164
165 bool is_active() {
166 CHECK(FLAG_scavenge_reclaim_unmodified_objects);
167 return IsActive::decode(flags_);
168 }
169 void set_active(bool v) {
170 CHECK(FLAG_scavenge_reclaim_unmodified_objects);
171 flags_ = IsActive::update(flags_, v);
172 }
173
149 bool is_in_new_space_list() { 174 bool is_in_new_space_list() {
150 return IsInNewSpaceList::decode(flags_); 175 return IsInNewSpaceList::decode(flags_);
151 } 176 }
152 void set_in_new_space_list(bool v) { 177 void set_in_new_space_list(bool v) {
153 flags_ = IsInNewSpaceList::update(flags_, v); 178 flags_ = IsInNewSpaceList::update(flags_, v);
154 } 179 }
155 180
156 WeaknessType weakness_type() const { 181 WeaknessType weakness_type() const {
157 return NodeWeaknessType::decode(flags_); 182 return NodeWeaknessType::decode(flags_);
158 } 183 }
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 // Wrapper class ID. 367 // Wrapper class ID.
343 uint16_t class_id_; 368 uint16_t class_id_;
344 369
345 // Index in the containing handle block. 370 // Index in the containing handle block.
346 uint8_t index_; 371 uint8_t index_;
347 372
348 // This stores three flags (independent, partially_dependent and 373 // This stores three flags (independent, partially_dependent and
349 // in_new_space_list) and a State. 374 // in_new_space_list) and a State.
350 class NodeState : public BitField<State, 0, 3> {}; 375 class NodeState : public BitField<State, 0, 3> {};
351 class IsIndependent : public BitField<bool, 3, 1> {}; 376 class IsIndependent : public BitField<bool, 3, 1> {};
377 // The following two fields are mutually exclusive
378 class IsActive : public BitField<bool, 4, 1> {};
352 class IsPartiallyDependent : public BitField<bool, 4, 1> {}; 379 class IsPartiallyDependent : public BitField<bool, 4, 1> {};
353 class IsInNewSpaceList : public BitField<bool, 5, 1> {}; 380 class IsInNewSpaceList : public BitField<bool, 5, 1> {};
354 class NodeWeaknessType : public BitField<WeaknessType, 6, 2> {}; 381 class NodeWeaknessType : public BitField<WeaknessType, 6, 2> {};
355 382
356 uint8_t flags_; 383 uint8_t flags_;
357 384
358 // Handle specific callback - might be a weak reference in disguise. 385 // Handle specific callback - might be a weak reference in disguise.
359 WeakCallback weak_callback_; 386 WeakCallback weak_callback_;
360 387
361 // Provided data for callback. In FREE state, this is used for 388 // Provided data for callback. In FREE state, this is used for
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 if (it.node()->IsWeak() && f(it.node()->location())) { 666 if (it.node()->IsWeak() && f(it.node()->location())) {
640 it.node()->MarkPending(); 667 it.node()->MarkPending();
641 } 668 }
642 } 669 }
643 } 670 }
644 671
645 672
646 void GlobalHandles::IterateNewSpaceStrongAndDependentRoots(ObjectVisitor* v) { 673 void GlobalHandles::IterateNewSpaceStrongAndDependentRoots(ObjectVisitor* v) {
647 for (int i = 0; i < new_space_nodes_.length(); ++i) { 674 for (int i = 0; i < new_space_nodes_.length(); ++i) {
648 Node* node = new_space_nodes_[i]; 675 Node* node = new_space_nodes_[i];
649 if (node->IsStrongRetainer() || 676 if (FLAG_scavenge_reclaim_unmodified_objects) {
650 (node->IsWeakRetainer() && !node->is_independent() && 677 if (node->IsStrongRetainer() ||
651 !node->is_partially_dependent())) { 678 (node->IsWeakRetainer() && !node->is_independent() &&
679 node->is_active())) {
652 v->VisitPointer(node->location()); 680 v->VisitPointer(node->location());
681 }
682 } else {
683 if (node->IsStrongRetainer() ||
684 (node->IsWeakRetainer() && !node->is_independent() &&
685 !node->is_partially_dependent())) {
686 v->VisitPointer(node->location());
687 }
653 } 688 }
654 } 689 }
655 } 690 }
656 691
657 692
658 void GlobalHandles::IdentifyNewSpaceWeakIndependentHandles( 693 void GlobalHandles::IdentifyNewSpaceWeakIndependentHandles(
659 WeakSlotCallbackWithHeap f) { 694 WeakSlotCallbackWithHeap f) {
660 for (int i = 0; i < new_space_nodes_.length(); ++i) { 695 for (int i = 0; i < new_space_nodes_.length(); ++i) {
661 Node* node = new_space_nodes_[i]; 696 Node* node = new_space_nodes_[i];
662 DCHECK(node->is_in_new_space_list()); 697 DCHECK(node->is_in_new_space_list());
(...skipping 17 matching lines...) Expand all
680 node->CollectPhantomCallbackData(isolate(), 715 node->CollectPhantomCallbackData(isolate(),
681 &pending_phantom_callbacks_); 716 &pending_phantom_callbacks_);
682 } else { 717 } else {
683 v->VisitPointer(node->location()); 718 v->VisitPointer(node->location());
684 } 719 }
685 } 720 }
686 } 721 }
687 } 722 }
688 723
689 724
725 void GlobalHandles::IdentifyWeakUnmodifiedObjects(
726 WeakSlotCallback is_unmodified) {
727 for (int i = 0; i < new_space_nodes_.length(); ++i) {
728 Node* node = new_space_nodes_[i];
729 if (node->IsWeak() && !is_unmodified(node->location())) {
730 node->set_active(true);
731 }
732 }
733 }
734
735
736 void GlobalHandles::MarkNewSpaceWeakUnmodifiedObjectsPending(
737 WeakSlotCallbackWithHeap is_unscavenged) {
738 for (int i = 0; i < new_space_nodes_.length(); ++i) {
739 Node* node = new_space_nodes_[i];
740 DCHECK(node->is_in_new_space_list());
741 if ((node->is_independent() || !node->is_active()) && node->IsWeak() &&
742 is_unscavenged(isolate_->heap(), node->location())) {
743 node->MarkPending();
744 }
745 }
746 }
747
748
749 void GlobalHandles::IterateNewSpaceWeakUnmodifiedRoots(ObjectVisitor* v) {
750 for (int i = 0; i < new_space_nodes_.length(); ++i) {
751 Node* node = new_space_nodes_[i];
752 DCHECK(node->is_in_new_space_list());
753 if ((node->is_independent() || !node->is_active()) &&
754 node->IsWeakRetainer()) {
755 // Pending weak phantom handles die immediately. Everything else survives.
756 if (node->state() == Node::PENDING &&
757 node->weakness_type() != NORMAL_WEAK) {
758 node->CollectPhantomCallbackData(isolate(),
759 &pending_phantom_callbacks_);
760 } else {
761 v->VisitPointer(node->location());
762 }
763 }
764 }
765 }
766
767
690 bool GlobalHandles::IterateObjectGroups(ObjectVisitor* v, 768 bool GlobalHandles::IterateObjectGroups(ObjectVisitor* v,
691 WeakSlotCallbackWithHeap can_skip) { 769 WeakSlotCallbackWithHeap can_skip) {
692 ComputeObjectGroupsAndImplicitReferences(); 770 ComputeObjectGroupsAndImplicitReferences();
693 int last = 0; 771 int last = 0;
694 bool any_group_was_visited = false; 772 bool any_group_was_visited = false;
695 for (int i = 0; i < object_groups_.length(); i++) { 773 for (int i = 0; i < object_groups_.length(); i++) {
696 ObjectGroup* entry = object_groups_.at(i); 774 ObjectGroup* entry = object_groups_.at(i);
697 DCHECK(entry != NULL); 775 DCHECK(entry != NULL);
698 776
699 Object*** objects = entry->objects; 777 Object*** objects = entry->objects;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 const int initial_post_gc_processing_count) { 828 const int initial_post_gc_processing_count) {
751 int freed_nodes = 0; 829 int freed_nodes = 0;
752 for (int i = 0; i < new_space_nodes_.length(); ++i) { 830 for (int i = 0; i < new_space_nodes_.length(); ++i) {
753 Node* node = new_space_nodes_[i]; 831 Node* node = new_space_nodes_[i];
754 DCHECK(node->is_in_new_space_list()); 832 DCHECK(node->is_in_new_space_list());
755 if (!node->IsRetainer()) { 833 if (!node->IsRetainer()) {
756 // Free nodes do not have weak callbacks. Do not use them to compute 834 // Free nodes do not have weak callbacks. Do not use them to compute
757 // the freed_nodes. 835 // the freed_nodes.
758 continue; 836 continue;
759 } 837 }
760 // Skip dependent handles. Their weak callbacks might expect to be 838 // Skip dependent or unmodified handles. Their weak callbacks might expect
839 // to be
761 // called between two global garbage collection callbacks which 840 // called between two global garbage collection callbacks which
762 // are not called for minor collections. 841 // are not called for minor collections.
763 if (!node->is_independent() && !node->is_partially_dependent()) { 842 if (FLAG_scavenge_reclaim_unmodified_objects) {
764 continue; 843 if (!node->is_independent() && (node->is_active())) {
844 node->set_active(false);
845 continue;
846 }
847 node->set_active(false);
848 } else {
849 if (!node->is_independent() && !node->is_partially_dependent()) {
850 continue;
851 }
852 node->clear_partially_dependent();
765 } 853 }
766 node->clear_partially_dependent(); 854
767 if (node->PostGarbageCollectionProcessing(isolate_)) { 855 if (node->PostGarbageCollectionProcessing(isolate_)) {
768 if (initial_post_gc_processing_count != post_gc_processing_count_) { 856 if (initial_post_gc_processing_count != post_gc_processing_count_) {
769 // Weak callback triggered another GC and another round of 857 // Weak callback triggered another GC and another round of
770 // PostGarbageCollection processing. The current node might 858 // PostGarbageCollection processing. The current node might
771 // have been deleted in that round, so we need to bail out (or 859 // have been deleted in that round, so we need to bail out (or
772 // restart the processing). 860 // restart the processing).
773 return freed_nodes; 861 return freed_nodes;
774 } 862 }
775 } 863 }
776 if (!node->IsRetainer()) { 864 if (!node->IsRetainer()) {
777 freed_nodes++; 865 freed_nodes++;
778 } 866 }
779 } 867 }
780 return freed_nodes; 868 return freed_nodes;
781 } 869 }
782 870
783 871
784 int GlobalHandles::PostMarkSweepProcessing( 872 int GlobalHandles::PostMarkSweepProcessing(
785 const int initial_post_gc_processing_count) { 873 const int initial_post_gc_processing_count) {
786 int freed_nodes = 0; 874 int freed_nodes = 0;
787 for (NodeIterator it(this); !it.done(); it.Advance()) { 875 for (NodeIterator it(this); !it.done(); it.Advance()) {
788 if (!it.node()->IsRetainer()) { 876 if (!it.node()->IsRetainer()) {
789 // Free nodes do not have weak callbacks. Do not use them to compute 877 // Free nodes do not have weak callbacks. Do not use them to compute
790 // the freed_nodes. 878 // the freed_nodes.
791 continue; 879 continue;
792 } 880 }
793 it.node()->clear_partially_dependent(); 881 if (FLAG_scavenge_reclaim_unmodified_objects) {
882 it.node()->set_active(false);
883 } else {
884 it.node()->clear_partially_dependent();
885 }
794 if (it.node()->PostGarbageCollectionProcessing(isolate_)) { 886 if (it.node()->PostGarbageCollectionProcessing(isolate_)) {
795 if (initial_post_gc_processing_count != post_gc_processing_count_) { 887 if (initial_post_gc_processing_count != post_gc_processing_count_) {
796 // See the comment above. 888 // See the comment above.
797 return freed_nodes; 889 return freed_nodes;
798 } 890 }
799 } 891 }
800 if (!it.node()->IsRetainer()) { 892 if (!it.node()->IsRetainer()) {
801 freed_nodes++; 893 freed_nodes++;
802 } 894 }
803 } 895 }
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 for (int i = 0; i < new_space_nodes_.length(); ++i) { 1040 for (int i = 0; i < new_space_nodes_.length(); ++i) {
949 Node* node = new_space_nodes_[i]; 1041 Node* node = new_space_nodes_[i];
950 if (node->IsRetainer() && node->has_wrapper_class_id()) { 1042 if (node->IsRetainer() && node->has_wrapper_class_id()) {
951 v->VisitEmbedderReference(node->location(), 1043 v->VisitEmbedderReference(node->location(),
952 node->wrapper_class_id()); 1044 node->wrapper_class_id());
953 } 1045 }
954 } 1046 }
955 } 1047 }
956 1048
957 1049
1050 void GlobalHandles::IterateWeakRootsInNewSpaceWithClassIds(ObjectVisitor* v) {
1051 for (int i = 0; i < new_space_nodes_.length(); ++i) {
1052 Node* node = new_space_nodes_[i];
1053 if (node->has_wrapper_class_id() && node->IsWeak()) {
1054 v->VisitEmbedderReference(node->location(), node->wrapper_class_id());
1055 }
1056 }
1057 }
1058
1059
958 int GlobalHandles::NumberOfWeakHandles() { 1060 int GlobalHandles::NumberOfWeakHandles() {
959 int count = 0; 1061 int count = 0;
960 for (NodeIterator it(this); !it.done(); it.Advance()) { 1062 for (NodeIterator it(this); !it.done(); it.Advance()) {
961 if (it.node()->IsWeakRetainer()) { 1063 if (it.node()->IsWeakRetainer()) {
962 count++; 1064 count++;
963 } 1065 }
964 } 1066 }
965 return count; 1067 return count;
966 } 1068 }
967 1069
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1274 blocks_[block][offset] = object; 1376 blocks_[block][offset] = object;
1275 if (isolate->heap()->InNewSpace(object)) { 1377 if (isolate->heap()->InNewSpace(object)) {
1276 new_space_indices_.Add(size_); 1378 new_space_indices_.Add(size_);
1277 } 1379 }
1278 *index = size_++; 1380 *index = size_++;
1279 } 1381 }
1280 1382
1281 1383
1282 } // namespace internal 1384 } // namespace internal
1283 } // namespace v8 1385 } // namespace v8
OLDNEW
« no previous file with comments | « src/global-handles.h ('k') | src/heap/heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698