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

Side by Side Diff: src/incremental-marking.h

Issue 6713075: Create an abstraction (MarkBit) object to hold the location of the... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: '' Created 9 years, 9 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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 if (state_ == COMPLETE) { 73 if (state_ == COMPLETE) {
74 state_ = MARKING; 74 state_ = MARKING;
75 if (FLAG_trace_incremental_marking) { 75 if (FLAG_trace_incremental_marking) {
76 PrintF("[IncrementalMarking] Restarting (new grey objects)\n"); 76 PrintF("[IncrementalMarking] Restarting (new grey objects)\n");
77 } 77 }
78 } 78 }
79 } 79 }
80 80
81 static inline void RecordWrite(HeapObject* obj, Object* value) { 81 static inline void RecordWrite(HeapObject* obj, Object* value) {
82 if (!IsStopped() && value->IsHeapObject()) { 82 if (!IsStopped() && value->IsHeapObject()) {
83 if (IsBlack(obj) && IsWhite(HeapObject::cast(value))) { 83 MarkBit value_bit = Marking::MarkBitFrom(HeapObject::cast(value));
84 BlackToGrey(obj); 84 if (IsWhite(value_bit)) {
85 RestartIfNotMarking(); 85 MarkBit obj_bit = Marking::MarkBitFrom(obj);
86 if (IsBlack(obj_bit)) {
87 BlackToGrey(obj, obj_bit);
88 RestartIfNotMarking();
89 }
86 } 90 }
87 } 91 }
88 } 92 }
89 93
90 static inline void RecordWriteOf(HeapObject* value) { 94 static inline void RecordWriteOf(HeapObject* value) {
91 if (state_ != STOPPED) { 95 if (state_ != STOPPED) {
92 if (IsWhite(value)) { 96 MarkBit value_bit = Marking::MarkBitFrom(value);
93 WhiteToGrey(value); 97 if (IsWhite(value_bit)) {
98 WhiteToGrey(value, value_bit);
94 RestartIfNotMarking(); 99 RestartIfNotMarking();
95 } 100 }
96 } 101 }
97 } 102 }
98 103
99 104
100 static inline void RecordWrites(HeapObject* obj) { 105 static inline void RecordWrites(HeapObject* obj) {
101 if (!IsStopped()) { 106 if (!IsStopped()) {
102 if (IsBlack(obj)) { 107 MarkBit obj_bit = Marking::MarkBitFrom(obj);
103 BlackToGrey(obj); 108 if (IsBlack(obj_bit)) {
109 BlackToGrey(obj, obj_bit);
104 RestartIfNotMarking(); 110 RestartIfNotMarking();
105 } 111 }
106 } 112 }
107 } 113 }
108 114
109 115 // Impossible markbits: 01
110 // Black markbits: 10 116 static inline bool IsImpossible(MarkBit mark_bit) {
111 static inline bool IsBlack(HeapObject* obj) { 117 return !mark_bit.Get() && mark_bit.Next().Get();
112 return Marking::IsMarked(obj->address());
113 } 118 }
114 119
115 // White markbits: 00 120 // Black markbits: 10 - this is required by the sweeper.
116 static inline bool IsWhite(HeapObject* obj) { 121 static inline bool IsBlack(MarkBit mark_bit) {
117 return !Marking::IsMarked(obj->address()) && 122 ASSERT(!IsImpossible(mark_bit));
118 !Marking::IsMarked(obj->address() + kPointerSize); 123 return mark_bit.Get() && !mark_bit.Next().Get();
119 } 124 }
120 125
121 // Grey markbits: 01 126 // White markbits: 00 - this is required by the mark bit clearer.
122 static inline bool IsGrey(HeapObject* obj) { 127 static inline bool IsWhite(MarkBit mark_bit) {
123 return Marking::IsMarked(obj->address() + kPointerSize); 128 ASSERT(!IsImpossible(mark_bit));
129 return !mark_bit.Get();
124 } 130 }
125 131
126 static inline void BlackToGrey(HeapObject* obj) { 132 // Grey markbits: 11
133 static inline bool IsGrey(MarkBit mark_bit) {
134 ASSERT(!IsImpossible(mark_bit));
135 return mark_bit.Get() && mark_bit.Next().Get();
136 }
137
138 static inline void BlackToGrey(HeapObject* obj, MarkBit mark_bit) {
139 ASSERT(Marking::MarkBitFrom(obj) == mark_bit);
127 ASSERT(obj->Size() >= 2*kPointerSize); 140 ASSERT(obj->Size() >= 2*kPointerSize);
128 ASSERT(!IsStopped()); 141 ASSERT(!IsStopped());
129 ASSERT(IsBlack(obj)); 142 ASSERT(IsBlack(mark_bit));
130 Marking::ClearMark(obj->address()); 143 mark_bit.Next().Set();
131 Marking::SetMark(obj->address() + kPointerSize); 144 ASSERT(IsGrey(mark_bit));
132 ASSERT(IsGrey(obj));
133 145
134 marking_stack_.Push(obj); 146 marking_stack_.Push(obj);
135 ASSERT(!marking_stack_.overflowed()); 147 ASSERT(!marking_stack_.overflowed());
136 } 148 }
137 149
138 static inline void WhiteToGrey(HeapObject* obj) { 150 static inline void WhiteToGrey(HeapObject* obj, MarkBit mark_bit) {
151 ASSERT(Marking::MarkBitFrom(obj) == mark_bit);
139 ASSERT(obj->Size() >= 2*kPointerSize); 152 ASSERT(obj->Size() >= 2*kPointerSize);
140 ASSERT(!IsStopped()); 153 ASSERT(!IsStopped());
141 ASSERT(IsWhite(obj)); 154 ASSERT(IsWhite(mark_bit));
142 Marking::SetMark(obj->address() + kPointerSize); 155 mark_bit.Set();
143 ASSERT(IsGrey(obj)); 156 mark_bit.Next().Set();
157 ASSERT(IsGrey(mark_bit));
144 158
145 marking_stack_.Push(obj); 159 marking_stack_.Push(obj);
146 ASSERT(!marking_stack_.overflowed()); 160 ASSERT(!marking_stack_.overflowed());
147 } 161 }
148 162
149 static inline void MarkBlack(HeapObject* obj) { 163 static inline void MarkBlack(MarkBit mark_bit) {
150 ASSERT(obj->Size() >= 2*kPointerSize); 164 mark_bit.Set();
151 Marking::SetMark(obj->address()); 165 mark_bit.Next().Clear();
152 Marking::ClearMark(obj->address() + kPointerSize); 166 ASSERT(IsBlack(mark_bit));
153 ASSERT(IsBlack(obj));
154 } 167 }
155 168
156 static inline const char* ColorStr(HeapObject* obj) { 169 static inline const char* ColorStr(MarkBit mark_bit) {
157 if (IsBlack(obj)) return "black"; 170 if (IsBlack(mark_bit)) return "black";
158 if (IsWhite(obj)) return "white"; 171 if (IsWhite(mark_bit)) return "white";
159 if (IsGrey(obj)) return "grey"; 172 if (IsGrey(mark_bit)) return "grey";
160 UNREACHABLE(); 173 UNREACHABLE();
161 return "???"; 174 return "???";
162 } 175 }
163 176
164 private: 177 private:
165 static State state_; 178 static State state_;
166 static MarkingStack marking_stack_; 179 static MarkingStack marking_stack_;
167 }; 180 };
168 181
169 } } // namespace v8::internal 182 } } // namespace v8::internal
170 183
171 #endif // V8_INCREMENTAL_MARKING_H_ 184 #endif // V8_INCREMENTAL_MARKING_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698