< prev index next >

src/hotspot/share/classfile/classLoaderData.hpp

Print this page
rev 57511 : [mq]: metaspace-improvement


  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  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_CLASSFILE_CLASSLOADERDATA_HPP
  26 #define SHARE_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/atomic.hpp"
  34 #include "runtime/mutex.hpp"
  35 #include "utilities/growableArray.hpp"
  36 #include "utilities/macros.hpp"
  37 #if INCLUDE_JFR
  38 #include "jfr/support/jfrTraceIdExtension.hpp"
  39 #endif
  40 
  41 // external name (synthetic) for the primordial "bootstrap" class loader instance
  42 #define BOOTSTRAP_LOADER_NAME "bootstrap"
  43 #define BOOTSTRAP_LOADER_NAME_LEN 9
  44 
  45 //
  46 // A class loader represents a linkset. Conceptually, a linkset identifies
  47 // the complete transitive closure of resolved links that a dynamic linker can
  48 // produce.
  49 //
  50 // A ClassLoaderData also encapsulates the allocation space, called a metaspace,
  51 // used by the dynamic linker to allocate the runtime representation of all
  52 // the types it defines.
  53 //
  54 // ClassLoaderData are stored in the runtime representation of classes,
  55 // and provides iterators for root tracing and other GC operations.
  56 
  57 class ClassLoaderDataGraph;
  58 class JNIMethodBlock;
  59 class ModuleEntry;
  60 class PackageEntry;
  61 class ModuleEntryTable;
  62 class PackageEntryTable;
  63 class DictionaryEntry;
  64 class Dictionary;
  65 




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


  96     void oops_do(OopClosure* f);
  97 
  98     int count() const;
  99   };
 100 
 101   friend class ClassLoaderDataGraph;
 102   friend class ClassLoaderDataGraphIterator;
 103   friend class ClassLoaderDataGraphKlassIteratorAtomic;
 104   friend class ClassLoaderDataGraphKlassIteratorStatic;
 105   friend class ClassLoaderDataGraphMetaspaceIterator;
 106   friend class Klass;
 107   friend class MetaDataFactory;
 108   friend class Method;
 109 
 110   static ClassLoaderData * _the_null_class_loader_data;
 111 
 112   WeakHandle<vm_class_loader_data> _holder; // The oop that determines lifetime of this class loader
 113   OopHandle _class_loader;    // The instance of java/lang/ClassLoader associated with
 114                               // this ClassLoaderData
 115 
 116   ClassLoaderMetaspace * volatile _metaspace;  // Meta-space where meta-data defined by the
 117                                     // classes in the class loader are allocated.
 118   Mutex* _metaspace_lock;  // Locks the metaspace for allocations and setup.
 119   bool _unloading;         // true if this class loader goes away
 120   bool _is_unsafe_anonymous; // CLD is dedicated to one class and that class determines the CLDs lifecycle.
 121                              // For example, an unsafe anonymous class.
 122 
 123   // Remembered sets support for the oops in the class loader data.
 124   bool _modified_oops;             // Card Table Equivalent (YC/CMS support)
 125   bool _accumulated_modified_oops; // Mod Union Equivalent (CMS support)
 126 
 127   s2 _keep_alive;          // if this CLD is kept alive.
 128                            // Used for unsafe anonymous classes and the boot class
 129                            // loader. _keep_alive does not need to be volatile or
 130                            // atomic since there is one unique CLD per unsafe anonymous class.
 131 
 132   volatile int _claim; // non-zero if claimed, for example during GC traces.
 133                        // To avoid applying oop closure more than once.
 134   ChunkedHandleList _handles; // Handles to constant pool arrays, Modules, etc, which
 135                               // have the same life cycle of the corresponding ClassLoader.
 136 


 206 
 207   // The "claim" is typically used to check if oops_do needs to be applied on
 208   // the CLD or not. Most GCs only perform strong marking during the marking phase.
 209   enum Claim {
 210     _claim_none         = 0,
 211     _claim_finalizable  = 2,
 212     _claim_strong       = 3,
 213     _claim_other        = 4
 214   };
 215   void clear_claim() { _claim = 0; }
 216   void clear_claim(int claim);
 217   bool claimed() const { return _claim != 0; }
 218   bool claimed(int claim) const { return (_claim & claim) == claim; }
 219   bool try_claim(int claim);
 220 
 221   // Computes if the CLD is alive or not. This is safe to call in concurrent
 222   // contexts.
 223   bool is_alive() const;
 224 
 225   // Accessors
 226   ClassLoaderMetaspace* metaspace_or_null() const { return _metaspace; }
 227 
 228   static ClassLoaderData* the_null_class_loader_data() {
 229     return _the_null_class_loader_data;
 230   }
 231 
 232   Mutex* metaspace_lock() const { return _metaspace_lock; }
 233 
 234   bool is_unsafe_anonymous() const { return _is_unsafe_anonymous; }
 235 
 236   static void init_null_class_loader_data();
 237 
 238   bool is_the_null_class_loader_data() const {
 239     return this == _the_null_class_loader_data;
 240   }
 241 
 242   // Returns true if this class loader data is for the system class loader.
 243   // (Note that the class loader data may be unsafe anonymous.)
 244   bool is_system_class_loader_data() const;
 245 
 246   // Returns true if this class loader data is for the platform class loader.
 247   // (Note that the class loader data may be unsafe anonymous.)
 248   bool is_platform_class_loader_data() const;
 249 
 250   // Returns true if this class loader data is for the boot class loader.
 251   // (Note that the class loader data may be unsafe anonymous.)
 252   inline bool is_boot_class_loader_data() const;
 253 
 254   bool is_builtin_class_loader_data() const;
 255   bool is_permanent_class_loader_data() const;
 256 
 257   // The Metaspace is created lazily so may be NULL.  This
 258   // method will allocate a Metaspace if needed.
 259   ClassLoaderMetaspace* metaspace_non_null();
 260 
 261   inline oop class_loader() const;
 262 
 263   // Returns true if this class loader data is for a loader going away.
 264   // Note that this is only safe after the GC has computed if the CLD is
 265   // unloading or not. In concurrent contexts where there are no such
 266   // guarantees, is_alive() should be used instead.
 267   bool is_unloading() const     {
 268     assert(!(is_the_null_class_loader_data() && _unloading), "The null class loader can never be unloaded");
 269     return _unloading;
 270   }
 271 
 272   // Used to refcount an unsafe anonymous class's CLD in order to
 273   // indicate their aliveness.
 274   void inc_keep_alive();
 275   void dec_keep_alive();
 276 
 277   void initialize_holder(Handle holder);
 278 
 279   void oops_do(OopClosure* f, int claim_value, bool clear_modified_oops = false);




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  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_CLASSFILE_CLASSLOADERDATA_HPP
  26 #define SHARE_CLASSFILE_CLASSLOADERDATA_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "memory/memRegion.hpp"

  30 #include "oops/oopHandle.hpp"
  31 #include "oops/weakHandle.hpp"
  32 #include "runtime/atomic.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 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 namespace metaspace {
  66   class ClassLoaderMetaspace;
  67 }
  68 
  69 // ClassLoaderData class
  70 
  71 class ClassLoaderData : public CHeapObj<mtClass> {
  72   friend class VMStructs;
  73 
  74  private:
  75   class ChunkedHandleList {
  76     struct Chunk : public CHeapObj<mtClass> {
  77       static const size_t CAPACITY = 32;
  78 
  79       oop _data[CAPACITY];
  80       volatile juint _size;
  81       Chunk* _next;
  82 
  83       Chunk(Chunk* c) : _size(0), _next(c) { }
  84     };
  85 
  86     Chunk* volatile _head;
  87 
  88     void oops_do_chunk(OopClosure* f, Chunk* c, const juint size);


  99     void oops_do(OopClosure* f);
 100 
 101     int count() const;
 102   };
 103 
 104   friend class ClassLoaderDataGraph;
 105   friend class ClassLoaderDataGraphIterator;
 106   friend class ClassLoaderDataGraphKlassIteratorAtomic;
 107   friend class ClassLoaderDataGraphKlassIteratorStatic;
 108   friend class ClassLoaderDataGraphMetaspaceIterator;
 109   friend class Klass;
 110   friend class MetaDataFactory;
 111   friend class Method;
 112 
 113   static ClassLoaderData * _the_null_class_loader_data;
 114 
 115   WeakHandle<vm_class_loader_data> _holder; // The oop that determines lifetime of this class loader
 116   OopHandle _class_loader;    // The instance of java/lang/ClassLoader associated with
 117                               // this ClassLoaderData
 118 
 119   metaspace::ClassLoaderMetaspace* volatile _metaspace;  // Meta-space where meta-data defined by the
 120                                     // classes in the class loader are allocated.
 121   Mutex* _metaspace_lock;  // Locks the metaspace for allocations and setup.
 122   bool _unloading;         // true if this class loader goes away
 123   bool _is_unsafe_anonymous; // CLD is dedicated to one class and that class determines the CLDs lifecycle.
 124                              // For example, an unsafe anonymous class.
 125 
 126   // Remembered sets support for the oops in the class loader data.
 127   bool _modified_oops;             // Card Table Equivalent (YC/CMS support)
 128   bool _accumulated_modified_oops; // Mod Union Equivalent (CMS support)
 129 
 130   s2 _keep_alive;          // if this CLD is kept alive.
 131                            // Used for unsafe anonymous classes and the boot class
 132                            // loader. _keep_alive does not need to be volatile or
 133                            // atomic since there is one unique CLD per unsafe anonymous class.
 134 
 135   volatile int _claim; // non-zero if claimed, for example during GC traces.
 136                        // To avoid applying oop closure more than once.
 137   ChunkedHandleList _handles; // Handles to constant pool arrays, Modules, etc, which
 138                               // have the same life cycle of the corresponding ClassLoader.
 139 


 209 
 210   // The "claim" is typically used to check if oops_do needs to be applied on
 211   // the CLD or not. Most GCs only perform strong marking during the marking phase.
 212   enum Claim {
 213     _claim_none         = 0,
 214     _claim_finalizable  = 2,
 215     _claim_strong       = 3,
 216     _claim_other        = 4
 217   };
 218   void clear_claim() { _claim = 0; }
 219   void clear_claim(int claim);
 220   bool claimed() const { return _claim != 0; }
 221   bool claimed(int claim) const { return (_claim & claim) == claim; }
 222   bool try_claim(int claim);
 223 
 224   // Computes if the CLD is alive or not. This is safe to call in concurrent
 225   // contexts.
 226   bool is_alive() const;
 227 
 228   // Accessors
 229   metaspace::ClassLoaderMetaspace* metaspace_or_null() const { return _metaspace; }
 230 
 231   static ClassLoaderData* the_null_class_loader_data() {
 232     return _the_null_class_loader_data;
 233   }
 234 
 235   Mutex* metaspace_lock() const { return _metaspace_lock; }
 236 
 237   bool is_unsafe_anonymous() const { return _is_unsafe_anonymous; }
 238 
 239   static void init_null_class_loader_data();
 240 
 241   bool is_the_null_class_loader_data() const {
 242     return this == _the_null_class_loader_data;
 243   }
 244 
 245   // Returns true if this class loader data is for the system class loader.
 246   // (Note that the class loader data may be unsafe anonymous.)
 247   bool is_system_class_loader_data() const;
 248 
 249   // Returns true if this class loader data is for the platform class loader.
 250   // (Note that the class loader data may be unsafe anonymous.)
 251   bool is_platform_class_loader_data() const;
 252 
 253   // Returns true if this class loader data is for the boot class loader.
 254   // (Note that the class loader data may be unsafe anonymous.)
 255   inline bool is_boot_class_loader_data() const;
 256 
 257   bool is_builtin_class_loader_data() const;
 258   bool is_permanent_class_loader_data() const;
 259 
 260   // The Metaspace is created lazily so may be NULL.  This
 261   // method will allocate a Metaspace if needed.
 262   metaspace::ClassLoaderMetaspace* metaspace_non_null();
 263 
 264   inline oop class_loader() const;
 265 
 266   // Returns true if this class loader data is for a loader going away.
 267   // Note that this is only safe after the GC has computed if the CLD is
 268   // unloading or not. In concurrent contexts where there are no such
 269   // guarantees, is_alive() should be used instead.
 270   bool is_unloading() const     {
 271     assert(!(is_the_null_class_loader_data() && _unloading), "The null class loader can never be unloaded");
 272     return _unloading;
 273   }
 274 
 275   // Used to refcount an unsafe anonymous class's CLD in order to
 276   // indicate their aliveness.
 277   void inc_keep_alive();
 278   void dec_keep_alive();
 279 
 280   void initialize_holder(Handle holder);
 281 
 282   void oops_do(OopClosure* f, int claim_value, bool clear_modified_oops = false);


< prev index next >