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 "oops/oopHandle.hpp" 32 #include "oops/weakHandle.hpp" 33 #include "runtime/mutex.hpp" 34 #include "utilities/growableArray.hpp" 35 #include "utilities/macros.hpp" 36 #if INCLUDE_JFR 37 #include "jfr/support/jfrTraceIdExtension.hpp" 38 #endif 39 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 53 class ClassLoaderData; 54 class JNIMethodBlock; 55 class Metadebug; 56 class ModuleEntry; 57 class PackageEntry; 58 class ModuleEntryTable; 59 class PackageEntryTable; 241 NOT_PRODUCT(volatile int _dependency_count;) // number of class loader dependencies 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; 257 258 // Support for walking class loader data objects 259 ClassLoaderData* _next; /// Next loader_datas created 260 261 // JFR support 262 Klass* _class_loader_klass; 263 Symbol* _class_loader_name; 264 JFR_ONLY(DEFINE_TRACE_ID_FIELD;) 265 266 void set_next(ClassLoaderData* next) { _next = next; } 267 ClassLoaderData* next() const { return _next; } 268 269 ClassLoaderData(Handle h_class_loader, bool is_anonymous); 270 ~ClassLoaderData(); 271 272 // The CLD are not placed in the Heap, so the Card Table or 273 // the Mod Union Table can't be used to mark when CLD have modified oops. 274 // The CT and MUT bits saves this information for the whole class loader data. 275 void clear_modified_oops() { _modified_oops = false; } 276 public: 277 void record_modified_oops() { _modified_oops = true; } 278 bool has_modified_oops() { return _modified_oops; } 279 280 void accumulate_modified_oops() { if (has_modified_oops()) _accumulated_modified_oops = true; } 281 void clear_accumulated_modified_oops() { _accumulated_modified_oops = false; } 282 bool has_accumulated_modified_oops() { return _accumulated_modified_oops; } 283 private: 345 346 // The Metaspace is created lazily so may be NULL. This 347 // method will allocate a Metaspace if needed. 348 ClassLoaderMetaspace* metaspace_non_null(); 349 350 inline oop class_loader() const; 351 352 // Returns true if this class loader data is for a loader going away. 353 bool is_unloading() const { 354 assert(!(is_the_null_class_loader_data() && _unloading), "The null class loader can never be unloaded"); 355 return _unloading; 356 } 357 358 // Used to refcount an anonymous class's CLD in order to 359 // indicate their aliveness. 360 void inc_keep_alive(); 361 void dec_keep_alive(); 362 363 void initialize_holder(Handle holder); 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 PRODUCT_RETURN; 377 void print_value() { print_value_on(tty); } 378 void print_value_on(outputStream* out) const; 379 void verify(); 380 const char* loader_name() const; 381 382 OopHandle add_handle(Handle h); 383 void remove_handle(OopHandle h); 384 void init_handle_locked(OopHandle& pd, Handle h); // used for concurrent access to ModuleEntry::_pd field 385 void add_class(Klass* k, bool publicize = true); 386 void remove_class(Klass* k); 387 bool contains_klass(Klass* k); 388 void record_dependency(const Klass* to); 389 PackageEntryTable* packages() { return _packages; } 390 ModuleEntry* unnamed_module() { return _unnamed_module; } 391 ModuleEntryTable* modules(); 392 bool modules_defined() { return (_modules != NULL); } 393 394 // Loaded class dictionary 395 Dictionary* dictionary() const { return _dictionary; } 396 397 void add_to_deallocate_list(Metadata* m); 398 399 static ClassLoaderData* class_loader_data(oop loader); 400 static ClassLoaderData* class_loader_data_or_null(oop loader); 401 static ClassLoaderData* anonymous_class_loader_data(Handle loader); 402 403 // Returns Klass* of associated class loader, or NULL if associated loader is <bootstrap>. 404 // Also works if unloading. 405 Klass* class_loader_klass() const { return _class_loader_klass; } 406 407 // Returns Name of associated class loader. 408 // Returns NULL if associated class loader is <bootstrap> or if no name has been set for 409 // this loader. 410 // Also works if unloading. 411 Symbol* class_loader_name() const { return _class_loader_name; } 412 413 JFR_ONLY(DEFINE_TRACE_ID_METHODS;) 414 }; 415 416 // An iterator that distributes Klasses to parallel worker threads. 417 class ClassLoaderDataGraphKlassIteratorAtomic : public StackObj { 418 Klass* volatile _next_klass; 419 public: 420 ClassLoaderDataGraphKlassIteratorAtomic(); 421 Klass* next_klass(); 422 private: 423 static Klass* next_klass_in_cldg(Klass* klass); 424 }; 425 426 class ClassLoaderDataGraphMetaspaceIterator : public StackObj { 427 ClassLoaderData* _data; 428 public: 429 ClassLoaderDataGraphMetaspaceIterator(); 430 ~ClassLoaderDataGraphMetaspaceIterator(); 431 bool repeat() { return _data != NULL; } | 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 "oops/oopHandle.hpp" 32 #include "oops/weakHandle.hpp" 33 #include "runtime/mutex.hpp" 34 #include "utilities/growableArray.hpp" 35 #include "utilities/macros.hpp" 36 #if INCLUDE_JFR 37 #include "jfr/support/jfrTraceIdExtension.hpp" 38 #endif 39 40 // external name (synthetic) for the primordial "'bootstrap'" class loader instance 41 #define BOOTSTRAP_LOADER_NAME "'bootstrap'" 42 #define BOOTSTRAP_LOADER_NAME_LEN 11 43 44 // 45 // A class loader represents a linkset. Conceptually, a linkset identifies 46 // the complete transitive closure of resolved links that a dynamic linker can 47 // produce. 48 // 49 // A ClassLoaderData also encapsulates the allocation space, called a metaspace, 50 // used by the dynamic linker to allocate the runtime representation of all 51 // the types it defines. 52 // 53 // ClassLoaderData are stored in the runtime representation of classes, 54 // and provides iterators for root tracing and other GC operations. 55 56 class ClassLoaderData; 57 class JNIMethodBlock; 58 class Metadebug; 59 class ModuleEntry; 60 class PackageEntry; 61 class ModuleEntryTable; 62 class PackageEntryTable; 244 NOT_PRODUCT(volatile int _dependency_count;) // number of class loader dependencies 245 246 Klass* volatile _klasses; // The classes defined by the class loader. 247 PackageEntryTable* volatile _packages; // The packages defined by the class loader. 248 ModuleEntryTable* volatile _modules; // The modules defined by the class loader. 249 ModuleEntry* _unnamed_module; // This class loader's unnamed module. 250 Dictionary* _dictionary; // The loaded InstanceKlasses, including initiated by this class loader 251 252 // These method IDs are created for the class loader and set to NULL when the 253 // class loader is unloaded. They are rarely freed, only for redefine classes 254 // and if they lose a data race in InstanceKlass. 255 JNIMethodBlock* _jmethod_ids; 256 257 // Metadata to be deallocated when it's safe at class unloading, when 258 // this class loader isn't unloaded itself. 259 GrowableArray<Metadata*>* _deallocate_list; 260 261 // Support for walking class loader data objects 262 ClassLoaderData* _next; /// Next loader_datas created 263 264 Klass* _class_loader_klass; 265 Symbol* _name; 266 Symbol* _name_and_id; 267 JFR_ONLY(DEFINE_TRACE_ID_FIELD;) 268 269 void set_next(ClassLoaderData* next) { _next = next; } 270 ClassLoaderData* next() const { return _next; } 271 272 ClassLoaderData(Handle h_class_loader, bool is_anonymous); 273 ~ClassLoaderData(); 274 275 // The CLD are not placed in the Heap, so the Card Table or 276 // the Mod Union Table can't be used to mark when CLD have modified oops. 277 // The CT and MUT bits saves this information for the whole class loader data. 278 void clear_modified_oops() { _modified_oops = false; } 279 public: 280 void record_modified_oops() { _modified_oops = true; } 281 bool has_modified_oops() { return _modified_oops; } 282 283 void accumulate_modified_oops() { if (has_modified_oops()) _accumulated_modified_oops = true; } 284 void clear_accumulated_modified_oops() { _accumulated_modified_oops = false; } 285 bool has_accumulated_modified_oops() { return _accumulated_modified_oops; } 286 private: 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 inline oop class_loader() const; 354 355 // Returns true if this class loader data is for a loader going away. 356 bool is_unloading() const { 357 assert(!(is_the_null_class_loader_data() && _unloading), "The null class loader can never be unloaded"); 358 return _unloading; 359 } 360 361 // Used to refcount an anonymous class's CLD in order to 362 // indicate their aliveness. 363 void inc_keep_alive(); 364 void dec_keep_alive(); 365 366 void initialize_holder(Handle holder); 367 368 void oops_do(OopClosure* f, bool must_claim, bool clear_modified_oops = false); 369 370 void classes_do(KlassClosure* klass_closure); 371 Klass* klasses() { return _klasses; } 372 373 JNIMethodBlock* jmethod_ids() const { return _jmethod_ids; } 374 void set_jmethod_ids(JNIMethodBlock* new_block) { _jmethod_ids = new_block; } 375 376 void print() { print_on(tty); } 377 void print_on(outputStream* out) const PRODUCT_RETURN; 378 void print_value() { print_value_on(tty); } 379 void print_value_on(outputStream* out) const; 380 void verify(); 381 382 OopHandle add_handle(Handle h); 383 void remove_handle(OopHandle h); 384 void init_handle_locked(OopHandle& pd, Handle h); // used for concurrent access to ModuleEntry::_pd field 385 void add_class(Klass* k, bool publicize = true); 386 void remove_class(Klass* k); 387 bool contains_klass(Klass* k); 388 void record_dependency(const Klass* to); 389 PackageEntryTable* packages() { return _packages; } 390 ModuleEntry* unnamed_module() { return _unnamed_module; } 391 ModuleEntryTable* modules(); 392 bool modules_defined() { return (_modules != NULL); } 393 394 // Loaded class dictionary 395 Dictionary* dictionary() const { return _dictionary; } 396 397 void add_to_deallocate_list(Metadata* m); 398 399 static ClassLoaderData* class_loader_data(oop loader); 400 static ClassLoaderData* class_loader_data_or_null(oop loader); 401 static ClassLoaderData* anonymous_class_loader_data(Handle loader); 402 403 // Returns Klass* of associated class loader, or NULL if associated loader is 'bootstrap'. 404 // Also works if unloading. 405 Klass* class_loader_klass() const { return _class_loader_klass; } 406 407 // Obtain the class loader's _name, works during unloading. 408 const char* loader_name() const; 409 Symbol* name() const { return _name; } 410 411 // Obtain the class loader's _name_and_id, works during unloading. 412 const char* loader_name_and_id() const; 413 Symbol* name_and_id() const { return _name_and_id; } 414 415 JFR_ONLY(DEFINE_TRACE_ID_METHODS;) 416 }; 417 418 // An iterator that distributes Klasses to parallel worker threads. 419 class ClassLoaderDataGraphKlassIteratorAtomic : public StackObj { 420 Klass* volatile _next_klass; 421 public: 422 ClassLoaderDataGraphKlassIteratorAtomic(); 423 Klass* next_klass(); 424 private: 425 static Klass* next_klass_in_cldg(Klass* klass); 426 }; 427 428 class ClassLoaderDataGraphMetaspaceIterator : public StackObj { 429 ClassLoaderData* _data; 430 public: 431 ClassLoaderDataGraphMetaspaceIterator(); 432 ~ClassLoaderDataGraphMetaspaceIterator(); 433 bool repeat() { return _data != NULL; } |