< prev index next >

src/hotspot/share/classfile/classLoaderData.hpp

Print this page




  70   friend class VMStructs;
  71  private:
  72   // All CLDs (except the null CLD) can be reached by walking _head->_next->...
  73   static ClassLoaderData* _head;
  74   static ClassLoaderData* _unloading;
  75   // CMS support.
  76   static ClassLoaderData* _saved_head;
  77   static ClassLoaderData* _saved_unloading;
  78   static bool _should_purge;
  79   // OOM has been seen in metaspace allocation. Used to prevent some
  80   // allocations until class unloading
  81   static bool _metaspace_oom;
  82 
  83   static ClassLoaderData* add(Handle class_loader, bool anonymous, TRAPS);
  84   static void post_class_unload_events();
  85  public:
  86   static ClassLoaderData* find_or_create(Handle class_loader, TRAPS);
  87   static void purge();
  88   static void clear_claimed_marks();
  89   // oops do
  90   static void oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim);
  91   static void keep_alive_oops_do(OopClosure* blk, KlassClosure* klass_closure, bool must_claim);
  92   static void always_strong_oops_do(OopClosure* blk, KlassClosure* klass_closure, bool must_claim);
  93   // cld do
  94   static void cld_do(CLDClosure* cl);
  95   static void cld_unloading_do(CLDClosure* cl);
  96   static void roots_cld_do(CLDClosure* strong, CLDClosure* weak);
  97   static void keep_alive_cld_do(CLDClosure* cl);
  98   static void always_strong_cld_do(CLDClosure* cl);
  99   // klass do
 100   // Walking classes through the ClassLoaderDataGraph include array classes.  It also includes
 101   // classes that are allocated but not loaded, classes that have errors, and scratch classes
 102   // for redefinition.  These classes are removed during the next class unloading.
 103   // Walking the ClassLoaderDataGraph also includes anonymous classes.
 104   static void classes_do(KlassClosure* klass_closure);
 105   static void classes_do(void f(Klass* const));
 106   static void methods_do(void f(Method*));
 107   static void modules_do(void f(ModuleEntry*));
 108   static void modules_unloading_do(void f(ModuleEntry*));
 109   static void packages_do(void f(PackageEntry*));
 110   static void packages_unloading_do(void f(PackageEntry*));
 111   static void loaded_classes_do(KlassClosure* klass_closure);
 112   static void classes_unloading_do(void f(Klass* const));


 217   friend class ClassLoaderDataGraphMetaspaceIterator;
 218   friend class MetaDataFactory;
 219   friend class Method;
 220 
 221   static ClassLoaderData * _the_null_class_loader_data;
 222 
 223   oop _class_loader;          // oop used to uniquely identify a class loader
 224                               // class loader or a canonical class path
 225   Dependencies _dependencies; // holds dependencies from this class loader
 226                               // data to others.
 227 
 228   Metaspace * volatile _metaspace;  // Meta-space where meta-data defined by the
 229                                     // classes in the class loader are allocated.
 230   Mutex* _metaspace_lock;  // Locks the metaspace for allocations and setup.
 231   bool _unloading;         // true if this class loader goes away
 232   bool _is_anonymous;      // if this CLD is for an anonymous class
 233   s2 _keep_alive;          // if this CLD is kept alive without a keep_alive_object().
 234                            // Used for anonymous classes and the boot class
 235                            // loader. _keep_alive does not need to be volatile or
 236                            // atomic since there is one unique CLD per anonymous class.





 237   volatile int _claimed;   // true if claimed, for example during GC traces.
 238                            // To avoid applying oop closure more than once.
 239                            // Has to be an int because we cas it.
 240   ChunkedHandleList _handles; // Handles to constant pool arrays, Modules, etc, which
 241                               // have the same life cycle of the corresponding ClassLoader.
 242 
 243   Klass* volatile _klasses;              // The classes defined by the class loader.
 244   PackageEntryTable* volatile _packages; // The packages defined by the class loader.
 245   ModuleEntryTable*  volatile _modules;  // The modules defined by the class loader.
 246   ModuleEntry* _unnamed_module;          // This class loader's unnamed module.
 247   Dictionary*  _dictionary;              // The loaded InstanceKlasses, including initiated by this class loader
 248 
 249   // These method IDs are created for the class loader and set to NULL when the
 250   // class loader is unloaded.  They are rarely freed, only for redefine classes
 251   // and if they lose a data race in InstanceKlass.
 252   JNIMethodBlock*                  _jmethod_ids;
 253 
 254   // Metadata to be deallocated when it's safe at class unloading, when
 255   // this class loader isn't unloaded itself.
 256   GrowableArray<Metadata*>*      _deallocate_list;


 259   ClassLoaderData* _next; /// Next loader_datas created
 260 
 261   // ReadOnly and ReadWrite metaspaces (static because only on the null
 262   // class loader for now).
 263   static Metaspace* _ro_metaspace;
 264   static Metaspace* _rw_metaspace;
 265 
 266   TRACE_DEFINE_TRACE_ID_FIELD;
 267 
 268   void set_next(ClassLoaderData* next) { _next = next; }
 269   ClassLoaderData* next() const        { return _next; }
 270 
 271   ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies);
 272   ~ClassLoaderData();
 273 
 274   // GC interface.
 275   void clear_claimed()          { _claimed = 0; }
 276   bool claimed() const          { return _claimed == 1; }
 277   bool claim();
 278 













 279   void unload();
 280   bool keep_alive() const       { return _keep_alive > 0; }
 281   void classes_do(void f(Klass*));
 282   void loaded_classes_do(KlassClosure* klass_closure);
 283   void classes_do(void f(InstanceKlass*));
 284   void methods_do(void f(Method*));
 285   void modules_do(void f(ModuleEntry*));
 286   void packages_do(void f(PackageEntry*));
 287 
 288   // Deallocate free list during class unloading.
 289   void free_deallocate_list();
 290 
 291   // Allocate out of this class loader data
 292   MetaWord* allocate(size_t size);
 293 
 294   Dictionary* create_dictionary();
 295  public:
 296 
 297   bool is_alive(BoolObjectClosure* is_alive_closure) const;
 298 


 329   Metaspace* metaspace_non_null();
 330 
 331   oop class_loader() const      { return _class_loader; }
 332 
 333   // The object the GC is using to keep this ClassLoaderData alive.
 334   oop keep_alive_object() const;
 335 
 336   // Returns true if this class loader data is for a loader going away.
 337   bool is_unloading() const     {
 338     assert(!(is_the_null_class_loader_data() && _unloading), "The null class loader can never be unloaded");
 339     return _unloading;
 340   }
 341 
 342   // Used to refcount an anonymous class's CLD in order to
 343   // indicate their aliveness without a keep_alive_object().
 344   void inc_keep_alive();
 345   void dec_keep_alive();
 346 
 347   inline unsigned int identity_hash() const { return (unsigned int)(((intptr_t)this) >> 3); }
 348 
 349   // Used when tracing from klasses.
 350   void oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim);
 351 
 352   void classes_do(KlassClosure* klass_closure);
 353   Klass* klasses() { return _klasses; }
 354 
 355   JNIMethodBlock* jmethod_ids() const              { return _jmethod_ids; }
 356   void set_jmethod_ids(JNIMethodBlock* new_block)  { _jmethod_ids = new_block; }
 357 
 358   void print()                                     { print_on(tty); }
 359   void print_on(outputStream* out) const;
 360   void print_value()                               { print_value_on(tty); }
 361   void print_value_on(outputStream* out) const;
 362   void dump(outputStream * const out) PRODUCT_RETURN;
 363   void verify();
 364   const char* loader_name();
 365 
 366   OopHandle add_handle(Handle h);
 367   void remove_handle(OopHandle h);
 368   void init_handle_locked(OopHandle& pd, Handle h);  // used for concurrent access to ModuleEntry::_pd field
 369   void add_class(Klass* k, bool publicize = true);
 370   void remove_class(Klass* k);




  70   friend class VMStructs;
  71  private:
  72   // All CLDs (except the null CLD) can be reached by walking _head->_next->...
  73   static ClassLoaderData* _head;
  74   static ClassLoaderData* _unloading;
  75   // CMS support.
  76   static ClassLoaderData* _saved_head;
  77   static ClassLoaderData* _saved_unloading;
  78   static bool _should_purge;
  79   // OOM has been seen in metaspace allocation. Used to prevent some
  80   // allocations until class unloading
  81   static bool _metaspace_oom;
  82 
  83   static ClassLoaderData* add(Handle class_loader, bool anonymous, TRAPS);
  84   static void post_class_unload_events();
  85  public:
  86   static ClassLoaderData* find_or_create(Handle class_loader, TRAPS);
  87   static void purge();
  88   static void clear_claimed_marks();
  89   // oops do
  90   static void oops_do(OopClosure* f, bool must_claim);
  91   static void keep_alive_oops_do(OopClosure* blk, bool must_claim);
  92   static void always_strong_oops_do(OopClosure* blk, bool must_claim);
  93   // cld do
  94   static void cld_do(CLDClosure* cl);
  95   static void cld_unloading_do(CLDClosure* cl);
  96   static void roots_cld_do(CLDClosure* strong, CLDClosure* weak);
  97   static void keep_alive_cld_do(CLDClosure* cl);
  98   static void always_strong_cld_do(CLDClosure* cl);
  99   // klass do
 100   // Walking classes through the ClassLoaderDataGraph include array classes.  It also includes
 101   // classes that are allocated but not loaded, classes that have errors, and scratch classes
 102   // for redefinition.  These classes are removed during the next class unloading.
 103   // Walking the ClassLoaderDataGraph also includes anonymous classes.
 104   static void classes_do(KlassClosure* klass_closure);
 105   static void classes_do(void f(Klass* const));
 106   static void methods_do(void f(Method*));
 107   static void modules_do(void f(ModuleEntry*));
 108   static void modules_unloading_do(void f(ModuleEntry*));
 109   static void packages_do(void f(PackageEntry*));
 110   static void packages_unloading_do(void f(PackageEntry*));
 111   static void loaded_classes_do(KlassClosure* klass_closure);
 112   static void classes_unloading_do(void f(Klass* const));


 217   friend class ClassLoaderDataGraphMetaspaceIterator;
 218   friend class MetaDataFactory;
 219   friend class Method;
 220 
 221   static ClassLoaderData * _the_null_class_loader_data;
 222 
 223   oop _class_loader;          // oop used to uniquely identify a class loader
 224                               // class loader or a canonical class path
 225   Dependencies _dependencies; // holds dependencies from this class loader
 226                               // data to others.
 227 
 228   Metaspace * volatile _metaspace;  // Meta-space where meta-data defined by the
 229                                     // classes in the class loader are allocated.
 230   Mutex* _metaspace_lock;  // Locks the metaspace for allocations and setup.
 231   bool _unloading;         // true if this class loader goes away
 232   bool _is_anonymous;      // if this CLD is for an anonymous class
 233   s2 _keep_alive;          // if this CLD is kept alive without a keep_alive_object().
 234                            // Used for anonymous classes and the boot class
 235                            // loader. _keep_alive does not need to be volatile or
 236                            // atomic since there is one unique CLD per anonymous class.
 237 
 238   // Remembered sets support for the oops in the class loader data.
 239   jbyte _modified_oops;             // Card Table Equivalent (YC/CMS support)
 240   jbyte _accumulated_modified_oops; // Mod Union Equivalent (CMS support)
 241 
 242   volatile int _claimed;   // true if claimed, for example during GC traces.
 243                            // To avoid applying oop closure more than once.
 244                            // Has to be an int because we cas it.
 245   ChunkedHandleList _handles; // Handles to constant pool arrays, Modules, etc, which
 246                               // have the same life cycle of the corresponding ClassLoader.
 247 
 248   Klass* volatile _klasses;              // The classes defined by the class loader.
 249   PackageEntryTable* volatile _packages; // The packages defined by the class loader.
 250   ModuleEntryTable*  volatile _modules;  // The modules defined by the class loader.
 251   ModuleEntry* _unnamed_module;          // This class loader's unnamed module.
 252   Dictionary*  _dictionary;              // The loaded InstanceKlasses, including initiated by this class loader
 253 
 254   // These method IDs are created for the class loader and set to NULL when the
 255   // class loader is unloaded.  They are rarely freed, only for redefine classes
 256   // and if they lose a data race in InstanceKlass.
 257   JNIMethodBlock*                  _jmethod_ids;
 258 
 259   // Metadata to be deallocated when it's safe at class unloading, when
 260   // this class loader isn't unloaded itself.
 261   GrowableArray<Metadata*>*      _deallocate_list;


 264   ClassLoaderData* _next; /// Next loader_datas created
 265 
 266   // ReadOnly and ReadWrite metaspaces (static because only on the null
 267   // class loader for now).
 268   static Metaspace* _ro_metaspace;
 269   static Metaspace* _rw_metaspace;
 270 
 271   TRACE_DEFINE_TRACE_ID_FIELD;
 272 
 273   void set_next(ClassLoaderData* next) { _next = next; }
 274   ClassLoaderData* next() const        { return _next; }
 275 
 276   ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies);
 277   ~ClassLoaderData();
 278 
 279   // GC interface.
 280   void clear_claimed()          { _claimed = 0; }
 281   bool claimed() const          { return _claimed == 1; }
 282   bool claim();
 283 
 284   // The CLD are not placed in the Heap, so the Card Table or
 285   // the Mod Union Table can't be used to mark when CLD have modified oops.
 286   // The CT and MUT bits saves this information for the whole class loader data.
 287   void clear_modified_oops()             { _modified_oops = 0; }
 288  public:
 289   void record_modified_oops()            { _modified_oops = 1; }
 290   bool has_modified_oops()               { return _modified_oops == 1; }
 291 
 292   void accumulate_modified_oops()        { if (has_modified_oops()) _accumulated_modified_oops = 1; }
 293   void clear_accumulated_modified_oops() { _accumulated_modified_oops = 0; }
 294   bool has_accumulated_modified_oops()   { return _accumulated_modified_oops == 1; }
 295  private:
 296 
 297   void unload();
 298   bool keep_alive() const       { return _keep_alive > 0; }
 299   void classes_do(void f(Klass*));
 300   void loaded_classes_do(KlassClosure* klass_closure);
 301   void classes_do(void f(InstanceKlass*));
 302   void methods_do(void f(Method*));
 303   void modules_do(void f(ModuleEntry*));
 304   void packages_do(void f(PackageEntry*));
 305 
 306   // Deallocate free list during class unloading.
 307   void free_deallocate_list();
 308 
 309   // Allocate out of this class loader data
 310   MetaWord* allocate(size_t size);
 311 
 312   Dictionary* create_dictionary();
 313  public:
 314 
 315   bool is_alive(BoolObjectClosure* is_alive_closure) const;
 316 


 347   Metaspace* metaspace_non_null();
 348 
 349   oop class_loader() const      { return _class_loader; }
 350 
 351   // The object the GC is using to keep this ClassLoaderData alive.
 352   oop keep_alive_object() const;
 353 
 354   // Returns true if this class loader data is for a loader going away.
 355   bool is_unloading() const     {
 356     assert(!(is_the_null_class_loader_data() && _unloading), "The null class loader can never be unloaded");
 357     return _unloading;
 358   }
 359 
 360   // Used to refcount an anonymous class's CLD in order to
 361   // indicate their aliveness without a keep_alive_object().
 362   void inc_keep_alive();
 363   void dec_keep_alive();
 364 
 365   inline unsigned int identity_hash() const { return (unsigned int)(((intptr_t)this) >> 3); }
 366 
 367   void oops_do(OopClosure* f, bool must_claim, bool clear_modified_oops = false);

 368 
 369   void classes_do(KlassClosure* klass_closure);
 370   Klass* klasses() { return _klasses; }
 371 
 372   JNIMethodBlock* jmethod_ids() const              { return _jmethod_ids; }
 373   void set_jmethod_ids(JNIMethodBlock* new_block)  { _jmethod_ids = new_block; }
 374 
 375   void print()                                     { print_on(tty); }
 376   void print_on(outputStream* out) const;
 377   void print_value()                               { print_value_on(tty); }
 378   void print_value_on(outputStream* out) const;
 379   void dump(outputStream * const out) PRODUCT_RETURN;
 380   void verify();
 381   const char* loader_name();
 382 
 383   OopHandle add_handle(Handle h);
 384   void remove_handle(OopHandle h);
 385   void init_handle_locked(OopHandle& pd, Handle h);  // used for concurrent access to ModuleEntry::_pd field
 386   void add_class(Klass* k, bool publicize = true);
 387   void remove_class(Klass* k);


< prev index next >