< prev index next >

src/hotspot/share/memory/iterator.hpp

Print this page




  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_VM_MEMORY_ITERATOR_HPP
  26 #define SHARE_VM_MEMORY_ITERATOR_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "memory/memRegion.hpp"
  30 #include "oops/oopsHierarchy.hpp"
  31 
  32 class CodeBlob;
  33 class nmethod;
  34 class ReferenceProcessor;
  35 class DataLayout;
  36 class KlassClosure;
  37 class ClassLoaderData;
  38 class Symbol;
  39 
  40 // The following classes are C++ `closures` for iterating over objects, roots and spaces
  41 
  42 class Closure : public StackObj { };
  43 
  44 // OopClosure is used for iterating through references to Java objects.
  45 class OopClosure : public Closure {
  46  public:
  47   virtual void do_oop(oop* o) = 0;
  48   virtual void do_oop(narrowOop* o) = 0;
  49 };
  50 
  51 class DoNothingClosure : public OopClosure {
  52  public:
  53   virtual void do_oop(oop* p)       {}
  54   virtual void do_oop(narrowOop* p) {}
  55 };
  56 extern DoNothingClosure do_nothing_cl;
  57 
  58 // ExtendedOopClosure adds extra code to be run during oop iterations.
  59 // This is needed by the GC and is extracted to a separate type to not
  60 // pollute the OopClosure interface.
  61 class ExtendedOopClosure : public OopClosure {
  62  private:
  63   ReferenceProcessor* _ref_processor;
  64 
  65  protected:
  66   ExtendedOopClosure(ReferenceProcessor* rp) : _ref_processor(rp) { }
  67   ExtendedOopClosure() : _ref_processor(NULL) { }
  68   ~ExtendedOopClosure() { }
  69 
  70   void set_ref_processor_internal(ReferenceProcessor* rp) { _ref_processor = rp; }
  71 
  72  public:
  73   ReferenceProcessor* ref_processor() const { return _ref_processor; }
  74 
  75   // Iteration of InstanceRefKlasses differ depending on the closure,
  76   // the below enum describes the different alternatives.
  77   enum ReferenceIterationMode {
  78     DO_DISCOVERY,                // Apply closure and discover references
  79     DO_DISCOVERED_AND_DISCOVERY, // Apply closure to discovered field and do discovery
  80     DO_FIELDS                    // Apply closure to all fields
  81   };
  82 
  83   // The default iteration mode is to do discovery.
  84   virtual ReferenceIterationMode reference_iteration_mode() { return DO_DISCOVERY; }
  85 
  86   // If the do_metadata functions return "true",
  87   // we invoke the following when running oop_iterate():
  88   //
  89   // 1) do_klass on the header klass pointer.
  90   // 2) do_klass on the klass pointer in the mirrors.
  91   // 3) do_cld   on the class loader data in class loaders.
  92   //
  93   // The virtual (without suffix) and the non-virtual (with _nv suffix) need


 148 
 149 class CLDToOopClosure : public CLDClosure {
 150   OopClosure*       _oop_closure;
 151   bool              _must_claim_cld;
 152 
 153  public:
 154   CLDToOopClosure(OopClosure* oop_closure, bool must_claim_cld = true) :
 155       _oop_closure(oop_closure),
 156       _must_claim_cld(must_claim_cld) {}
 157 
 158   void do_cld(ClassLoaderData* cld);
 159 };
 160 
 161 // The base class for all concurrent marking closures,
 162 // that participates in class unloading.
 163 // It's used to proxy through the metadata to the oops defined in them.
 164 class MetadataAwareOopClosure: public ExtendedOopClosure {
 165 
 166  public:
 167   MetadataAwareOopClosure() : ExtendedOopClosure() { }
 168   MetadataAwareOopClosure(ReferenceProcessor* rp) : ExtendedOopClosure(rp) { }
 169 
 170   bool do_metadata_nv()      { return true; }
 171   virtual bool do_metadata() { return do_metadata_nv(); }
 172 
 173   void do_klass_nv(Klass* k);
 174   virtual void do_klass(Klass* k) { do_klass_nv(k); }
 175 
 176   void do_cld_nv(ClassLoaderData* cld);
 177   virtual void do_cld(ClassLoaderData* cld) { do_cld_nv(cld); }
 178 };
 179 
 180 // ObjectClosure is used for iterating through an object space
 181 
 182 class ObjectClosure : public Closure {
 183  public:
 184   // Called for each object.
 185   virtual void do_object(oop obj) = 0;
 186 };
 187 
 188 




  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_VM_MEMORY_ITERATOR_HPP
  26 #define SHARE_VM_MEMORY_ITERATOR_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "memory/memRegion.hpp"
  30 #include "oops/oopsHierarchy.hpp"
  31 
  32 class CodeBlob;
  33 class nmethod;
  34 class ReferenceDiscoverer;
  35 class DataLayout;
  36 class KlassClosure;
  37 class ClassLoaderData;
  38 class Symbol;
  39 
  40 // The following classes are C++ `closures` for iterating over objects, roots and spaces
  41 
  42 class Closure : public StackObj { };
  43 
  44 // OopClosure is used for iterating through references to Java objects.
  45 class OopClosure : public Closure {
  46  public:
  47   virtual void do_oop(oop* o) = 0;
  48   virtual void do_oop(narrowOop* o) = 0;
  49 };
  50 
  51 class DoNothingClosure : public OopClosure {
  52  public:
  53   virtual void do_oop(oop* p)       {}
  54   virtual void do_oop(narrowOop* p) {}
  55 };
  56 extern DoNothingClosure do_nothing_cl;
  57 
  58 // ExtendedOopClosure adds extra code to be run during oop iterations.
  59 // This is needed by the GC and is extracted to a separate type to not
  60 // pollute the OopClosure interface.
  61 class ExtendedOopClosure : public OopClosure {
  62  private:
  63   ReferenceDiscoverer* _ref_discoverer;
  64 
  65  protected:
  66   ExtendedOopClosure(ReferenceDiscoverer* rd) : _ref_discoverer(rd) { }
  67   ExtendedOopClosure() : _ref_discoverer(NULL) { }
  68   ~ExtendedOopClosure() { }
  69 
  70   void set_ref_discoverer_internal(ReferenceDiscoverer* rd) { _ref_discoverer = rd; }
  71 
  72  public:
  73   ReferenceDiscoverer* ref_discoverer() const { return _ref_discoverer; }
  74 
  75   // Iteration of InstanceRefKlasses differ depending on the closure,
  76   // the below enum describes the different alternatives.
  77   enum ReferenceIterationMode {
  78     DO_DISCOVERY,                // Apply closure and discover references
  79     DO_DISCOVERED_AND_DISCOVERY, // Apply closure to discovered field and do discovery
  80     DO_FIELDS                    // Apply closure to all fields
  81   };
  82 
  83   // The default iteration mode is to do discovery.
  84   virtual ReferenceIterationMode reference_iteration_mode() { return DO_DISCOVERY; }
  85 
  86   // If the do_metadata functions return "true",
  87   // we invoke the following when running oop_iterate():
  88   //
  89   // 1) do_klass on the header klass pointer.
  90   // 2) do_klass on the klass pointer in the mirrors.
  91   // 3) do_cld   on the class loader data in class loaders.
  92   //
  93   // The virtual (without suffix) and the non-virtual (with _nv suffix) need


 148 
 149 class CLDToOopClosure : public CLDClosure {
 150   OopClosure*       _oop_closure;
 151   bool              _must_claim_cld;
 152 
 153  public:
 154   CLDToOopClosure(OopClosure* oop_closure, bool must_claim_cld = true) :
 155       _oop_closure(oop_closure),
 156       _must_claim_cld(must_claim_cld) {}
 157 
 158   void do_cld(ClassLoaderData* cld);
 159 };
 160 
 161 // The base class for all concurrent marking closures,
 162 // that participates in class unloading.
 163 // It's used to proxy through the metadata to the oops defined in them.
 164 class MetadataAwareOopClosure: public ExtendedOopClosure {
 165 
 166  public:
 167   MetadataAwareOopClosure() : ExtendedOopClosure() { }
 168   MetadataAwareOopClosure(ReferenceDiscoverer* rd) : ExtendedOopClosure(rd) { }
 169 
 170   bool do_metadata_nv()      { return true; }
 171   virtual bool do_metadata() { return do_metadata_nv(); }
 172 
 173   void do_klass_nv(Klass* k);
 174   virtual void do_klass(Klass* k) { do_klass_nv(k); }
 175 
 176   void do_cld_nv(ClassLoaderData* cld);
 177   virtual void do_cld(ClassLoaderData* cld) { do_cld_nv(cld); }
 178 };
 179 
 180 // ObjectClosure is used for iterating through an object space
 181 
 182 class ObjectClosure : public Closure {
 183  public:
 184   // Called for each object.
 185   virtual void do_object(oop obj) = 0;
 186 };
 187 
 188 


< prev index next >