27 #include "cds/archiveBuilder.hpp"
28 #include "cds/archiveHeapLoader.inline.hpp"
29 #include "cds/archiveHeapWriter.hpp"
30 #include "cds/archiveUtils.inline.hpp"
31 #include "cds/cds_globals.hpp"
32 #include "cds/cdsConfig.hpp"
33 #include "cds/dynamicArchive.hpp"
34 #include "cds/filemap.hpp"
35 #include "cds/heapShared.hpp"
36 #include "cds/metaspaceShared.hpp"
37 #include "classfile/altHashing.hpp"
38 #include "classfile/classFileStream.hpp"
39 #include "classfile/classLoader.hpp"
40 #include "classfile/classLoader.inline.hpp"
41 #include "classfile/classLoaderData.inline.hpp"
42 #include "classfile/classLoaderExt.hpp"
43 #include "classfile/symbolTable.hpp"
44 #include "classfile/systemDictionaryShared.hpp"
45 #include "classfile/vmClasses.hpp"
46 #include "classfile/vmSymbols.hpp"
47 #include "jvm.h"
48 #include "logging/log.hpp"
49 #include "logging/logMessage.hpp"
50 #include "logging/logStream.hpp"
51 #include "memory/iterator.inline.hpp"
52 #include "memory/metadataFactory.hpp"
53 #include "memory/metaspaceClosure.hpp"
54 #include "memory/oopFactory.hpp"
55 #include "memory/universe.hpp"
56 #include "nmt/memTracker.hpp"
57 #include "oops/access.hpp"
58 #include "oops/compressedOops.hpp"
59 #include "oops/compressedOops.inline.hpp"
60 #include "oops/compressedKlass.hpp"
61 #include "oops/objArrayOop.hpp"
62 #include "oops/oop.inline.hpp"
63 #include "oops/trainingData.hpp"
64 #include "oops/typeArrayKlass.hpp"
65 #include "prims/jvmtiExport.hpp"
66 #include "runtime/arguments.hpp"
215 }
216 _core_region_alignment = core_region_alignment;
217 _obj_alignment = ObjectAlignmentInBytes;
218 _compact_strings = CompactStrings;
219 _compact_headers = UseCompactObjectHeaders;
220 if (CDSConfig::is_dumping_heap()) {
221 _narrow_oop_mode = CompressedOops::mode();
222 _narrow_oop_base = CompressedOops::base();
223 _narrow_oop_shift = CompressedOops::shift();
224 }
225 _compressed_oops = UseCompressedOops;
226 _compressed_class_ptrs = UseCompressedClassPointers;
227 if (UseCompressedClassPointers) {
228 #ifdef _LP64
229 _narrow_klass_pointer_bits = CompressedKlassPointers::narrow_klass_pointer_bits();
230 _narrow_klass_shift = ArchiveBuilder::precomputed_narrow_klass_shift();
231 #endif
232 } else {
233 _narrow_klass_pointer_bits = _narrow_klass_shift = -1;
234 }
235 _type_profile_level = TypeProfileLevel;
236 _type_profile_args_limit = TypeProfileArgsLimit;
237 _type_profile_parms_limit = TypeProfileParmsLimit;
238 _type_profile_width = TypeProfileWidth;
239 _bci_profile_width = BciProfileWidth;
240 _profile_traps = ProfileTraps;
241 _type_profile_casts = TypeProfileCasts;
242 _spec_trap_limit_extra_entries = SpecTrapLimitExtraEntries;
243 _max_heap_size = MaxHeapSize;
244 _use_optimized_module_handling = CDSConfig::is_using_optimized_module_handling();
245 _has_aot_linked_classes = CDSConfig::is_dumping_aot_linked_classes();
246 _has_full_module_graph = CDSConfig::is_dumping_full_module_graph();
247
248 // The following fields are for sanity checks for whether this archive
249 // will function correctly with this JVM and the bootclasspath it's
250 // invoked with.
251
252 // JVM version string ... changes on each build.
253 get_header_version(_jvm_ident);
254
255 _verify_local = BytecodeVerificationLocal;
256 _verify_remote = BytecodeVerificationRemote;
257 _has_platform_or_app_classes = AOTClassLocationConfig::dumptime()->has_platform_or_app_classes();
258 _requested_base_address = (char*)SharedBaseAddress;
259 _mapped_base_address = (char*)SharedBaseAddress;
260 _allow_archiving_with_java_agent = AllowArchivingWithJavaAgent;
261 }
262
263 void FileMapHeader::copy_base_archive_name(const char* archive) {
264 assert(base_archive_name_size() != 0, "_base_archive_name_size not set");
265 assert(base_archive_name_offset() != 0, "_base_archive_name_offset not set");
266 assert(header_size() > sizeof(*this), "_base_archive_name_size not included in header size?");
301 st->print_cr("- jvm_ident: %s", _jvm_ident);
302 st->print_cr("- class_location_config_offset: 0x%zx", _class_location_config_offset);
303 st->print_cr("- verify_local: %d", _verify_local);
304 st->print_cr("- verify_remote: %d", _verify_remote);
305 st->print_cr("- has_platform_or_app_classes: %d", _has_platform_or_app_classes);
306 st->print_cr("- requested_base_address: " INTPTR_FORMAT, p2i(_requested_base_address));
307 st->print_cr("- mapped_base_address: " INTPTR_FORMAT, p2i(_mapped_base_address));
308 st->print_cr("- heap_root_segments.roots_count: %d" , _heap_root_segments.roots_count());
309 st->print_cr("- heap_root_segments.base_offset: 0x%zx", _heap_root_segments.base_offset());
310 st->print_cr("- heap_root_segments.count: %zu", _heap_root_segments.count());
311 st->print_cr("- heap_root_segments.max_size_elems: %d", _heap_root_segments.max_size_in_elems());
312 st->print_cr("- heap_root_segments.max_size_bytes: %d", _heap_root_segments.max_size_in_bytes());
313 st->print_cr("- _heap_oopmap_start_pos: %zu", _heap_oopmap_start_pos);
314 st->print_cr("- _heap_ptrmap_start_pos: %zu", _heap_ptrmap_start_pos);
315 st->print_cr("- _rw_ptrmap_start_pos: %zu", _rw_ptrmap_start_pos);
316 st->print_cr("- _ro_ptrmap_start_pos: %zu", _ro_ptrmap_start_pos);
317 st->print_cr("- allow_archiving_with_java_agent:%d", _allow_archiving_with_java_agent);
318 st->print_cr("- use_optimized_module_handling: %d", _use_optimized_module_handling);
319 st->print_cr("- has_full_module_graph %d", _has_full_module_graph);
320 st->print_cr("- has_aot_linked_classes %d", _has_aot_linked_classes);
321 }
322
323 bool FileMapInfo::validate_class_location() {
324 assert(CDSConfig::is_using_archive(), "runtime only");
325
326 AOTClassLocationConfig* config = header()->class_location_config();
327 bool has_extra_module_paths = false;
328 if (!config->validate(header()->has_aot_linked_classes(), &has_extra_module_paths)) {
329 if (PrintSharedArchiveAndExit) {
330 MetaspaceShared::set_archive_loading_failed();
331 return true;
332 } else {
333 return false;
334 }
335 }
336
337 if (header()->has_full_module_graph() && has_extra_module_paths) {
338 CDSConfig::stop_using_optimized_module_handling();
339 MetaspaceShared::report_loading_error("optimized module handling: disabled because extra module path(s) are specified");
340 }
903 assert((mapping_offset >> CompressedOops::shift()) << CompressedOops::shift() == mapping_offset, "must be");
904 } else {
905 mapping_offset = 0; // not used with !UseCompressedOops
906 }
907 #endif // INCLUDE_CDS_JAVA_HEAP
908 } else {
909 char* requested_SharedBaseAddress = (char*)MetaspaceShared::requested_base_address();
910 requested_base = ArchiveBuilder::current()->to_requested(base);
911 assert(requested_base >= requested_SharedBaseAddress, "must be");
912 mapping_offset = requested_base - requested_SharedBaseAddress;
913 }
914
915 r->set_file_offset(_file_offset);
916 int crc = ClassLoader::crc32(0, base, (jint)size);
917 if (size > 0) {
918 aot_log_info(aot)("Shared file region (%s) %d: %8zu"
919 " bytes, addr " INTPTR_FORMAT " file offset 0x%08" PRIxPTR
920 " crc 0x%08x",
921 region_name(region), region, size, p2i(requested_base), _file_offset, crc);
922 } else {
923 aot_log_info(aot)("Shared file region (%s) %d: %8zu"
924 " bytes", region_name(region), region, size);
925 }
926
927 r->init(region, mapping_offset, size, read_only, allow_exec, crc);
928
929 if (base != nullptr) {
930 write_bytes_aligned(base, size);
931 }
932 }
933
934 static size_t write_bitmap(const CHeapBitMap* map, char* output, size_t offset) {
935 size_t size_in_bytes = map->size_in_bytes();
936 map->write_to((BitMap::bm_word_t*)(output + offset), size_in_bytes);
937 return offset + size_in_bytes;
938 }
939
940 // The sorting code groups the objects with non-null oop/ptrs together.
941 // Relevant bitmaps then have lots of leading and trailing zeros, which
942 // we do not have to store.
943 size_t FileMapInfo::remove_bitmap_zeros(CHeapBitMap* map) {
944 BitMap::idx_t first_set = map->find_first_set_bit(0);
945 BitMap::idx_t last_set = map->find_last_set_bit(0);
946 size_t old_size = map->size();
947
948 // Slice and resize bitmap
949 map->truncate(first_set, last_set + 1);
950
951 assert(map->at(0), "First bit should be set");
952 assert(map->at(map->size() - 1), "Last bit should be set");
953 assert(map->size() <= old_size, "sanity");
954
955 return first_set;
956 }
957
958 char* FileMapInfo::write_bitmap_region(CHeapBitMap* rw_ptrmap, CHeapBitMap* ro_ptrmap, ArchiveHeapInfo* heap_info,
959 size_t &size_in_bytes) {
960 size_t removed_rw_leading_zeros = remove_bitmap_zeros(rw_ptrmap);
961 size_t removed_ro_leading_zeros = remove_bitmap_zeros(ro_ptrmap);
962 header()->set_rw_ptrmap_start_pos(removed_rw_leading_zeros);
963 header()->set_ro_ptrmap_start_pos(removed_ro_leading_zeros);
964 size_in_bytes = rw_ptrmap->size_in_bytes() + ro_ptrmap->size_in_bytes();
965
966 if (heap_info->is_used()) {
967 // Remove leading and trailing zeros
968 size_t removed_oop_leading_zeros = remove_bitmap_zeros(heap_info->oopmap());
969 size_t removed_ptr_leading_zeros = remove_bitmap_zeros(heap_info->ptrmap());
970 header()->set_heap_oopmap_start_pos(removed_oop_leading_zeros);
971 header()->set_heap_ptrmap_start_pos(removed_ptr_leading_zeros);
972
973 size_in_bytes += heap_info->oopmap()->size_in_bytes();
974 size_in_bytes += heap_info->ptrmap()->size_in_bytes();
975 }
976
977 // The bitmap region contains up to 4 parts:
978 // rw_ptrmap: metaspace pointers inside the read-write region
979 // ro_ptrmap: metaspace pointers inside the read-only region
980 // heap_info->oopmap(): Java oop pointers in the heap region
981 // heap_info->ptrmap(): metaspace pointers in the heap region
982 char* buffer = NEW_C_HEAP_ARRAY(char, size_in_bytes, mtClassShared);
983 size_t written = 0;
984
985 region_at(MetaspaceShared::rw)->init_ptrmap(0, rw_ptrmap->size());
986 written = write_bitmap(rw_ptrmap, buffer, written);
987
988 region_at(MetaspaceShared::ro)->init_ptrmap(written, ro_ptrmap->size());
989 written = write_bitmap(ro_ptrmap, buffer, written);
990
991 if (heap_info->is_used()) {
992 FileMapRegion* r = region_at(MetaspaceShared::hp);
993
994 r->init_oopmap(written, heap_info->oopmap()->size());
995 written = write_bitmap(heap_info->oopmap(), buffer, written);
996
997 r->init_ptrmap(written, heap_info->ptrmap()->size());
998 written = write_bitmap(heap_info->ptrmap(), buffer, written);
999 }
1000
1001 write_region(MetaspaceShared::bm, (char*)buffer, size_in_bytes, /*read_only=*/true, /*allow_exec=*/false);
1002 return buffer;
1003 }
1004
1005 size_t FileMapInfo::write_heap_region(ArchiveHeapInfo* heap_info) {
1006 char* buffer_start = heap_info->buffer_start();
1007 size_t buffer_size = heap_info->buffer_byte_size();
1008 write_region(MetaspaceShared::hp, buffer_start, buffer_size, false, false);
1009 header()->set_heap_root_segments(heap_info->heap_root_segments());
1010 return buffer_size;
1209 } else if (addr_delta != 0) {
1210 r->set_read_only(false); // Need to patch the pointers
1211 }
1212
1213 if (MetaspaceShared::use_windows_memory_mapping() && rs.is_reserved()) {
1214 // This is the second time we try to map the archive(s). We have already created a ReservedSpace
1215 // that covers all the FileMapRegions to ensure all regions can be mapped. However, Windows
1216 // can't mmap into a ReservedSpace, so we just ::read() the data. We're going to patch all the
1217 // regions anyway, so there's no benefit for mmap anyway.
1218 if (!read_region(i, requested_addr, size, /* do_commit = */ true)) {
1219 aot_log_info(aot)("Failed to read %s shared space into reserved space at " INTPTR_FORMAT,
1220 shared_region_name[i], p2i(requested_addr));
1221 return MAP_ARCHIVE_OTHER_FAILURE; // oom or I/O error.
1222 } else {
1223 assert(r->mapped_base() != nullptr, "must be initialized");
1224 }
1225 } else {
1226 // Note that this may either be a "fresh" mapping into unreserved address
1227 // space (Windows, first mapping attempt), or a mapping into pre-reserved
1228 // space (Posix). See also comment in MetaspaceShared::map_archives().
1229 char* base = map_memory(_fd, _full_path, r->file_offset(),
1230 requested_addr, size, r->read_only(),
1231 r->allow_exec(), mtClassShared);
1232 if (base != requested_addr) {
1233 aot_log_info(aot)("Unable to map %s shared space at " INTPTR_FORMAT,
1234 shared_region_name[i], p2i(requested_addr));
1235 _memory_mapping_failed = true;
1236 return MAP_ARCHIVE_MMAP_FAILURE;
1237 }
1238
1239 if (VerifySharedSpaces && !r->check_region_crc(requested_addr)) {
1240 return MAP_ARCHIVE_OTHER_FAILURE;
1241 }
1242
1243 r->set_mapped_from_file(true);
1244 r->set_mapped_base(requested_addr);
1245 }
1246
1247 if (rs.is_reserved()) {
1248 char* mapped_base = r->mapped_base();
1249 assert(rs.base() <= mapped_base && mapped_base + size <= rs.end(),
1250 PTR_FORMAT " <= " PTR_FORMAT " < " PTR_FORMAT " <= " PTR_FORMAT,
1298 if (!read_region(MetaspaceShared::ac, requested_base, r->used_aligned(), /* do_commit = */ true)) {
1299 aot_log_info(aot)("Failed to read aot code shared space into reserved space at " INTPTR_FORMAT,
1300 p2i(requested_base));
1301 return false;
1302 }
1303 mapped_base = requested_base;
1304 } else {
1305 // We do not execute in-place in the AOT code region.
1306 // AOT code is copied to the CodeCache for execution.
1307 bool read_only = false, allow_exec = false;
1308 mapped_base = map_memory(_fd, _full_path, r->file_offset(),
1309 requested_base, r->used_aligned(), read_only, allow_exec, mtClassShared);
1310 }
1311 if (mapped_base == nullptr) {
1312 aot_log_info(aot)("failed to map aot code region");
1313 return false;
1314 } else {
1315 assert(mapped_base == requested_base, "must be");
1316 r->set_mapped_from_file(true);
1317 r->set_mapped_base(mapped_base);
1318 aot_log_info(aot)("Mapped static region #%d at base " INTPTR_FORMAT " top " INTPTR_FORMAT " (%s)",
1319 MetaspaceShared::ac, p2i(r->mapped_base()), p2i(r->mapped_end()),
1320 shared_region_name[MetaspaceShared::ac]);
1321 return true;
1322 }
1323 }
1324
1325 class SharedDataRelocationTask : public ArchiveWorkerTask {
1326 private:
1327 BitMapView* const _rw_bm;
1328 BitMapView* const _ro_bm;
1329 SharedDataRelocator* const _rw_reloc;
1330 SharedDataRelocator* const _ro_reloc;
1331
1332 public:
1333 SharedDataRelocationTask(BitMapView* rw_bm, BitMapView* ro_bm, SharedDataRelocator* rw_reloc, SharedDataRelocator* ro_reloc) :
1334 ArchiveWorkerTask("Shared Data Relocation"),
1335 _rw_bm(rw_bm), _ro_bm(ro_bm), _rw_reloc(rw_reloc), _ro_reloc(ro_reloc) {}
1336
1337 void work(int chunk, int max_chunks) override {
1338 work_on(chunk, max_chunks, _rw_bm, _rw_reloc);
1339 work_on(chunk, max_chunks, _ro_bm, _ro_reloc);
1340 }
1341
1342 void work_on(int chunk, int max_chunks, BitMapView* bm, SharedDataRelocator* reloc) {
1343 BitMap::idx_t size = bm->size();
1344 BitMap::idx_t start = MIN2(size, size * chunk / max_chunks);
1454 }
1455
1456 void FileMapInfo::map_or_load_heap_region() {
1457 bool success = false;
1458
1459 if (can_use_heap_region()) {
1460 if (ArchiveHeapLoader::can_map()) {
1461 success = map_heap_region();
1462 } else if (ArchiveHeapLoader::can_load()) {
1463 success = ArchiveHeapLoader::load_heap_region(this);
1464 } else {
1465 if (!UseCompressedOops && !ArchiveHeapLoader::can_map()) {
1466 MetaspaceShared::report_loading_error("Cannot use CDS heap data. Selected GC not compatible -XX:-UseCompressedOops");
1467 } else {
1468 MetaspaceShared::report_loading_error("Cannot use CDS heap data. UseEpsilonGC, UseG1GC, UseSerialGC, UseParallelGC, or UseShenandoahGC are required.");
1469 }
1470 }
1471 }
1472
1473 if (!success) {
1474 if (CDSConfig::is_using_aot_linked_classes()) {
1475 // It's too late to recover -- we have already committed to use the archived metaspace objects, but
1476 // the archived heap objects cannot be loaded, so we don't have the archived FMG to guarantee that
1477 // all AOT-linked classes are visible.
1478 //
1479 // We get here because the heap is too small. The app will fail anyway. So let's quit.
1480 aot_log_error(aot)("%s has aot-linked classes but the archived "
1481 "heap objects cannot be loaded. Try increasing your heap size.",
1482 CDSConfig::type_of_archive_being_loaded());
1483 MetaspaceShared::unrecoverable_loading_error();
1484 }
1485 CDSConfig::stop_using_full_module_graph("archive heap loading failed");
1486 }
1487 }
1488
1489 bool FileMapInfo::can_use_heap_region() {
1490 if (!has_heap_region()) {
1491 return false;
1492 }
1493 if (JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::has_early_class_hook_env()) {
1494 ShouldNotReachHere(); // CDS should have been disabled.
1862 return false;
1863 }
1864 if (JvmtiExport::has_early_vmstart_env()) {
1865 aot_log_error(aot)("%s has aot-linked classes. It cannot be used when JVMTI early vm start is in use.",
1866 archive_type);
1867 return false;
1868 }
1869 if (!CDSConfig::is_using_full_module_graph()) {
1870 aot_log_error(aot)("%s has aot-linked classes. It cannot be used when archived full module graph is not used.",
1871 archive_type);
1872 return false;
1873 }
1874
1875 const char* prop = Arguments::get_property("java.security.manager");
1876 if (prop != nullptr && strcmp(prop, "disallow") != 0) {
1877 aot_log_error(aot)("%s has aot-linked classes. It cannot be used with -Djava.security.manager=%s.",
1878 archive_type, prop);
1879 return false;
1880 }
1881
1882 #if INCLUDE_JVMTI
1883 if (Arguments::has_jdwp_agent()) {
1884 aot_log_error(aot)("%s has aot-linked classes. It cannot be used with JDWP agent", archive_type);
1885 return false;
1886 }
1887 #endif
1888 }
1889
1890 return true;
1891 }
1892
1893 // The 2 core spaces are RW->RO
1894 FileMapRegion* FileMapInfo::first_core_region() const {
1895 return region_at(MetaspaceShared::rw);
1896 }
1897
1898 FileMapRegion* FileMapInfo::last_core_region() const {
1899 return region_at(MetaspaceShared::ro);
1900 }
1901
1918 int crc = ClassLoader::crc32(0, buf, (jint)sz);
1919 return crc;
1920 }
1921
1922 // This function should only be called during run time with UseSharedSpaces enabled.
1923 bool FileMapHeader::validate() {
1924 const char* file_type = CDSConfig::type_of_archive_being_loaded();
1925 if (_obj_alignment != ObjectAlignmentInBytes) {
1926 aot_log_info(aot)("The %s's ObjectAlignmentInBytes of %d"
1927 " does not equal the current ObjectAlignmentInBytes of %d.",
1928 file_type, _obj_alignment, ObjectAlignmentInBytes);
1929 return false;
1930 }
1931 if (_compact_strings != CompactStrings) {
1932 aot_log_info(aot)("The %s's CompactStrings setting (%s)"
1933 " does not equal the current CompactStrings setting (%s).", file_type,
1934 _compact_strings ? "enabled" : "disabled",
1935 CompactStrings ? "enabled" : "disabled");
1936 return false;
1937 }
1938 if (TrainingData::have_data()) {
1939 if (_type_profile_level != TypeProfileLevel) {
1940 MetaspaceShared::report_loading_error("The %s's TypeProfileLevel setting (%d)"
1941 " does not equal the current TypeProfileLevel setting (%d).", file_type,
1942 _type_profile_level, TypeProfileLevel);
1943 return false;
1944 }
1945 if (_type_profile_args_limit != TypeProfileArgsLimit) {
1946 MetaspaceShared::report_loading_error("The %s's TypeProfileArgsLimit setting (%d)"
1947 " does not equal the current TypeProfileArgsLimit setting (%d).", file_type,
1948 _type_profile_args_limit, TypeProfileArgsLimit);
1949 return false;
1950 }
1951 if (_type_profile_parms_limit != TypeProfileParmsLimit) {
1952 MetaspaceShared::report_loading_error("The %s's TypeProfileParamsLimit setting (%d)"
1953 " does not equal the current TypeProfileParamsLimit setting (%d).", file_type,
1954 _type_profile_args_limit, TypeProfileArgsLimit);
1955 return false;
1956
1957 }
2055 }
2056
2057 if (compact_headers() != UseCompactObjectHeaders) {
2058 aot_log_warning(aot)("Unable to use %s.\nThe %s's UseCompactObjectHeaders setting (%s)"
2059 " does not equal the current UseCompactObjectHeaders setting (%s).", file_type, file_type,
2060 _compact_headers ? "enabled" : "disabled",
2061 UseCompactObjectHeaders ? "enabled" : "disabled");
2062 return false;
2063 }
2064
2065 if (!_use_optimized_module_handling && !CDSConfig::is_dumping_final_static_archive()) {
2066 CDSConfig::stop_using_optimized_module_handling();
2067 aot_log_info(aot)("optimized module handling: disabled because archive was created without optimized module handling");
2068 }
2069
2070 if (is_static()) {
2071 // Only the static archive can contain the full module graph.
2072 if (!_has_full_module_graph) {
2073 CDSConfig::stop_using_full_module_graph("archive was created without full module graph");
2074 }
2075 }
2076
2077 return true;
2078 }
2079
2080 bool FileMapInfo::validate_header() {
2081 if (!header()->validate()) {
2082 return false;
2083 }
2084 if (_is_static) {
2085 return true;
2086 } else {
2087 return DynamicArchive::validate(this);
2088 }
2089 }
2090
2091 #if INCLUDE_JVMTI
2092 ClassPathEntry** FileMapInfo::_classpath_entries_for_jvmti = nullptr;
2093
2094 ClassPathEntry* FileMapInfo::get_classpath_entry_for_jvmti(int i, TRAPS) {
|
27 #include "cds/archiveBuilder.hpp"
28 #include "cds/archiveHeapLoader.inline.hpp"
29 #include "cds/archiveHeapWriter.hpp"
30 #include "cds/archiveUtils.inline.hpp"
31 #include "cds/cds_globals.hpp"
32 #include "cds/cdsConfig.hpp"
33 #include "cds/dynamicArchive.hpp"
34 #include "cds/filemap.hpp"
35 #include "cds/heapShared.hpp"
36 #include "cds/metaspaceShared.hpp"
37 #include "classfile/altHashing.hpp"
38 #include "classfile/classFileStream.hpp"
39 #include "classfile/classLoader.hpp"
40 #include "classfile/classLoader.inline.hpp"
41 #include "classfile/classLoaderData.inline.hpp"
42 #include "classfile/classLoaderExt.hpp"
43 #include "classfile/symbolTable.hpp"
44 #include "classfile/systemDictionaryShared.hpp"
45 #include "classfile/vmClasses.hpp"
46 #include "classfile/vmSymbols.hpp"
47 #include "compiler/compilerDefinitions.inline.hpp"
48 #include "jvm.h"
49 #include "logging/log.hpp"
50 #include "logging/logMessage.hpp"
51 #include "logging/logStream.hpp"
52 #include "memory/iterator.inline.hpp"
53 #include "memory/metadataFactory.hpp"
54 #include "memory/metaspaceClosure.hpp"
55 #include "memory/oopFactory.hpp"
56 #include "memory/universe.hpp"
57 #include "nmt/memTracker.hpp"
58 #include "oops/access.hpp"
59 #include "oops/compressedOops.hpp"
60 #include "oops/compressedOops.inline.hpp"
61 #include "oops/compressedKlass.hpp"
62 #include "oops/objArrayOop.hpp"
63 #include "oops/oop.inline.hpp"
64 #include "oops/trainingData.hpp"
65 #include "oops/typeArrayKlass.hpp"
66 #include "prims/jvmtiExport.hpp"
67 #include "runtime/arguments.hpp"
216 }
217 _core_region_alignment = core_region_alignment;
218 _obj_alignment = ObjectAlignmentInBytes;
219 _compact_strings = CompactStrings;
220 _compact_headers = UseCompactObjectHeaders;
221 if (CDSConfig::is_dumping_heap()) {
222 _narrow_oop_mode = CompressedOops::mode();
223 _narrow_oop_base = CompressedOops::base();
224 _narrow_oop_shift = CompressedOops::shift();
225 }
226 _compressed_oops = UseCompressedOops;
227 _compressed_class_ptrs = UseCompressedClassPointers;
228 if (UseCompressedClassPointers) {
229 #ifdef _LP64
230 _narrow_klass_pointer_bits = CompressedKlassPointers::narrow_klass_pointer_bits();
231 _narrow_klass_shift = ArchiveBuilder::precomputed_narrow_klass_shift();
232 #endif
233 } else {
234 _narrow_klass_pointer_bits = _narrow_klass_shift = -1;
235 }
236 // Which JIT compier is used
237 _compiler_type = (u1)CompilerConfig::compiler_type();
238 _type_profile_level = TypeProfileLevel;
239 _type_profile_args_limit = TypeProfileArgsLimit;
240 _type_profile_parms_limit = TypeProfileParmsLimit;
241 _type_profile_width = TypeProfileWidth;
242 _bci_profile_width = BciProfileWidth;
243 _profile_traps = ProfileTraps;
244 _type_profile_casts = TypeProfileCasts;
245 _spec_trap_limit_extra_entries = SpecTrapLimitExtraEntries;
246 _max_heap_size = MaxHeapSize;
247 _use_optimized_module_handling = CDSConfig::is_using_optimized_module_handling();
248 _has_aot_linked_classes = CDSConfig::is_dumping_aot_linked_classes();
249 _has_full_module_graph = CDSConfig::is_dumping_full_module_graph();
250 _has_archived_packages = CDSConfig::is_dumping_packages();
251 _has_archived_protection_domains = CDSConfig::is_dumping_protection_domains();
252 _gc_kind = (int)Universe::heap()->kind();
253 jio_snprintf(_gc_name, sizeof(_gc_name), Universe::heap()->name());
254
255 // The following fields are for sanity checks for whether this archive
256 // will function correctly with this JVM and the bootclasspath it's
257 // invoked with.
258
259 // JVM version string ... changes on each build.
260 get_header_version(_jvm_ident);
261
262 _verify_local = BytecodeVerificationLocal;
263 _verify_remote = BytecodeVerificationRemote;
264 _has_platform_or_app_classes = AOTClassLocationConfig::dumptime()->has_platform_or_app_classes();
265 _requested_base_address = (char*)SharedBaseAddress;
266 _mapped_base_address = (char*)SharedBaseAddress;
267 _allow_archiving_with_java_agent = AllowArchivingWithJavaAgent;
268 }
269
270 void FileMapHeader::copy_base_archive_name(const char* archive) {
271 assert(base_archive_name_size() != 0, "_base_archive_name_size not set");
272 assert(base_archive_name_offset() != 0, "_base_archive_name_offset not set");
273 assert(header_size() > sizeof(*this), "_base_archive_name_size not included in header size?");
308 st->print_cr("- jvm_ident: %s", _jvm_ident);
309 st->print_cr("- class_location_config_offset: 0x%zx", _class_location_config_offset);
310 st->print_cr("- verify_local: %d", _verify_local);
311 st->print_cr("- verify_remote: %d", _verify_remote);
312 st->print_cr("- has_platform_or_app_classes: %d", _has_platform_or_app_classes);
313 st->print_cr("- requested_base_address: " INTPTR_FORMAT, p2i(_requested_base_address));
314 st->print_cr("- mapped_base_address: " INTPTR_FORMAT, p2i(_mapped_base_address));
315 st->print_cr("- heap_root_segments.roots_count: %d" , _heap_root_segments.roots_count());
316 st->print_cr("- heap_root_segments.base_offset: 0x%zx", _heap_root_segments.base_offset());
317 st->print_cr("- heap_root_segments.count: %zu", _heap_root_segments.count());
318 st->print_cr("- heap_root_segments.max_size_elems: %d", _heap_root_segments.max_size_in_elems());
319 st->print_cr("- heap_root_segments.max_size_bytes: %d", _heap_root_segments.max_size_in_bytes());
320 st->print_cr("- _heap_oopmap_start_pos: %zu", _heap_oopmap_start_pos);
321 st->print_cr("- _heap_ptrmap_start_pos: %zu", _heap_ptrmap_start_pos);
322 st->print_cr("- _rw_ptrmap_start_pos: %zu", _rw_ptrmap_start_pos);
323 st->print_cr("- _ro_ptrmap_start_pos: %zu", _ro_ptrmap_start_pos);
324 st->print_cr("- allow_archiving_with_java_agent:%d", _allow_archiving_with_java_agent);
325 st->print_cr("- use_optimized_module_handling: %d", _use_optimized_module_handling);
326 st->print_cr("- has_full_module_graph %d", _has_full_module_graph);
327 st->print_cr("- has_aot_linked_classes %d", _has_aot_linked_classes);
328 st->print_cr("- has_archived_packages %d", _has_archived_packages);
329 st->print_cr("- has_archived_protection_domains %d", _has_archived_protection_domains);
330 st->print_cr("- ptrmap_size_in_bits: %zu", _ptrmap_size_in_bits);
331 }
332
333 bool FileMapInfo::validate_class_location() {
334 assert(CDSConfig::is_using_archive(), "runtime only");
335
336 AOTClassLocationConfig* config = header()->class_location_config();
337 bool has_extra_module_paths = false;
338 if (!config->validate(header()->has_aot_linked_classes(), &has_extra_module_paths)) {
339 if (PrintSharedArchiveAndExit) {
340 MetaspaceShared::set_archive_loading_failed();
341 return true;
342 } else {
343 return false;
344 }
345 }
346
347 if (header()->has_full_module_graph() && has_extra_module_paths) {
348 CDSConfig::stop_using_optimized_module_handling();
349 MetaspaceShared::report_loading_error("optimized module handling: disabled because extra module path(s) are specified");
350 }
913 assert((mapping_offset >> CompressedOops::shift()) << CompressedOops::shift() == mapping_offset, "must be");
914 } else {
915 mapping_offset = 0; // not used with !UseCompressedOops
916 }
917 #endif // INCLUDE_CDS_JAVA_HEAP
918 } else {
919 char* requested_SharedBaseAddress = (char*)MetaspaceShared::requested_base_address();
920 requested_base = ArchiveBuilder::current()->to_requested(base);
921 assert(requested_base >= requested_SharedBaseAddress, "must be");
922 mapping_offset = requested_base - requested_SharedBaseAddress;
923 }
924
925 r->set_file_offset(_file_offset);
926 int crc = ClassLoader::crc32(0, base, (jint)size);
927 if (size > 0) {
928 aot_log_info(aot)("Shared file region (%s) %d: %8zu"
929 " bytes, addr " INTPTR_FORMAT " file offset 0x%08" PRIxPTR
930 " crc 0x%08x",
931 region_name(region), region, size, p2i(requested_base), _file_offset, crc);
932 } else {
933 aot_log_info(aot)("Shared file region (%s) %d: %8zu"
934 " bytes", region_name(region), region, size);
935 }
936
937 r->init(region, mapping_offset, size, read_only, allow_exec, crc);
938
939 if (base != nullptr) {
940 write_bytes_aligned(base, size);
941 }
942 }
943
944 static size_t write_bitmap(const CHeapBitMap* map, char* output, size_t offset) {
945 size_t size_in_bytes = map->size_in_bytes();
946 map->write_to((BitMap::bm_word_t*)(output + offset), size_in_bytes);
947 return offset + size_in_bytes;
948 }
949
950 // The sorting code groups the objects with non-null oop/ptrs together.
951 // Relevant bitmaps then have lots of leading and trailing zeros, which
952 // we do not have to store.
953 size_t FileMapInfo::remove_bitmap_zeros(CHeapBitMap* map) {
954 BitMap::idx_t first_set = map->find_first_set_bit(0);
955 BitMap::idx_t last_set = map->find_last_set_bit(0);
956 size_t old_size = map->size();
957
958 // Slice and resize bitmap
959 map->truncate(first_set, last_set + 1);
960
961 assert(map->at(0), "First bit should be set");
962 assert(map->at(map->size() - 1), "Last bit should be set");
963 assert(map->size() <= old_size, "sanity");
964
965 return first_set;
966 }
967
968 char* FileMapInfo::write_bitmap_region(CHeapBitMap* rw_ptrmap, CHeapBitMap* ro_ptrmap,
969 CHeapBitMap* ac_ptrmap,
970 ArchiveHeapInfo* heap_info,
971 size_t &size_in_bytes) {
972 size_t removed_rw_leading_zeros = remove_bitmap_zeros(rw_ptrmap);
973 size_t removed_ro_leading_zeros = remove_bitmap_zeros(ro_ptrmap);
974 header()->set_rw_ptrmap_start_pos(removed_rw_leading_zeros);
975 header()->set_ro_ptrmap_start_pos(removed_ro_leading_zeros);
976 size_in_bytes = rw_ptrmap->size_in_bytes() + ro_ptrmap->size_in_bytes() + ac_ptrmap->size_in_bytes();
977
978 if (heap_info->is_used()) {
979 // Remove leading and trailing zeros
980 size_t removed_oop_leading_zeros = remove_bitmap_zeros(heap_info->oopmap());
981 size_t removed_ptr_leading_zeros = remove_bitmap_zeros(heap_info->ptrmap());
982 header()->set_heap_oopmap_start_pos(removed_oop_leading_zeros);
983 header()->set_heap_ptrmap_start_pos(removed_ptr_leading_zeros);
984
985 size_in_bytes += heap_info->oopmap()->size_in_bytes();
986 size_in_bytes += heap_info->ptrmap()->size_in_bytes();
987 }
988
989 // The bitmap region contains up to 4 parts:
990 // rw_ptrmap: metaspace pointers inside the read-write region
991 // ro_ptrmap: metaspace pointers inside the read-only region
992 // heap_info->oopmap(): Java oop pointers in the heap region
993 // heap_info->ptrmap(): metaspace pointers in the heap region
994 char* buffer = NEW_C_HEAP_ARRAY(char, size_in_bytes, mtClassShared);
995 size_t written = 0;
996
997 region_at(MetaspaceShared::rw)->init_ptrmap(0, rw_ptrmap->size());
998 written = write_bitmap(rw_ptrmap, buffer, written);
999
1000 region_at(MetaspaceShared::ro)->init_ptrmap(written, ro_ptrmap->size());
1001 written = write_bitmap(ro_ptrmap, buffer, written);
1002
1003 region_at(MetaspaceShared::ac)->init_ptrmap(written, ac_ptrmap->size());
1004 written = write_bitmap(ac_ptrmap, buffer, written);
1005
1006 if (heap_info->is_used()) {
1007 FileMapRegion* r = region_at(MetaspaceShared::hp);
1008
1009 r->init_oopmap(written, heap_info->oopmap()->size());
1010 written = write_bitmap(heap_info->oopmap(), buffer, written);
1011
1012 r->init_ptrmap(written, heap_info->ptrmap()->size());
1013 written = write_bitmap(heap_info->ptrmap(), buffer, written);
1014 }
1015
1016 write_region(MetaspaceShared::bm, (char*)buffer, size_in_bytes, /*read_only=*/true, /*allow_exec=*/false);
1017 return buffer;
1018 }
1019
1020 size_t FileMapInfo::write_heap_region(ArchiveHeapInfo* heap_info) {
1021 char* buffer_start = heap_info->buffer_start();
1022 size_t buffer_size = heap_info->buffer_byte_size();
1023 write_region(MetaspaceShared::hp, buffer_start, buffer_size, false, false);
1024 header()->set_heap_root_segments(heap_info->heap_root_segments());
1025 return buffer_size;
1224 } else if (addr_delta != 0) {
1225 r->set_read_only(false); // Need to patch the pointers
1226 }
1227
1228 if (MetaspaceShared::use_windows_memory_mapping() && rs.is_reserved()) {
1229 // This is the second time we try to map the archive(s). We have already created a ReservedSpace
1230 // that covers all the FileMapRegions to ensure all regions can be mapped. However, Windows
1231 // can't mmap into a ReservedSpace, so we just ::read() the data. We're going to patch all the
1232 // regions anyway, so there's no benefit for mmap anyway.
1233 if (!read_region(i, requested_addr, size, /* do_commit = */ true)) {
1234 aot_log_info(aot)("Failed to read %s shared space into reserved space at " INTPTR_FORMAT,
1235 shared_region_name[i], p2i(requested_addr));
1236 return MAP_ARCHIVE_OTHER_FAILURE; // oom or I/O error.
1237 } else {
1238 assert(r->mapped_base() != nullptr, "must be initialized");
1239 }
1240 } else {
1241 // Note that this may either be a "fresh" mapping into unreserved address
1242 // space (Windows, first mapping attempt), or a mapping into pre-reserved
1243 // space (Posix). See also comment in MetaspaceShared::map_archives().
1244 bool read_only = r->read_only() && !CDSConfig::is_dumping_final_static_archive();
1245 char* base = map_memory(_fd, _full_path, r->file_offset(),
1246 requested_addr, size, read_only,
1247 r->allow_exec(), mtClassShared);
1248 if (base != requested_addr) {
1249 aot_log_info(aot)("Unable to map %s shared space at " INTPTR_FORMAT,
1250 shared_region_name[i], p2i(requested_addr));
1251 _memory_mapping_failed = true;
1252 return MAP_ARCHIVE_MMAP_FAILURE;
1253 }
1254
1255 if (VerifySharedSpaces && !r->check_region_crc(requested_addr)) {
1256 return MAP_ARCHIVE_OTHER_FAILURE;
1257 }
1258
1259 r->set_mapped_from_file(true);
1260 r->set_mapped_base(requested_addr);
1261 }
1262
1263 if (rs.is_reserved()) {
1264 char* mapped_base = r->mapped_base();
1265 assert(rs.base() <= mapped_base && mapped_base + size <= rs.end(),
1266 PTR_FORMAT " <= " PTR_FORMAT " < " PTR_FORMAT " <= " PTR_FORMAT,
1314 if (!read_region(MetaspaceShared::ac, requested_base, r->used_aligned(), /* do_commit = */ true)) {
1315 aot_log_info(aot)("Failed to read aot code shared space into reserved space at " INTPTR_FORMAT,
1316 p2i(requested_base));
1317 return false;
1318 }
1319 mapped_base = requested_base;
1320 } else {
1321 // We do not execute in-place in the AOT code region.
1322 // AOT code is copied to the CodeCache for execution.
1323 bool read_only = false, allow_exec = false;
1324 mapped_base = map_memory(_fd, _full_path, r->file_offset(),
1325 requested_base, r->used_aligned(), read_only, allow_exec, mtClassShared);
1326 }
1327 if (mapped_base == nullptr) {
1328 aot_log_info(aot)("failed to map aot code region");
1329 return false;
1330 } else {
1331 assert(mapped_base == requested_base, "must be");
1332 r->set_mapped_from_file(true);
1333 r->set_mapped_base(mapped_base);
1334 relocate_pointers_in_aot_code_region();
1335 aot_log_info(aot)("Mapped static region #%d at base " INTPTR_FORMAT " top " INTPTR_FORMAT " (%s)",
1336 MetaspaceShared::ac, p2i(r->mapped_base()), p2i(r->mapped_end()),
1337 shared_region_name[MetaspaceShared::ac]);
1338 return true;
1339 }
1340 }
1341
1342 class CachedCodeRelocator: public BitMapClosure {
1343 address _code_requested_base;
1344 address* _patch_base;
1345 intx _code_delta;
1346 intx _metadata_delta;
1347
1348 public:
1349 CachedCodeRelocator(address code_requested_base, address code_mapped_base,
1350 intx metadata_delta) {
1351 _code_requested_base = code_requested_base;
1352 _patch_base = (address*)code_mapped_base;
1353 _code_delta = code_mapped_base - code_requested_base;
1354 _metadata_delta = metadata_delta;
1355 }
1356
1357 bool do_bit(size_t offset) {
1358 address* p = _patch_base + offset;
1359 address requested_ptr = *p;
1360 if (requested_ptr < _code_requested_base) {
1361 *p = requested_ptr + _metadata_delta;
1362 } else {
1363 *p = requested_ptr + _code_delta;
1364 }
1365 return true; // keep iterating
1366 }
1367 };
1368
1369 void FileMapInfo::relocate_pointers_in_aot_code_region() {
1370 FileMapRegion* r = region_at(MetaspaceShared::ac);
1371 char* bitmap_base = map_bitmap_region();
1372
1373 BitMapView ac_ptrmap = ptrmap_view(MetaspaceShared::ac);
1374 if (ac_ptrmap.size() == 0) {
1375 return;
1376 }
1377
1378 address core_regions_requested_base = (address)header()->requested_base_address();
1379 address core_regions_mapped_base = (address)header()->mapped_base_address();
1380 address ac_region_requested_base = core_regions_requested_base + r->mapping_offset();
1381 address ac_region_mapped_base = (address)r->mapped_base();
1382
1383 size_t max_bits_for_core_regions = pointer_delta(mapped_end(), mapped_base(), // FIXME - renamed to core_regions_mapped_base(), etc
1384 sizeof(address));
1385
1386 CachedCodeRelocator patcher(ac_region_requested_base, ac_region_mapped_base,
1387 core_regions_mapped_base - core_regions_requested_base);
1388 ac_ptrmap.iterate(&patcher);
1389 }
1390
1391 class SharedDataRelocationTask : public ArchiveWorkerTask {
1392 private:
1393 BitMapView* const _rw_bm;
1394 BitMapView* const _ro_bm;
1395 SharedDataRelocator* const _rw_reloc;
1396 SharedDataRelocator* const _ro_reloc;
1397
1398 public:
1399 SharedDataRelocationTask(BitMapView* rw_bm, BitMapView* ro_bm, SharedDataRelocator* rw_reloc, SharedDataRelocator* ro_reloc) :
1400 ArchiveWorkerTask("Shared Data Relocation"),
1401 _rw_bm(rw_bm), _ro_bm(ro_bm), _rw_reloc(rw_reloc), _ro_reloc(ro_reloc) {}
1402
1403 void work(int chunk, int max_chunks) override {
1404 work_on(chunk, max_chunks, _rw_bm, _rw_reloc);
1405 work_on(chunk, max_chunks, _ro_bm, _ro_reloc);
1406 }
1407
1408 void work_on(int chunk, int max_chunks, BitMapView* bm, SharedDataRelocator* reloc) {
1409 BitMap::idx_t size = bm->size();
1410 BitMap::idx_t start = MIN2(size, size * chunk / max_chunks);
1520 }
1521
1522 void FileMapInfo::map_or_load_heap_region() {
1523 bool success = false;
1524
1525 if (can_use_heap_region()) {
1526 if (ArchiveHeapLoader::can_map()) {
1527 success = map_heap_region();
1528 } else if (ArchiveHeapLoader::can_load()) {
1529 success = ArchiveHeapLoader::load_heap_region(this);
1530 } else {
1531 if (!UseCompressedOops && !ArchiveHeapLoader::can_map()) {
1532 MetaspaceShared::report_loading_error("Cannot use CDS heap data. Selected GC not compatible -XX:-UseCompressedOops");
1533 } else {
1534 MetaspaceShared::report_loading_error("Cannot use CDS heap data. UseEpsilonGC, UseG1GC, UseSerialGC, UseParallelGC, or UseShenandoahGC are required.");
1535 }
1536 }
1537 }
1538
1539 if (!success) {
1540 if (CDSConfig::is_using_aot_linked_classes() && !CDSConfig::is_dumping_final_static_archive()) {
1541 // It's too late to recover -- we have already committed to use the archived metaspace objects, but
1542 // the archived heap objects cannot be loaded, so we don't have the archived FMG to guarantee that
1543 // all AOT-linked classes are visible.
1544 //
1545 // We get here because the heap is too small. The app will fail anyway. So let's quit.
1546 aot_log_error(aot)("%s has aot-linked classes but the archived "
1547 "heap objects cannot be loaded. Try increasing your heap size.",
1548 CDSConfig::type_of_archive_being_loaded());
1549 MetaspaceShared::unrecoverable_loading_error();
1550 }
1551 CDSConfig::stop_using_full_module_graph("archive heap loading failed");
1552 }
1553 }
1554
1555 bool FileMapInfo::can_use_heap_region() {
1556 if (!has_heap_region()) {
1557 return false;
1558 }
1559 if (JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::has_early_class_hook_env()) {
1560 ShouldNotReachHere(); // CDS should have been disabled.
1928 return false;
1929 }
1930 if (JvmtiExport::has_early_vmstart_env()) {
1931 aot_log_error(aot)("%s has aot-linked classes. It cannot be used when JVMTI early vm start is in use.",
1932 archive_type);
1933 return false;
1934 }
1935 if (!CDSConfig::is_using_full_module_graph()) {
1936 aot_log_error(aot)("%s has aot-linked classes. It cannot be used when archived full module graph is not used.",
1937 archive_type);
1938 return false;
1939 }
1940
1941 const char* prop = Arguments::get_property("java.security.manager");
1942 if (prop != nullptr && strcmp(prop, "disallow") != 0) {
1943 aot_log_error(aot)("%s has aot-linked classes. It cannot be used with -Djava.security.manager=%s.",
1944 archive_type, prop);
1945 return false;
1946 }
1947
1948 if (header()->gc_kind() != (int)Universe::heap()->kind()) {
1949 log_error(cds)("CDS archive has aot-linked classes. It cannot be used because GC used during dump time (%s) is not the same as runtime (%s)",
1950 header()->gc_name(), Universe::heap()->name());
1951 return false;
1952 }
1953
1954 #if INCLUDE_JVMTI
1955 if (Arguments::has_jdwp_agent()) {
1956 aot_log_error(aot)("%s has aot-linked classes. It cannot be used with JDWP agent", archive_type);
1957 return false;
1958 }
1959 #endif
1960 }
1961
1962 return true;
1963 }
1964
1965 // The 2 core spaces are RW->RO
1966 FileMapRegion* FileMapInfo::first_core_region() const {
1967 return region_at(MetaspaceShared::rw);
1968 }
1969
1970 FileMapRegion* FileMapInfo::last_core_region() const {
1971 return region_at(MetaspaceShared::ro);
1972 }
1973
1990 int crc = ClassLoader::crc32(0, buf, (jint)sz);
1991 return crc;
1992 }
1993
1994 // This function should only be called during run time with UseSharedSpaces enabled.
1995 bool FileMapHeader::validate() {
1996 const char* file_type = CDSConfig::type_of_archive_being_loaded();
1997 if (_obj_alignment != ObjectAlignmentInBytes) {
1998 aot_log_info(aot)("The %s's ObjectAlignmentInBytes of %d"
1999 " does not equal the current ObjectAlignmentInBytes of %d.",
2000 file_type, _obj_alignment, ObjectAlignmentInBytes);
2001 return false;
2002 }
2003 if (_compact_strings != CompactStrings) {
2004 aot_log_info(aot)("The %s's CompactStrings setting (%s)"
2005 " does not equal the current CompactStrings setting (%s).", file_type,
2006 _compact_strings ? "enabled" : "disabled",
2007 CompactStrings ? "enabled" : "disabled");
2008 return false;
2009 }
2010 bool jvmci_compiler_is_enabled = CompilerConfig::is_jvmci_compiler_enabled();
2011 CompilerType compiler_type = CompilerConfig::compiler_type();
2012 CompilerType archive_compiler_type = CompilerType(_compiler_type);
2013 // JVMCI compiler does different type profiling settigns and generate
2014 // different code. We can't use archive which was produced
2015 // without it and reverse.
2016 // Only allow mix when JIT compilation is disabled.
2017 // Interpreter is used by default when dumping archive.
2018 bool intepreter_is_used = (archive_compiler_type == CompilerType::compiler_none) ||
2019 (compiler_type == CompilerType::compiler_none);
2020 if (!intepreter_is_used &&
2021 jvmci_compiler_is_enabled != (archive_compiler_type == CompilerType::compiler_jvmci)) {
2022 MetaspaceShared::report_loading_error("The %s's JIT compiler setting (%s)"
2023 " does not equal the current setting (%s).", file_type,
2024 compilertype2name(archive_compiler_type), compilertype2name(compiler_type));
2025 return false;
2026 }
2027 if (TrainingData::have_data()) {
2028 if (_type_profile_level != TypeProfileLevel) {
2029 MetaspaceShared::report_loading_error("The %s's TypeProfileLevel setting (%d)"
2030 " does not equal the current TypeProfileLevel setting (%d).", file_type,
2031 _type_profile_level, TypeProfileLevel);
2032 return false;
2033 }
2034 if (_type_profile_args_limit != TypeProfileArgsLimit) {
2035 MetaspaceShared::report_loading_error("The %s's TypeProfileArgsLimit setting (%d)"
2036 " does not equal the current TypeProfileArgsLimit setting (%d).", file_type,
2037 _type_profile_args_limit, TypeProfileArgsLimit);
2038 return false;
2039 }
2040 if (_type_profile_parms_limit != TypeProfileParmsLimit) {
2041 MetaspaceShared::report_loading_error("The %s's TypeProfileParamsLimit setting (%d)"
2042 " does not equal the current TypeProfileParamsLimit setting (%d).", file_type,
2043 _type_profile_args_limit, TypeProfileArgsLimit);
2044 return false;
2045
2046 }
2144 }
2145
2146 if (compact_headers() != UseCompactObjectHeaders) {
2147 aot_log_warning(aot)("Unable to use %s.\nThe %s's UseCompactObjectHeaders setting (%s)"
2148 " does not equal the current UseCompactObjectHeaders setting (%s).", file_type, file_type,
2149 _compact_headers ? "enabled" : "disabled",
2150 UseCompactObjectHeaders ? "enabled" : "disabled");
2151 return false;
2152 }
2153
2154 if (!_use_optimized_module_handling && !CDSConfig::is_dumping_final_static_archive()) {
2155 CDSConfig::stop_using_optimized_module_handling();
2156 aot_log_info(aot)("optimized module handling: disabled because archive was created without optimized module handling");
2157 }
2158
2159 if (is_static()) {
2160 // Only the static archive can contain the full module graph.
2161 if (!_has_full_module_graph) {
2162 CDSConfig::stop_using_full_module_graph("archive was created without full module graph");
2163 }
2164
2165 if (_has_archived_packages) {
2166 CDSConfig::set_is_loading_packages();
2167 }
2168 if (_has_archived_protection_domains) {
2169 CDSConfig::set_is_loading_protection_domains();
2170 }
2171 }
2172
2173 return true;
2174 }
2175
2176 bool FileMapInfo::validate_header() {
2177 if (!header()->validate()) {
2178 return false;
2179 }
2180 if (_is_static) {
2181 return true;
2182 } else {
2183 return DynamicArchive::validate(this);
2184 }
2185 }
2186
2187 #if INCLUDE_JVMTI
2188 ClassPathEntry** FileMapInfo::_classpath_entries_for_jvmti = nullptr;
2189
2190 ClassPathEntry* FileMapInfo::get_classpath_entry_for_jvmti(int i, TRAPS) {
|