--- old/src/hotspot/share/memory/metaspaceShared.cpp 2020-08-12 15:00:57.172541400 -0700 +++ new/src/hotspot/share/memory/metaspaceShared.cpp 2020-08-12 15:00:56.860529655 -0700 @@ -25,6 +25,7 @@ #include "precompiled.hpp" #include "jvm.h" #include "classfile/classLoaderDataGraph.hpp" +#include "classfile/classLoaderDataShared.hpp" #include "classfile/classListParser.hpp" #include "classfile/classLoaderExt.hpp" #include "classfile/dictionary.hpp" @@ -90,6 +91,7 @@ intx MetaspaceShared::_relocation_delta; char* MetaspaceShared::_requested_base_address; bool MetaspaceShared::_use_optimized_module_handling = true; +bool MetaspaceShared::_use_full_module_graph = true; // The CDS archive is divided into the following regions: // mc - misc code (the method entry trampolines, c++ vtables) @@ -240,6 +242,10 @@ return _ro_region.allocate(num_bytes); } +char* MetaspaceShared::read_write_space_alloc(size_t num_bytes) { + return _rw_region.allocate(num_bytes); +} + size_t MetaspaceShared::reserved_space_alignment() { return os::vm_allocation_granularity(); } static bool shared_base_valid(char* shared_base) { @@ -589,6 +595,8 @@ serialize_cloned_cpp_vtptrs(soc); soc->do_tag(--tag); + CDS_JAVA_HEAP_ONLY(ClassLoaderDataShared::serialize(soc)); + soc->do_tag(666); } @@ -1083,6 +1091,7 @@ f(SymbolBucket) \ f(StringHashentry) \ f(StringBucket) \ + f(ModulesNatives) \ f(Other) enum Type { @@ -1118,6 +1127,11 @@ _bytes [which][type] += byte_size; } + void record_modules(int byte_size, bool read_only) { + int which = (read_only) ? RO : RW; + _bytes [which][ModulesNativesType] += byte_size; + } + void record_other_type(int byte_size, bool read_only) { int which = (read_only) ? RO : RW; _bytes [which][OtherType] += byte_size; @@ -1407,6 +1421,13 @@ ResourceMark rm; ShallowCopier rw_copier(false); iterate_roots(&rw_copier); + +#if INCLUDE_CDS_JAVA_HEAP + // Archive the ModuleEntry's and PackageEntry's of the 3 built-in loaders + char* start = _rw_region.top(); + ClassLoaderDataShared::allocate_archived_tables(); + ArchiveCompactor::alloc_stats()->record_modules(_rw_region.top() - start, /*read_only*/false); +#endif } { // allocate and shallow-copy of RO object, immediately following the RW region @@ -1416,6 +1437,11 @@ ResourceMark rm; ShallowCopier ro_copier(true); iterate_roots(&ro_copier); +#if INCLUDE_CDS_JAVA_HEAP + char* start = _ro_region.top(); + ClassLoaderDataShared::init_archived_tables(); + ArchiveCompactor::alloc_stats()->record_modules(_ro_region.top() - start, /*read_only*/true); +#endif } { log_info(cds)("Relocating embedded pointers ... "); @@ -1510,6 +1536,13 @@ assert(klass->is_klass(), "must be"); return klass; } + + static Symbol* get_relocated_symbol(Symbol* orig_symbol) { + assert(DumpSharedSpaces, "dump time only"); + address* pp = _new_loc_table->lookup((address)orig_symbol); + assert(pp != NULL, "must be"); + return (Symbol*)(*pp); + } }; DumpAllocStats* ArchiveCompactor::_alloc_stats; @@ -1814,6 +1847,10 @@ return k; } +Symbol* MetaspaceShared::get_relocated_symbol(Symbol* orig_symbol) { + return ArchiveCompactor::get_relocated_symbol(orig_symbol); +} + class LinkSharedClassesClosure : public KlassClosure { Thread* THREAD; bool _made_progress; @@ -1928,6 +1965,12 @@ link_and_cleanup_shared_classes(CATCH); log_info(cds)("Rewriting and linking classes: done"); +#if INCLUDE_CDS_JAVA_HEAP + if (use_full_module_graph()) { + HeapShared::reset_archived_object_states(THREAD); + } +#endif + VM_PopulateDumpSharedSpace op; MutexLocker ml(THREAD, HeapShared::is_heap_object_archiving_allowed() ? Heap_lock : NULL); // needed by HeapShared::run_gc() @@ -2345,7 +2388,8 @@ static_mapinfo->map_heap_regions(); } }); - log_info(cds)("Using optimized module handling %s", MetaspaceShared::use_optimized_module_handling() ? "enabled" : "disabled"); + log_info(cds)("optimized module handling: %s", MetaspaceShared::use_optimized_module_handling() ? "enabled" : "disabled"); + log_info(cds)("full module graph: %s", MetaspaceShared::use_full_module_graph() ? "enabled" : "disabled"); } else { unmap_archive(static_mapinfo); unmap_archive(dynamic_mapinfo); @@ -2670,6 +2714,11 @@ - intx(SharedBaseAddress); // .. but the base archive is mapped at here at dump time } +bool MetaspaceShared::use_full_module_graph() { + return _use_optimized_module_handling && _use_full_module_graph && + (UseSharedSpaces || DumpSharedSpaces) && HeapShared::is_heap_object_archiving_allowed(); +} + void MetaspaceShared::print_on(outputStream* st) { if (UseSharedSpaces || DumpSharedSpaces) { st->print("CDS archive(s) mapped at: "); @@ -2692,8 +2741,3 @@ } st->cr(); } - - - - -