< prev index next >

src/hotspot/share/cds/metaspaceShared.cpp

Print this page

  60 #include "classfile/systemDictionaryShared.hpp"
  61 #include "classfile/vmClasses.hpp"
  62 #include "classfile/vmSymbols.hpp"
  63 #include "code/aotCodeCache.hpp"
  64 #include "code/codeCache.hpp"
  65 #include "gc/shared/gcVMOperations.hpp"
  66 #include "interpreter/bytecodeStream.hpp"
  67 #include "interpreter/bytecodes.hpp"
  68 #include "jvm_io.h"
  69 #include "logging/log.hpp"
  70 #include "logging/logMessage.hpp"
  71 #include "logging/logStream.hpp"
  72 #include "memory/memoryReserver.hpp"
  73 #include "memory/metaspace.hpp"
  74 #include "memory/metaspaceClosure.hpp"
  75 #include "memory/oopFactory.hpp"
  76 #include "memory/resourceArea.hpp"
  77 #include "memory/universe.hpp"
  78 #include "nmt/memTracker.hpp"
  79 #include "oops/compressedKlass.hpp"


  80 #include "oops/instanceMirrorKlass.hpp"
  81 #include "oops/klass.inline.hpp"
  82 #include "oops/objArrayOop.hpp"
  83 #include "oops/oop.inline.hpp"
  84 #include "oops/oopHandle.hpp"
  85 #include "oops/trainingData.hpp"
  86 #include "prims/jvmtiExport.hpp"
  87 #include "runtime/arguments.hpp"
  88 #include "runtime/globals.hpp"
  89 #include "runtime/globals_extension.hpp"
  90 #include "runtime/handles.inline.hpp"
  91 #include "runtime/javaCalls.hpp"
  92 #include "runtime/os.inline.hpp"
  93 #include "runtime/safepointVerifiers.hpp"
  94 #include "runtime/sharedRuntime.hpp"
  95 #include "runtime/vmOperations.hpp"
  96 #include "runtime/vmThread.hpp"
  97 #include "sanitizers/leak.hpp"
  98 #include "utilities/align.hpp"
  99 #include "utilities/bitMap.inline.hpp"

 107 ReservedSpace MetaspaceShared::_symbol_rs;
 108 VirtualSpace MetaspaceShared::_symbol_vs;
 109 bool MetaspaceShared::_archive_loading_failed = false;
 110 bool MetaspaceShared::_remapped_readwrite = false;
 111 void* MetaspaceShared::_shared_metaspace_static_top = nullptr;
 112 intx MetaspaceShared::_relocation_delta;
 113 char* MetaspaceShared::_requested_base_address;
 114 Array<Method*>* MetaspaceShared::_archived_method_handle_intrinsics = nullptr;
 115 bool MetaspaceShared::_use_optimized_module_handling = true;
 116 
 117 // The CDS archive is divided into the following regions:
 118 //     rw  - read-write metadata
 119 //     ro  - read-only metadata and read-only tables
 120 //     hp  - heap region
 121 //     bm  - bitmap for relocating the above 7 regions.
 122 //
 123 // The rw and ro regions are linearly allocated, in the order of rw->ro.
 124 // These regions are aligned with MetaspaceShared::core_region_alignment().
 125 //
 126 // These 2 regions are populated in the following steps:
 127 // [0] All classes are loaded in MetaspaceShared::preload_classes(). All metadata are
 128 //     temporarily allocated outside of the shared regions.
 129 // [1] We enter a safepoint and allocate a buffer for the rw/ro regions.
 130 // [2] C++ vtables are copied into the rw region.
 131 // [3] ArchiveBuilder copies RW metadata into the rw region.
 132 // [4] ArchiveBuilder copies RO metadata into the ro region.
 133 // [5] SymbolTable, StringTable, SystemDictionary, and a few other read-only data
 134 //     are copied into the ro region as read-only tables.
 135 //
 136 // The heap region is written by HeapShared::write_heap().
 137 //
 138 // The bitmap region is used to relocate the ro/rw/hp regions.
 139 
 140 static DumpRegion _symbol_region("symbols");
 141 
 142 char* MetaspaceShared::symbol_space_alloc(size_t num_bytes) {
 143   return _symbol_region.allocate(num_bytes);
 144 }
 145 
 146 // os::vm_allocation_granularity() is usually 4K for most OSes. However, some platforms
 147 // such as linux-aarch64 and macos-x64 ...

 443 // MetaspaceShared::early_serialize(). Such functions must not produce side effects that
 444 // assume we will always decides to map the archive.
 445 
 446 void MetaspaceShared::early_serialize(SerializeClosure* soc) {
 447   int tag = 0;
 448   soc->do_tag(--tag);
 449   CDS_JAVA_HEAP_ONLY(Modules::serialize_archived_module_info(soc);)
 450   soc->do_tag(666);
 451 }
 452 
 453 void MetaspaceShared::serialize(SerializeClosure* soc) {
 454   int tag = 0;
 455   soc->do_tag(--tag);
 456 
 457   // Verify the sizes of various metadata in the system.
 458   soc->do_tag(sizeof(Method));
 459   soc->do_tag(sizeof(ConstMethod));
 460   soc->do_tag(arrayOopDesc::base_offset_in_bytes(T_BYTE));
 461   soc->do_tag(sizeof(ConstantPool));
 462   soc->do_tag(sizeof(ConstantPoolCache));
 463   soc->do_tag(objArrayOopDesc::base_offset_in_bytes());
 464   soc->do_tag(typeArrayOopDesc::base_offset_in_bytes(T_BYTE));
 465   soc->do_tag(sizeof(Symbol));
 466 
 467   // Need to do this first, as subsequent steps may call virtual functions
 468   // in archived Metadata objects.
 469   CppVtables::serialize(soc);
 470   soc->do_tag(--tag);
 471 
 472   // Dump/restore miscellaneous metadata.
 473   JavaClasses::serialize_offsets(soc);
 474   Universe::serialize(soc);
 475   soc->do_tag(--tag);
 476 
 477   // Dump/restore references to commonly used names and signatures.
 478   vmSymbols::serialize(soc);
 479   soc->do_tag(--tag);
 480 
 481   // Dump/restore the symbol/string/subgraph_info tables
 482   SymbolTable::serialize_shared_table_header(soc);
 483   StringTable::serialize_shared_table_header(soc);

 858     log_debug(aot)("Setting MinHeapSize to 4G for CDS dumping, original size = %zuM", MinHeapSize/M);
 859     FLAG_SET_ERGO(MinHeapSize, max_heap_size);
 860   }
 861   if (InitialHeapSize > max_heap_size) {
 862     log_debug(aot)("Setting InitialHeapSize to 4G for CDS dumping, original size = %zuM", InitialHeapSize/M);
 863     FLAG_SET_ERGO(InitialHeapSize, max_heap_size);
 864   }
 865   if (MaxHeapSize > max_heap_size) {
 866     log_debug(aot)("Setting MaxHeapSize to 4G for CDS dumping, original size = %zuM", MaxHeapSize/M);
 867     FLAG_SET_ERGO(MaxHeapSize, max_heap_size);
 868   }
 869 }
 870 #endif // INCLUDE_CDS_JAVA_HEAP && _LP64
 871 
 872 void MetaspaceShared::get_default_classlist(char* default_classlist, const size_t buf_size) {
 873   const char* filesep = os::file_separator();
 874   jio_snprintf(default_classlist, buf_size, "%s%slib%sclasslist",
 875                Arguments::get_java_home(), filesep, filesep);
 876 }
 877 
 878 void MetaspaceShared::preload_classes(TRAPS) {
 879   char default_classlist[JVM_MAXPATHLEN];
 880   const char* classlist_path;
 881 
 882   get_default_classlist(default_classlist, JVM_MAXPATHLEN);
 883   if (SharedClassListFile == nullptr) {
 884     classlist_path = default_classlist;
 885   } else {
 886     classlist_path = SharedClassListFile;
 887   }
 888 
 889   aot_log_info(aot)("Loading classes to share ...");
 890   ClassListParser::parse_classlist(classlist_path,
 891                                    ClassListParser::_parse_all, CHECK);
 892   if (ExtraSharedClassListFile) {
 893     ClassListParser::parse_classlist(ExtraSharedClassListFile,
 894                                      ClassListParser::_parse_all, CHECK);
 895   }
 896   if (classlist_path != default_classlist) {
 897     struct stat statbuf;
 898     if (os::stat(default_classlist, &statbuf) == 0) {

 905   // Some classes are used at CDS runtime but are not loaded, and therefore archived, at
 906   // dumptime. We can perform dummmy calls to these classes at dumptime to ensure they
 907   // are archived.
 908   exercise_runtime_cds_code(CHECK);
 909 
 910   aot_log_info(aot)("Loading classes to share: done.");
 911 }
 912 
 913 void MetaspaceShared::exercise_runtime_cds_code(TRAPS) {
 914   // Exercise the manifest processing code
 915   const char* dummy = "Manifest-Version: 1.0\n";
 916   CDSProtectionDomain::create_jar_manifest(dummy, strlen(dummy), CHECK);
 917 
 918   // Exercise FileSystem and URL code
 919   CDSProtectionDomain::to_file_URL("dummy.jar", Handle(), CHECK);
 920 }
 921 
 922 void MetaspaceShared::preload_and_dump_impl(StaticArchiveBuilder& builder, TRAPS) {
 923   if (CDSConfig::is_dumping_classic_static_archive()) {
 924     // We are running with -Xshare:dump
 925     preload_classes(CHECK);
 926 
 927     if (SharedArchiveConfigFile) {
 928       log_info(aot)("Reading extra data from %s ...", SharedArchiveConfigFile);
 929       read_extra_data(THREAD, SharedArchiveConfigFile);
 930       log_info(aot)("Reading extra data: done.");
 931     }
 932   }
 933 
 934   if (CDSConfig::is_dumping_preimage_static_archive()) {
 935     log_info(aot)("Reading lambda form invokers from JDK default classlist ...");
 936     char default_classlist[JVM_MAXPATHLEN];
 937     get_default_classlist(default_classlist, JVM_MAXPATHLEN);
 938     struct stat statbuf;
 939     if (os::stat(default_classlist, &statbuf) == 0) {
 940       ClassListParser::parse_classlist(default_classlist,
 941                                        ClassListParser::_parse_lambda_forms_invokers_only, CHECK);
 942     }
 943   }
 944 
 945 #if INCLUDE_CDS_JAVA_HEAP

1210     }
1211     ik->link_class(THREAD);
1212     if (HAS_PENDING_EXCEPTION) {
1213       ResourceMark rm(THREAD);
1214       aot_log_warning(aot)("Preload Warning: Verification failed for %s",
1215                     ik->external_name());
1216       CLEAR_PENDING_EXCEPTION;
1217       SystemDictionaryShared::set_class_has_failed_verification(ik);
1218     } else {
1219       assert(!SystemDictionaryShared::has_class_failed_verification(ik), "sanity");
1220       ik->compute_has_loops_flag_for_methods();
1221     }
1222     BytecodeVerificationLocal = saved;
1223     return true;
1224   } else {
1225     return false;
1226   }
1227 }
1228 
1229 void VM_PopulateDumpSharedSpace::dump_java_heap_objects() {





1230   if (CDSConfig::is_dumping_heap()) {
1231     HeapShared::write_heap(&_heap_info);
1232   } else {
1233     CDSConfig::log_reasons_for_not_dumping_heap();
1234   }
1235 }
1236 
1237 void MetaspaceShared::set_shared_metaspace_range(void* base, void *static_top, void* top) {
1238   assert(base <= static_top && static_top <= top, "must be");
1239   _shared_metaspace_static_top = static_top;
1240   MetaspaceObj::set_shared_metaspace_range(base, top);
1241 }
1242 
1243 bool MetaspaceShared::is_shared_dynamic(void* p) {
1244   if ((p < MetaspaceObj::shared_metaspace_top()) &&
1245       (p >= _shared_metaspace_static_top)) {
1246     return true;
1247   } else {
1248     return false;
1249   }

  60 #include "classfile/systemDictionaryShared.hpp"
  61 #include "classfile/vmClasses.hpp"
  62 #include "classfile/vmSymbols.hpp"
  63 #include "code/aotCodeCache.hpp"
  64 #include "code/codeCache.hpp"
  65 #include "gc/shared/gcVMOperations.hpp"
  66 #include "interpreter/bytecodeStream.hpp"
  67 #include "interpreter/bytecodes.hpp"
  68 #include "jvm_io.h"
  69 #include "logging/log.hpp"
  70 #include "logging/logMessage.hpp"
  71 #include "logging/logStream.hpp"
  72 #include "memory/memoryReserver.hpp"
  73 #include "memory/metaspace.hpp"
  74 #include "memory/metaspaceClosure.hpp"
  75 #include "memory/oopFactory.hpp"
  76 #include "memory/resourceArea.hpp"
  77 #include "memory/universe.hpp"
  78 #include "nmt/memTracker.hpp"
  79 #include "oops/compressedKlass.hpp"
  80 #include "oops/flatArrayKlass.hpp"
  81 #include "oops/inlineKlass.hpp"
  82 #include "oops/instanceMirrorKlass.hpp"
  83 #include "oops/klass.inline.hpp"
  84 #include "oops/objArrayOop.hpp"
  85 #include "oops/oop.inline.hpp"
  86 #include "oops/oopHandle.hpp"
  87 #include "oops/trainingData.hpp"
  88 #include "prims/jvmtiExport.hpp"
  89 #include "runtime/arguments.hpp"
  90 #include "runtime/globals.hpp"
  91 #include "runtime/globals_extension.hpp"
  92 #include "runtime/handles.inline.hpp"
  93 #include "runtime/javaCalls.hpp"
  94 #include "runtime/os.inline.hpp"
  95 #include "runtime/safepointVerifiers.hpp"
  96 #include "runtime/sharedRuntime.hpp"
  97 #include "runtime/vmOperations.hpp"
  98 #include "runtime/vmThread.hpp"
  99 #include "sanitizers/leak.hpp"
 100 #include "utilities/align.hpp"
 101 #include "utilities/bitMap.inline.hpp"

 109 ReservedSpace MetaspaceShared::_symbol_rs;
 110 VirtualSpace MetaspaceShared::_symbol_vs;
 111 bool MetaspaceShared::_archive_loading_failed = false;
 112 bool MetaspaceShared::_remapped_readwrite = false;
 113 void* MetaspaceShared::_shared_metaspace_static_top = nullptr;
 114 intx MetaspaceShared::_relocation_delta;
 115 char* MetaspaceShared::_requested_base_address;
 116 Array<Method*>* MetaspaceShared::_archived_method_handle_intrinsics = nullptr;
 117 bool MetaspaceShared::_use_optimized_module_handling = true;
 118 
 119 // The CDS archive is divided into the following regions:
 120 //     rw  - read-write metadata
 121 //     ro  - read-only metadata and read-only tables
 122 //     hp  - heap region
 123 //     bm  - bitmap for relocating the above 7 regions.
 124 //
 125 // The rw and ro regions are linearly allocated, in the order of rw->ro.
 126 // These regions are aligned with MetaspaceShared::core_region_alignment().
 127 //
 128 // These 2 regions are populated in the following steps:
 129 // [0] All classes are loaded in MetaspaceShared::loadable_descriptors(). All metadata are
 130 //     temporarily allocated outside of the shared regions.
 131 // [1] We enter a safepoint and allocate a buffer for the rw/ro regions.
 132 // [2] C++ vtables are copied into the rw region.
 133 // [3] ArchiveBuilder copies RW metadata into the rw region.
 134 // [4] ArchiveBuilder copies RO metadata into the ro region.
 135 // [5] SymbolTable, StringTable, SystemDictionary, and a few other read-only data
 136 //     are copied into the ro region as read-only tables.
 137 //
 138 // The heap region is written by HeapShared::write_heap().
 139 //
 140 // The bitmap region is used to relocate the ro/rw/hp regions.
 141 
 142 static DumpRegion _symbol_region("symbols");
 143 
 144 char* MetaspaceShared::symbol_space_alloc(size_t num_bytes) {
 145   return _symbol_region.allocate(num_bytes);
 146 }
 147 
 148 // os::vm_allocation_granularity() is usually 4K for most OSes. However, some platforms
 149 // such as linux-aarch64 and macos-x64 ...

 445 // MetaspaceShared::early_serialize(). Such functions must not produce side effects that
 446 // assume we will always decides to map the archive.
 447 
 448 void MetaspaceShared::early_serialize(SerializeClosure* soc) {
 449   int tag = 0;
 450   soc->do_tag(--tag);
 451   CDS_JAVA_HEAP_ONLY(Modules::serialize_archived_module_info(soc);)
 452   soc->do_tag(666);
 453 }
 454 
 455 void MetaspaceShared::serialize(SerializeClosure* soc) {
 456   int tag = 0;
 457   soc->do_tag(--tag);
 458 
 459   // Verify the sizes of various metadata in the system.
 460   soc->do_tag(sizeof(Method));
 461   soc->do_tag(sizeof(ConstMethod));
 462   soc->do_tag(arrayOopDesc::base_offset_in_bytes(T_BYTE));
 463   soc->do_tag(sizeof(ConstantPool));
 464   soc->do_tag(sizeof(ConstantPoolCache));
 465   soc->do_tag(refArrayOopDesc::base_offset_in_bytes());
 466   soc->do_tag(typeArrayOopDesc::base_offset_in_bytes(T_BYTE));
 467   soc->do_tag(sizeof(Symbol));
 468 
 469   // Need to do this first, as subsequent steps may call virtual functions
 470   // in archived Metadata objects.
 471   CppVtables::serialize(soc);
 472   soc->do_tag(--tag);
 473 
 474   // Dump/restore miscellaneous metadata.
 475   JavaClasses::serialize_offsets(soc);
 476   Universe::serialize(soc);
 477   soc->do_tag(--tag);
 478 
 479   // Dump/restore references to commonly used names and signatures.
 480   vmSymbols::serialize(soc);
 481   soc->do_tag(--tag);
 482 
 483   // Dump/restore the symbol/string/subgraph_info tables
 484   SymbolTable::serialize_shared_table_header(soc);
 485   StringTable::serialize_shared_table_header(soc);

 860     log_debug(aot)("Setting MinHeapSize to 4G for CDS dumping, original size = %zuM", MinHeapSize/M);
 861     FLAG_SET_ERGO(MinHeapSize, max_heap_size);
 862   }
 863   if (InitialHeapSize > max_heap_size) {
 864     log_debug(aot)("Setting InitialHeapSize to 4G for CDS dumping, original size = %zuM", InitialHeapSize/M);
 865     FLAG_SET_ERGO(InitialHeapSize, max_heap_size);
 866   }
 867   if (MaxHeapSize > max_heap_size) {
 868     log_debug(aot)("Setting MaxHeapSize to 4G for CDS dumping, original size = %zuM", MaxHeapSize/M);
 869     FLAG_SET_ERGO(MaxHeapSize, max_heap_size);
 870   }
 871 }
 872 #endif // INCLUDE_CDS_JAVA_HEAP && _LP64
 873 
 874 void MetaspaceShared::get_default_classlist(char* default_classlist, const size_t buf_size) {
 875   const char* filesep = os::file_separator();
 876   jio_snprintf(default_classlist, buf_size, "%s%slib%sclasslist",
 877                Arguments::get_java_home(), filesep, filesep);
 878 }
 879 
 880 void MetaspaceShared::loadable_descriptors(TRAPS) {
 881   char default_classlist[JVM_MAXPATHLEN];
 882   const char* classlist_path;
 883 
 884   get_default_classlist(default_classlist, JVM_MAXPATHLEN);
 885   if (SharedClassListFile == nullptr) {
 886     classlist_path = default_classlist;
 887   } else {
 888     classlist_path = SharedClassListFile;
 889   }
 890 
 891   aot_log_info(aot)("Loading classes to share ...");
 892   ClassListParser::parse_classlist(classlist_path,
 893                                    ClassListParser::_parse_all, CHECK);
 894   if (ExtraSharedClassListFile) {
 895     ClassListParser::parse_classlist(ExtraSharedClassListFile,
 896                                      ClassListParser::_parse_all, CHECK);
 897   }
 898   if (classlist_path != default_classlist) {
 899     struct stat statbuf;
 900     if (os::stat(default_classlist, &statbuf) == 0) {

 907   // Some classes are used at CDS runtime but are not loaded, and therefore archived, at
 908   // dumptime. We can perform dummmy calls to these classes at dumptime to ensure they
 909   // are archived.
 910   exercise_runtime_cds_code(CHECK);
 911 
 912   aot_log_info(aot)("Loading classes to share: done.");
 913 }
 914 
 915 void MetaspaceShared::exercise_runtime_cds_code(TRAPS) {
 916   // Exercise the manifest processing code
 917   const char* dummy = "Manifest-Version: 1.0\n";
 918   CDSProtectionDomain::create_jar_manifest(dummy, strlen(dummy), CHECK);
 919 
 920   // Exercise FileSystem and URL code
 921   CDSProtectionDomain::to_file_URL("dummy.jar", Handle(), CHECK);
 922 }
 923 
 924 void MetaspaceShared::preload_and_dump_impl(StaticArchiveBuilder& builder, TRAPS) {
 925   if (CDSConfig::is_dumping_classic_static_archive()) {
 926     // We are running with -Xshare:dump
 927     loadable_descriptors(CHECK);
 928 
 929     if (SharedArchiveConfigFile) {
 930       log_info(aot)("Reading extra data from %s ...", SharedArchiveConfigFile);
 931       read_extra_data(THREAD, SharedArchiveConfigFile);
 932       log_info(aot)("Reading extra data: done.");
 933     }
 934   }
 935 
 936   if (CDSConfig::is_dumping_preimage_static_archive()) {
 937     log_info(aot)("Reading lambda form invokers from JDK default classlist ...");
 938     char default_classlist[JVM_MAXPATHLEN];
 939     get_default_classlist(default_classlist, JVM_MAXPATHLEN);
 940     struct stat statbuf;
 941     if (os::stat(default_classlist, &statbuf) == 0) {
 942       ClassListParser::parse_classlist(default_classlist,
 943                                        ClassListParser::_parse_lambda_forms_invokers_only, CHECK);
 944     }
 945   }
 946 
 947 #if INCLUDE_CDS_JAVA_HEAP

1212     }
1213     ik->link_class(THREAD);
1214     if (HAS_PENDING_EXCEPTION) {
1215       ResourceMark rm(THREAD);
1216       aot_log_warning(aot)("Preload Warning: Verification failed for %s",
1217                     ik->external_name());
1218       CLEAR_PENDING_EXCEPTION;
1219       SystemDictionaryShared::set_class_has_failed_verification(ik);
1220     } else {
1221       assert(!SystemDictionaryShared::has_class_failed_verification(ik), "sanity");
1222       ik->compute_has_loops_flag_for_methods();
1223     }
1224     BytecodeVerificationLocal = saved;
1225     return true;
1226   } else {
1227     return false;
1228   }
1229 }
1230 
1231 void VM_PopulateDumpSharedSpace::dump_java_heap_objects() {
1232   if (CDSConfig::is_valhalla_preview()) {
1233     log_info(cds)("Archived java heap is not yet supported with Valhalla preview");
1234     return;
1235   }
1236 
1237   if (CDSConfig::is_dumping_heap()) {
1238     HeapShared::write_heap(&_heap_info);
1239   } else {
1240     CDSConfig::log_reasons_for_not_dumping_heap();
1241   }
1242 }
1243 
1244 void MetaspaceShared::set_shared_metaspace_range(void* base, void *static_top, void* top) {
1245   assert(base <= static_top && static_top <= top, "must be");
1246   _shared_metaspace_static_top = static_top;
1247   MetaspaceObj::set_shared_metaspace_range(base, top);
1248 }
1249 
1250 bool MetaspaceShared::is_shared_dynamic(void* p) {
1251   if ((p < MetaspaceObj::shared_metaspace_top()) &&
1252       (p >= _shared_metaspace_static_top)) {
1253     return true;
1254   } else {
1255     return false;
1256   }
< prev index next >