< prev index next >

src/hotspot/share/classfile/classLoaderData.hpp

Print this page




  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 9
  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;
  63 class DictionaryEntry;
  64 class Dictionary;
  65 
  66 // GC root for walking class loader data created
  67 
  68 class ClassLoaderDataGraph : public AllStatic {
  69   friend class ClassLoaderData;
  70   friend class ClassLoaderDataGraphMetaspaceIterator;
  71   friend class ClassLoaderDataGraphKlassIteratorAtomic;
  72   friend class ClassLoaderDataGraphKlassIteratorStatic;
  73   friend class ClassLoaderDataGraphIterator;
  74   friend class VMStructs;
  75  private:
  76   // All CLDs (except the null CLD) can be reached by walking _head->_next->...
  77   static ClassLoaderData* _head;
  78   static ClassLoaderData* _unloading;
  79   // CMS support.
  80   static ClassLoaderData* _saved_head;
  81   static ClassLoaderData* _saved_unloading;
  82   static bool _should_purge;
  83 
  84   // Set if there's anything to purge in the deallocate lists or previous versions
  85   // during a safepoint after class unloading in a full GC.
  86   static bool _should_clean_deallocate_lists;
  87   static bool _safepoint_cleanup_needed;
  88 
  89   // OOM has been seen in metaspace allocation. Used to prevent some
  90   // allocations until class unloading
  91   static bool _metaspace_oom;
  92 
  93   static volatile size_t  _num_instance_classes;
  94   static volatile size_t  _num_array_classes;
  95 
  96   static ClassLoaderData* add_to_graph(Handle class_loader, bool is_unsafe_anonymous);
  97   static ClassLoaderData* add(Handle class_loader, bool is_unsafe_anonymous);
  98 
  99  public:
 100   static ClassLoaderData* find_or_create(Handle class_loader);
 101   static void clean_module_and_package_info();
 102   static void purge();
 103   static void clear_claimed_marks();
 104   // Iteration through CLDG inside a safepoint; GC support
 105   static void cld_do(CLDClosure* cl);
 106   static void cld_unloading_do(CLDClosure* cl);
 107   static void roots_cld_do(CLDClosure* strong, CLDClosure* weak);
 108   static void always_strong_cld_do(CLDClosure* cl);
 109   // klass do
 110   // Walking classes through the ClassLoaderDataGraph include array classes.  It also includes
 111   // classes that are allocated but not loaded, classes that have errors, and scratch classes
 112   // for redefinition.  These classes are removed during the next class unloading.
 113   // Walking the ClassLoaderDataGraph also includes unsafe anonymous classes.
 114   static void classes_do(KlassClosure* klass_closure);
 115   static void classes_do(void f(Klass* const));
 116   static void methods_do(void f(Method*));
 117   static void modules_do(void f(ModuleEntry*));
 118   static void modules_unloading_do(void f(ModuleEntry*));
 119   static void packages_do(void f(PackageEntry*));
 120   static void packages_unloading_do(void f(PackageEntry*));
 121   static void loaded_classes_do(KlassClosure* klass_closure);
 122   static void unlocked_loaded_classes_do(KlassClosure* klass_closure);
 123   static void classes_unloading_do(void f(Klass* const));
 124   static bool do_unloading(bool do_cleaning);
 125 
 126   // Expose state to avoid logging overhead in safepoint cleanup tasks.
 127   static inline bool should_clean_metaspaces_and_reset();
 128   static void set_should_clean_deallocate_lists() { _should_clean_deallocate_lists = true; }
 129   static void clean_deallocate_lists(bool purge_previous_versions);
 130   static void walk_metadata_and_clean_metaspaces();
 131 
 132   // dictionary do
 133   // Iterate over all klasses in dictionary, but
 134   // just the classes from defining class loaders.
 135   static void dictionary_classes_do(void f(InstanceKlass*));
 136   // Added for initialize_itable_for_klass to handle exceptions.
 137   static void dictionary_classes_do(void f(InstanceKlass*, TRAPS), TRAPS);
 138 
 139   // VM_CounterDecay iteration support
 140   static InstanceKlass* try_get_next_class();
 141 
 142   static void verify_dictionary();
 143   static void print_dictionary(outputStream* st);
 144   static void print_dictionary_statistics(outputStream* st);
 145 
 146   // CMS support.
 147   static void remember_new_clds(bool remember) { _saved_head = (remember ? _head : NULL); }
 148   static GrowableArray<ClassLoaderData*>* new_clds();
 149 
 150   static void set_should_purge(bool b) { _should_purge = b; }
 151   static void purge_if_needed() {
 152     // Only purge the CLDG for CMS if concurrent sweep is complete.
 153     if (_should_purge) {
 154       purge();
 155       // reset for next time.
 156       set_should_purge(false);
 157     }
 158   }
 159 
 160   static int resize_if_needed();
 161 
 162   static bool has_metaspace_oom()           { return _metaspace_oom; }
 163   static void set_metaspace_oom(bool value) { _metaspace_oom = value; }
 164 
 165   static void print_on(outputStream * const out) PRODUCT_RETURN;
 166   static void print() { print_on(tty); }
 167   static void verify();
 168 
 169   // instance and array class counters
 170   static inline size_t num_instance_classes();
 171   static inline size_t num_array_classes();
 172   static inline void inc_instance_classes(size_t count);
 173   static inline void dec_instance_classes(size_t count);
 174   static inline void inc_array_classes(size_t count);
 175   static inline void dec_array_classes(size_t count);
 176 
 177 #ifndef PRODUCT
 178   static bool contains_loader_data(ClassLoaderData* loader_data);
 179 #endif
 180 };
 181 
 182 class LockedClassesDo : public KlassClosure {
 183   typedef void (*classes_do_func_t)(Klass*);
 184   classes_do_func_t _function;
 185 public:
 186   LockedClassesDo();  // For callers who provide their own do_klass
 187   LockedClassesDo(classes_do_func_t function);
 188   ~LockedClassesDo();
 189 
 190   void do_klass(Klass* k) {
 191     (*_function)(k);
 192   }
 193 };
 194 
 195 
 196 // ClassLoaderData class
 197 
 198 class ClassLoaderData : public CHeapObj<mtClass> {
 199   friend class VMStructs;
 200 
 201  private:
 202   class ChunkedHandleList {
 203     struct Chunk : public CHeapObj<mtClass> {
 204       static const size_t CAPACITY = 32;
 205 
 206       oop _data[CAPACITY];
 207       volatile juint _size;
 208       Chunk* _next;
 209 
 210       Chunk(Chunk* c) : _size(0), _next(c) { }
 211     };
 212 
 213     Chunk* volatile _head;
 214 
 215     void oops_do_chunk(OopClosure* f, Chunk* c, const juint size);


 431   static ClassLoaderData* unsafe_anonymous_class_loader_data(Handle loader);
 432 
 433   // Returns Klass* of associated class loader, or NULL if associated loader is 'bootstrap'.
 434   // Also works if unloading.
 435   Klass* class_loader_klass() const { return _class_loader_klass; }
 436 
 437   // Returns the class loader's explict name as specified during
 438   // construction or the class loader's qualified class name.
 439   // Works during unloading.
 440   const char* loader_name() const;
 441   // Returns the explicitly specified class loader name or NULL.
 442   Symbol* name() const { return _name; }
 443 
 444   // Obtain the class loader's _name_and_id, works during unloading.
 445   const char* loader_name_and_id() const;
 446   Symbol* name_and_id() const { return _name_and_id; }
 447 
 448   JFR_ONLY(DEFINE_TRACE_ID_METHODS;)
 449 };
 450 
 451 // An iterator that distributes Klasses to parallel worker threads.
 452 class ClassLoaderDataGraphKlassIteratorAtomic : public StackObj {
 453  Klass* volatile _next_klass;
 454  public:
 455   ClassLoaderDataGraphKlassIteratorAtomic();
 456   Klass* next_klass();
 457  private:
 458   static Klass* next_klass_in_cldg(Klass* klass);
 459 };
 460 
 461 class ClassLoaderDataGraphMetaspaceIterator : public StackObj {
 462   ClassLoaderData* _data;
 463  public:
 464   ClassLoaderDataGraphMetaspaceIterator();
 465   ~ClassLoaderDataGraphMetaspaceIterator();
 466   bool repeat() { return _data != NULL; }
 467   ClassLoaderMetaspace* get_next() {
 468     assert(_data != NULL, "Should not be NULL in call to the iterator");
 469     ClassLoaderMetaspace* result = _data->metaspace_or_null();
 470     _data = _data->next();
 471     // This result might be NULL for class loaders without metaspace
 472     // yet.  It would be nice to return only non-null results but
 473     // there is no guarantee that there will be a non-null result
 474     // down the list so the caller is going to have to check.
 475     return result;
 476   }
 477 };
 478 #endif // SHARE_VM_CLASSFILE_CLASSLOADERDATA_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 9
  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 ClassLoaderDataGraph;
  57 class JNIMethodBlock;

  58 class ModuleEntry;
  59 class PackageEntry;
  60 class ModuleEntryTable;
  61 class PackageEntryTable;
  62 class DictionaryEntry;
  63 class Dictionary;
  64 


































































































































  65 // ClassLoaderData class
  66 
  67 class ClassLoaderData : public CHeapObj<mtClass> {
  68   friend class VMStructs;
  69 
  70  private:
  71   class ChunkedHandleList {
  72     struct Chunk : public CHeapObj<mtClass> {
  73       static const size_t CAPACITY = 32;
  74 
  75       oop _data[CAPACITY];
  76       volatile juint _size;
  77       Chunk* _next;
  78 
  79       Chunk(Chunk* c) : _size(0), _next(c) { }
  80     };
  81 
  82     Chunk* volatile _head;
  83 
  84     void oops_do_chunk(OopClosure* f, Chunk* c, const juint size);


 300   static ClassLoaderData* unsafe_anonymous_class_loader_data(Handle loader);
 301 
 302   // Returns Klass* of associated class loader, or NULL if associated loader is 'bootstrap'.
 303   // Also works if unloading.
 304   Klass* class_loader_klass() const { return _class_loader_klass; }
 305 
 306   // Returns the class loader's explict name as specified during
 307   // construction or the class loader's qualified class name.
 308   // Works during unloading.
 309   const char* loader_name() const;
 310   // Returns the explicitly specified class loader name or NULL.
 311   Symbol* name() const { return _name; }
 312 
 313   // Obtain the class loader's _name_and_id, works during unloading.
 314   const char* loader_name_and_id() const;
 315   Symbol* name_and_id() const { return _name_and_id; }
 316 
 317   JFR_ONLY(DEFINE_TRACE_ID_METHODS;)
 318 };
 319 



























 320 #endif // SHARE_VM_CLASSFILE_CLASSLOADERDATA_HPP
< prev index next >