< prev index next >

src/hotspot/share/classfile/classLoaderData.hpp

Print this page




  99 
 100   friend class ClassLoaderDataGraph;
 101   friend class ClassLoaderDataGraphIterator;
 102   friend class ClassLoaderDataGraphKlassIteratorAtomic;
 103   friend class ClassLoaderDataGraphKlassIteratorStatic;
 104   friend class ClassLoaderDataGraphMetaspaceIterator;
 105   friend class Klass;
 106   friend class MetaDataFactory;
 107   friend class Method;
 108 
 109   static ClassLoaderData * _the_null_class_loader_data;
 110 
 111   WeakHandle<vm_class_loader_data> _holder; // The oop that determines lifetime of this class loader
 112   OopHandle _class_loader;    // The instance of java/lang/ClassLoader associated with
 113                               // this ClassLoaderData
 114 
 115   ClassLoaderMetaspace * volatile _metaspace;  // Meta-space where meta-data defined by the
 116                                     // classes in the class loader are allocated.
 117   Mutex* _metaspace_lock;  // Locks the metaspace for allocations and setup.
 118   bool _unloading;         // true if this class loader goes away
 119   bool _is_unsafe_anonymous; // CLD is dedicated to one class and that class determines the CLDs lifecycle.
 120                              // For example, an unsafe anonymous class.
 121 
 122   // Remembered sets support for the oops in the class loader data.
 123   bool _modified_oops;             // Card Table Equivalent (YC/CMS support)
 124   bool _accumulated_modified_oops; // Mod Union Equivalent (CMS support)
 125 
 126   s2 _keep_alive;          // if this CLD is kept alive.
 127                            // Used for unsafe anonymous classes and the boot class
 128                            // loader. _keep_alive does not need to be volatile or
 129                            // atomic since there is one unique CLD per unsafe anonymous class.
 130 
 131   volatile int _claim; // non-zero if claimed, for example during GC traces.
 132                        // To avoid applying oop closure more than once.
 133   ChunkedHandleList _handles; // Handles to constant pool arrays, Modules, etc, which
 134                               // have the same life cycle of the corresponding ClassLoader.
 135 
 136   NOT_PRODUCT(volatile int _dependency_count;)  // number of class loader dependencies
 137 
 138   Klass* volatile _klasses;              // The classes defined by the class loader.
 139   PackageEntryTable* volatile _packages; // The packages defined by the class loader.
 140   ModuleEntryTable*  volatile _modules;  // The modules defined by the class loader.
 141   ModuleEntry* _unnamed_module;          // This class loader's unnamed module.
 142   Dictionary*  _dictionary;              // The loaded InstanceKlasses, including initiated by this class loader
 143 
 144   // These method IDs are created for the class loader and set to NULL when the
 145   // class loader is unloaded.  They are rarely freed, only for redefine classes
 146   // and if they lose a data race in InstanceKlass.
 147   JNIMethodBlock*                  _jmethod_ids;
 148 
 149   // Metadata to be deallocated when it's safe at class unloading, when
 150   // this class loader isn't unloaded itself.
 151   GrowableArray<Metadata*>*      _deallocate_list;
 152 
 153   // Support for walking class loader data objects
 154   ClassLoaderData* _next; /// Next loader_datas created
 155 
 156   Klass*  _class_loader_klass;
 157   Symbol* _name;
 158   Symbol* _name_and_id;
 159   JFR_ONLY(DEFINE_TRACE_ID_FIELD;)
 160 
 161   void set_next(ClassLoaderData* next) { _next = next; }
 162   ClassLoaderData* next() const        { return _next; }
 163 
 164   ClassLoaderData(Handle h_class_loader, bool is_unsafe_anonymous);
 165   ~ClassLoaderData();
 166 
 167   // The CLD are not placed in the Heap, so the Card Table or
 168   // the Mod Union Table can't be used to mark when CLD have modified oops.
 169   // The CT and MUT bits saves this information for the whole class loader data.
 170   void clear_modified_oops()             { _modified_oops = false; }
 171  public:
 172   void record_modified_oops()            { _modified_oops = true; }
 173   bool has_modified_oops()               { return _modified_oops; }
 174 
 175   void accumulate_modified_oops()        { if (has_modified_oops()) _accumulated_modified_oops = true; }
 176   void clear_accumulated_modified_oops() { _accumulated_modified_oops = false; }
 177   bool has_accumulated_modified_oops()   { return _accumulated_modified_oops; }
 178   oop holder_no_keepalive() const;
 179   oop holder_phantom() const;
 180 
 181  private:
 182   void unload();
 183   bool keep_alive() const       { return _keep_alive > 0; }
 184 


 212   };
 213   void clear_claim() { _claim = 0; }
 214   bool claimed() const { return _claim != 0; }
 215   bool try_claim(int claim);
 216   int get_claim() const { return _claim; }
 217   void set_claim(int claim) { _claim = claim; }
 218 
 219   // Computes if the CLD is alive or not. This is safe to call in concurrent
 220   // contexts.
 221   bool is_alive() const;
 222 
 223   // Accessors
 224   ClassLoaderMetaspace* metaspace_or_null() const { return _metaspace; }
 225 
 226   static ClassLoaderData* the_null_class_loader_data() {
 227     return _the_null_class_loader_data;
 228   }
 229 
 230   Mutex* metaspace_lock() const { return _metaspace_lock; }
 231 
 232   bool is_unsafe_anonymous() const { return _is_unsafe_anonymous; }
 233 
 234   static void init_null_class_loader_data();
 235 
 236   bool is_the_null_class_loader_data() const {
 237     return this == _the_null_class_loader_data;
 238   }
 239 
 240   // Returns true if this class loader data is for the system class loader.
 241   // (Note that the class loader data may be unsafe anonymous.)
 242   bool is_system_class_loader_data() const;
 243 
 244   // Returns true if this class loader data is for the platform class loader.
 245   // (Note that the class loader data may be unsafe anonymous.)
 246   bool is_platform_class_loader_data() const;
 247 
 248   // Returns true if this class loader data is for the boot class loader.
 249   // (Note that the class loader data may be unsafe anonymous.)
 250   inline bool is_boot_class_loader_data() const;
 251 
 252   bool is_builtin_class_loader_data() const;
 253   bool is_permanent_class_loader_data() const;
 254 
 255   // The Metaspace is created lazily so may be NULL.  This
 256   // method will allocate a Metaspace if needed.
 257   ClassLoaderMetaspace* metaspace_non_null();
 258 
 259   inline oop class_loader() const;
 260 
 261   // Returns true if this class loader data is for a loader going away.
 262   // Note that this is only safe after the GC has computed if the CLD is
 263   // unloading or not. In concurrent contexts where there are no such
 264   // guarantees, is_alive() should be used instead.
 265   bool is_unloading() const     {
 266     assert(!(is_the_null_class_loader_data() && _unloading), "The null class loader can never be unloaded");
 267     return _unloading;
 268   }
 269 
 270   // Used to refcount an unsafe anonymous class's CLD in order to
 271   // indicate their aliveness.
 272   void inc_keep_alive();
 273   void dec_keep_alive();
 274 
 275   void initialize_holder(Handle holder);
 276 
 277   void oops_do(OopClosure* f, int claim_value, bool clear_modified_oops = false);
 278 
 279   void classes_do(KlassClosure* klass_closure);
 280   Klass* klasses() { return _klasses; }
 281 
 282   JNIMethodBlock* jmethod_ids() const              { return _jmethod_ids; }
 283   void set_jmethod_ids(JNIMethodBlock* new_block)  { _jmethod_ids = new_block; }
 284 
 285   void print()                                     { print_on(tty); }
 286   void print_on(outputStream* out) const PRODUCT_RETURN;
 287   void print_value()                               { print_value_on(tty); }
 288   void print_value_on(outputStream* out) const;
 289   void verify();
 290 
 291   OopHandle add_handle(Handle h);
 292   void remove_handle(OopHandle h);
 293   void init_handle_locked(OopHandle& pd, Handle h);  // used for concurrent access to ModuleEntry::_pd field
 294   void add_class(Klass* k, bool publicize = true);
 295   void remove_class(Klass* k);
 296   bool contains_klass(Klass* k);
 297   void record_dependency(const Klass* to);
 298   PackageEntryTable* packages() { return _packages; }
 299   ModuleEntry* unnamed_module() { return _unnamed_module; }
 300   ModuleEntryTable* modules();
 301   bool modules_defined() { return (_modules != NULL); }
 302 
 303   // Loaded class dictionary
 304   Dictionary* dictionary() const { return _dictionary; }
 305 
 306   void add_to_deallocate_list(Metadata* m);
 307 
 308   static ClassLoaderData* class_loader_data(oop loader);
 309   static ClassLoaderData* class_loader_data_or_null(oop loader);
 310   static ClassLoaderData* unsafe_anonymous_class_loader_data(Handle loader);
 311 
 312   // Returns Klass* of associated class loader, or NULL if associated loader is 'bootstrap'.
 313   // Also works if unloading.
 314   Klass* class_loader_klass() const { return _class_loader_klass; }
 315 
 316   // Returns the class loader's explict name as specified during
 317   // construction or the class loader's qualified class name.
 318   // Works during unloading.
 319   const char* loader_name() const;
 320   // Returns the explicitly specified class loader name or NULL.
 321   Symbol* name() const { return _name; }
 322 
 323   // Obtain the class loader's _name_and_id, works during unloading.
 324   const char* loader_name_and_id() const;
 325   Symbol* name_and_id() const { return _name_and_id; }
 326 
 327   JFR_ONLY(DEFINE_TRACE_ID_METHODS;)
 328 };
 329 
 330 #endif // SHARE_CLASSFILE_CLASSLOADERDATA_HPP


  99 
 100   friend class ClassLoaderDataGraph;
 101   friend class ClassLoaderDataGraphIterator;
 102   friend class ClassLoaderDataGraphKlassIteratorAtomic;
 103   friend class ClassLoaderDataGraphKlassIteratorStatic;
 104   friend class ClassLoaderDataGraphMetaspaceIterator;
 105   friend class Klass;
 106   friend class MetaDataFactory;
 107   friend class Method;
 108 
 109   static ClassLoaderData * _the_null_class_loader_data;
 110 
 111   WeakHandle<vm_class_loader_data> _holder; // The oop that determines lifetime of this class loader
 112   OopHandle _class_loader;    // The instance of java/lang/ClassLoader associated with
 113                               // this ClassLoaderData
 114 
 115   ClassLoaderMetaspace * volatile _metaspace;  // Meta-space where meta-data defined by the
 116                                     // classes in the class loader are allocated.
 117   Mutex* _metaspace_lock;  // Locks the metaspace for allocations and setup.
 118   bool _unloading;         // true if this class loader goes away
 119   bool _is_shortlived;     // CLD is dedicated to one class and that class determines the CLDs lifecycle.
 120                            // For example, a weak nonfindable or an unsafe anonymous class.
 121 
 122   // Remembered sets support for the oops in the class loader data.
 123   bool _modified_oops;             // Card Table Equivalent (YC/CMS support)
 124   bool _accumulated_modified_oops; // Mod Union Equivalent (CMS support)
 125 
 126   s2 _keep_alive;          // if this CLD is kept alive.
 127                            // Used for weak nonfindable classes, unsafe anonymous classes and the
 128                            // boot class loader. _keep_alive does not need to be volatile or
 129                            // atomic since there is one unique CLD per weak nonfindable or unsafe anonymous class.
 130 
 131   volatile int _claim; // non-zero if claimed, for example during GC traces.
 132                        // To avoid applying oop closure more than once.
 133   ChunkedHandleList _handles; // Handles to constant pool arrays, Modules, etc, which
 134                               // have the same life cycle of the corresponding ClassLoader.
 135 
 136   NOT_PRODUCT(volatile int _dependency_count;)  // number of class loader dependencies
 137 
 138   Klass* volatile _klasses;              // The classes defined by the class loader.
 139   PackageEntryTable* volatile _packages; // The packages defined by the class loader.
 140   ModuleEntryTable*  volatile _modules;  // The modules defined by the class loader.
 141   ModuleEntry* _unnamed_module;          // This class loader's unnamed module.
 142   Dictionary*  _dictionary;              // The loaded InstanceKlasses, including initiated by this class loader
 143 
 144   // These method IDs are created for the class loader and set to NULL when the
 145   // class loader is unloaded.  They are rarely freed, only for redefine classes
 146   // and if they lose a data race in InstanceKlass.
 147   JNIMethodBlock*                  _jmethod_ids;
 148 
 149   // Metadata to be deallocated when it's safe at class unloading, when
 150   // this class loader isn't unloaded itself.
 151   GrowableArray<Metadata*>*      _deallocate_list;
 152 
 153   // Support for walking class loader data objects
 154   ClassLoaderData* _next; /// Next loader_datas created
 155 
 156   Klass*  _class_loader_klass;
 157   Symbol* _name;
 158   Symbol* _name_and_id;
 159   JFR_ONLY(DEFINE_TRACE_ID_FIELD;)
 160 
 161   void set_next(ClassLoaderData* next) { _next = next; }
 162   ClassLoaderData* next() const        { return _next; }
 163 
 164   ClassLoaderData(Handle h_class_loader, bool is_shortlived);
 165   ~ClassLoaderData();
 166 
 167   // The CLD are not placed in the Heap, so the Card Table or
 168   // the Mod Union Table can't be used to mark when CLD have modified oops.
 169   // The CT and MUT bits saves this information for the whole class loader data.
 170   void clear_modified_oops()             { _modified_oops = false; }
 171  public:
 172   void record_modified_oops()            { _modified_oops = true; }
 173   bool has_modified_oops()               { return _modified_oops; }
 174 
 175   void accumulate_modified_oops()        { if (has_modified_oops()) _accumulated_modified_oops = true; }
 176   void clear_accumulated_modified_oops() { _accumulated_modified_oops = false; }
 177   bool has_accumulated_modified_oops()   { return _accumulated_modified_oops; }
 178   oop holder_no_keepalive() const;
 179   oop holder_phantom() const;
 180 
 181  private:
 182   void unload();
 183   bool keep_alive() const       { return _keep_alive > 0; }
 184 


 212   };
 213   void clear_claim() { _claim = 0; }
 214   bool claimed() const { return _claim != 0; }
 215   bool try_claim(int claim);
 216   int get_claim() const { return _claim; }
 217   void set_claim(int claim) { _claim = claim; }
 218 
 219   // Computes if the CLD is alive or not. This is safe to call in concurrent
 220   // contexts.
 221   bool is_alive() const;
 222 
 223   // Accessors
 224   ClassLoaderMetaspace* metaspace_or_null() const { return _metaspace; }
 225 
 226   static ClassLoaderData* the_null_class_loader_data() {
 227     return _the_null_class_loader_data;
 228   }
 229 
 230   Mutex* metaspace_lock() const { return _metaspace_lock; }
 231 
 232   bool is_shortlived() const { return _is_shortlived; }
 233 
 234   static void init_null_class_loader_data();
 235 
 236   bool is_the_null_class_loader_data() const {
 237     return this == _the_null_class_loader_data;
 238   }
 239 
 240   // Returns true if this class loader data is for the system class loader.
 241   // (Note that the class loader data may be for an weak nonfindable or unsafe anonymous class)
 242   bool is_system_class_loader_data() const;
 243 
 244   // Returns true if this class loader data is for the platform class loader.
 245   // (Note that the class loader data may be for an weak nonfindable or unsafe anonymous class)
 246   bool is_platform_class_loader_data() const;
 247 
 248   // Returns true if this class loader data is for the boot class loader.
 249   // (Note that the class loader data may be for an weak nonfindable unsafe anonymous class)
 250   inline bool is_boot_class_loader_data() const;
 251 
 252   bool is_builtin_class_loader_data() const;
 253   bool is_permanent_class_loader_data() const;
 254 
 255   // The Metaspace is created lazily so may be NULL.  This
 256   // method will allocate a Metaspace if needed.
 257   ClassLoaderMetaspace* metaspace_non_null();
 258 
 259   inline oop class_loader() const;
 260 
 261   // Returns true if this class loader data is for a loader going away.
 262   // Note that this is only safe after the GC has computed if the CLD is
 263   // unloading or not. In concurrent contexts where there are no such
 264   // guarantees, is_alive() should be used instead.
 265   bool is_unloading() const     {
 266     assert(!(is_the_null_class_loader_data() && _unloading), "The null class loader can never be unloaded");
 267     return _unloading;
 268   }
 269 
 270   // Used to refcount an weak nonfindable or unsafe anonymous class's CLD in order to
 271   // indicate their aliveness.
 272   void inc_keep_alive();
 273   void dec_keep_alive();
 274 
 275   void initialize_holder(Handle holder);
 276 
 277   void oops_do(OopClosure* f, int claim_value, bool clear_modified_oops = false);
 278 
 279   void classes_do(KlassClosure* klass_closure);
 280   Klass* klasses() { return _klasses; }
 281 
 282   JNIMethodBlock* jmethod_ids() const              { return _jmethod_ids; }
 283   void set_jmethod_ids(JNIMethodBlock* new_block)  { _jmethod_ids = new_block; }
 284 
 285   void print()                                     { print_on(tty); }
 286   void print_on(outputStream* out) const PRODUCT_RETURN;
 287   void print_value()                               { print_value_on(tty); }
 288   void print_value_on(outputStream* out) const;
 289   void verify();
 290 
 291   OopHandle add_handle(Handle h);
 292   void remove_handle(OopHandle h);
 293   void init_handle_locked(OopHandle& pd, Handle h);  // used for concurrent access to ModuleEntry::_pd field
 294   void add_class(Klass* k, bool publicize = true);
 295   void remove_class(Klass* k);
 296   bool contains_klass(Klass* k);
 297   void record_dependency(const Klass* to);
 298   PackageEntryTable* packages() { return _packages; }
 299   ModuleEntry* unnamed_module() { return _unnamed_module; }
 300   ModuleEntryTable* modules();
 301   bool modules_defined() { return (_modules != NULL); }
 302 
 303   // Loaded class dictionary
 304   Dictionary* dictionary() const { return _dictionary; }
 305 
 306   void add_to_deallocate_list(Metadata* m);
 307 
 308   static ClassLoaderData* class_loader_data(oop loader);
 309   static ClassLoaderData* class_loader_data_or_null(oop loader);
 310   static ClassLoaderData* shortlived_class_loader_data(Handle loader);
 311 
 312   // Returns Klass* of associated class loader, or NULL if associated loader is 'bootstrap'.
 313   // Also works if unloading.
 314   Klass* class_loader_klass() const { return _class_loader_klass; }
 315 
 316   // Returns the class loader's explict name as specified during
 317   // construction or the class loader's qualified class name.
 318   // Works during unloading.
 319   const char* loader_name() const;
 320   // Returns the explicitly specified class loader name or NULL.
 321   Symbol* name() const { return _name; }
 322 
 323   // Obtain the class loader's _name_and_id, works during unloading.
 324   const char* loader_name_and_id() const;
 325   Symbol* name_and_id() const { return _name_and_id; }
 326 
 327   JFR_ONLY(DEFINE_TRACE_ID_METHODS;)
 328 };
 329 
 330 #endif // SHARE_CLASSFILE_CLASSLOADERDATA_HPP
< prev index next >