--- old/src/hotspot/share/memory/metaspace.hpp 2018-03-11 11:43:24.776251200 +0100 +++ new/src/hotspot/share/memory/metaspace.hpp 2018-03-11 11:43:24.447232400 +0100 @@ -80,16 +80,11 @@ // allocate() method returns a block for use as a // quantum of metadata. -class Metaspace : public CHeapObj { - friend class VMStructs; - friend class SpaceManager; - friend class VM_CollectForMetadataAllocation; - friend class MetaspaceGC; - friend class MetaspaceUtils; +// Namespace for important central static functions +// (auxiliary stuff goes into MetaspaceUtils) +class Metaspace : public AllStatic { + friend class MetaspaceShared; - friend class CollectedHeap; - friend class PrintCLDMetaspaceInfoClosure; - friend class MetaspaceAllocationTest; public: enum MetadataType { @@ -105,15 +100,6 @@ }; private: - static void verify_global_initialization(); - - void initialize(Mutex* lock, MetaspaceType type); - - // Initialize the first chunk for a Metaspace. Used for - // special cases such as the boot class loader, reflection - // class loader and anonymous class loader. - void initialize_first_chunk(MetaspaceType type, MetadataType mdtype); - Metachunk* get_initialization_chunk(MetaspaceType type, MetadataType mdtype); // Align up the word size to the allocation word size static size_t align_word_size_up(size_t); @@ -136,23 +122,6 @@ static size_t _reserve_alignment; DEBUG_ONLY(static bool _frozen;) - SpaceManager* _vsm; - SpaceManager* vsm() const { return _vsm; } - - SpaceManager* _class_vsm; - SpaceManager* class_vsm() const { return _class_vsm; } - SpaceManager* get_space_manager(MetadataType mdtype) { - assert(mdtype != MetadataTypeCount, "MetadaTypeCount can't be used as mdtype"); - return mdtype == ClassType ? class_vsm() : vsm(); - } - - // Allocate space for metadata of type mdtype. This is space - // within a Metachunk and is used by - // allocate(ClassLoaderData*, size_t, bool, MetadataType, TRAPS) - MetaWord* allocate(size_t word_size, MetadataType mdtype); - - MetaWord* expand_and_allocate(size_t size, MetadataType mdtype); - // Virtual Space lists for both classes and other metadata static VirtualSpaceList* _space_list; static VirtualSpaceList* _class_space_list; @@ -187,6 +156,9 @@ assert(DumpSharedSpaces, "sanity"); DEBUG_ONLY(_frozen = true;) } + static void assert_not_frozen() { + assert(!_frozen, "sanity"); + } #ifdef _LP64 static void allocate_metaspace_compressed_klass_ptrs(char* requested_addr, address cds_base); #endif @@ -201,17 +173,15 @@ static void initialize_class_space(ReservedSpace rs); #endif - size_t class_chunk_size(size_t word_size); public: - Metaspace(Mutex* lock, MetaspaceType type); - ~Metaspace(); - static void ergo_initialize(); static void global_initialize(); static void post_initialize(); + static void verify_global_initialization(); + static size_t first_chunk_word_size() { return _first_chunk_word_size; } static size_t first_class_chunk_word_size() { return _first_class_chunk_word_size; } @@ -220,16 +190,6 @@ static size_t commit_alignment() { return _commit_alignment; } static size_t commit_alignment_words() { return _commit_alignment / BytesPerWord; } - size_t used_words_slow(MetadataType mdtype) const; - size_t free_words_slow(MetadataType mdtype) const; - size_t capacity_words_slow(MetadataType mdtype) const; - - size_t used_bytes_slow(MetadataType mdtype) const; - size_t capacity_bytes_slow(MetadataType mdtype) const; - - size_t allocated_blocks_bytes() const; - size_t allocated_chunks_bytes() const; - static MetaWord* allocate(ClassLoaderData* loader_data, size_t word_size, MetaspaceObj::Type type, TRAPS); void deallocate(MetaWord* ptr, size_t byte_size, bool is_class); @@ -237,8 +197,6 @@ static bool contains(const void* ptr); static bool contains_non_shared(const void* ptr); - void dump(outputStream* const out) const; - // Free empty virtualspaces static void purge(MetadataType mdtype); static void purge(); @@ -248,10 +206,6 @@ static const char* metadata_type_name(Metaspace::MetadataType mdtype); - void print_on(outputStream* st) const; - // Debugging support - void verify(); - static void print_compressed_class_space(outputStream* st, const char* requested_addr = 0) NOT_LP64({}); // Return TRUE only if UseCompressedClassPointers is True. @@ -265,6 +219,69 @@ }; +// Manages the metaspace portion belonging to a class loader +class ClassLoaderMetaspace : public CHeapObj { + friend class CollectedHeap; // For expand_and_allocate() + friend class Metaspace; + friend class MetaspaceUtils; + friend class PrintCLDMetaspaceInfoClosure; + friend class VM_CollectForMetadataAllocation; // For expand_and_allocate() + + private: + + void initialize(Mutex* lock, Metaspace::MetaspaceType type); + + // Initialize the first chunk for a Metaspace. Used for + // special cases such as the boot class loader, reflection + // class loader and anonymous class loader. + void initialize_first_chunk(Metaspace::MetaspaceType type, Metaspace::MetadataType mdtype); + Metachunk* get_initialization_chunk(Metaspace::MetaspaceType type, Metaspace::MetadataType mdtype); + + SpaceManager* _vsm; + SpaceManager* vsm() const { return _vsm; } + + SpaceManager* _class_vsm; + SpaceManager* class_vsm() const { return _class_vsm; } + SpaceManager* get_space_manager(Metaspace::MetadataType mdtype) { + assert(mdtype != Metaspace::MetadataTypeCount, "MetadaTypeCount can't be used as mdtype"); + return mdtype == Metaspace::ClassType ? class_vsm() : vsm(); + } + + MetaWord* expand_and_allocate(size_t size, Metaspace::MetadataType mdtype); + + size_t class_chunk_size(size_t word_size); + + public: + + ClassLoaderMetaspace(Mutex* lock, Metaspace::MetaspaceType type); + ~ClassLoaderMetaspace(); + + // Allocate space for metadata of type mdtype. This is space + // within a Metachunk and is used by + // allocate(ClassLoaderData*, size_t, bool, MetadataType, TRAPS) + MetaWord* allocate(size_t word_size, Metaspace::MetadataType mdtype); + + size_t used_words_slow(Metaspace::MetadataType mdtype) const; + size_t free_words_slow(Metaspace::MetadataType mdtype) const; + size_t capacity_words_slow(Metaspace::MetadataType mdtype) const; + + size_t used_bytes_slow(Metaspace::MetadataType mdtype) const; + size_t capacity_bytes_slow(Metaspace::MetadataType mdtype) const; + + size_t allocated_blocks_bytes() const; + size_t allocated_chunks_bytes() const; + + void deallocate(MetaWord* ptr, size_t byte_size, bool is_class); + + void dump(outputStream* const out) const; + + void print_on(outputStream* st) const; + // Debugging support + void verify(); + +}; // ClassLoaderMetaspace + + class MetaspaceUtils : AllStatic { static size_t free_chunks_total_words(Metaspace::MetadataType mdtype);