< prev index next >

src/hotspot/share/classfile/classLoaderData.hpp

Print this page




  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_VM_CLASSFILE_CLASSLOADERDATA_HPP
  26 #define SHARE_VM_CLASSFILE_CLASSLOADERDATA_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "memory/memRegion.hpp"
  30 #include "memory/metaspace.hpp"
  31 #include "memory/metaspaceCounters.hpp"
  32 #include "oops/oopHandle.hpp"

  33 #include "runtime/mutex.hpp"
  34 #include "trace/traceMacros.hpp"
  35 #include "utilities/growableArray.hpp"
  36 #include "utilities/macros.hpp"
  37 #if INCLUDE_TRACE
  38 #include "utilities/ticks.hpp"
  39 #endif
  40 
  41 //
  42 // A class loader represents a linkset. Conceptually, a linkset identifies
  43 // the complete transitive closure of resolved links that a dynamic linker can
  44 // produce.
  45 //
  46 // A ClassLoaderData also encapsulates the allocation space, called a metaspace,
  47 // used by the dynamic linker to allocate the runtime representation of all
  48 // the types it defines.
  49 //
  50 // ClassLoaderData are stored in the runtime representation of classes,
  51 // and provides iterators for root tracing and other GC operations.
  52 


  96   // cld do
  97   static void cld_do(CLDClosure* cl);
  98   static void cld_unloading_do(CLDClosure* cl);
  99   static void roots_cld_do(CLDClosure* strong, CLDClosure* weak);
 100   static void keep_alive_cld_do(CLDClosure* cl);
 101   static void always_strong_cld_do(CLDClosure* cl);
 102   // klass do
 103   // Walking classes through the ClassLoaderDataGraph include array classes.  It also includes
 104   // classes that are allocated but not loaded, classes that have errors, and scratch classes
 105   // for redefinition.  These classes are removed during the next class unloading.
 106   // Walking the ClassLoaderDataGraph also includes anonymous classes.
 107   static void classes_do(KlassClosure* klass_closure);
 108   static void classes_do(void f(Klass* const));
 109   static void methods_do(void f(Method*));
 110   static void modules_do(void f(ModuleEntry*));
 111   static void modules_unloading_do(void f(ModuleEntry*));
 112   static void packages_do(void f(PackageEntry*));
 113   static void packages_unloading_do(void f(PackageEntry*));
 114   static void loaded_classes_do(KlassClosure* klass_closure);
 115   static void classes_unloading_do(void f(Klass* const));
 116   static bool do_unloading(BoolObjectClosure* is_alive, bool clean_previous_versions);
 117 
 118   // dictionary do
 119   // Iterate over all klasses in dictionary, but
 120   // just the classes from defining class loaders.
 121   static void dictionary_classes_do(void f(InstanceKlass*));
 122   // Added for initialize_itable_for_klass to handle exceptions.
 123   static void dictionary_classes_do(void f(InstanceKlass*, TRAPS), TRAPS);
 124 
 125   // Iterate all classes and their class loaders, including initiating class loaders.
 126   static void dictionary_all_entries_do(void f(InstanceKlass*, ClassLoaderData*));
 127 
 128   // VM_CounterDecay iteration support
 129   static InstanceKlass* try_get_next_class();
 130 
 131   static void verify_dictionary();
 132   static void print_dictionary(outputStream* st);
 133   static void print_dictionary_statistics(outputStream* st);
 134 
 135   // CMS support.
 136   static void remember_new_clds(bool remember) { _saved_head = (remember ? _head : NULL); }


 202     // Only one thread at a time can add, guarded by ClassLoaderData::metaspace_lock().
 203     // However, multiple threads can execute oops_do concurrently with add.
 204     oop* add(oop o);
 205     bool contains(oop p);
 206     NOT_PRODUCT(bool owner_of(oop* p);)
 207     void oops_do(OopClosure* f);
 208 
 209     int count() const;
 210   };
 211 
 212   friend class ClassLoaderDataGraph;
 213   friend class ClassLoaderDataGraphKlassIteratorAtomic;
 214   friend class ClassLoaderDataGraphKlassIteratorStatic;
 215   friend class ClassLoaderDataGraphMetaspaceIterator;
 216   friend class InstanceKlass;
 217   friend class MetaDataFactory;
 218   friend class Method;
 219 
 220   static ClassLoaderData * _the_null_class_loader_data;
 221 

 222   oop _class_loader;          // oop used to uniquely identify a class loader
 223                               // class loader or a canonical class path
 224 
 225   ClassLoaderMetaspace * volatile _metaspace;  // Meta-space where meta-data defined by the
 226                                     // classes in the class loader are allocated.
 227   Mutex* _metaspace_lock;  // Locks the metaspace for allocations and setup.
 228   bool _unloading;         // true if this class loader goes away
 229   bool _is_anonymous;      // if this CLD is for an anonymous class
 230 
 231   // Remembered sets support for the oops in the class loader data.
 232   bool _modified_oops;             // Card Table Equivalent (YC/CMS support)
 233   bool _accumulated_modified_oops; // Mod Union Equivalent (CMS support)
 234 
 235   s2 _keep_alive;          // if this CLD is kept alive without a keep_alive_object().
 236                            // Used for anonymous classes and the boot class
 237                            // loader. _keep_alive does not need to be volatile or
 238                            // atomic since there is one unique CLD per anonymous class.
 239 
 240   volatile int _claimed;   // true if claimed, for example during GC traces.
 241                            // To avoid applying oop closure more than once.


 291   void loaded_classes_do(KlassClosure* klass_closure);
 292   void classes_do(void f(InstanceKlass*));
 293   void methods_do(void f(Method*));
 294   void modules_do(void f(ModuleEntry*));
 295   void packages_do(void f(PackageEntry*));
 296 
 297   // Deallocate free list during class unloading.
 298   void free_deallocate_list();      // for the classes that are not unloaded
 299   void unload_deallocate_list();    // for the classes that are unloaded
 300 
 301   // Allocate out of this class loader data
 302   MetaWord* allocate(size_t size);
 303 
 304   Dictionary* create_dictionary();
 305  public:
 306   // GC interface.
 307   void clear_claimed() { _claimed = 0; }
 308   bool claimed() const { return _claimed == 1; }
 309   bool claim();
 310 
 311   bool is_alive(BoolObjectClosure* is_alive_closure) const;
 312 
 313   // Accessors
 314   ClassLoaderMetaspace* metaspace_or_null() const { return _metaspace; }
 315 
 316   static ClassLoaderData* the_null_class_loader_data() {
 317     return _the_null_class_loader_data;
 318   }
 319 
 320   Mutex* metaspace_lock() const { return _metaspace_lock; }
 321 
 322   bool is_anonymous() const { return _is_anonymous; }
 323 
 324   static void init_null_class_loader_data();
 325 
 326   bool is_the_null_class_loader_data() const {
 327     return this == _the_null_class_loader_data;
 328   }
 329 
 330   // Returns true if this class loader data is for the system class loader.
 331   // (Note that the class loader data may be anonymous.)


 346 
 347   // The Metaspace is created lazily so may be NULL.  This
 348   // method will allocate a Metaspace if needed.
 349   ClassLoaderMetaspace* metaspace_non_null();
 350 
 351   oop class_loader() const      { return _class_loader; }
 352 
 353   // The object the GC is using to keep this ClassLoaderData alive.
 354   oop keep_alive_object() const;
 355 
 356   // Returns true if this class loader data is for a loader going away.
 357   bool is_unloading() const     {
 358     assert(!(is_the_null_class_loader_data() && _unloading), "The null class loader can never be unloaded");
 359     return _unloading;
 360   }
 361 
 362   // Used to refcount an anonymous class's CLD in order to
 363   // indicate their aliveness without a keep_alive_object().
 364   void inc_keep_alive();
 365   void dec_keep_alive();


 366 
 367   inline unsigned int identity_hash() const { return (unsigned int)(((intptr_t)this) >> 3); }
 368 
 369   void oops_do(OopClosure* f, bool must_claim, bool clear_modified_oops = false);
 370 
 371   void classes_do(KlassClosure* klass_closure);
 372   Klass* klasses() { return _klasses; }
 373 
 374   JNIMethodBlock* jmethod_ids() const              { return _jmethod_ids; }
 375   void set_jmethod_ids(JNIMethodBlock* new_block)  { _jmethod_ids = new_block; }
 376 
 377   void print()                                     { print_on(tty); }
 378   void print_on(outputStream* out) const PRODUCT_RETURN;
 379   void print_value()                               { print_value_on(tty); }
 380   void print_value_on(outputStream* out) const;
 381   void verify();
 382   const char* loader_name() const;
 383 
 384   OopHandle add_handle(Handle h);
 385   void remove_handle(OopHandle h);




  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_VM_CLASSFILE_CLASSLOADERDATA_HPP
  26 #define SHARE_VM_CLASSFILE_CLASSLOADERDATA_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "memory/memRegion.hpp"
  30 #include "memory/metaspace.hpp"
  31 #include "memory/metaspaceCounters.hpp"
  32 #include "oops/oopHandle.hpp"
  33 #include "oops/weakHandle.hpp"
  34 #include "runtime/mutex.hpp"
  35 #include "trace/traceMacros.hpp"
  36 #include "utilities/growableArray.hpp"
  37 #include "utilities/macros.hpp"
  38 #if INCLUDE_TRACE
  39 #include "utilities/ticks.hpp"
  40 #endif
  41 
  42 //
  43 // A class loader represents a linkset. Conceptually, a linkset identifies
  44 // the complete transitive closure of resolved links that a dynamic linker can
  45 // produce.
  46 //
  47 // A ClassLoaderData also encapsulates the allocation space, called a metaspace,
  48 // used by the dynamic linker to allocate the runtime representation of all
  49 // the types it defines.
  50 //
  51 // ClassLoaderData are stored in the runtime representation of classes,
  52 // and provides iterators for root tracing and other GC operations.
  53 


  97   // cld do
  98   static void cld_do(CLDClosure* cl);
  99   static void cld_unloading_do(CLDClosure* cl);
 100   static void roots_cld_do(CLDClosure* strong, CLDClosure* weak);
 101   static void keep_alive_cld_do(CLDClosure* cl);
 102   static void always_strong_cld_do(CLDClosure* cl);
 103   // klass do
 104   // Walking classes through the ClassLoaderDataGraph include array classes.  It also includes
 105   // classes that are allocated but not loaded, classes that have errors, and scratch classes
 106   // for redefinition.  These classes are removed during the next class unloading.
 107   // Walking the ClassLoaderDataGraph also includes anonymous classes.
 108   static void classes_do(KlassClosure* klass_closure);
 109   static void classes_do(void f(Klass* const));
 110   static void methods_do(void f(Method*));
 111   static void modules_do(void f(ModuleEntry*));
 112   static void modules_unloading_do(void f(ModuleEntry*));
 113   static void packages_do(void f(PackageEntry*));
 114   static void packages_unloading_do(void f(PackageEntry*));
 115   static void loaded_classes_do(KlassClosure* klass_closure);
 116   static void classes_unloading_do(void f(Klass* const));
 117   static bool do_unloading(BoolObjectClosure* is_alive_closure, bool clean_previous_versions);
 118 
 119   // dictionary do
 120   // Iterate over all klasses in dictionary, but
 121   // just the classes from defining class loaders.
 122   static void dictionary_classes_do(void f(InstanceKlass*));
 123   // Added for initialize_itable_for_klass to handle exceptions.
 124   static void dictionary_classes_do(void f(InstanceKlass*, TRAPS), TRAPS);
 125 
 126   // Iterate all classes and their class loaders, including initiating class loaders.
 127   static void dictionary_all_entries_do(void f(InstanceKlass*, ClassLoaderData*));
 128 
 129   // VM_CounterDecay iteration support
 130   static InstanceKlass* try_get_next_class();
 131 
 132   static void verify_dictionary();
 133   static void print_dictionary(outputStream* st);
 134   static void print_dictionary_statistics(outputStream* st);
 135 
 136   // CMS support.
 137   static void remember_new_clds(bool remember) { _saved_head = (remember ? _head : NULL); }


 203     // Only one thread at a time can add, guarded by ClassLoaderData::metaspace_lock().
 204     // However, multiple threads can execute oops_do concurrently with add.
 205     oop* add(oop o);
 206     bool contains(oop p);
 207     NOT_PRODUCT(bool owner_of(oop* p);)
 208     void oops_do(OopClosure* f);
 209 
 210     int count() const;
 211   };
 212 
 213   friend class ClassLoaderDataGraph;
 214   friend class ClassLoaderDataGraphKlassIteratorAtomic;
 215   friend class ClassLoaderDataGraphKlassIteratorStatic;
 216   friend class ClassLoaderDataGraphMetaspaceIterator;
 217   friend class InstanceKlass;
 218   friend class MetaDataFactory;
 219   friend class Method;
 220 
 221   static ClassLoaderData * _the_null_class_loader_data;
 222 
 223   WeakHandle _holder;         // The oop that determines lifetime of this class loader
 224   oop _class_loader;          // oop used to uniquely identify a class loader
 225                               // class loader or a canonical class path
 226 
 227   ClassLoaderMetaspace * volatile _metaspace;  // Meta-space where meta-data defined by the
 228                                     // classes in the class loader are allocated.
 229   Mutex* _metaspace_lock;  // Locks the metaspace for allocations and setup.
 230   bool _unloading;         // true if this class loader goes away
 231   bool _is_anonymous;      // if this CLD is for an anonymous class
 232 
 233   // Remembered sets support for the oops in the class loader data.
 234   bool _modified_oops;             // Card Table Equivalent (YC/CMS support)
 235   bool _accumulated_modified_oops; // Mod Union Equivalent (CMS support)
 236 
 237   s2 _keep_alive;          // if this CLD is kept alive without a keep_alive_object().
 238                            // Used for anonymous classes and the boot class
 239                            // loader. _keep_alive does not need to be volatile or
 240                            // atomic since there is one unique CLD per anonymous class.
 241 
 242   volatile int _claimed;   // true if claimed, for example during GC traces.
 243                            // To avoid applying oop closure more than once.


 293   void loaded_classes_do(KlassClosure* klass_closure);
 294   void classes_do(void f(InstanceKlass*));
 295   void methods_do(void f(Method*));
 296   void modules_do(void f(ModuleEntry*));
 297   void packages_do(void f(PackageEntry*));
 298 
 299   // Deallocate free list during class unloading.
 300   void free_deallocate_list();      // for the classes that are not unloaded
 301   void unload_deallocate_list();    // for the classes that are unloaded
 302 
 303   // Allocate out of this class loader data
 304   MetaWord* allocate(size_t size);
 305 
 306   Dictionary* create_dictionary();
 307  public:
 308   // GC interface.
 309   void clear_claimed() { _claimed = 0; }
 310   bool claimed() const { return _claimed == 1; }
 311   bool claim();
 312 
 313   bool is_alive() const;
 314 
 315   // Accessors
 316   ClassLoaderMetaspace* metaspace_or_null() const { return _metaspace; }
 317 
 318   static ClassLoaderData* the_null_class_loader_data() {
 319     return _the_null_class_loader_data;
 320   }
 321 
 322   Mutex* metaspace_lock() const { return _metaspace_lock; }
 323 
 324   bool is_anonymous() const { return _is_anonymous; }
 325 
 326   static void init_null_class_loader_data();
 327 
 328   bool is_the_null_class_loader_data() const {
 329     return this == _the_null_class_loader_data;
 330   }
 331 
 332   // Returns true if this class loader data is for the system class loader.
 333   // (Note that the class loader data may be anonymous.)


 348 
 349   // The Metaspace is created lazily so may be NULL.  This
 350   // method will allocate a Metaspace if needed.
 351   ClassLoaderMetaspace* metaspace_non_null();
 352 
 353   oop class_loader() const      { return _class_loader; }
 354 
 355   // The object the GC is using to keep this ClassLoaderData alive.
 356   oop keep_alive_object() const;
 357 
 358   // Returns true if this class loader data is for a loader going away.
 359   bool is_unloading() const     {
 360     assert(!(is_the_null_class_loader_data() && _unloading), "The null class loader can never be unloaded");
 361     return _unloading;
 362   }
 363 
 364   // Used to refcount an anonymous class's CLD in order to
 365   // indicate their aliveness without a keep_alive_object().
 366   void inc_keep_alive();
 367   void dec_keep_alive();
 368 
 369   void update_holder(Handle holder);
 370 
 371   inline unsigned int identity_hash() const { return (unsigned int)(((intptr_t)this) >> 3); }
 372 
 373   void oops_do(OopClosure* f, bool must_claim, bool clear_modified_oops = false);
 374 
 375   void classes_do(KlassClosure* klass_closure);
 376   Klass* klasses() { return _klasses; }
 377 
 378   JNIMethodBlock* jmethod_ids() const              { return _jmethod_ids; }
 379   void set_jmethod_ids(JNIMethodBlock* new_block)  { _jmethod_ids = new_block; }
 380 
 381   void print()                                     { print_on(tty); }
 382   void print_on(outputStream* out) const PRODUCT_RETURN;
 383   void print_value()                               { print_value_on(tty); }
 384   void print_value_on(outputStream* out) const;
 385   void verify();
 386   const char* loader_name() const;
 387 
 388   OopHandle add_handle(Handle h);
 389   void remove_handle(OopHandle h);


< prev index next >