< prev index next >

src/hotspot/share/memory/metaspace.hpp

Print this page
rev 50187 : imported patch metaspace-split


  38 //
  39 //    block X ---+       +-------------------+
  40 //               |       |  Virtualspace     |
  41 //               |       |                   |
  42 //               |       |                   |
  43 //               |       |-------------------|
  44 //               |       || Chunk            |
  45 //               |       ||                  |
  46 //               |       ||----------        |
  47 //               +------>||| block 0 |       |
  48 //                       ||----------        |
  49 //                       ||| block 1 |       |
  50 //                       ||----------        |
  51 //                       ||                  |
  52 //                       |-------------------|
  53 //                       |                   |
  54 //                       |                   |
  55 //                       +-------------------+
  56 //
  57 
  58 class ChunkManager;
  59 class ClassLoaderData;
  60 class Metablock;
  61 class Metachunk;
  62 class MetaspaceTracer;
  63 class MetaWord;
  64 class Mutex;
  65 class outputStream;
  66 class PrintCLDMetaspaceInfoClosure;
  67 class SpaceManager;
  68 class VirtualSpaceList;
  69 class CollectedHeap;
  70 
  71 namespace metaspace {
  72 namespace internals {
  73   class ClassLoaderMetaspaceStatistics;
  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 VirtualSpaceList* _space_list;
 135   static VirtualSpaceList* _class_space_list;
 136 
 137   static ChunkManager* _chunk_manager_metadata;
 138   static ChunkManager* _chunk_manager_class;
 139 
 140   static const MetaspaceTracer* _tracer;
 141 
 142  public:
 143   static VirtualSpaceList* space_list()       { return _space_list; }
 144   static VirtualSpaceList* class_space_list() { return _class_space_list; }
 145   static 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 ChunkManager* chunk_manager_metadata() { return _chunk_manager_metadata; }
 151   static ChunkManager* chunk_manager_class()    { return _chunk_manager_class; }
 152   static 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 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 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   Metachunk* get_initialization_chunk(Metaspace::MetaspaceType type, Metaspace::MetadataType mdtype);
 246 
 247   const Metaspace::MetaspaceType _space_type;
 248   Mutex* const  _lock;
 249   SpaceManager* _vsm;
 250   SpaceManager* _class_vsm;
 251 
 252   SpaceManager* vsm() const { return _vsm; }
 253   SpaceManager* class_vsm() const { return _class_vsm; }
 254   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::internals::ClassLoaderMetaspaceStatistics* out) const;


 267 
 268  public:
 269 
 270   ClassLoaderMetaspace(Mutex* lock, Metaspace::MetaspaceType type);
 271   ~ClassLoaderMetaspace();
 272 
 273   Metaspace::MetaspaceType space_type() const { return _space_type; }
 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::internals::ClassLoaderMetaspaceStatistics* out) const;
 291 
 292 }; // ClassLoaderMetaspace
 293 
 294 class MetaspaceUtils : AllStatic {
 295 
 296   // Spacemanager updates running counters.
 297   friend class 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::internals::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);




  38 //
  39 //    block X ---+       +-------------------+
  40 //               |       |  Virtualspace     |
  41 //               |       |                   |
  42 //               |       |                   |
  43 //               |       |-------------------|
  44 //               |       || Chunk            |
  45 //               |       ||                  |
  46 //               |       ||----------        |
  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 >