< prev index next >

src/hotspot/share/memory/metaspace.hpp

Print this page
rev 50187 : imported patch metaspace-split
rev 50188 : [mq]: 8176808-split-metaspace-cpp-2


  47 //               +------>||| block 0 |       |
  48 //                       ||----------        |
  49 //                       ||| block 1 |       |
  50 //                       ||----------        |
  51 //                       ||                  |
  52 //                       |-------------------|
  53 //                       |                   |
  54 //                       |                   |
  55 //                       +-------------------+
  56 //
  57 
  58 class ClassLoaderData;
  59 class MetaspaceTracer;
  60 class MetaWord;
  61 class Mutex;
  62 class outputStream;
  63 
  64 class CollectedHeap;
  65 
  66 namespace metaspace {
  67 namespace internals {
  68   class ChunkManager;
  69   class ClassLoaderMetaspaceStatistics;
  70   class Metablock;
  71   class Metachunk;
  72   class PrintCLDMetaspaceInfoClosure;
  73   class SpaceManager;
  74   class VirtualSpaceList;
  75 }}
  76 
  77 // Metaspaces each have a  SpaceManager and allocations
  78 // are done by the SpaceManager.  Allocations are done
  79 // out of the current Metachunk.  When the current Metachunk
  80 // is exhausted, the SpaceManager gets a new one from
  81 // the current VirtualSpace.  When the VirtualSpace is exhausted
  82 // the SpaceManager gets a new one.  The SpaceManager
  83 // also manages freelists of available Chunks.
  84 //
  85 // Currently the space manager maintains the list of
  86 // virtual spaces and the list of chunks in use.  Its
  87 // allocate() method returns a block for use as a
  88 // quantum of metadata.
  89 
  90 // Namespace for important central static functions
  91 // (auxiliary stuff goes into MetaspaceUtils)
  92 class Metaspace : public AllStatic {
  93 
  94   friend class MetaspaceShared;
  95 


 115 
 116   // Aligned size of the metaspace.
 117   static size_t _compressed_class_space_size;
 118 
 119   static size_t compressed_class_space_size() {
 120     return _compressed_class_space_size;
 121   }
 122 
 123   static void set_compressed_class_space_size(size_t size) {
 124     _compressed_class_space_size = size;
 125   }
 126 
 127   static size_t _first_chunk_word_size;
 128   static size_t _first_class_chunk_word_size;
 129 
 130   static size_t _commit_alignment;
 131   static size_t _reserve_alignment;
 132   DEBUG_ONLY(static bool   _frozen;)
 133 
 134   // Virtual Space lists for both classes and other metadata
 135   static metaspace::internals::VirtualSpaceList* _space_list;
 136   static metaspace::internals::VirtualSpaceList* _class_space_list;
 137 
 138   static metaspace::internals::ChunkManager* _chunk_manager_metadata;
 139   static metaspace::internals::ChunkManager* _chunk_manager_class;
 140 
 141   static const MetaspaceTracer* _tracer;
 142 
 143  public:
 144   static metaspace::internals::VirtualSpaceList* space_list()       { return _space_list; }
 145   static metaspace::internals::VirtualSpaceList* class_space_list() { return _class_space_list; }
 146   static metaspace::internals::VirtualSpaceList* get_space_list(MetadataType mdtype) {
 147     assert(mdtype != MetadataTypeCount, "MetadaTypeCount can't be used as mdtype");
 148     return mdtype == ClassType ? class_space_list() : space_list();
 149   }
 150 
 151   static metaspace::internals::ChunkManager* chunk_manager_metadata() { return _chunk_manager_metadata; }
 152   static metaspace::internals::ChunkManager* chunk_manager_class()    { return _chunk_manager_class; }
 153   static metaspace::internals::ChunkManager* get_chunk_manager(MetadataType mdtype) {
 154     assert(mdtype != MetadataTypeCount, "MetadaTypeCount can't be used as mdtype");
 155     return mdtype == ClassType ? chunk_manager_class() : chunk_manager_metadata();
 156   }
 157 
 158   // convenience function
 159   static metaspace::internals::ChunkManager* get_chunk_manager(bool is_class) {
 160     return is_class ? chunk_manager_class() : chunk_manager_metadata();
 161   }
 162 
 163   static const MetaspaceTracer* tracer() { return _tracer; }
 164   static void freeze() {
 165     assert(DumpSharedSpaces, "sanity");
 166     DEBUG_ONLY(_frozen = true;)
 167   }
 168   static void assert_not_frozen() {
 169     assert(!_frozen, "sanity");
 170   }
 171 #ifdef _LP64
 172   static void allocate_metaspace_compressed_klass_ptrs(char* requested_addr, address cds_base);
 173 #endif
 174 
 175  private:
 176 
 177 #ifdef _LP64
 178   static void set_narrow_klass_base_and_shift(address metaspace_base, address cds_base);
 179 


 215   static const char* metadata_type_name(Metaspace::MetadataType mdtype);
 216 
 217   static void print_compressed_class_space(outputStream* st, const char* requested_addr = 0) NOT_LP64({});
 218 
 219   // Return TRUE only if UseCompressedClassPointers is True.
 220   static bool using_class_space() {
 221     return NOT_LP64(false) LP64_ONLY(UseCompressedClassPointers);
 222   }
 223 
 224   static bool is_class_space_allocation(MetadataType mdType) {
 225     return mdType == ClassType && using_class_space();
 226   }
 227 
 228 };
 229 
 230 // Manages the metaspace portion belonging to a class loader
 231 class ClassLoaderMetaspace : public CHeapObj<mtClass> {
 232   friend class CollectedHeap; // For expand_and_allocate()
 233   friend class Metaspace;
 234   friend class MetaspaceUtils;
 235   friend class metaspace::internals::PrintCLDMetaspaceInfoClosure;
 236   friend class VM_CollectForMetadataAllocation; // For expand_and_allocate()
 237 
 238  private:
 239 
 240   void initialize(Mutex* lock, Metaspace::MetaspaceType type);
 241 
 242   // Initialize the first chunk for a Metaspace.  Used for
 243   // special cases such as the boot class loader, reflection
 244   // class loader and anonymous class loader.
 245   void initialize_first_chunk(Metaspace::MetaspaceType type, Metaspace::MetadataType mdtype);
 246   metaspace::internals::Metachunk* get_initialization_chunk(Metaspace::MetaspaceType type, Metaspace::MetadataType mdtype);
 247 
 248   const Metaspace::MetaspaceType _space_type;
 249   Mutex* const  _lock;
 250   metaspace::internals::SpaceManager* _vsm;
 251   metaspace::internals::SpaceManager* _class_vsm;
 252 
 253   metaspace::internals::SpaceManager* vsm() const { return _vsm; }
 254   metaspace::internals::SpaceManager* class_vsm() const { return _class_vsm; }
 255   metaspace::internals::SpaceManager* get_space_manager(Metaspace::MetadataType mdtype) {
 256     assert(mdtype != Metaspace::MetadataTypeCount, "MetadaTypeCount can't be used as mdtype");
 257     return mdtype == Metaspace::ClassType ? class_vsm() : vsm();
 258   }
 259 
 260   Mutex* lock() const { return _lock; }
 261 
 262   MetaWord* expand_and_allocate(size_t size, Metaspace::MetadataType mdtype);
 263 
 264   size_t class_chunk_size(size_t word_size);
 265 
 266   // Adds to the given statistic object. Must be locked with CLD metaspace lock.
 267   void add_to_statistics_locked(metaspace::internals::ClassLoaderMetaspaceStatistics* out) const;
 268 
 269   Metaspace::MetaspaceType space_type() const { return _space_type; }
 270 
 271  public:
 272 
 273   ClassLoaderMetaspace(Mutex* lock, Metaspace::MetaspaceType type);
 274   ~ClassLoaderMetaspace();
 275 
 276   // Allocate space for metadata of type mdtype. This is space
 277   // within a Metachunk and is used by
 278   //   allocate(ClassLoaderData*, size_t, bool, MetadataType, TRAPS)
 279   MetaWord* allocate(size_t word_size, Metaspace::MetadataType mdtype);
 280 
 281   size_t allocated_blocks_bytes() const;
 282   size_t allocated_chunks_bytes() const;
 283 
 284   void deallocate(MetaWord* ptr, size_t byte_size, bool is_class);
 285 
 286   void print_on(outputStream* st) const;
 287   // Debugging support
 288   void verify();
 289 
 290   // Adds to the given statistic object. Will lock with CLD metaspace lock.
 291   void add_to_statistics(metaspace::internals::ClassLoaderMetaspaceStatistics* out) const;
 292 
 293 }; // ClassLoaderMetaspace
 294 
 295 class MetaspaceUtils : AllStatic {
 296 
 297   // Spacemanager updates running counters.
 298   friend class metaspace::internals::SpaceManager;
 299 
 300   // Running counters for statistics concerning in-use chunks.
 301   // Note: capacity = used + free + waste + overhead. Note that we do not
 302   // count free and waste. Their sum can be deduces from the three other values.
 303   // For more details, one should call print_report() from within a safe point.
 304   static size_t _capacity_words [Metaspace:: MetadataTypeCount];
 305   static size_t _overhead_words [Metaspace:: MetadataTypeCount];
 306   static volatile size_t _used_words [Metaspace:: MetadataTypeCount];
 307 
 308   // Atomically decrement or increment in-use statistic counters
 309   static void dec_capacity(Metaspace::MetadataType mdtype, size_t words);
 310   static void inc_capacity(Metaspace::MetadataType mdtype, size_t words);
 311   static void dec_used(Metaspace::MetadataType mdtype, size_t words);
 312   static void inc_used(Metaspace::MetadataType mdtype, size_t words);
 313   static void dec_overhead(Metaspace::MetadataType mdtype, size_t words);
 314   static void inc_overhead(Metaspace::MetadataType mdtype, size_t words);
 315 
 316 
 317   // Getters for the in-use counters.
 318   static size_t capacity_words(Metaspace::MetadataType mdtype)        { return _capacity_words[mdtype]; }
 319   static size_t used_words(Metaspace::MetadataType mdtype)            { return _used_words[mdtype]; }
 320   static size_t overhead_words(Metaspace::MetadataType mdtype)        { return _overhead_words[mdtype]; }
 321 
 322   static size_t free_chunks_total_words(Metaspace::MetadataType mdtype);
 323 
 324   // Helper for print_xx_report.
 325   static void print_vs(outputStream* out, size_t scale);
 326 
 327 public:
 328 
 329   // Collect used metaspace statistics. This involves walking the CLDG. The resulting
 330   // output will be the accumulated values for all live metaspaces.
 331   // Note: method does not do any locking.
 332   static void collect_statistics(metaspace::internals::ClassLoaderMetaspaceStatistics* out);
 333 
 334   // Used by MetaspaceCounters
 335   static size_t free_chunks_total_words();
 336   static size_t free_chunks_total_bytes();
 337   static size_t free_chunks_total_bytes(Metaspace::MetadataType mdtype);
 338 
 339   static size_t capacity_words() {
 340     return capacity_words(Metaspace::NonClassType) +
 341            capacity_words(Metaspace::ClassType);
 342   }
 343   static size_t capacity_bytes(Metaspace::MetadataType mdtype) {
 344     return capacity_words(mdtype) * BytesPerWord;
 345   }
 346   static size_t capacity_bytes() {
 347     return capacity_words() * BytesPerWord;
 348   }
 349 
 350   static size_t used_words() {
 351     return used_words(Metaspace::NonClassType) +
 352            used_words(Metaspace::ClassType);




  47 //               +------>||| block 0 |       |
  48 //                       ||----------        |
  49 //                       ||| block 1 |       |
  50 //                       ||----------        |
  51 //                       ||                  |
  52 //                       |-------------------|
  53 //                       |                   |
  54 //                       |                   |
  55 //                       +-------------------+
  56 //
  57 
  58 class ClassLoaderData;
  59 class MetaspaceTracer;
  60 class MetaWord;
  61 class Mutex;
  62 class outputStream;
  63 
  64 class CollectedHeap;
  65 
  66 namespace metaspace {

  67   class ChunkManager;
  68   class ClassLoaderMetaspaceStatistics;
  69   class Metablock;
  70   class Metachunk;
  71   class PrintCLDMetaspaceInfoClosure;
  72   class SpaceManager;
  73   class VirtualSpaceList;
  74 }
  75 
  76 // Metaspaces each have a  SpaceManager and allocations
  77 // are done by the SpaceManager.  Allocations are done
  78 // out of the current Metachunk.  When the current Metachunk
  79 // is exhausted, the SpaceManager gets a new one from
  80 // the current VirtualSpace.  When the VirtualSpace is exhausted
  81 // the SpaceManager gets a new one.  The SpaceManager
  82 // also manages freelists of available Chunks.
  83 //
  84 // Currently the space manager maintains the list of
  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 


 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;
 127   static size_t _first_class_chunk_word_size;
 128 
 129   static size_t _commit_alignment;
 130   static size_t _reserve_alignment;
 131   DEBUG_ONLY(static bool   _frozen;)
 132 
 133   // Virtual Space lists for both classes and other metadata
 134   static metaspace::VirtualSpaceList* _space_list;
 135   static metaspace::VirtualSpaceList* _class_space_list;
 136 
 137   static metaspace::ChunkManager* _chunk_manager_metadata;
 138   static metaspace::ChunkManager* _chunk_manager_class;
 139 
 140   static const MetaspaceTracer* _tracer;
 141 
 142  public:
 143   static metaspace::VirtualSpaceList* space_list()       { return _space_list; }
 144   static metaspace::VirtualSpaceList* class_space_list() { return _class_space_list; }
 145   static metaspace::VirtualSpaceList* get_space_list(MetadataType mdtype) {
 146     assert(mdtype != MetadataTypeCount, "MetadaTypeCount can't be used as mdtype");
 147     return mdtype == ClassType ? class_space_list() : space_list();
 148   }
 149 
 150   static metaspace::ChunkManager* chunk_manager_metadata() { return _chunk_manager_metadata; }
 151   static metaspace::ChunkManager* chunk_manager_class()    { return _chunk_manager_class; }
 152   static metaspace::ChunkManager* get_chunk_manager(MetadataType mdtype) {
 153     assert(mdtype != MetadataTypeCount, "MetadaTypeCount can't be used as mdtype");
 154     return mdtype == ClassType ? chunk_manager_class() : chunk_manager_metadata();
 155   }
 156 
 157   // convenience function
 158   static metaspace::ChunkManager* get_chunk_manager(bool is_class) {
 159     return is_class ? chunk_manager_class() : chunk_manager_metadata();
 160   }
 161 
 162   static const MetaspaceTracer* tracer() { return _tracer; }
 163   static void freeze() {
 164     assert(DumpSharedSpaces, "sanity");
 165     DEBUG_ONLY(_frozen = true;)
 166   }
 167   static void assert_not_frozen() {
 168     assert(!_frozen, "sanity");
 169   }
 170 #ifdef _LP64
 171   static void allocate_metaspace_compressed_klass_ptrs(char* requested_addr, address cds_base);
 172 #endif
 173 
 174  private:
 175 
 176 #ifdef _LP64
 177   static void set_narrow_klass_base_and_shift(address metaspace_base, address cds_base);
 178 


 214   static const char* metadata_type_name(Metaspace::MetadataType mdtype);
 215 
 216   static void print_compressed_class_space(outputStream* st, const char* requested_addr = 0) NOT_LP64({});
 217 
 218   // Return TRUE only if UseCompressedClassPointers is True.
 219   static bool using_class_space() {
 220     return NOT_LP64(false) LP64_ONLY(UseCompressedClassPointers);
 221   }
 222 
 223   static bool is_class_space_allocation(MetadataType mdType) {
 224     return mdType == ClassType && using_class_space();
 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 Metaspace;
 233   friend class MetaspaceUtils;
 234   friend class metaspace::PrintCLDMetaspaceInfoClosure;
 235   friend class VM_CollectForMetadataAllocation; // For expand_and_allocate()
 236 
 237  private:
 238 
 239   void initialize(Mutex* lock, Metaspace::MetaspaceType type);
 240 
 241   // Initialize the first chunk for a Metaspace.  Used for
 242   // special cases such as the boot class loader, reflection
 243   // class loader and anonymous class loader.
 244   void initialize_first_chunk(Metaspace::MetaspaceType type, Metaspace::MetadataType mdtype);
 245   metaspace::Metachunk* get_initialization_chunk(Metaspace::MetaspaceType type, Metaspace::MetadataType mdtype);
 246 
 247   const Metaspace::MetaspaceType _space_type;
 248   Mutex* const  _lock;
 249   metaspace::SpaceManager* _vsm;
 250   metaspace::SpaceManager* _class_vsm;
 251 
 252   metaspace::SpaceManager* vsm() const { return _vsm; }
 253   metaspace::SpaceManager* class_vsm() const { return _class_vsm; }
 254   metaspace::SpaceManager* get_space_manager(Metaspace::MetadataType mdtype) {
 255     assert(mdtype != Metaspace::MetadataTypeCount, "MetadaTypeCount can't be used as mdtype");
 256     return mdtype == Metaspace::ClassType ? class_vsm() : vsm();
 257   }
 258 
 259   Mutex* lock() const { return _lock; }
 260 
 261   MetaWord* expand_and_allocate(size_t size, Metaspace::MetadataType mdtype);
 262 
 263   size_t class_chunk_size(size_t word_size);
 264 
 265   // Adds to the given statistic object. Must be locked with CLD metaspace lock.
 266   void add_to_statistics_locked(metaspace::ClassLoaderMetaspaceStatistics* out) const;
 267 
 268   Metaspace::MetaspaceType space_type() const { return _space_type; }
 269 
 270  public:
 271 
 272   ClassLoaderMetaspace(Mutex* lock, Metaspace::MetaspaceType type);
 273   ~ClassLoaderMetaspace();
 274 
 275   // Allocate space for metadata of type mdtype. This is space
 276   // within a Metachunk and is used by
 277   //   allocate(ClassLoaderData*, size_t, bool, MetadataType, TRAPS)
 278   MetaWord* allocate(size_t word_size, Metaspace::MetadataType mdtype);
 279 
 280   size_t allocated_blocks_bytes() const;
 281   size_t allocated_chunks_bytes() const;
 282 
 283   void deallocate(MetaWord* ptr, size_t byte_size, bool is_class);
 284 
 285   void print_on(outputStream* st) const;
 286   // Debugging support
 287   void verify();
 288 
 289   // Adds to the given statistic object. Will lock with CLD metaspace lock.
 290   void add_to_statistics(metaspace::ClassLoaderMetaspaceStatistics* out) const;
 291 
 292 }; // ClassLoaderMetaspace
 293 
 294 class MetaspaceUtils : AllStatic {
 295 
 296   // Spacemanager updates running counters.
 297   friend class metaspace::SpaceManager;
 298 
 299   // Running counters for statistics concerning in-use chunks.
 300   // Note: capacity = used + free + waste + overhead. Note that we do not
 301   // count free and waste. Their sum can be deduces from the three other values.
 302   // For more details, one should call print_report() from within a safe point.
 303   static size_t _capacity_words [Metaspace:: MetadataTypeCount];
 304   static size_t _overhead_words [Metaspace:: MetadataTypeCount];
 305   static volatile size_t _used_words [Metaspace:: MetadataTypeCount];
 306 
 307   // Atomically decrement or increment in-use statistic counters
 308   static void dec_capacity(Metaspace::MetadataType mdtype, size_t words);
 309   static void inc_capacity(Metaspace::MetadataType mdtype, size_t words);
 310   static void dec_used(Metaspace::MetadataType mdtype, size_t words);
 311   static void inc_used(Metaspace::MetadataType mdtype, size_t words);
 312   static void dec_overhead(Metaspace::MetadataType mdtype, size_t words);
 313   static void inc_overhead(Metaspace::MetadataType mdtype, size_t words);
 314 
 315 
 316   // Getters for the in-use counters.
 317   static size_t capacity_words(Metaspace::MetadataType mdtype)        { return _capacity_words[mdtype]; }
 318   static size_t used_words(Metaspace::MetadataType mdtype)            { return _used_words[mdtype]; }
 319   static size_t overhead_words(Metaspace::MetadataType mdtype)        { return _overhead_words[mdtype]; }
 320 
 321   static size_t free_chunks_total_words(Metaspace::MetadataType mdtype);
 322 
 323   // Helper for print_xx_report.
 324   static void print_vs(outputStream* out, size_t scale);
 325 
 326 public:
 327 
 328   // Collect used metaspace statistics. This involves walking the CLDG. The resulting
 329   // output will be the accumulated values for all live metaspaces.
 330   // Note: method does not do any locking.
 331   static void collect_statistics(metaspace::ClassLoaderMetaspaceStatistics* out);
 332 
 333   // Used by MetaspaceCounters
 334   static size_t free_chunks_total_words();
 335   static size_t free_chunks_total_bytes();
 336   static size_t free_chunks_total_bytes(Metaspace::MetadataType mdtype);
 337 
 338   static size_t capacity_words() {
 339     return capacity_words(Metaspace::NonClassType) +
 340            capacity_words(Metaspace::ClassType);
 341   }
 342   static size_t capacity_bytes(Metaspace::MetadataType mdtype) {
 343     return capacity_words(mdtype) * BytesPerWord;
 344   }
 345   static size_t capacity_bytes() {
 346     return capacity_words() * BytesPerWord;
 347   }
 348 
 349   static size_t used_words() {
 350     return used_words(Metaspace::NonClassType) +
 351            used_words(Metaspace::ClassType);


< prev index next >