< prev index next >

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

Print this page




  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_GC_SERIAL_MARKSWEEP_HPP
  26 #define SHARE_GC_SERIAL_MARKSWEEP_HPP
  27 
  28 #include "gc/shared/collectedHeap.hpp"
  29 #include "gc/shared/genOopClosures.hpp"
  30 #include "gc/shared/taskqueue.hpp"
  31 #include "memory/iterator.hpp"
  32 #include "oops/markWord.hpp"
  33 #include "oops/oop.hpp"
  34 #include "runtime/timer.hpp"
  35 #include "utilities/growableArray.hpp"
  36 #include "utilities/stack.hpp"
  37 
  38 class ReferenceProcessor;
  39 class DataLayout;
  40 class SerialOldTracer;
  41 class STWGCTimer;
  42 
  43 // MarkSweep takes care of global mark-compact garbage collection for a
  44 // GenCollectedHeap using a four-phase pointer forwarding algorithm.  All
  45 // generations are assumed to support marking; those that can also support
  46 // compaction.
  47 //
  48 // Class unloading will only occur when a full gc is invoked.
  49 
  50 // declared at end
  51 class PreservedMark;
  52 class MarkAndPushClosure;


  83 
  84   //
  85   // Friend decls
  86   //
  87   friend class AdjustPointerClosure;
  88   friend class KeepAliveClosure;
  89   friend class VM_MarkSweep;
  90 
  91   //
  92   // Vars
  93   //
  94  protected:
  95   // Total invocations of a MarkSweep collection
  96   static uint _total_invocations;
  97 
  98   // Traversal stacks used during phase1
  99   static Stack<oop, mtGC>                      _marking_stack;
 100   static Stack<ObjArrayTask, mtGC>             _objarray_stack;
 101 
 102   // Space for storing/restoring mark word
 103   static Stack<markWord, mtGC>                 _preserved_mark_stack;
 104   static Stack<oop, mtGC>                      _preserved_oop_stack;
 105   static size_t                          _preserved_count;
 106   static size_t                          _preserved_count_max;
 107   static PreservedMark*                  _preserved_marks;
 108 
 109   // Reference processing (used in ...follow_contents)
 110   static ReferenceProcessor*             _ref_processor;
 111 
 112   static STWGCTimer*                     _gc_timer;
 113   static SerialOldTracer*                _gc_tracer;
 114 
 115   // Non public closures
 116   static KeepAliveClosure keep_alive;
 117 
 118  public:
 119   static void initialize();
 120 
 121   // Public closures
 122   static IsAliveClosure       is_alive;
 123   static FollowRootClosure    follow_root_closure;
 124   static MarkAndPushClosure   mark_and_push_closure;
 125   static FollowStackClosure   follow_stack_closure;
 126   static CLDToOopClosure      follow_cld_closure;
 127   static AdjustPointerClosure adjust_pointer_closure;
 128   static CLDToOopClosure      adjust_cld_closure;
 129 
 130   // Accessors
 131   static uint total_invocations() { return _total_invocations; }
 132 
 133   // Reference Processing
 134   static ReferenceProcessor* const ref_processor() { return _ref_processor; }
 135   static void set_ref_processor(ReferenceProcessor* rp);
 136 
 137   static STWGCTimer* gc_timer() { return _gc_timer; }
 138   static SerialOldTracer* gc_tracer() { return _gc_tracer; }
 139 
 140   static void preserve_mark(oop p, markWord mark);
 141                                 // Save the mark word so it can be restored later
 142   static void adjust_marks();   // Adjust the pointers in the preserved marks table
 143   static void restore_marks();  // Restore the marks that we saved in preserve_mark
 144 
 145   static int adjust_pointers(oop obj);
 146 
 147   static void follow_stack();   // Empty marking stack.
 148 
 149   static void follow_klass(Klass* klass);
 150 
 151   static void follow_cld(ClassLoaderData* cld);
 152 
 153   template <class T> static inline void adjust_pointer(T* p);
 154 
 155   // Check mark and maybe push on marking stack
 156   template <class T> static void mark_and_push(T* p);
 157 
 158  private:
 159   // Call backs for marking
 160   static void mark_object(oop obj);


 182 
 183   void set_ref_discoverer(ReferenceDiscoverer* rd) {
 184     set_ref_discoverer_internal(rd);
 185   }
 186 };
 187 
 188 class AdjustPointerClosure: public BasicOopsInGenClosure {
 189  public:
 190   template <typename T> void do_oop_work(T* p);
 191   virtual void do_oop(oop* p);
 192   virtual void do_oop(narrowOop* p);
 193   virtual ReferenceIterationMode reference_iteration_mode() { return DO_FIELDS; }
 194 
 195   // This closure provides its own oop verification code.
 196   debug_only(virtual bool should_verify_oops() { return false; })
 197 };
 198 
 199 class PreservedMark {
 200 private:
 201   oop _obj;
 202   markWord _mark;
 203 
 204 public:
 205   void init(oop obj, markWord mark) {
 206     _obj = obj;
 207     _mark = mark;
 208   }
 209 
 210   void adjust_pointer();
 211   void restore();
 212 };
 213 
 214 #endif // SHARE_GC_SERIAL_MARKSWEEP_HPP


  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_GC_SERIAL_MARKSWEEP_HPP
  26 #define SHARE_GC_SERIAL_MARKSWEEP_HPP
  27 
  28 #include "gc/shared/collectedHeap.hpp"
  29 #include "gc/shared/genOopClosures.hpp"
  30 #include "gc/shared/taskqueue.hpp"
  31 #include "memory/iterator.hpp"
  32 #include "oops/markOop.hpp"
  33 #include "oops/oop.hpp"
  34 #include "runtime/timer.hpp"
  35 #include "utilities/growableArray.hpp"
  36 #include "utilities/stack.hpp"
  37 
  38 class ReferenceProcessor;
  39 class DataLayout;
  40 class SerialOldTracer;
  41 class STWGCTimer;
  42 
  43 // MarkSweep takes care of global mark-compact garbage collection for a
  44 // GenCollectedHeap using a four-phase pointer forwarding algorithm.  All
  45 // generations are assumed to support marking; those that can also support
  46 // compaction.
  47 //
  48 // Class unloading will only occur when a full gc is invoked.
  49 
  50 // declared at end
  51 class PreservedMark;
  52 class MarkAndPushClosure;


  83 
  84   //
  85   // Friend decls
  86   //
  87   friend class AdjustPointerClosure;
  88   friend class KeepAliveClosure;
  89   friend class VM_MarkSweep;
  90 
  91   //
  92   // Vars
  93   //
  94  protected:
  95   // Total invocations of a MarkSweep collection
  96   static uint _total_invocations;
  97 
  98   // Traversal stacks used during phase1
  99   static Stack<oop, mtGC>                      _marking_stack;
 100   static Stack<ObjArrayTask, mtGC>             _objarray_stack;
 101 
 102   // Space for storing/restoring mark word
 103   static Stack<markOop, mtGC>                  _preserved_mark_stack;
 104   static Stack<oop, mtGC>                      _preserved_oop_stack;
 105   static size_t                          _preserved_count;
 106   static size_t                          _preserved_count_max;
 107   static PreservedMark*                  _preserved_marks;
 108 
 109   // Reference processing (used in ...follow_contents)
 110   static ReferenceProcessor*             _ref_processor;
 111 
 112   static STWGCTimer*                     _gc_timer;
 113   static SerialOldTracer*                _gc_tracer;
 114 
 115   // Non public closures
 116   static KeepAliveClosure keep_alive;
 117 
 118  public:
 119   static void initialize();
 120 
 121   // Public closures
 122   static IsAliveClosure       is_alive;
 123   static FollowRootClosure    follow_root_closure;
 124   static MarkAndPushClosure   mark_and_push_closure;
 125   static FollowStackClosure   follow_stack_closure;
 126   static CLDToOopClosure      follow_cld_closure;
 127   static AdjustPointerClosure adjust_pointer_closure;
 128   static CLDToOopClosure      adjust_cld_closure;
 129 
 130   // Accessors
 131   static uint total_invocations() { return _total_invocations; }
 132 
 133   // Reference Processing
 134   static ReferenceProcessor* const ref_processor() { return _ref_processor; }
 135   static void set_ref_processor(ReferenceProcessor* rp);
 136 
 137   static STWGCTimer* gc_timer() { return _gc_timer; }
 138   static SerialOldTracer* gc_tracer() { return _gc_tracer; }
 139 
 140   static void preserve_mark(oop p, markOop mark);
 141                                 // Save the mark word so it can be restored later
 142   static void adjust_marks();   // Adjust the pointers in the preserved marks table
 143   static void restore_marks();  // Restore the marks that we saved in preserve_mark
 144 
 145   static int adjust_pointers(oop obj);
 146 
 147   static void follow_stack();   // Empty marking stack.
 148 
 149   static void follow_klass(Klass* klass);
 150 
 151   static void follow_cld(ClassLoaderData* cld);
 152 
 153   template <class T> static inline void adjust_pointer(T* p);
 154 
 155   // Check mark and maybe push on marking stack
 156   template <class T> static void mark_and_push(T* p);
 157 
 158  private:
 159   // Call backs for marking
 160   static void mark_object(oop obj);


 182 
 183   void set_ref_discoverer(ReferenceDiscoverer* rd) {
 184     set_ref_discoverer_internal(rd);
 185   }
 186 };
 187 
 188 class AdjustPointerClosure: public BasicOopsInGenClosure {
 189  public:
 190   template <typename T> void do_oop_work(T* p);
 191   virtual void do_oop(oop* p);
 192   virtual void do_oop(narrowOop* p);
 193   virtual ReferenceIterationMode reference_iteration_mode() { return DO_FIELDS; }
 194 
 195   // This closure provides its own oop verification code.
 196   debug_only(virtual bool should_verify_oops() { return false; })
 197 };
 198 
 199 class PreservedMark {
 200 private:
 201   oop _obj;
 202   markOop _mark;
 203 
 204 public:
 205   void init(oop obj, markOop mark) {
 206     _obj = obj;
 207     _mark = mark;
 208   }
 209 
 210   void adjust_pointer();
 211   void restore();
 212 };
 213 
 214 #endif // SHARE_GC_SERIAL_MARKSWEEP_HPP
< prev index next >