src/hotspot/share/memory/metaspace.hpp
branchstuefe-improved-metaspace
changeset 57464 32e61f51ee09
parent 55586 014c8cd323af
equal deleted inserted replaced
55634:0f1e29c77e50 57464:32e61f51ee09
   191   static void global_initialize();
   191   static void global_initialize();
   192   static void post_initialize();
   192   static void post_initialize();
   193 
   193 
   194   static void verify_global_initialization();
   194   static void verify_global_initialization();
   195 
   195 
   196   static size_t first_chunk_word_size() { return _first_chunk_word_size; }
       
   197   static size_t first_class_chunk_word_size() { return _first_class_chunk_word_size; }
       
   198 
       
   199   static size_t reserve_alignment()       { return _reserve_alignment; }
   196   static size_t reserve_alignment()       { return _reserve_alignment; }
   200   static size_t reserve_alignment_words() { return _reserve_alignment / BytesPerWord; }
   197   static size_t reserve_alignment_words() { return _reserve_alignment / BytesPerWord; }
   201   static size_t commit_alignment()        { return _commit_alignment; }
   198   static size_t commit_alignment()        { return _commit_alignment; }
   202   static size_t commit_alignment_words()  { return _commit_alignment / BytesPerWord; }
   199   static size_t commit_alignment_words()  { return _commit_alignment / BytesPerWord; }
   203 
   200 
   228   }
   225   }
   229 
   226 
   230   static bool initialized() { return _initialized; }
   227   static bool initialized() { return _initialized; }
   231 
   228 
   232 };
   229 };
   233 
       
   234 // Manages the metaspace portion belonging to a class loader
       
   235 class ClassLoaderMetaspace : public CHeapObj<mtClass> {
       
   236   friend class CollectedHeap; // For expand_and_allocate()
       
   237   friend class ZCollectedHeap; // For expand_and_allocate()
       
   238   friend class ShenandoahHeap; // For expand_and_allocate()
       
   239   friend class Metaspace;
       
   240   friend class MetaspaceUtils;
       
   241   friend class metaspace::PrintCLDMetaspaceInfoClosure;
       
   242   friend class VM_CollectForMetadataAllocation; // For expand_and_allocate()
       
   243 
       
   244  private:
       
   245 
       
   246   void initialize(Mutex* lock, Metaspace::MetaspaceType type);
       
   247 
       
   248   // Initialize the first chunk for a Metaspace.  Used for
       
   249   // special cases such as the boot class loader, reflection
       
   250   // class loader and anonymous class loader.
       
   251   void initialize_first_chunk(Metaspace::MetaspaceType type, Metaspace::MetadataType mdtype);
       
   252   metaspace::Metachunk* get_initialization_chunk(Metaspace::MetaspaceType type, Metaspace::MetadataType mdtype);
       
   253 
       
   254   const Metaspace::MetaspaceType _space_type;
       
   255   Mutex* const  _lock;
       
   256   metaspace::SpaceManager* _vsm;
       
   257   metaspace::SpaceManager* _class_vsm;
       
   258 
       
   259   metaspace::SpaceManager* vsm() const { return _vsm; }
       
   260   metaspace::SpaceManager* class_vsm() const { return _class_vsm; }
       
   261   metaspace::SpaceManager* get_space_manager(Metaspace::MetadataType mdtype) {
       
   262     assert(mdtype != Metaspace::MetadataTypeCount, "MetadaTypeCount can't be used as mdtype");
       
   263     return mdtype == Metaspace::ClassType ? class_vsm() : vsm();
       
   264   }
       
   265 
       
   266   Mutex* lock() const { return _lock; }
       
   267 
       
   268   MetaWord* expand_and_allocate(size_t size, Metaspace::MetadataType mdtype);
       
   269 
       
   270   size_t class_chunk_size(size_t word_size);
       
   271 
       
   272   // Adds to the given statistic object. Must be locked with CLD metaspace lock.
       
   273   void add_to_statistics_locked(metaspace::ClassLoaderMetaspaceStatistics* out) const;
       
   274 
       
   275   Metaspace::MetaspaceType space_type() const { return _space_type; }
       
   276 
       
   277  public:
       
   278 
       
   279   ClassLoaderMetaspace(Mutex* lock, Metaspace::MetaspaceType type);
       
   280   ~ClassLoaderMetaspace();
       
   281 
       
   282   // Allocate space for metadata of type mdtype. This is space
       
   283   // within a Metachunk and is used by
       
   284   //   allocate(ClassLoaderData*, size_t, bool, MetadataType, TRAPS)
       
   285   MetaWord* allocate(size_t word_size, Metaspace::MetadataType mdtype);
       
   286 
       
   287   size_t allocated_blocks_bytes() const;
       
   288   size_t allocated_chunks_bytes() const;
       
   289 
       
   290   void deallocate(MetaWord* ptr, size_t byte_size, bool is_class);
       
   291 
       
   292   void print_on(outputStream* st) const;
       
   293   // Debugging support
       
   294   void verify();
       
   295 
       
   296   // Adds to the given statistic object. Will lock with CLD metaspace lock.
       
   297   void add_to_statistics(metaspace::ClassLoaderMetaspaceStatistics* out) const;
       
   298 
       
   299 }; // ClassLoaderMetaspace
       
   300 
   230 
   301 class MetaspaceUtils : AllStatic {
   231 class MetaspaceUtils : AllStatic {
   302 
   232 
   303   // Spacemanager updates running counters.
   233   // Spacemanager updates running counters.
   304   friend class metaspace::SpaceManager;
   234   friend class metaspace::SpaceManager;