hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsOopClosures.hpp
changeset 25356 4a4a482298a6
parent 23539 6382fd0ea303
equal deleted inserted replaced
25355:29c97629997e 25356:4a4a482298a6
    24 
    24 
    25 #ifndef SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_CMSOOPCLOSURES_HPP
    25 #ifndef SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_CMSOOPCLOSURES_HPP
    26 #define SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_CMSOOPCLOSURES_HPP
    26 #define SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_CMSOOPCLOSURES_HPP
    27 
    27 
    28 #include "memory/genOopClosures.hpp"
    28 #include "memory/genOopClosures.hpp"
       
    29 #include "memory/iterator.hpp"
    29 
    30 
    30 /////////////////////////////////////////////////////////////////
    31 /////////////////////////////////////////////////////////////////
    31 // Closures used by ConcurrentMarkSweepGeneration's collector
    32 // Closures used by ConcurrentMarkSweepGeneration's collector
    32 /////////////////////////////////////////////////////////////////
    33 /////////////////////////////////////////////////////////////////
    33 class ConcurrentMarkSweepGeneration;
    34 class ConcurrentMarkSweepGeneration;
    46       oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);       \
    47       oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);       \
    47       do_oop(obj);                                        \
    48       do_oop(obj);                                        \
    48     }                                                     \
    49     }                                                     \
    49   }
    50   }
    50 
    51 
    51 // Applies the given oop closure to all oops in all klasses visited.
    52 // TODO: This duplication of the MetadataAwareOopClosure class is only needed
    52 class CMKlassClosure : public KlassClosure {
    53 //       because some CMS OopClosures derive from OopsInGenClosure. It would be
    53   friend class CMSOopClosure;
    54 //       good to get rid of them completely.
    54   friend class CMSOopsInGenClosure;
    55 class MetadataAwareOopsInGenClosure: public OopsInGenClosure {
    55 
    56   KlassToOopClosure _klass_closure;
    56   OopClosure* _oop_closure;
    57  public:
    57 
    58   MetadataAwareOopsInGenClosure() {
    58   // Used when _oop_closure couldn't be set in an initialization list.
       
    59   void initialize(OopClosure* oop_closure) {
       
    60     assert(_oop_closure == NULL, "Should only be called once");
       
    61     _oop_closure = oop_closure;
       
    62   }
       
    63  public:
       
    64   CMKlassClosure(OopClosure* oop_closure = NULL) : _oop_closure(oop_closure) { }
       
    65 
       
    66   void do_klass(Klass* k);
       
    67 };
       
    68 
       
    69 // The base class for all CMS marking closures.
       
    70 // It's used to proxy through the metadata to the oops defined in them.
       
    71 class CMSOopClosure: public ExtendedOopClosure {
       
    72   CMKlassClosure      _klass_closure;
       
    73  public:
       
    74   CMSOopClosure() : ExtendedOopClosure() {
       
    75     _klass_closure.initialize(this);
    59     _klass_closure.initialize(this);
    76   }
    60   }
    77   CMSOopClosure(ReferenceProcessor* rp) : ExtendedOopClosure(rp) {
       
    78     _klass_closure.initialize(this);
       
    79   }
       
    80 
    61 
    81   virtual bool do_metadata()    { return do_metadata_nv(); }
    62   virtual bool do_metadata()    { return do_metadata_nv(); }
    82   inline  bool do_metadata_nv() { return true; }
    63   inline  bool do_metadata_nv() { return true; }
    83 
    64 
    84   virtual void do_klass(Klass* k);
    65   virtual void do_klass(Klass* k);
    85   void do_klass_nv(Klass* k);
    66   void do_klass_nv(Klass* k);
    86 
    67 
    87   virtual void do_class_loader_data(ClassLoaderData* cld);
    68   virtual void do_class_loader_data(ClassLoaderData* cld);
    88 };
    69 };
    89 
    70 
    90 // TODO: This duplication of the CMSOopClosure class is only needed because
    71 class MarkRefsIntoClosure: public MetadataAwareOopsInGenClosure {
    91 //       some CMS OopClosures derive from OopsInGenClosure. It would be good
       
    92 //       to get rid of them completely.
       
    93 class CMSOopsInGenClosure: public OopsInGenClosure {
       
    94   CMKlassClosure _klass_closure;
       
    95  public:
       
    96   CMSOopsInGenClosure() {
       
    97     _klass_closure.initialize(this);
       
    98   }
       
    99 
       
   100   virtual bool do_metadata()    { return do_metadata_nv(); }
       
   101   inline  bool do_metadata_nv() { return true; }
       
   102 
       
   103   virtual void do_klass(Klass* k);
       
   104   void do_klass_nv(Klass* k);
       
   105 
       
   106   virtual void do_class_loader_data(ClassLoaderData* cld);
       
   107 };
       
   108 
       
   109 class MarkRefsIntoClosure: public CMSOopsInGenClosure {
       
   110  private:
    72  private:
   111   const MemRegion _span;
    73   const MemRegion _span;
   112   CMSBitMap*      _bitMap;
    74   CMSBitMap*      _bitMap;
   113  protected:
    75  protected:
   114   DO_OOP_WORK_DEFN
    76   DO_OOP_WORK_DEFN
   116   MarkRefsIntoClosure(MemRegion span, CMSBitMap* bitMap);
    78   MarkRefsIntoClosure(MemRegion span, CMSBitMap* bitMap);
   117   virtual void do_oop(oop* p);
    79   virtual void do_oop(oop* p);
   118   virtual void do_oop(narrowOop* p);
    80   virtual void do_oop(narrowOop* p);
   119 };
    81 };
   120 
    82 
   121 class Par_MarkRefsIntoClosure: public CMSOopsInGenClosure {
    83 class Par_MarkRefsIntoClosure: public MetadataAwareOopsInGenClosure {
   122  private:
    84  private:
   123   const MemRegion _span;
    85   const MemRegion _span;
   124   CMSBitMap*      _bitMap;
    86   CMSBitMap*      _bitMap;
   125  protected:
    87  protected:
   126   DO_OOP_WORK_DEFN
    88   DO_OOP_WORK_DEFN
   130   virtual void do_oop(narrowOop* p);
    92   virtual void do_oop(narrowOop* p);
   131 };
    93 };
   132 
    94 
   133 // A variant of the above used in certain kinds of CMS
    95 // A variant of the above used in certain kinds of CMS
   134 // marking verification.
    96 // marking verification.
   135 class MarkRefsIntoVerifyClosure: public CMSOopsInGenClosure {
    97 class MarkRefsIntoVerifyClosure: public MetadataAwareOopsInGenClosure {
   136  private:
    98  private:
   137   const MemRegion _span;
    99   const MemRegion _span;
   138   CMSBitMap*      _verification_bm;
   100   CMSBitMap*      _verification_bm;
   139   CMSBitMap*      _cms_bm;
   101   CMSBitMap*      _cms_bm;
   140  protected:
   102  protected:
   145   virtual void do_oop(oop* p);
   107   virtual void do_oop(oop* p);
   146   virtual void do_oop(narrowOop* p);
   108   virtual void do_oop(narrowOop* p);
   147 };
   109 };
   148 
   110 
   149 // The non-parallel version (the parallel version appears further below).
   111 // The non-parallel version (the parallel version appears further below).
   150 class PushAndMarkClosure: public CMSOopClosure {
   112 class PushAndMarkClosure: public MetadataAwareOopClosure {
   151  private:
   113  private:
   152   CMSCollector* _collector;
   114   CMSCollector* _collector;
   153   MemRegion     _span;
   115   MemRegion     _span;
   154   CMSBitMap*    _bit_map;
   116   CMSBitMap*    _bit_map;
   155   CMSBitMap*    _mod_union_table;
   117   CMSBitMap*    _mod_union_table;
   175 // reference processor are currently all shared. Access to
   137 // reference processor are currently all shared. Access to
   176 // these shared mutable structures must use appropriate
   138 // these shared mutable structures must use appropriate
   177 // synchronization (for instance, via CAS). The marking stack
   139 // synchronization (for instance, via CAS). The marking stack
   178 // used in the non-parallel case above is here replaced with
   140 // used in the non-parallel case above is here replaced with
   179 // an OopTaskQueue structure to allow efficient work stealing.
   141 // an OopTaskQueue structure to allow efficient work stealing.
   180 class Par_PushAndMarkClosure: public CMSOopClosure {
   142 class Par_PushAndMarkClosure: public MetadataAwareOopClosure {
   181  private:
   143  private:
   182   CMSCollector* _collector;
   144   CMSCollector* _collector;
   183   MemRegion     _span;
   145   MemRegion     _span;
   184   CMSBitMap*    _bit_map;
   146   CMSBitMap*    _bit_map;
   185   OopTaskQueue* _work_queue;
   147   OopTaskQueue* _work_queue;
   196   inline void do_oop_nv(oop* p)       { Par_PushAndMarkClosure::do_oop_work(p); }
   158   inline void do_oop_nv(oop* p)       { Par_PushAndMarkClosure::do_oop_work(p); }
   197   inline void do_oop_nv(narrowOop* p) { Par_PushAndMarkClosure::do_oop_work(p); }
   159   inline void do_oop_nv(narrowOop* p) { Par_PushAndMarkClosure::do_oop_work(p); }
   198 };
   160 };
   199 
   161 
   200 // The non-parallel version (the parallel version appears further below).
   162 // The non-parallel version (the parallel version appears further below).
   201 class MarkRefsIntoAndScanClosure: public CMSOopsInGenClosure {
   163 class MarkRefsIntoAndScanClosure: public MetadataAwareOopsInGenClosure {
   202  private:
   164  private:
   203   MemRegion          _span;
   165   MemRegion          _span;
   204   CMSBitMap*         _bit_map;
   166   CMSBitMap*         _bit_map;
   205   CMSMarkStack*      _mark_stack;
   167   CMSMarkStack*      _mark_stack;
   206   PushAndMarkClosure _pushAndMarkClosure;
   168   PushAndMarkClosure _pushAndMarkClosure;
   237 
   199 
   238 // In this, the parallel avatar of MarkRefsIntoAndScanClosure, the revisit
   200 // In this, the parallel avatar of MarkRefsIntoAndScanClosure, the revisit
   239 // stack and the bitMap are shared, so access needs to be suitably
   201 // stack and the bitMap are shared, so access needs to be suitably
   240 // synchronized. An OopTaskQueue structure, supporting efficient
   202 // synchronized. An OopTaskQueue structure, supporting efficient
   241 // work stealing, replaces a CMSMarkStack for storing grey objects.
   203 // work stealing, replaces a CMSMarkStack for storing grey objects.
   242 class Par_MarkRefsIntoAndScanClosure: public CMSOopsInGenClosure {
   204 class Par_MarkRefsIntoAndScanClosure: public MetadataAwareOopsInGenClosure {
   243  private:
   205  private:
   244   MemRegion              _span;
   206   MemRegion              _span;
   245   CMSBitMap*             _bit_map;
   207   CMSBitMap*             _bit_map;
   246   OopTaskQueue*          _work_queue;
   208   OopTaskQueue*          _work_queue;
   247   const uint             _low_water_mark;
   209   const uint             _low_water_mark;
   263 };
   225 };
   264 
   226 
   265 // This closure is used during the concurrent marking phase
   227 // This closure is used during the concurrent marking phase
   266 // following the first checkpoint. Its use is buried in
   228 // following the first checkpoint. Its use is buried in
   267 // the closure MarkFromRootsClosure.
   229 // the closure MarkFromRootsClosure.
   268 class PushOrMarkClosure: public CMSOopClosure {
   230 class PushOrMarkClosure: public MetadataAwareOopClosure {
   269  private:
   231  private:
   270   CMSCollector*   _collector;
   232   CMSCollector*   _collector;
   271   MemRegion       _span;
   233   MemRegion       _span;
   272   CMSBitMap*      _bitMap;
   234   CMSBitMap*      _bitMap;
   273   CMSMarkStack*   _markStack;
   235   CMSMarkStack*   _markStack;
   296 
   258 
   297 // A parallel (MT) version of the above.
   259 // A parallel (MT) version of the above.
   298 // This closure is used during the concurrent marking phase
   260 // This closure is used during the concurrent marking phase
   299 // following the first checkpoint. Its use is buried in
   261 // following the first checkpoint. Its use is buried in
   300 // the closure Par_MarkFromRootsClosure.
   262 // the closure Par_MarkFromRootsClosure.
   301 class Par_PushOrMarkClosure: public CMSOopClosure {
   263 class Par_PushOrMarkClosure: public MetadataAwareOopClosure {
   302  private:
   264  private:
   303   CMSCollector*    _collector;
   265   CMSCollector*    _collector;
   304   MemRegion        _whole_span;
   266   MemRegion        _whole_span;
   305   MemRegion        _span;        // local chunk
   267   MemRegion        _span;        // local chunk
   306   CMSBitMap*       _bit_map;
   268   CMSBitMap*       _bit_map;
   336 // given objects (transitively) as being reachable/live.
   298 // given objects (transitively) as being reachable/live.
   337 // This is currently used during the (weak) reference object
   299 // This is currently used during the (weak) reference object
   338 // processing phase of the CMS final checkpoint step, as
   300 // processing phase of the CMS final checkpoint step, as
   339 // well as during the concurrent precleaning of the discovered
   301 // well as during the concurrent precleaning of the discovered
   340 // reference lists.
   302 // reference lists.
   341 class CMSKeepAliveClosure: public CMSOopClosure {
   303 class CMSKeepAliveClosure: public MetadataAwareOopClosure {
   342  private:
   304  private:
   343   CMSCollector* _collector;
   305   CMSCollector* _collector;
   344   const MemRegion _span;
   306   const MemRegion _span;
   345   CMSMarkStack* _mark_stack;
   307   CMSMarkStack* _mark_stack;
   346   CMSBitMap*    _bit_map;
   308   CMSBitMap*    _bit_map;
   356   virtual void do_oop(narrowOop* p);
   318   virtual void do_oop(narrowOop* p);
   357   inline void do_oop_nv(oop* p)       { CMSKeepAliveClosure::do_oop_work(p); }
   319   inline void do_oop_nv(oop* p)       { CMSKeepAliveClosure::do_oop_work(p); }
   358   inline void do_oop_nv(narrowOop* p) { CMSKeepAliveClosure::do_oop_work(p); }
   320   inline void do_oop_nv(narrowOop* p) { CMSKeepAliveClosure::do_oop_work(p); }
   359 };
   321 };
   360 
   322 
   361 class CMSInnerParMarkAndPushClosure: public CMSOopClosure {
   323 class CMSInnerParMarkAndPushClosure: public MetadataAwareOopClosure {
   362  private:
   324  private:
   363   CMSCollector* _collector;
   325   CMSCollector* _collector;
   364   MemRegion     _span;
   326   MemRegion     _span;
   365   OopTaskQueue* _work_queue;
   327   OopTaskQueue* _work_queue;
   366   CMSBitMap*    _bit_map;
   328   CMSBitMap*    _bit_map;
   377 };
   339 };
   378 
   340 
   379 // A parallel (MT) version of the above, used when
   341 // A parallel (MT) version of the above, used when
   380 // reference processing is parallel; the only difference
   342 // reference processing is parallel; the only difference
   381 // is in the do_oop method.
   343 // is in the do_oop method.
   382 class CMSParKeepAliveClosure: public CMSOopClosure {
   344 class CMSParKeepAliveClosure: public MetadataAwareOopClosure {
   383  private:
   345  private:
   384   MemRegion     _span;
   346   MemRegion     _span;
   385   OopTaskQueue* _work_queue;
   347   OopTaskQueue* _work_queue;
   386   CMSBitMap*    _bit_map;
   348   CMSBitMap*    _bit_map;
   387   CMSInnerParMarkAndPushClosure
   349   CMSInnerParMarkAndPushClosure