< prev index next >

src/hotspot/share/memory/metaspace.hpp

Print this page




  85 // virtual spaces and the list of chunks in use.  Its
  86 // allocate() method returns a block for use as a
  87 // quantum of metadata.
  88 
  89 // Namespace for important central static functions
  90 // (auxiliary stuff goes into MetaspaceUtils)
  91 class Metaspace : public AllStatic {
  92 
  93   friend class MetaspaceShared;
  94 
  95  public:
  96   enum MetadataType {
  97     ClassType,
  98     NonClassType,
  99     MetadataTypeCount
 100   };
 101   enum MetaspaceType {
 102     ZeroMetaspaceType = 0,
 103     StandardMetaspaceType = ZeroMetaspaceType,
 104     BootMetaspaceType = StandardMetaspaceType + 1,
 105     UnsafeAnonymousMetaspaceType = BootMetaspaceType + 1,
 106     ReflectionMetaspaceType = UnsafeAnonymousMetaspaceType + 1,
 107     MetaspaceTypeCount
 108   };
 109 
 110  private:
 111 
 112   // Align up the word size to the allocation word size
 113   static size_t align_word_size_up(size_t);
 114 
 115   // Aligned size of the metaspace.
 116   static size_t _compressed_class_space_size;
 117 
 118   static size_t compressed_class_space_size() {
 119     return _compressed_class_space_size;
 120   }
 121 
 122   static void set_compressed_class_space_size(size_t size) {
 123     _compressed_class_space_size = size;
 124   }
 125 
 126   static size_t _first_chunk_word_size;


 225   }
 226 
 227 };
 228 
 229 // Manages the metaspace portion belonging to a class loader
 230 class ClassLoaderMetaspace : public CHeapObj<mtClass> {
 231   friend class CollectedHeap; // For expand_and_allocate()
 232   friend class ZCollectedHeap; // For expand_and_allocate()
 233   friend class ShenandoahHeap; // For expand_and_allocate()
 234   friend class Metaspace;
 235   friend class MetaspaceUtils;
 236   friend class metaspace::PrintCLDMetaspaceInfoClosure;
 237   friend class VM_CollectForMetadataAllocation; // For expand_and_allocate()
 238 
 239  private:
 240 
 241   void initialize(Mutex* lock, Metaspace::MetaspaceType type);
 242 
 243   // Initialize the first chunk for a Metaspace.  Used for
 244   // special cases such as the boot class loader, reflection
 245   // class loader and anonymous class loader.
 246   void initialize_first_chunk(Metaspace::MetaspaceType type, Metaspace::MetadataType mdtype);
 247   metaspace::Metachunk* get_initialization_chunk(Metaspace::MetaspaceType type, Metaspace::MetadataType mdtype);
 248 
 249   const Metaspace::MetaspaceType _space_type;
 250   Mutex* const  _lock;
 251   metaspace::SpaceManager* _vsm;
 252   metaspace::SpaceManager* _class_vsm;
 253 
 254   metaspace::SpaceManager* vsm() const { return _vsm; }
 255   metaspace::SpaceManager* class_vsm() const { return _class_vsm; }
 256   metaspace::SpaceManager* get_space_manager(Metaspace::MetadataType mdtype) {
 257     assert(mdtype != Metaspace::MetadataTypeCount, "MetadaTypeCount can't be used as mdtype");
 258     return mdtype == Metaspace::ClassType ? class_vsm() : vsm();
 259   }
 260 
 261   Mutex* lock() const { return _lock; }
 262 
 263   MetaWord* expand_and_allocate(size_t size, Metaspace::MetadataType mdtype);
 264 
 265   size_t class_chunk_size(size_t word_size);


 375   static size_t reserved_bytes(Metaspace::MetadataType mdtype);
 376   static size_t reserved_bytes() {
 377     return reserved_bytes(Metaspace::ClassType) +
 378            reserved_bytes(Metaspace::NonClassType);
 379   }
 380 
 381   static size_t committed_bytes(Metaspace::MetadataType mdtype);
 382   static size_t committed_bytes() {
 383     return committed_bytes(Metaspace::ClassType) +
 384            committed_bytes(Metaspace::NonClassType);
 385   }
 386 
 387   static size_t min_chunk_size_words();
 388 
 389   // Flags for print_report().
 390   enum ReportFlag {
 391     // Show usage by class loader.
 392     rf_show_loaders                 = (1 << 0),
 393     // Breaks report down by chunk type (small, medium, ...).
 394     rf_break_down_by_chunktype      = (1 << 1),
 395     // Breaks report down by space type (anonymous, reflection, ...).
 396     rf_break_down_by_spacetype      = (1 << 2),
 397     // Print details about the underlying virtual spaces.
 398     rf_show_vslist                  = (1 << 3),
 399     // Print metaspace map.
 400     rf_show_vsmap                   = (1 << 4),
 401     // If show_loaders: show loaded classes for each loader.
 402     rf_show_classes                 = (1 << 5)
 403   };
 404 
 405   // This will print out a basic metaspace usage report but
 406   // unlike print_report() is guaranteed not to lock or to walk the CLDG.
 407   static void print_basic_report(outputStream* st, size_t scale);
 408 
 409   // Prints a report about the current metaspace state.
 410   // Optional parts can be enabled via flags.
 411   // Function will walk the CLDG and will lock the expand lock; if that is not
 412   // convenient, use print_basic_report() instead.
 413   static void print_report(outputStream* out, size_t scale = 0, int flags = 0);
 414 
 415   static bool has_chunk_free_list(Metaspace::MetadataType mdtype);




  85 // virtual spaces and the list of chunks in use.  Its
  86 // allocate() method returns a block for use as a
  87 // quantum of metadata.
  88 
  89 // Namespace for important central static functions
  90 // (auxiliary stuff goes into MetaspaceUtils)
  91 class Metaspace : public AllStatic {
  92 
  93   friend class MetaspaceShared;
  94 
  95  public:
  96   enum MetadataType {
  97     ClassType,
  98     NonClassType,
  99     MetadataTypeCount
 100   };
 101   enum MetaspaceType {
 102     ZeroMetaspaceType = 0,
 103     StandardMetaspaceType = ZeroMetaspaceType,
 104     BootMetaspaceType = StandardMetaspaceType + 1,
 105     ShortLivedMetaspaceType = BootMetaspaceType + 1,
 106     ReflectionMetaspaceType = ShortLivedMetaspaceType + 1,
 107     MetaspaceTypeCount
 108   };
 109 
 110  private:
 111 
 112   // Align up the word size to the allocation word size
 113   static size_t align_word_size_up(size_t);
 114 
 115   // Aligned size of the metaspace.
 116   static size_t _compressed_class_space_size;
 117 
 118   static size_t compressed_class_space_size() {
 119     return _compressed_class_space_size;
 120   }
 121 
 122   static void set_compressed_class_space_size(size_t size) {
 123     _compressed_class_space_size = size;
 124   }
 125 
 126   static size_t _first_chunk_word_size;


 225   }
 226 
 227 };
 228 
 229 // Manages the metaspace portion belonging to a class loader
 230 class ClassLoaderMetaspace : public CHeapObj<mtClass> {
 231   friend class CollectedHeap; // For expand_and_allocate()
 232   friend class ZCollectedHeap; // For expand_and_allocate()
 233   friend class ShenandoahHeap; // For expand_and_allocate()
 234   friend class Metaspace;
 235   friend class MetaspaceUtils;
 236   friend class metaspace::PrintCLDMetaspaceInfoClosure;
 237   friend class VM_CollectForMetadataAllocation; // For expand_and_allocate()
 238 
 239  private:
 240 
 241   void initialize(Mutex* lock, Metaspace::MetaspaceType type);
 242 
 243   // Initialize the first chunk for a Metaspace.  Used for
 244   // special cases such as the boot class loader, reflection
 245   // class loader and nonfindable class loader.
 246   void initialize_first_chunk(Metaspace::MetaspaceType type, Metaspace::MetadataType mdtype);
 247   metaspace::Metachunk* get_initialization_chunk(Metaspace::MetaspaceType type, Metaspace::MetadataType mdtype);
 248 
 249   const Metaspace::MetaspaceType _space_type;
 250   Mutex* const  _lock;
 251   metaspace::SpaceManager* _vsm;
 252   metaspace::SpaceManager* _class_vsm;
 253 
 254   metaspace::SpaceManager* vsm() const { return _vsm; }
 255   metaspace::SpaceManager* class_vsm() const { return _class_vsm; }
 256   metaspace::SpaceManager* get_space_manager(Metaspace::MetadataType mdtype) {
 257     assert(mdtype != Metaspace::MetadataTypeCount, "MetadaTypeCount can't be used as mdtype");
 258     return mdtype == Metaspace::ClassType ? class_vsm() : vsm();
 259   }
 260 
 261   Mutex* lock() const { return _lock; }
 262 
 263   MetaWord* expand_and_allocate(size_t size, Metaspace::MetadataType mdtype);
 264 
 265   size_t class_chunk_size(size_t word_size);


 375   static size_t reserved_bytes(Metaspace::MetadataType mdtype);
 376   static size_t reserved_bytes() {
 377     return reserved_bytes(Metaspace::ClassType) +
 378            reserved_bytes(Metaspace::NonClassType);
 379   }
 380 
 381   static size_t committed_bytes(Metaspace::MetadataType mdtype);
 382   static size_t committed_bytes() {
 383     return committed_bytes(Metaspace::ClassType) +
 384            committed_bytes(Metaspace::NonClassType);
 385   }
 386 
 387   static size_t min_chunk_size_words();
 388 
 389   // Flags for print_report().
 390   enum ReportFlag {
 391     // Show usage by class loader.
 392     rf_show_loaders                 = (1 << 0),
 393     // Breaks report down by chunk type (small, medium, ...).
 394     rf_break_down_by_chunktype      = (1 << 1),
 395     // Breaks report down by space type (nonfindable, reflection, ...).
 396     rf_break_down_by_spacetype      = (1 << 2),
 397     // Print details about the underlying virtual spaces.
 398     rf_show_vslist                  = (1 << 3),
 399     // Print metaspace map.
 400     rf_show_vsmap                   = (1 << 4),
 401     // If show_loaders: show loaded classes for each loader.
 402     rf_show_classes                 = (1 << 5)
 403   };
 404 
 405   // This will print out a basic metaspace usage report but
 406   // unlike print_report() is guaranteed not to lock or to walk the CLDG.
 407   static void print_basic_report(outputStream* st, size_t scale);
 408 
 409   // Prints a report about the current metaspace state.
 410   // Optional parts can be enabled via flags.
 411   // Function will walk the CLDG and will lock the expand lock; if that is not
 412   // convenient, use print_basic_report() instead.
 413   static void print_report(outputStream* out, size_t scale = 0, int flags = 0);
 414 
 415   static bool has_chunk_free_list(Metaspace::MetadataType mdtype);


< prev index next >