< prev index next >

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

Print this page

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

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

147 void PreservedMark::adjust_pointer() {
148   MarkSweep::adjust_pointer(&_obj);
149 }
150 
151 void PreservedMark::restore() {
152   _obj->set_mark(_mark);
153 }
154 
155 // We preserve the mark which should be replaced at the end and the location
156 // that it will go.  Note that the object that this markWord belongs to isn't
157 // currently at that address but it will be after phase4
158 void MarkSweep::preserve_mark(oop obj, markWord mark) {
159   // We try to store preserved marks in the to space of the new generation since
160   // this is storage which should be available.  Most of the time this should be
161   // sufficient space for the marks we need to preserve but if it isn't we fall
162   // back to using Stacks to keep track of the overflow.
163   if (_preserved_count < _preserved_count_max) {
164     _preserved_marks[_preserved_count++].init(obj, mark);
165   } else {
166     _preserved_mark_stack.push(mark);
167     _preserved_oop_stack.push(obj);
168   }
169 }
170 
171 void MarkSweep::set_ref_processor(ReferenceProcessor* rp) {
172   _ref_processor = rp;
173   mark_and_push_closure.set_ref_discoverer(_ref_processor);
174 }
175 
176 AdjustPointerClosure MarkSweep::adjust_pointer_closure;
177 
178 void MarkSweep::adjust_marks() {
179   assert( _preserved_oop_stack.size() == _preserved_mark_stack.size(),
180          "inconsistent preserved oop stacks");
181 
182   // adjust the oops we saved earlier
183   for (size_t i = 0; i < _preserved_count; i++) {
184     _preserved_marks[i].adjust_pointer();
185   }
186 
187   // deal with the overflow stack
188   StackIterator<oop, mtGC> iter(_preserved_oop_stack);
189   while (!iter.is_empty()) {
190     oop* p = iter.next_addr();
191     adjust_pointer(p);








192   }
193 }
194 
195 void MarkSweep::restore_marks() {
196   assert(_preserved_oop_stack.size() == _preserved_mark_stack.size(),
197          "inconsistent preserved oop stacks");
198   log_trace(gc)("Restoring " SIZE_FORMAT " marks", _preserved_count + _preserved_oop_stack.size());
199 
200   // restore the marks we saved earlier
201   for (size_t i = 0; i < _preserved_count; i++) {
202     _preserved_marks[i].restore();
203   }
204 
205   // deal with the overflow
206   while (!_preserved_oop_stack.is_empty()) {
207     oop obj       = _preserved_oop_stack.pop();
208     markWord mark = _preserved_mark_stack.pop();
209     obj->set_mark(mark);
210   }
211 }

 45 #include "utilities/stack.inline.hpp"
 46 
 47 uint                    MarkSweep::_total_invocations = 0;
 48 
 49 Stack<oop, mtGC>              MarkSweep::_marking_stack;
 50 Stack<ObjArrayTask, mtGC>     MarkSweep::_objarray_stack;
 51 
 52 Stack<oop, mtGC>              MarkSweep::_preserved_oop_stack;
 53 Stack<markWord, mtGC>         MarkSweep::_preserved_mark_stack;
 54 size_t                  MarkSweep::_preserved_count = 0;
 55 size_t                  MarkSweep::_preserved_count_max = 0;
 56 PreservedMark*          MarkSweep::_preserved_marks = NULL;
 57 ReferenceProcessor*     MarkSweep::_ref_processor   = NULL;
 58 STWGCTimer*             MarkSweep::_gc_timer        = NULL;
 59 SerialOldTracer*        MarkSweep::_gc_tracer       = NULL;
 60 
 61 MarkSweep::FollowRootClosure  MarkSweep::follow_root_closure;
 62 
 63 MarkAndPushClosure MarkSweep::mark_and_push_closure;
 64 CLDToOopClosure    MarkSweep::follow_cld_closure(&mark_and_push_closure, ClassLoaderData::_claim_strong);

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

126 
127 void MarkSweep::FollowStackClosure::do_void() { follow_stack(); }
128 
129 template <class T> inline void MarkSweep::follow_root(T* p) {
130   assert(!Universe::heap()->is_in(p),
131          "roots shouldn't be things within the heap");
132   T heap_oop = RawAccess<>::oop_load(p);
133   if (!CompressedOops::is_null(heap_oop)) {
134     oop obj = CompressedOops::decode_not_null(heap_oop);
135     if (!obj->mark().is_marked()) {
136       mark_object(obj);
137       follow_object(obj);
138     }
139   }
140   follow_stack();
141 }
142 
143 void MarkSweep::FollowRootClosure::do_oop(oop* p)       { follow_root(p); }
144 void MarkSweep::FollowRootClosure::do_oop(narrowOop* p) { follow_root(p); }
145 
146 template <bool ALT_FWD>
147 void PreservedMark::adjust_pointer() {
148   MarkSweep::adjust_pointer<ALT_FWD>(&_obj);
149 }
150 
151 void PreservedMark::restore() {
152   _obj->set_mark(_mark);
153 }
154 
155 // We preserve the mark which should be replaced at the end and the location
156 // that it will go.  Note that the object that this markWord belongs to isn't
157 // currently at that address but it will be after phase4
158 void MarkSweep::preserve_mark(oop obj, markWord mark) {
159   // We try to store preserved marks in the to space of the new generation since
160   // this is storage which should be available.  Most of the time this should be
161   // sufficient space for the marks we need to preserve but if it isn't we fall
162   // back to using Stacks to keep track of the overflow.
163   if (_preserved_count < _preserved_count_max) {
164     _preserved_marks[_preserved_count++].init(obj, mark);
165   } else {
166     _preserved_mark_stack.push(mark);
167     _preserved_oop_stack.push(obj);
168   }
169 }
170 
171 void MarkSweep::set_ref_processor(ReferenceProcessor* rp) {
172   _ref_processor = rp;
173   mark_and_push_closure.set_ref_discoverer(_ref_processor);
174 }
175 
176 template <bool ALT_FWD>
177 void MarkSweep::adjust_marks_impl() {

178   assert( _preserved_oop_stack.size() == _preserved_mark_stack.size(),
179          "inconsistent preserved oop stacks");
180 
181   // adjust the oops we saved earlier
182   for (size_t i = 0; i < _preserved_count; i++) {
183     _preserved_marks[i].adjust_pointer<ALT_FWD>();
184   }
185 
186   // deal with the overflow stack
187   StackIterator<oop, mtGC> iter(_preserved_oop_stack);
188   while (!iter.is_empty()) {
189     oop* p = iter.next_addr();
190     adjust_pointer<ALT_FWD>(p);
191   }
192 }
193 
194 void MarkSweep::adjust_marks() {
195   if (UseAltGCForwarding) {
196     adjust_marks_impl<true>();
197   } else {
198     adjust_marks_impl<false>();
199   }
200 }
201 
202 void MarkSweep::restore_marks() {
203   assert(_preserved_oop_stack.size() == _preserved_mark_stack.size(),
204          "inconsistent preserved oop stacks");
205   log_trace(gc)("Restoring " SIZE_FORMAT " marks", _preserved_count + _preserved_oop_stack.size());
206 
207   // restore the marks we saved earlier
208   for (size_t i = 0; i < _preserved_count; i++) {
209     _preserved_marks[i].restore();
210   }
211 
212   // deal with the overflow
213   while (!_preserved_oop_stack.is_empty()) {
214     oop obj       = _preserved_oop_stack.pop();
215     markWord mark = _preserved_mark_stack.pop();
216     obj->set_mark(mark);
217   }
218 }
< prev index next >