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 MetaspaceShared::_symbol_rs;
108 VirtualSpace MetaspaceShared::_symbol_vs;
109 bool MetaspaceShared::_archive_loading_failed = false;
110 bool MetaspaceShared::_remapped_readwrite = false;
111 void* MetaspaceShared::_aot_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 ...
461 // MetaspaceShared::early_serialize(). Such functions must not produce side effects that
462 // assume we will always decides to map the archive.
463
464 void MetaspaceShared::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 MetaspaceShared::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);
876 log_debug(aot)("Setting MinHeapSize to 4G for CDS dumping, original size = %zuM", MinHeapSize/M);
877 FLAG_SET_ERGO(MinHeapSize, max_heap_size);
878 }
879 if (InitialHeapSize > max_heap_size) {
880 log_debug(aot)("Setting InitialHeapSize to 4G for CDS dumping, original size = %zuM", InitialHeapSize/M);
881 FLAG_SET_ERGO(InitialHeapSize, max_heap_size);
882 }
883 if (MaxHeapSize > max_heap_size) {
884 log_debug(aot)("Setting MaxHeapSize to 4G for CDS dumping, original size = %zuM", MaxHeapSize/M);
885 FLAG_SET_ERGO(MaxHeapSize, max_heap_size);
886 }
887 }
888 #endif // INCLUDE_CDS_JAVA_HEAP && _LP64
889
890 void MetaspaceShared::get_default_classlist(char* default_classlist, const size_t buf_size) {
891 const char* filesep = os::file_separator();
892 jio_snprintf(default_classlist, buf_size, "%s%slib%sclasslist",
893 Arguments::get_java_home(), filesep, filesep);
894 }
895
896 void MetaspaceShared::preload_classes(TRAPS) {
897 char default_classlist[JVM_MAXPATHLEN];
898 const char* classlist_path;
899
900 get_default_classlist(default_classlist, JVM_MAXPATHLEN);
901 if (SharedClassListFile == nullptr) {
902 classlist_path = default_classlist;
903 } else {
904 classlist_path = SharedClassListFile;
905 }
906
907 aot_log_info(aot)("Loading classes to share ...");
908 ClassListParser::parse_classlist(classlist_path,
909 ClassListParser::_parse_all, CHECK);
910 if (ExtraSharedClassListFile) {
911 ClassListParser::parse_classlist(ExtraSharedClassListFile,
912 ClassListParser::_parse_all, CHECK);
913 }
914 if (classlist_path != default_classlist) {
915 struct stat statbuf;
916 if (os::stat(default_classlist, &statbuf) == 0) {
923 // Some classes are used at CDS runtime but are not loaded, and therefore archived, at
924 // dumptime. We can perform dummmy calls to these classes at dumptime to ensure they
925 // are archived.
926 exercise_runtime_cds_code(CHECK);
927
928 aot_log_info(aot)("Loading classes to share: done.");
929 }
930
931 void MetaspaceShared::exercise_runtime_cds_code(TRAPS) {
932 // Exercise the manifest processing code
933 const char* dummy = "Manifest-Version: 1.0\n";
934 CDSProtectionDomain::create_jar_manifest(dummy, strlen(dummy), CHECK);
935
936 // Exercise FileSystem and URL code
937 CDSProtectionDomain::to_file_URL("dummy.jar", Handle(), CHECK);
938 }
939
940 void MetaspaceShared::preload_and_dump_impl(StaticArchiveBuilder& builder, TRAPS) {
941 if (CDSConfig::is_dumping_classic_static_archive()) {
942 // We are running with -Xshare:dump
943 preload_classes(CHECK);
944
945 if (SharedArchiveConfigFile) {
946 log_info(aot)("Reading extra data from %s ...", SharedArchiveConfigFile);
947 read_extra_data(THREAD, SharedArchiveConfigFile);
948 log_info(aot)("Reading extra data: done.");
949 }
950 }
951
952 if (CDSConfig::is_dumping_preimage_static_archive()) {
953 log_info(aot)("Reading lambda form invokers from JDK default classlist ...");
954 char default_classlist[JVM_MAXPATHLEN];
955 get_default_classlist(default_classlist, JVM_MAXPATHLEN);
956 struct stat statbuf;
957 if (os::stat(default_classlist, &statbuf) == 0) {
958 ClassListParser::parse_classlist(default_classlist,
959 ClassListParser::_parse_lambda_forms_invokers_only, CHECK);
960 }
961 }
962
963 #if INCLUDE_CDS_JAVA_HEAP
1228 }
1229 ik->link_class(THREAD);
1230 if (HAS_PENDING_EXCEPTION) {
1231 ResourceMark rm(THREAD);
1232 aot_log_warning(aot)("Preload Warning: Verification failed for %s",
1233 ik->external_name());
1234 CLEAR_PENDING_EXCEPTION;
1235 SystemDictionaryShared::set_class_has_failed_verification(ik);
1236 } else {
1237 assert(!SystemDictionaryShared::has_class_failed_verification(ik), "sanity");
1238 ik->compute_has_loops_flag_for_methods();
1239 }
1240 BytecodeVerificationLocal = saved;
1241 return true;
1242 } else {
1243 return false;
1244 }
1245 }
1246
1247 void VM_PopulateDumpSharedSpace::dump_java_heap_objects() {
1248 if (CDSConfig::is_dumping_heap()) {
1249 HeapShared::write_heap(&_heap_info);
1250 } else {
1251 CDSConfig::log_reasons_for_not_dumping_heap();
1252 }
1253 }
1254
1255 void MetaspaceShared::set_aot_metaspace_range(void* base, void *static_top, void* top) {
1256 assert(base <= static_top && static_top <= top, "must be");
1257 _aot_metaspace_static_top = static_top;
1258 MetaspaceObj::set_aot_metaspace_range(base, top);
1259 }
1260
1261 bool MetaspaceShared::in_aot_cache_dynamic_region(void* p) {
1262 if ((p < MetaspaceObj::aot_metaspace_top()) &&
1263 (p >= _aot_metaspace_static_top)) {
1264 return true;
1265 } else {
1266 return false;
1267 }
|
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 MetaspaceShared::_symbol_rs;
110 VirtualSpace MetaspaceShared::_symbol_vs;
111 bool MetaspaceShared::_archive_loading_failed = false;
112 bool MetaspaceShared::_remapped_readwrite = false;
113 void* MetaspaceShared::_aot_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 ...
463 // MetaspaceShared::early_serialize(). Such functions must not produce side effects that
464 // assume we will always decides to map the archive.
465
466 void MetaspaceShared::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 MetaspaceShared::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);
878 log_debug(aot)("Setting MinHeapSize to 4G for CDS dumping, original size = %zuM", MinHeapSize/M);
879 FLAG_SET_ERGO(MinHeapSize, max_heap_size);
880 }
881 if (InitialHeapSize > max_heap_size) {
882 log_debug(aot)("Setting InitialHeapSize to 4G for CDS dumping, original size = %zuM", InitialHeapSize/M);
883 FLAG_SET_ERGO(InitialHeapSize, max_heap_size);
884 }
885 if (MaxHeapSize > max_heap_size) {
886 log_debug(aot)("Setting MaxHeapSize to 4G for CDS dumping, original size = %zuM", MaxHeapSize/M);
887 FLAG_SET_ERGO(MaxHeapSize, max_heap_size);
888 }
889 }
890 #endif // INCLUDE_CDS_JAVA_HEAP && _LP64
891
892 void MetaspaceShared::get_default_classlist(char* default_classlist, const size_t buf_size) {
893 const char* filesep = os::file_separator();
894 jio_snprintf(default_classlist, buf_size, "%s%slib%sclasslist",
895 Arguments::get_java_home(), filesep, filesep);
896 }
897
898 void MetaspaceShared::loadable_descriptors(TRAPS) {
899 char default_classlist[JVM_MAXPATHLEN];
900 const char* classlist_path;
901
902 get_default_classlist(default_classlist, JVM_MAXPATHLEN);
903 if (SharedClassListFile == nullptr) {
904 classlist_path = default_classlist;
905 } else {
906 classlist_path = SharedClassListFile;
907 }
908
909 aot_log_info(aot)("Loading classes to share ...");
910 ClassListParser::parse_classlist(classlist_path,
911 ClassListParser::_parse_all, CHECK);
912 if (ExtraSharedClassListFile) {
913 ClassListParser::parse_classlist(ExtraSharedClassListFile,
914 ClassListParser::_parse_all, CHECK);
915 }
916 if (classlist_path != default_classlist) {
917 struct stat statbuf;
918 if (os::stat(default_classlist, &statbuf) == 0) {
925 // Some classes are used at CDS runtime but are not loaded, and therefore archived, at
926 // dumptime. We can perform dummmy calls to these classes at dumptime to ensure they
927 // are archived.
928 exercise_runtime_cds_code(CHECK);
929
930 aot_log_info(aot)("Loading classes to share: done.");
931 }
932
933 void MetaspaceShared::exercise_runtime_cds_code(TRAPS) {
934 // Exercise the manifest processing code
935 const char* dummy = "Manifest-Version: 1.0\n";
936 CDSProtectionDomain::create_jar_manifest(dummy, strlen(dummy), CHECK);
937
938 // Exercise FileSystem and URL code
939 CDSProtectionDomain::to_file_URL("dummy.jar", Handle(), CHECK);
940 }
941
942 void MetaspaceShared::preload_and_dump_impl(StaticArchiveBuilder& builder, TRAPS) {
943 if (CDSConfig::is_dumping_classic_static_archive()) {
944 // We are running with -Xshare:dump
945 loadable_descriptors(CHECK);
946
947 if (SharedArchiveConfigFile) {
948 log_info(aot)("Reading extra data from %s ...", SharedArchiveConfigFile);
949 read_extra_data(THREAD, SharedArchiveConfigFile);
950 log_info(aot)("Reading extra data: done.");
951 }
952 }
953
954 if (CDSConfig::is_dumping_preimage_static_archive()) {
955 log_info(aot)("Reading lambda form invokers from JDK default classlist ...");
956 char default_classlist[JVM_MAXPATHLEN];
957 get_default_classlist(default_classlist, JVM_MAXPATHLEN);
958 struct stat statbuf;
959 if (os::stat(default_classlist, &statbuf) == 0) {
960 ClassListParser::parse_classlist(default_classlist,
961 ClassListParser::_parse_lambda_forms_invokers_only, CHECK);
962 }
963 }
964
965 #if INCLUDE_CDS_JAVA_HEAP
1230 }
1231 ik->link_class(THREAD);
1232 if (HAS_PENDING_EXCEPTION) {
1233 ResourceMark rm(THREAD);
1234 aot_log_warning(aot)("Preload Warning: Verification failed for %s",
1235 ik->external_name());
1236 CLEAR_PENDING_EXCEPTION;
1237 SystemDictionaryShared::set_class_has_failed_verification(ik);
1238 } else {
1239 assert(!SystemDictionaryShared::has_class_failed_verification(ik), "sanity");
1240 ik->compute_has_loops_flag_for_methods();
1241 }
1242 BytecodeVerificationLocal = saved;
1243 return true;
1244 } else {
1245 return false;
1246 }
1247 }
1248
1249 void VM_PopulateDumpSharedSpace::dump_java_heap_objects() {
1250 if (CDSConfig::is_valhalla_preview()) {
1251 log_info(cds)("Archived java heap is not yet supported with Valhalla preview");
1252 return;
1253 }
1254
1255 if (CDSConfig::is_dumping_heap()) {
1256 HeapShared::write_heap(&_heap_info);
1257 } else {
1258 CDSConfig::log_reasons_for_not_dumping_heap();
1259 }
1260 }
1261
1262 void MetaspaceShared::set_aot_metaspace_range(void* base, void *static_top, void* top) {
1263 assert(base <= static_top && static_top <= top, "must be");
1264 _aot_metaspace_static_top = static_top;
1265 MetaspaceObj::set_aot_metaspace_range(base, top);
1266 }
1267
1268 bool MetaspaceShared::in_aot_cache_dynamic_region(void* p) {
1269 if ((p < MetaspaceObj::aot_metaspace_top()) &&
1270 (p >= _aot_metaspace_static_top)) {
1271 return true;
1272 } else {
1273 return false;
1274 }
|