< prev index next >

src/hotspot/share/gc/serial/markSweep.cpp

Print this page

 43 
 44 Stack<oop, mtGC>              MarkSweep::_marking_stack;
 45 Stack<ObjArrayTask, mtGC>     MarkSweep::_objarray_stack;
 46 
 47 Stack<PreservedMark, mtGC>    MarkSweep::_preserved_overflow_stack;
 48 size_t                  MarkSweep::_preserved_count = 0;
 49 size_t                  MarkSweep::_preserved_count_max = 0;
 50 PreservedMark*          MarkSweep::_preserved_marks = nullptr;
 51 STWGCTimer*             MarkSweep::_gc_timer        = nullptr;
 52 SerialOldTracer*        MarkSweep::_gc_tracer       = nullptr;
 53 
 54 AlwaysTrueClosure   MarkSweep::_always_true_closure;
 55 ReferenceProcessor* MarkSweep::_ref_processor;
 56 
 57 StringDedup::Requests*  MarkSweep::_string_dedup_requests = nullptr;
 58 
 59 MarkSweep::FollowRootClosure  MarkSweep::follow_root_closure;
 60 
 61 MarkAndPushClosure MarkSweep::mark_and_push_closure(ClassLoaderData::_claim_stw_fullgc_mark);
 62 CLDToOopClosure    MarkSweep::follow_cld_closure(&mark_and_push_closure, ClassLoaderData::_claim_stw_fullgc_mark);
 63 CLDToOopClosure    MarkSweep::adjust_cld_closure(&adjust_pointer_closure, ClassLoaderData::_claim_stw_fullgc_adjust);
 64 
 65 template <class T> void MarkSweep::KeepAliveClosure::do_oop_work(T* p) {
 66   mark_and_push(p);
 67 }
 68 
 69 void MarkSweep::push_objarray(oop obj, size_t index) {
 70   ObjArrayTask task(obj, index);
 71   assert(task.is_valid(), "bad ObjArrayTask");
 72   _objarray_stack.push(task);
 73 }
 74 
 75 void MarkSweep::follow_array(objArrayOop array) {
 76   mark_and_push_closure.do_klass(array->klass());
 77   // Don't push empty arrays to avoid unnecessary work.
 78   if (array->length() > 0) {
 79     MarkSweep::push_objarray(array, 0);
 80   }
 81 }
 82 
 83 void MarkSweep::follow_object(oop obj) {

125 
126 void MarkSweep::FollowStackClosure::do_void() { follow_stack(); }
127 
128 template <class T> void MarkSweep::follow_root(T* p) {
129   assert(!Universe::heap()->is_in(p),
130          "roots shouldn't be things within the heap");
131   T heap_oop = RawAccess<>::oop_load(p);
132   if (!CompressedOops::is_null(heap_oop)) {
133     oop obj = CompressedOops::decode_not_null(heap_oop);
134     if (!obj->mark().is_marked()) {
135       mark_object(obj);
136       follow_object(obj);
137     }
138   }
139   follow_stack();
140 }
141 
142 void MarkSweep::FollowRootClosure::do_oop(oop* p)       { follow_root(p); }
143 void MarkSweep::FollowRootClosure::do_oop(narrowOop* p) { follow_root(p); }
144 

145 void PreservedMark::adjust_pointer() {
146   MarkSweep::adjust_pointer(&_obj);
147 }
148 
149 void PreservedMark::restore() {
150   _obj->set_mark(_mark);
151 }
152 
153 // We preserve the mark which should be replaced at the end and the location
154 // that it will go.  Note that the object that this markWord belongs to isn't
155 // currently at that address but it will be after phase4
156 void MarkSweep::preserve_mark(oop obj, markWord mark) {
157   // We try to store preserved marks in the to space of the new generation since
158   // this is storage which should be available.  Most of the time this should be
159   // sufficient space for the marks we need to preserve but if it isn't we fall
160   // back to using Stacks to keep track of the overflow.
161   if (_preserved_count < _preserved_count_max) {
162     _preserved_marks[_preserved_count++] = PreservedMark(obj, mark);
163   } else {
164     _preserved_overflow_stack.push(PreservedMark(obj, mark));
165   }
166 }
167 
168 void MarkSweep::mark_object(oop obj) {
169   if (StringDedup::is_enabled() &&
170       java_lang_String::is_instance(obj) &&
171       SerialStringDedup::is_candidate_from_mark(obj)) {
172     _string_dedup_requests->add(obj);
173   }
174 




175   // some marks may contain information we need to preserve so we store them away
176   // and overwrite the mark.  We'll restore it at the end of markSweep.
177   markWord mark = obj->mark();
178   obj->set_mark(markWord::prototype().set_marked());
179 
180   ContinuationGCSupport::transform_stack_chunk(obj);
181 
182   if (obj->mark_must_be_preserved(mark)) {
183     preserve_mark(obj, mark);
184   }
185 }
186 
187 template <class T> void MarkSweep::mark_and_push(T* p) {
188   T heap_oop = RawAccess<>::oop_load(p);
189   if (!CompressedOops::is_null(heap_oop)) {
190     oop obj = CompressedOops::decode_not_null(heap_oop);
191     if (!obj->mark().is_marked()) {
192       mark_object(obj);
193       _marking_stack.push(obj);
194     }
195   }
196 }
197 
198 template <typename T>
199 void MarkAndPushClosure::do_oop_work(T* p)            { MarkSweep::mark_and_push(p); }
200 void MarkAndPushClosure::do_oop(      oop* p)         { do_oop_work(p); }
201 void MarkAndPushClosure::do_oop(narrowOop* p)         { do_oop_work(p); }
202 
203 AdjustPointerClosure MarkSweep::adjust_pointer_closure;
204 
205 void MarkSweep::adjust_marks() {
206   // adjust the oops we saved earlier
207   for (size_t i = 0; i < _preserved_count; i++) {
208     _preserved_marks[i].adjust_pointer();
209   }
210 
211   // deal with the overflow stack
212   StackIterator<PreservedMark, mtGC> iter(_preserved_overflow_stack);
213   while (!iter.is_empty()) {
214     PreservedMark* p = iter.next_addr();
215     p->adjust_pointer();








216   }
217 }
218 
219 void MarkSweep::restore_marks() {
220   log_trace(gc)("Restoring " SIZE_FORMAT " marks", _preserved_count + _preserved_overflow_stack.size());
221 
222   // restore the marks we saved earlier
223   for (size_t i = 0; i < _preserved_count; i++) {
224     _preserved_marks[i].restore();
225   }
226 
227   // deal with the overflow
228   while (!_preserved_overflow_stack.is_empty()) {
229     PreservedMark p = _preserved_overflow_stack.pop();
230     p.restore();
231   }
232 }
233 
234 MarkSweep::IsAliveClosure   MarkSweep::is_alive;
235 

 43 
 44 Stack<oop, mtGC>              MarkSweep::_marking_stack;
 45 Stack<ObjArrayTask, mtGC>     MarkSweep::_objarray_stack;
 46 
 47 Stack<PreservedMark, mtGC>    MarkSweep::_preserved_overflow_stack;
 48 size_t                  MarkSweep::_preserved_count = 0;
 49 size_t                  MarkSweep::_preserved_count_max = 0;
 50 PreservedMark*          MarkSweep::_preserved_marks = nullptr;
 51 STWGCTimer*             MarkSweep::_gc_timer        = nullptr;
 52 SerialOldTracer*        MarkSweep::_gc_tracer       = nullptr;
 53 
 54 AlwaysTrueClosure   MarkSweep::_always_true_closure;
 55 ReferenceProcessor* MarkSweep::_ref_processor;
 56 
 57 StringDedup::Requests*  MarkSweep::_string_dedup_requests = nullptr;
 58 
 59 MarkSweep::FollowRootClosure  MarkSweep::follow_root_closure;
 60 
 61 MarkAndPushClosure MarkSweep::mark_and_push_closure(ClassLoaderData::_claim_stw_fullgc_mark);
 62 CLDToOopClosure    MarkSweep::follow_cld_closure(&mark_and_push_closure, ClassLoaderData::_claim_stw_fullgc_mark);

 63 
 64 template <class T> void MarkSweep::KeepAliveClosure::do_oop_work(T* p) {
 65   mark_and_push(p);
 66 }
 67 
 68 void MarkSweep::push_objarray(oop obj, size_t index) {
 69   ObjArrayTask task(obj, index);
 70   assert(task.is_valid(), "bad ObjArrayTask");
 71   _objarray_stack.push(task);
 72 }
 73 
 74 void MarkSweep::follow_array(objArrayOop array) {
 75   mark_and_push_closure.do_klass(array->klass());
 76   // Don't push empty arrays to avoid unnecessary work.
 77   if (array->length() > 0) {
 78     MarkSweep::push_objarray(array, 0);
 79   }
 80 }
 81 
 82 void MarkSweep::follow_object(oop obj) {

124 
125 void MarkSweep::FollowStackClosure::do_void() { follow_stack(); }
126 
127 template <class T> void MarkSweep::follow_root(T* p) {
128   assert(!Universe::heap()->is_in(p),
129          "roots shouldn't be things within the heap");
130   T heap_oop = RawAccess<>::oop_load(p);
131   if (!CompressedOops::is_null(heap_oop)) {
132     oop obj = CompressedOops::decode_not_null(heap_oop);
133     if (!obj->mark().is_marked()) {
134       mark_object(obj);
135       follow_object(obj);
136     }
137   }
138   follow_stack();
139 }
140 
141 void MarkSweep::FollowRootClosure::do_oop(oop* p)       { follow_root(p); }
142 void MarkSweep::FollowRootClosure::do_oop(narrowOop* p) { follow_root(p); }
143 
144 template <bool ALT_FWD>
145 void PreservedMark::adjust_pointer() {
146   MarkSweep::adjust_pointer<ALT_FWD>(&_obj);
147 }
148 
149 void PreservedMark::restore() {
150   _obj->set_mark(_mark);
151 }
152 
153 // We preserve the mark which should be replaced at the end and the location
154 // that it will go.  Note that the object that this markWord belongs to isn't
155 // currently at that address but it will be after phase4
156 void MarkSweep::preserve_mark(oop obj, markWord mark) {
157   // We try to store preserved marks in the to space of the new generation since
158   // this is storage which should be available.  Most of the time this should be
159   // sufficient space for the marks we need to preserve but if it isn't we fall
160   // back to using Stacks to keep track of the overflow.
161   if (_preserved_count < _preserved_count_max) {
162     _preserved_marks[_preserved_count++] = PreservedMark(obj, mark);
163   } else {
164     _preserved_overflow_stack.push(PreservedMark(obj, mark));
165   }
166 }
167 
168 void MarkSweep::mark_object(oop obj) {
169   if (StringDedup::is_enabled() &&
170       java_lang_String::is_instance(obj) &&
171       SerialStringDedup::is_candidate_from_mark(obj)) {
172     _string_dedup_requests->add(obj);
173   }
174 
175   // Do the transform while we still have the header intact,
176   // which might include important class information.
177   ContinuationGCSupport::transform_stack_chunk(obj);
178 
179   // some marks may contain information we need to preserve so we store them away
180   // and overwrite the mark.  We'll restore it at the end of markSweep.
181   markWord mark = obj->mark();
182   obj->set_mark(obj->prototype_mark().set_marked());


183 
184   if (obj->mark_must_be_preserved(mark)) {
185     preserve_mark(obj, mark);
186   }
187 }
188 
189 template <class T> void MarkSweep::mark_and_push(T* p) {
190   T heap_oop = RawAccess<>::oop_load(p);
191   if (!CompressedOops::is_null(heap_oop)) {
192     oop obj = CompressedOops::decode_not_null(heap_oop);
193     if (!obj->mark().is_marked()) {
194       mark_object(obj);
195       _marking_stack.push(obj);
196     }
197   }
198 }
199 
200 template <typename T>
201 void MarkAndPushClosure::do_oop_work(T* p)            { MarkSweep::mark_and_push(p); }
202 void MarkAndPushClosure::do_oop(      oop* p)         { do_oop_work(p); }
203 void MarkAndPushClosure::do_oop(narrowOop* p)         { do_oop_work(p); }
204 
205 template <bool ALT_FWD>
206 void MarkSweep::adjust_marks_impl() {

207   // adjust the oops we saved earlier
208   for (size_t i = 0; i < _preserved_count; i++) {
209     _preserved_marks[i].adjust_pointer<ALT_FWD>();
210   }
211 
212   // deal with the overflow stack
213   StackIterator<PreservedMark, mtGC> iter(_preserved_overflow_stack);
214   while (!iter.is_empty()) {
215     PreservedMark* p = iter.next_addr();
216     p->adjust_pointer<ALT_FWD>();
217   }
218 }
219 
220 void MarkSweep::adjust_marks() {
221   if (UseAltGCForwarding) {
222     adjust_marks_impl<true>();
223   } else {
224     adjust_marks_impl<false>();
225   }
226 }
227 
228 void MarkSweep::restore_marks() {
229   log_trace(gc)("Restoring " SIZE_FORMAT " marks", _preserved_count + _preserved_overflow_stack.size());
230 
231   // restore the marks we saved earlier
232   for (size_t i = 0; i < _preserved_count; i++) {
233     _preserved_marks[i].restore();
234   }
235 
236   // deal with the overflow
237   while (!_preserved_overflow_stack.is_empty()) {
238     PreservedMark p = _preserved_overflow_stack.pop();
239     p.restore();
240   }
241 }
242 
243 MarkSweep::IsAliveClosure   MarkSweep::is_alive;
244 
< prev index next >