< prev index next >

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

Print this page




  32 #include "memory/universe.hpp"
  33 #include "oops/access.inline.hpp"
  34 #include "oops/compressedOops.inline.hpp"
  35 #include "oops/instanceClassLoaderKlass.inline.hpp"
  36 #include "oops/instanceKlass.inline.hpp"
  37 #include "oops/instanceMirrorKlass.inline.hpp"
  38 #include "oops/instanceRefKlass.inline.hpp"
  39 #include "oops/methodData.hpp"
  40 #include "oops/objArrayKlass.inline.hpp"
  41 #include "oops/oop.inline.hpp"
  42 #include "oops/typeArrayOop.inline.hpp"
  43 #include "utilities/macros.hpp"
  44 #include "utilities/stack.inline.hpp"
  45 
  46 uint                    MarkSweep::_total_invocations = 0;
  47 
  48 Stack<oop, mtGC>              MarkSweep::_marking_stack;
  49 Stack<ObjArrayTask, mtGC>     MarkSweep::_objarray_stack;
  50 
  51 Stack<oop, mtGC>              MarkSweep::_preserved_oop_stack;
  52 Stack<markWord, mtGC>         MarkSweep::_preserved_mark_stack;
  53 size_t                  MarkSweep::_preserved_count = 0;
  54 size_t                  MarkSweep::_preserved_count_max = 0;
  55 PreservedMark*          MarkSweep::_preserved_marks = NULL;
  56 ReferenceProcessor*     MarkSweep::_ref_processor   = NULL;
  57 STWGCTimer*             MarkSweep::_gc_timer        = NULL;
  58 SerialOldTracer*        MarkSweep::_gc_tracer       = NULL;
  59 
  60 MarkSweep::FollowRootClosure  MarkSweep::follow_root_closure;
  61 
  62 MarkAndPushClosure MarkSweep::mark_and_push_closure;
  63 CLDToOopClosure    MarkSweep::follow_cld_closure(&mark_and_push_closure, ClassLoaderData::_claim_strong);
  64 CLDToOopClosure    MarkSweep::adjust_cld_closure(&adjust_pointer_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");


 110 void MarkSweep::follow_stack() {
 111   do {
 112     while (!_marking_stack.is_empty()) {
 113       oop obj = _marking_stack.pop();
 114       assert (obj->is_gc_marked(), "p must be marked");
 115       follow_object(obj);
 116     }
 117     // Process ObjArrays one at a time to avoid marking stack bloat.
 118     if (!_objarray_stack.is_empty()) {
 119       ObjArrayTask task = _objarray_stack.pop();
 120       follow_array_chunk(objArrayOop(task.obj()), task.index());
 121     }
 122   } while (!_marking_stack.is_empty() || !_objarray_stack.is_empty());
 123 }
 124 
 125 MarkSweep::FollowStackClosure MarkSweep::follow_stack_closure;
 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_raw().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 void PreservedMark::adjust_pointer() {
 147   MarkSweep::adjust_pointer(&_obj);
 148 }
 149 
 150 void PreservedMark::restore() {
 151   _obj->set_mark_raw(_mark);
 152 }
 153 
 154 // We preserve the mark which should be replaced at the end and the location
 155 // that it will go.  Note that the object that this markWord belongs to isn't
 156 // currently at that address but it will be after phase4
 157 void MarkSweep::preserve_mark(oop obj, markWord mark) {
 158   // We try to store preserved marks in the to space of the new generation since
 159   // this is storage which should be available.  Most of the time this should be
 160   // sufficient space for the marks we need to preserve but if it isn't we fall
 161   // back to using Stacks to keep track of the overflow.
 162   if (_preserved_count < _preserved_count_max) {
 163     _preserved_marks[_preserved_count++].init(obj, mark);
 164   } else {
 165     _preserved_mark_stack.push(mark);
 166     _preserved_oop_stack.push(obj);
 167   }
 168 }
 169 
 170 void MarkSweep::set_ref_processor(ReferenceProcessor* rp) {
 171   _ref_processor = rp;
 172   mark_and_push_closure.set_ref_discoverer(_ref_processor);
 173 }
 174 
 175 AdjustPointerClosure MarkSweep::adjust_pointer_closure;
 176 
 177 void MarkSweep::adjust_marks() {


 187   StackIterator<oop, mtGC> iter(_preserved_oop_stack);
 188   while (!iter.is_empty()) {
 189     oop* p = iter.next_addr();
 190     adjust_pointer(p);
 191   }
 192 }
 193 
 194 void MarkSweep::restore_marks() {
 195   assert(_preserved_oop_stack.size() == _preserved_mark_stack.size(),
 196          "inconsistent preserved oop stacks");
 197   log_trace(gc)("Restoring " SIZE_FORMAT " marks", _preserved_count + _preserved_oop_stack.size());
 198 
 199   // restore the marks we saved earlier
 200   for (size_t i = 0; i < _preserved_count; i++) {
 201     _preserved_marks[i].restore();
 202   }
 203 
 204   // deal with the overflow
 205   while (!_preserved_oop_stack.is_empty()) {
 206     oop obj       = _preserved_oop_stack.pop();
 207     markWord mark = _preserved_mark_stack.pop();
 208     obj->set_mark_raw(mark);
 209   }
 210 }
 211 
 212 MarkSweep::IsAliveClosure   MarkSweep::is_alive;
 213 
 214 bool MarkSweep::IsAliveClosure::do_object_b(oop p) { return p->is_gc_marked(); }
 215 
 216 MarkSweep::KeepAliveClosure MarkSweep::keep_alive;
 217 
 218 void MarkSweep::KeepAliveClosure::do_oop(oop* p)       { MarkSweep::KeepAliveClosure::do_oop_work(p); }
 219 void MarkSweep::KeepAliveClosure::do_oop(narrowOop* p) { MarkSweep::KeepAliveClosure::do_oop_work(p); }
 220 
 221 void MarkSweep::initialize() {
 222   MarkSweep::_gc_timer = new (ResourceObj::C_HEAP, mtGC) STWGCTimer();
 223   MarkSweep::_gc_tracer = new (ResourceObj::C_HEAP, mtGC) SerialOldTracer();
 224 }


  32 #include "memory/universe.hpp"
  33 #include "oops/access.inline.hpp"
  34 #include "oops/compressedOops.inline.hpp"
  35 #include "oops/instanceClassLoaderKlass.inline.hpp"
  36 #include "oops/instanceKlass.inline.hpp"
  37 #include "oops/instanceMirrorKlass.inline.hpp"
  38 #include "oops/instanceRefKlass.inline.hpp"
  39 #include "oops/methodData.hpp"
  40 #include "oops/objArrayKlass.inline.hpp"
  41 #include "oops/oop.inline.hpp"
  42 #include "oops/typeArrayOop.inline.hpp"
  43 #include "utilities/macros.hpp"
  44 #include "utilities/stack.inline.hpp"
  45 
  46 uint                    MarkSweep::_total_invocations = 0;
  47 
  48 Stack<oop, mtGC>              MarkSweep::_marking_stack;
  49 Stack<ObjArrayTask, mtGC>     MarkSweep::_objarray_stack;
  50 
  51 Stack<oop, mtGC>              MarkSweep::_preserved_oop_stack;
  52 Stack<markOop, mtGC>          MarkSweep::_preserved_mark_stack;
  53 size_t                  MarkSweep::_preserved_count = 0;
  54 size_t                  MarkSweep::_preserved_count_max = 0;
  55 PreservedMark*          MarkSweep::_preserved_marks = NULL;
  56 ReferenceProcessor*     MarkSweep::_ref_processor   = NULL;
  57 STWGCTimer*             MarkSweep::_gc_timer        = NULL;
  58 SerialOldTracer*        MarkSweep::_gc_tracer       = NULL;
  59 
  60 MarkSweep::FollowRootClosure  MarkSweep::follow_root_closure;
  61 
  62 MarkAndPushClosure MarkSweep::mark_and_push_closure;
  63 CLDToOopClosure    MarkSweep::follow_cld_closure(&mark_and_push_closure, ClassLoaderData::_claim_strong);
  64 CLDToOopClosure    MarkSweep::adjust_cld_closure(&adjust_pointer_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");


 110 void MarkSweep::follow_stack() {
 111   do {
 112     while (!_marking_stack.is_empty()) {
 113       oop obj = _marking_stack.pop();
 114       assert (obj->is_gc_marked(), "p must be marked");
 115       follow_object(obj);
 116     }
 117     // Process ObjArrays one at a time to avoid marking stack bloat.
 118     if (!_objarray_stack.is_empty()) {
 119       ObjArrayTask task = _objarray_stack.pop();
 120       follow_array_chunk(objArrayOop(task.obj()), task.index());
 121     }
 122   } while (!_marking_stack.is_empty() || !_objarray_stack.is_empty());
 123 }
 124 
 125 MarkSweep::FollowStackClosure MarkSweep::follow_stack_closure;
 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_reserved(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_raw()->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 void PreservedMark::adjust_pointer() {
 147   MarkSweep::adjust_pointer(&_obj);
 148 }
 149 
 150 void PreservedMark::restore() {
 151   _obj->set_mark_raw(_mark);
 152 }
 153 
 154 // We preserve the mark which should be replaced at the end and the location
 155 // that it will go.  Note that the object that this markOop belongs to isn't
 156 // currently at that address but it will be after phase4
 157 void MarkSweep::preserve_mark(oop obj, markOop mark) {
 158   // We try to store preserved marks in the to space of the new generation since
 159   // this is storage which should be available.  Most of the time this should be
 160   // sufficient space for the marks we need to preserve but if it isn't we fall
 161   // back to using Stacks to keep track of the overflow.
 162   if (_preserved_count < _preserved_count_max) {
 163     _preserved_marks[_preserved_count++].init(obj, mark);
 164   } else {
 165     _preserved_mark_stack.push(mark);
 166     _preserved_oop_stack.push(obj);
 167   }
 168 }
 169 
 170 void MarkSweep::set_ref_processor(ReferenceProcessor* rp) {
 171   _ref_processor = rp;
 172   mark_and_push_closure.set_ref_discoverer(_ref_processor);
 173 }
 174 
 175 AdjustPointerClosure MarkSweep::adjust_pointer_closure;
 176 
 177 void MarkSweep::adjust_marks() {


 187   StackIterator<oop, mtGC> iter(_preserved_oop_stack);
 188   while (!iter.is_empty()) {
 189     oop* p = iter.next_addr();
 190     adjust_pointer(p);
 191   }
 192 }
 193 
 194 void MarkSweep::restore_marks() {
 195   assert(_preserved_oop_stack.size() == _preserved_mark_stack.size(),
 196          "inconsistent preserved oop stacks");
 197   log_trace(gc)("Restoring " SIZE_FORMAT " marks", _preserved_count + _preserved_oop_stack.size());
 198 
 199   // restore the marks we saved earlier
 200   for (size_t i = 0; i < _preserved_count; i++) {
 201     _preserved_marks[i].restore();
 202   }
 203 
 204   // deal with the overflow
 205   while (!_preserved_oop_stack.is_empty()) {
 206     oop obj       = _preserved_oop_stack.pop();
 207     markOop mark  = _preserved_mark_stack.pop();
 208     obj->set_mark_raw(mark);
 209   }
 210 }
 211 
 212 MarkSweep::IsAliveClosure   MarkSweep::is_alive;
 213 
 214 bool MarkSweep::IsAliveClosure::do_object_b(oop p) { return p->is_gc_marked(); }
 215 
 216 MarkSweep::KeepAliveClosure MarkSweep::keep_alive;
 217 
 218 void MarkSweep::KeepAliveClosure::do_oop(oop* p)       { MarkSweep::KeepAliveClosure::do_oop_work(p); }
 219 void MarkSweep::KeepAliveClosure::do_oop(narrowOop* p) { MarkSweep::KeepAliveClosure::do_oop_work(p); }
 220 
 221 void MarkSweep::initialize() {
 222   MarkSweep::_gc_timer = new (ResourceObj::C_HEAP, mtGC) STWGCTimer();
 223   MarkSweep::_gc_tracer = new (ResourceObj::C_HEAP, mtGC) SerialOldTracer();
 224 }
< prev index next >