< prev index next >

src/hotspot/share/cds/aotMetaspace.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/bytecodes.hpp"
  67 #include "interpreter/bytecodeStream.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 AOTMetaspace::_symbol_rs;
 108 VirtualSpace AOTMetaspace::_symbol_vs;
 109 bool AOTMetaspace::_archive_loading_failed = false;
 110 bool AOTMetaspace::_remapped_readwrite = false;
 111 void* AOTMetaspace::_aot_metaspace_static_top = nullptr;
 112 intx AOTMetaspace::_relocation_delta;
 113 char* AOTMetaspace::_requested_base_address;
 114 Array<Method*>* AOTMetaspace::_archived_method_handle_intrinsics = nullptr;
 115 bool AOTMetaspace::_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 AOTMetaspace::core_region_alignment().
 125 //
 126 // These 2 regions are populated in the following steps:
 127 // [0] All classes are loaded in AOTMetaspace::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* AOTMetaspace::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 ...

 461 // AOTMetaspace::early_serialize(). Such functions must not produce side effects that
 462 // assume we will always decides to map the archive.
 463 
 464 void AOTMetaspace::early_serialize(SerializeClosure* soc) {
 465   int tag = 0;
 466   soc->do_tag(--tag);
 467   CDS_JAVA_HEAP_ONLY(Modules::serialize_archived_module_info(soc);)
 468   soc->do_tag(666);
 469 }
 470 
 471 void AOTMetaspace::serialize(SerializeClosure* soc) {
 472   int tag = 0;
 473   soc->do_tag(--tag);
 474 
 475   // Verify the sizes of various metadata in the system.
 476   soc->do_tag(sizeof(Method));
 477   soc->do_tag(sizeof(ConstMethod));
 478   soc->do_tag(arrayOopDesc::base_offset_in_bytes(T_BYTE));
 479   soc->do_tag(sizeof(ConstantPool));
 480   soc->do_tag(sizeof(ConstantPoolCache));
 481   soc->do_tag(objArrayOopDesc::base_offset_in_bytes());
 482   soc->do_tag(typeArrayOopDesc::base_offset_in_bytes(T_BYTE));
 483   soc->do_tag(sizeof(Symbol));
 484 
 485   // Need to do this first, as subsequent steps may call virtual functions
 486   // in archived Metadata objects.
 487   CppVtables::serialize(soc);
 488   soc->do_tag(--tag);
 489 
 490   // Dump/restore miscellaneous metadata.
 491   JavaClasses::serialize_offsets(soc);
 492   Universe::serialize(soc);
 493   soc->do_tag(--tag);
 494 
 495   // Dump/restore references to commonly used names and signatures.
 496   vmSymbols::serialize(soc);
 497   soc->do_tag(--tag);
 498 
 499   // Dump/restore the symbol/string/subgraph_info tables
 500   SymbolTable::serialize_shared_table_header(soc);
 501   StringTable::serialize_shared_table_header(soc);

 884     log_debug(aot)("Setting MinHeapSize to 4G for CDS dumping, original size = %zuM", MinHeapSize/M);
 885     FLAG_SET_ERGO(MinHeapSize, max_heap_size);
 886   }
 887   if (InitialHeapSize > max_heap_size) {
 888     log_debug(aot)("Setting InitialHeapSize to 4G for CDS dumping, original size = %zuM", InitialHeapSize/M);
 889     FLAG_SET_ERGO(InitialHeapSize, max_heap_size);
 890   }
 891   if (MaxHeapSize > max_heap_size) {
 892     log_debug(aot)("Setting MaxHeapSize to 4G for CDS dumping, original size = %zuM", MaxHeapSize/M);
 893     FLAG_SET_ERGO(MaxHeapSize, max_heap_size);
 894   }
 895 }
 896 #endif // INCLUDE_CDS_JAVA_HEAP && _LP64
 897 
 898 void AOTMetaspace::get_default_classlist(char* default_classlist, const size_t buf_size) {
 899   const char* filesep = os::file_separator();
 900   jio_snprintf(default_classlist, buf_size, "%s%slib%sclasslist",
 901                Arguments::get_java_home(), filesep, filesep);
 902 }
 903 
 904 void AOTMetaspace::preload_classes(TRAPS) {
 905   char default_classlist[JVM_MAXPATHLEN];
 906   const char* classlist_path;
 907 
 908   get_default_classlist(default_classlist, JVM_MAXPATHLEN);
 909   if (SharedClassListFile == nullptr) {
 910     classlist_path = default_classlist;
 911   } else {
 912     classlist_path = SharedClassListFile;
 913   }
 914 
 915   aot_log_info(aot)("Loading classes to share ...");
 916   ClassListParser::parse_classlist(classlist_path,
 917                                    ClassListParser::_parse_all, CHECK);
 918   if (ExtraSharedClassListFile) {
 919     ClassListParser::parse_classlist(ExtraSharedClassListFile,
 920                                      ClassListParser::_parse_all, CHECK);
 921   }
 922   if (classlist_path != default_classlist) {
 923     struct stat statbuf;
 924     if (os::stat(default_classlist, &statbuf) == 0) {

 931   // Some classes are used at CDS runtime but are not loaded, and therefore archived, at
 932   // dumptime. We can perform dummmy calls to these classes at dumptime to ensure they
 933   // are archived.
 934   exercise_runtime_cds_code(CHECK);
 935 
 936   aot_log_info(aot)("Loading classes to share: done.");
 937 }
 938 
 939 void AOTMetaspace::exercise_runtime_cds_code(TRAPS) {
 940   // Exercise the manifest processing code
 941   const char* dummy = "Manifest-Version: 1.0\n";
 942   CDSProtectionDomain::create_jar_manifest(dummy, strlen(dummy), CHECK);
 943 
 944   // Exercise FileSystem and URL code
 945   CDSProtectionDomain::to_file_URL("dummy.jar", Handle(), CHECK);
 946 }
 947 
 948 void AOTMetaspace::preload_and_dump_impl(StaticArchiveBuilder& builder, TRAPS) {
 949   if (CDSConfig::is_dumping_classic_static_archive()) {
 950     // We are running with -Xshare:dump
 951     preload_classes(CHECK);
 952 
 953     if (SharedArchiveConfigFile) {
 954       log_info(aot)("Reading extra data from %s ...", SharedArchiveConfigFile);
 955       read_extra_data(THREAD, SharedArchiveConfigFile);
 956       log_info(aot)("Reading extra data: done.");
 957     }
 958   }
 959 
 960   if (CDSConfig::is_dumping_preimage_static_archive()) {
 961     log_info(aot)("Reading lambda form invokers from JDK default classlist ...");
 962     char default_classlist[JVM_MAXPATHLEN];
 963     get_default_classlist(default_classlist, JVM_MAXPATHLEN);
 964     struct stat statbuf;
 965     if (os::stat(default_classlist, &statbuf) == 0) {
 966       ClassListParser::parse_classlist(default_classlist,
 967                                        ClassListParser::_parse_lambda_forms_invokers_only, CHECK);
 968     }
 969   }
 970 
 971 #if INCLUDE_CDS_JAVA_HEAP

1236     }
1237     ik->link_class(THREAD);
1238     if (HAS_PENDING_EXCEPTION) {
1239       ResourceMark rm(THREAD);
1240       aot_log_warning(aot)("Preload Warning: Verification failed for %s",
1241                     ik->external_name());
1242       CLEAR_PENDING_EXCEPTION;
1243       SystemDictionaryShared::set_class_has_failed_verification(ik);
1244     } else {
1245       assert(!SystemDictionaryShared::has_class_failed_verification(ik), "sanity");
1246       ik->compute_has_loops_flag_for_methods();
1247     }
1248     BytecodeVerificationLocal = saved;
1249     return true;
1250   } else {
1251     return false;
1252   }
1253 }
1254 
1255 void VM_PopulateDumpSharedSpace::dump_java_heap_objects() {





1256   if (CDSConfig::is_dumping_heap()) {
1257     HeapShared::write_heap(&_heap_info);
1258   } else {
1259     CDSConfig::log_reasons_for_not_dumping_heap();
1260   }
1261 }
1262 
1263 void AOTMetaspace::set_aot_metaspace_range(void* base, void *static_top, void* top) {
1264   assert(base <= static_top && static_top <= top, "must be");
1265   _aot_metaspace_static_top = static_top;
1266   MetaspaceObj::set_aot_metaspace_range(base, top);
1267 }
1268 
1269 bool AOTMetaspace::in_aot_cache_dynamic_region(void* p) {
1270   if ((p < MetaspaceObj::aot_metaspace_top()) &&
1271       (p >= _aot_metaspace_static_top)) {
1272     return true;
1273   } else {
1274     return false;
1275   }

  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/bytecodes.hpp"
  67 #include "interpreter/bytecodeStream.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 AOTMetaspace::_symbol_rs;
 110 VirtualSpace AOTMetaspace::_symbol_vs;
 111 bool AOTMetaspace::_archive_loading_failed = false;
 112 bool AOTMetaspace::_remapped_readwrite = false;
 113 void* AOTMetaspace::_aot_metaspace_static_top = nullptr;
 114 intx AOTMetaspace::_relocation_delta;
 115 char* AOTMetaspace::_requested_base_address;
 116 Array<Method*>* AOTMetaspace::_archived_method_handle_intrinsics = nullptr;
 117 bool AOTMetaspace::_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 AOTMetaspace::core_region_alignment().
 127 //
 128 // These 2 regions are populated in the following steps:
 129 // [0] All classes are loaded in AOTMetaspace::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* AOTMetaspace::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 ...

 463 // AOTMetaspace::early_serialize(). Such functions must not produce side effects that
 464 // assume we will always decides to map the archive.
 465 
 466 void AOTMetaspace::early_serialize(SerializeClosure* soc) {
 467   int tag = 0;
 468   soc->do_tag(--tag);
 469   CDS_JAVA_HEAP_ONLY(Modules::serialize_archived_module_info(soc);)
 470   soc->do_tag(666);
 471 }
 472 
 473 void AOTMetaspace::serialize(SerializeClosure* soc) {
 474   int tag = 0;
 475   soc->do_tag(--tag);
 476 
 477   // Verify the sizes of various metadata in the system.
 478   soc->do_tag(sizeof(Method));
 479   soc->do_tag(sizeof(ConstMethod));
 480   soc->do_tag(arrayOopDesc::base_offset_in_bytes(T_BYTE));
 481   soc->do_tag(sizeof(ConstantPool));
 482   soc->do_tag(sizeof(ConstantPoolCache));
 483   soc->do_tag(refArrayOopDesc::base_offset_in_bytes());
 484   soc->do_tag(typeArrayOopDesc::base_offset_in_bytes(T_BYTE));
 485   soc->do_tag(sizeof(Symbol));
 486 
 487   // Need to do this first, as subsequent steps may call virtual functions
 488   // in archived Metadata objects.
 489   CppVtables::serialize(soc);
 490   soc->do_tag(--tag);
 491 
 492   // Dump/restore miscellaneous metadata.
 493   JavaClasses::serialize_offsets(soc);
 494   Universe::serialize(soc);
 495   soc->do_tag(--tag);
 496 
 497   // Dump/restore references to commonly used names and signatures.
 498   vmSymbols::serialize(soc);
 499   soc->do_tag(--tag);
 500 
 501   // Dump/restore the symbol/string/subgraph_info tables
 502   SymbolTable::serialize_shared_table_header(soc);
 503   StringTable::serialize_shared_table_header(soc);

 886     log_debug(aot)("Setting MinHeapSize to 4G for CDS dumping, original size = %zuM", MinHeapSize/M);
 887     FLAG_SET_ERGO(MinHeapSize, max_heap_size);
 888   }
 889   if (InitialHeapSize > max_heap_size) {
 890     log_debug(aot)("Setting InitialHeapSize to 4G for CDS dumping, original size = %zuM", InitialHeapSize/M);
 891     FLAG_SET_ERGO(InitialHeapSize, max_heap_size);
 892   }
 893   if (MaxHeapSize > max_heap_size) {
 894     log_debug(aot)("Setting MaxHeapSize to 4G for CDS dumping, original size = %zuM", MaxHeapSize/M);
 895     FLAG_SET_ERGO(MaxHeapSize, max_heap_size);
 896   }
 897 }
 898 #endif // INCLUDE_CDS_JAVA_HEAP && _LP64
 899 
 900 void AOTMetaspace::get_default_classlist(char* default_classlist, const size_t buf_size) {
 901   const char* filesep = os::file_separator();
 902   jio_snprintf(default_classlist, buf_size, "%s%slib%sclasslist",
 903                Arguments::get_java_home(), filesep, filesep);
 904 }
 905 
 906 void AOTMetaspace::loadable_descriptors(TRAPS) {
 907   char default_classlist[JVM_MAXPATHLEN];
 908   const char* classlist_path;
 909 
 910   get_default_classlist(default_classlist, JVM_MAXPATHLEN);
 911   if (SharedClassListFile == nullptr) {
 912     classlist_path = default_classlist;
 913   } else {
 914     classlist_path = SharedClassListFile;
 915   }
 916 
 917   aot_log_info(aot)("Loading classes to share ...");
 918   ClassListParser::parse_classlist(classlist_path,
 919                                    ClassListParser::_parse_all, CHECK);
 920   if (ExtraSharedClassListFile) {
 921     ClassListParser::parse_classlist(ExtraSharedClassListFile,
 922                                      ClassListParser::_parse_all, CHECK);
 923   }
 924   if (classlist_path != default_classlist) {
 925     struct stat statbuf;
 926     if (os::stat(default_classlist, &statbuf) == 0) {

 933   // Some classes are used at CDS runtime but are not loaded, and therefore archived, at
 934   // dumptime. We can perform dummmy calls to these classes at dumptime to ensure they
 935   // are archived.
 936   exercise_runtime_cds_code(CHECK);
 937 
 938   aot_log_info(aot)("Loading classes to share: done.");
 939 }
 940 
 941 void AOTMetaspace::exercise_runtime_cds_code(TRAPS) {
 942   // Exercise the manifest processing code
 943   const char* dummy = "Manifest-Version: 1.0\n";
 944   CDSProtectionDomain::create_jar_manifest(dummy, strlen(dummy), CHECK);
 945 
 946   // Exercise FileSystem and URL code
 947   CDSProtectionDomain::to_file_URL("dummy.jar", Handle(), CHECK);
 948 }
 949 
 950 void AOTMetaspace::preload_and_dump_impl(StaticArchiveBuilder& builder, TRAPS) {
 951   if (CDSConfig::is_dumping_classic_static_archive()) {
 952     // We are running with -Xshare:dump
 953     loadable_descriptors(CHECK);
 954 
 955     if (SharedArchiveConfigFile) {
 956       log_info(aot)("Reading extra data from %s ...", SharedArchiveConfigFile);
 957       read_extra_data(THREAD, SharedArchiveConfigFile);
 958       log_info(aot)("Reading extra data: done.");
 959     }
 960   }
 961 
 962   if (CDSConfig::is_dumping_preimage_static_archive()) {
 963     log_info(aot)("Reading lambda form invokers from JDK default classlist ...");
 964     char default_classlist[JVM_MAXPATHLEN];
 965     get_default_classlist(default_classlist, JVM_MAXPATHLEN);
 966     struct stat statbuf;
 967     if (os::stat(default_classlist, &statbuf) == 0) {
 968       ClassListParser::parse_classlist(default_classlist,
 969                                        ClassListParser::_parse_lambda_forms_invokers_only, CHECK);
 970     }
 971   }
 972 
 973 #if INCLUDE_CDS_JAVA_HEAP

1238     }
1239     ik->link_class(THREAD);
1240     if (HAS_PENDING_EXCEPTION) {
1241       ResourceMark rm(THREAD);
1242       aot_log_warning(aot)("Preload Warning: Verification failed for %s",
1243                     ik->external_name());
1244       CLEAR_PENDING_EXCEPTION;
1245       SystemDictionaryShared::set_class_has_failed_verification(ik);
1246     } else {
1247       assert(!SystemDictionaryShared::has_class_failed_verification(ik), "sanity");
1248       ik->compute_has_loops_flag_for_methods();
1249     }
1250     BytecodeVerificationLocal = saved;
1251     return true;
1252   } else {
1253     return false;
1254   }
1255 }
1256 
1257 void VM_PopulateDumpSharedSpace::dump_java_heap_objects() {
1258   if (CDSConfig::is_valhalla_preview()) {
1259     log_info(cds)("Archived java heap is not yet supported with Valhalla preview");
1260     return;
1261   }
1262 
1263   if (CDSConfig::is_dumping_heap()) {
1264     HeapShared::write_heap(&_heap_info);
1265   } else {
1266     CDSConfig::log_reasons_for_not_dumping_heap();
1267   }
1268 }
1269 
1270 void AOTMetaspace::set_aot_metaspace_range(void* base, void *static_top, void* top) {
1271   assert(base <= static_top && static_top <= top, "must be");
1272   _aot_metaspace_static_top = static_top;
1273   MetaspaceObj::set_aot_metaspace_range(base, top);
1274 }
1275 
1276 bool AOTMetaspace::in_aot_cache_dynamic_region(void* p) {
1277   if ((p < MetaspaceObj::aot_metaspace_top()) &&
1278       (p >= _aot_metaspace_static_top)) {
1279     return true;
1280   } else {
1281     return false;
1282   }
< prev index next >