218 if (CDSConfig::is_dumping_heap()) {
219 _narrow_oop_mode = CompressedOops::mode();
220 _narrow_oop_base = CompressedOops::base();
221 _narrow_oop_shift = CompressedOops::shift();
222 }
223 _compressed_oops = UseCompressedOops;
224 _compressed_class_ptrs = UseCompressedClassPointers;
225 if (UseCompressedClassPointers) {
226 #ifdef _LP64
227 _narrow_klass_pointer_bits = CompressedKlassPointers::narrow_klass_pointer_bits();
228 _narrow_klass_shift = ArchiveBuilder::precomputed_narrow_klass_shift();
229 #endif
230 } else {
231 _narrow_klass_pointer_bits = _narrow_klass_shift = -1;
232 }
233 _max_heap_size = MaxHeapSize;
234 _use_optimized_module_handling = CDSConfig::is_using_optimized_module_handling();
235 _has_aot_linked_classes = CDSConfig::is_dumping_aot_linked_classes();
236 _has_full_module_graph = CDSConfig::is_dumping_full_module_graph();
237 _has_archived_invokedynamic = CDSConfig::is_dumping_invokedynamic();
238
239 // The following fields are for sanity checks for whether this archive
240 // will function correctly with this JVM and the bootclasspath it's
241 // invoked with.
242
243 // JVM version string ... changes on each build.
244 get_header_version(_jvm_ident);
245
246 _verify_local = BytecodeVerificationLocal;
247 _verify_remote = BytecodeVerificationRemote;
248 _has_platform_or_app_classes = AOTClassLocationConfig::dumptime()->has_platform_or_app_classes();
249 _requested_base_address = (char*)SharedBaseAddress;
250 _mapped_base_address = (char*)SharedBaseAddress;
251 _allow_archiving_with_java_agent = AllowArchivingWithJavaAgent;
252 }
253
254 void FileMapHeader::copy_base_archive_name(const char* archive) {
255 assert(base_archive_name_size() != 0, "_base_archive_name_size not set");
256 assert(base_archive_name_offset() != 0, "_base_archive_name_offset not set");
257 assert(header_size() > sizeof(*this), "_base_archive_name_size not included in header size?");
293 st->print_cr("- class_location_config_offset: 0x%zx", _class_location_config_offset);
294 st->print_cr("- verify_local: %d", _verify_local);
295 st->print_cr("- verify_remote: %d", _verify_remote);
296 st->print_cr("- has_platform_or_app_classes: %d", _has_platform_or_app_classes);
297 st->print_cr("- requested_base_address: " INTPTR_FORMAT, p2i(_requested_base_address));
298 st->print_cr("- mapped_base_address: " INTPTR_FORMAT, p2i(_mapped_base_address));
299 st->print_cr("- heap_root_segments.roots_count: %d" , _heap_root_segments.roots_count());
300 st->print_cr("- heap_root_segments.base_offset: 0x%zx", _heap_root_segments.base_offset());
301 st->print_cr("- heap_root_segments.count: %zu", _heap_root_segments.count());
302 st->print_cr("- heap_root_segments.max_size_elems: %d", _heap_root_segments.max_size_in_elems());
303 st->print_cr("- heap_root_segments.max_size_bytes: %d", _heap_root_segments.max_size_in_bytes());
304 st->print_cr("- _heap_oopmap_start_pos: %zu", _heap_oopmap_start_pos);
305 st->print_cr("- _heap_ptrmap_start_pos: %zu", _heap_ptrmap_start_pos);
306 st->print_cr("- _rw_ptrmap_start_pos: %zu", _rw_ptrmap_start_pos);
307 st->print_cr("- _ro_ptrmap_start_pos: %zu", _ro_ptrmap_start_pos);
308 st->print_cr("- allow_archiving_with_java_agent:%d", _allow_archiving_with_java_agent);
309 st->print_cr("- use_optimized_module_handling: %d", _use_optimized_module_handling);
310 st->print_cr("- has_full_module_graph %d", _has_full_module_graph);
311 st->print_cr("- has_aot_linked_classes %d", _has_aot_linked_classes);
312 st->print_cr("- has_archived_invokedynamic %d", _has_archived_invokedynamic);
313 }
314
315 bool FileMapInfo::validate_class_location() {
316 assert(CDSConfig::is_using_archive(), "runtime only");
317
318 AOTClassLocationConfig* config = header()->class_location_config();
319 bool has_extra_module_paths = false;
320 if (!config->validate(header()->has_aot_linked_classes(), &has_extra_module_paths)) {
321 if (PrintSharedArchiveAndExit) {
322 MetaspaceShared::set_archive_loading_failed();
323 return true;
324 } else {
325 return false;
326 }
327 }
328
329 if (header()->has_full_module_graph() && has_extra_module_paths) {
330 CDSConfig::stop_using_optimized_module_handling();
331 log_info(cds)("optimized module handling: disabled because extra module path(s) are specified");
332 }
809 bool FileMapRegion::check_region_crc(char* base) const {
810 // This function should be called after the region has been properly
811 // loaded into memory via FileMapInfo::map_region() or FileMapInfo::read_region().
812 // I.e., this->mapped_base() must be valid.
813 size_t sz = used();
814 if (sz == 0) {
815 return true;
816 }
817
818 assert(base != nullptr, "must be initialized");
819 int crc = ClassLoader::crc32(0, base, (jint)sz);
820 if (crc != this->crc()) {
821 log_warning(cds)("Checksum verification failed.");
822 return false;
823 }
824 return true;
825 }
826
827 static const char* region_name(int region_index) {
828 static const char* names[] = {
829 "rw", "ro", "bm", "hp"
830 };
831 const int num_regions = sizeof(names)/sizeof(names[0]);
832 assert(0 <= region_index && region_index < num_regions, "sanity");
833
834 return names[region_index];
835 }
836
837 BitMapView FileMapInfo::bitmap_view(int region_index, bool is_oopmap) {
838 FileMapRegion* r = region_at(region_index);
839 char* bitmap_base = is_static() ? FileMapInfo::current_info()->map_bitmap_region() : FileMapInfo::dynamic_info()->map_bitmap_region();
840 bitmap_base += is_oopmap ? r->oopmap_offset() : r->ptrmap_offset();
841 size_t size_in_bits = is_oopmap ? r->oopmap_size_in_bits() : r->ptrmap_size_in_bits();
842
843 log_debug(cds, reloc)("mapped %s relocation %smap @ " INTPTR_FORMAT " (%zu bits)",
844 region_name(region_index), is_oopmap ? "oop" : "ptr",
845 p2i(bitmap_base), size_in_bits);
846
847 return BitMapView((BitMap::bm_word_t*)(bitmap_base), size_in_bits);
848 }
849
895 mapping_offset = (size_t)((address)requested_base - CompressedOops::base());
896 assert((mapping_offset >> CompressedOops::shift()) << CompressedOops::shift() == mapping_offset, "must be");
897 } else {
898 mapping_offset = 0; // not used with !UseCompressedOops
899 }
900 #endif // INCLUDE_CDS_JAVA_HEAP
901 } else {
902 char* requested_SharedBaseAddress = (char*)MetaspaceShared::requested_base_address();
903 requested_base = ArchiveBuilder::current()->to_requested(base);
904 assert(requested_base >= requested_SharedBaseAddress, "must be");
905 mapping_offset = requested_base - requested_SharedBaseAddress;
906 }
907
908 r->set_file_offset(_file_offset);
909 int crc = ClassLoader::crc32(0, base, (jint)size);
910 if (size > 0) {
911 log_info(cds)("Shared file region (%s) %d: %8zu"
912 " bytes, addr " INTPTR_FORMAT " file offset 0x%08" PRIxPTR
913 " crc 0x%08x",
914 region_name(region), region, size, p2i(requested_base), _file_offset, crc);
915 }
916
917 r->init(region, mapping_offset, size, read_only, allow_exec, crc);
918
919 if (base != nullptr) {
920 write_bytes_aligned(base, size);
921 }
922 }
923
924 static size_t write_bitmap(const CHeapBitMap* map, char* output, size_t offset) {
925 size_t size_in_bytes = map->size_in_bytes();
926 map->write_to((BitMap::bm_word_t*)(output + offset), size_in_bytes);
927 return offset + size_in_bytes;
928 }
929
930 // The sorting code groups the objects with non-null oop/ptrs together.
931 // Relevant bitmaps then have lots of leading and trailing zeros, which
932 // we do not have to store.
933 size_t FileMapInfo::remove_bitmap_zeros(CHeapBitMap* map) {
934 BitMap::idx_t first_set = map->find_first_set_bit(0);
935 BitMap::idx_t last_set = map->find_last_set_bit(0);
936 size_t old_size = map->size();
937
938 // Slice and resize bitmap
939 map->truncate(first_set, last_set + 1);
940
941 assert(map->at(0), "First bit should be set");
942 assert(map->at(map->size() - 1), "Last bit should be set");
943 assert(map->size() <= old_size, "sanity");
944
945 return first_set;
946 }
947
948 char* FileMapInfo::write_bitmap_region(CHeapBitMap* rw_ptrmap, CHeapBitMap* ro_ptrmap, ArchiveHeapInfo* heap_info,
949 size_t &size_in_bytes) {
950 size_t removed_rw_leading_zeros = remove_bitmap_zeros(rw_ptrmap);
951 size_t removed_ro_leading_zeros = remove_bitmap_zeros(ro_ptrmap);
952 header()->set_rw_ptrmap_start_pos(removed_rw_leading_zeros);
953 header()->set_ro_ptrmap_start_pos(removed_ro_leading_zeros);
954 size_in_bytes = rw_ptrmap->size_in_bytes() + ro_ptrmap->size_in_bytes();
955
956 if (heap_info->is_used()) {
957 // Remove leading and trailing zeros
958 size_t removed_oop_leading_zeros = remove_bitmap_zeros(heap_info->oopmap());
959 size_t removed_ptr_leading_zeros = remove_bitmap_zeros(heap_info->ptrmap());
960 header()->set_heap_oopmap_start_pos(removed_oop_leading_zeros);
961 header()->set_heap_ptrmap_start_pos(removed_ptr_leading_zeros);
962
963 size_in_bytes += heap_info->oopmap()->size_in_bytes();
964 size_in_bytes += heap_info->ptrmap()->size_in_bytes();
965 }
966
967 // The bitmap region contains up to 4 parts:
968 // rw_ptrmap: metaspace pointers inside the read-write region
969 // ro_ptrmap: metaspace pointers inside the read-only region
970 // heap_info->oopmap(): Java oop pointers in the heap region
971 // heap_info->ptrmap(): metaspace pointers in the heap region
972 char* buffer = NEW_C_HEAP_ARRAY(char, size_in_bytes, mtClassShared);
973 size_t written = 0;
974
975 region_at(MetaspaceShared::rw)->init_ptrmap(0, rw_ptrmap->size());
976 written = write_bitmap(rw_ptrmap, buffer, written);
977
978 region_at(MetaspaceShared::ro)->init_ptrmap(written, ro_ptrmap->size());
979 written = write_bitmap(ro_ptrmap, buffer, written);
980
981 if (heap_info->is_used()) {
982 FileMapRegion* r = region_at(MetaspaceShared::hp);
983
984 r->init_oopmap(written, heap_info->oopmap()->size());
985 written = write_bitmap(heap_info->oopmap(), buffer, written);
986
987 r->init_ptrmap(written, heap_info->ptrmap()->size());
988 written = write_bitmap(heap_info->ptrmap(), buffer, written);
989 }
990
991 write_region(MetaspaceShared::bm, (char*)buffer, size_in_bytes, /*read_only=*/true, /*allow_exec=*/false);
992 return buffer;
993 }
994
995 size_t FileMapInfo::write_heap_region(ArchiveHeapInfo* heap_info) {
996 char* buffer_start = heap_info->buffer_start();
997 size_t buffer_size = heap_info->buffer_byte_size();
998 write_region(MetaspaceShared::hp, buffer_start, buffer_size, false, false);
999 header()->set_heap_root_segments(heap_info->heap_root_segments());
1000 return buffer_size;
1096 assert(WINDOWS_ONLY(false) NOT_WINDOWS(true), "Don't call on Windows");
1097 // Replace old mapping with new one that is writable.
1098 char *base = os::map_memory(_fd, _full_path, r->file_offset(),
1099 addr, size, false /* !read_only */,
1100 r->allow_exec());
1101 close();
1102 // These have to be errors because the shared region is now unmapped.
1103 if (base == nullptr) {
1104 log_error(cds)("Unable to remap shared readonly space (errno=%d).", errno);
1105 vm_exit(1);
1106 }
1107 if (base != addr) {
1108 log_error(cds)("Unable to remap shared readonly space (errno=%d).", errno);
1109 vm_exit(1);
1110 }
1111 r->set_read_only(false);
1112 return true;
1113 }
1114
1115 // Memory map a region in the address space.
1116 static const char* shared_region_name[] = { "ReadWrite", "ReadOnly", "Bitmap", "Heap" };
1117
1118 MapArchiveResult FileMapInfo::map_regions(int regions[], int num_regions, char* mapped_base_address, ReservedSpace rs) {
1119 DEBUG_ONLY(FileMapRegion* last_region = nullptr);
1120 intx addr_delta = mapped_base_address - header()->requested_base_address();
1121
1122 // Make sure we don't attempt to use header()->mapped_base_address() unless
1123 // it's been successfully mapped.
1124 DEBUG_ONLY(header()->set_mapped_base_address((char*)(uintptr_t)0xdeadbeef);)
1125
1126 for (int i = 0; i < num_regions; i++) {
1127 int idx = regions[i];
1128 MapArchiveResult result = map_region(idx, addr_delta, mapped_base_address, rs);
1129 if (result != MAP_ARCHIVE_SUCCESS) {
1130 return result;
1131 }
1132 FileMapRegion* r = region_at(idx);
1133 DEBUG_ONLY(if (last_region != nullptr) {
1134 // Ensure that the OS won't be able to allocate new memory spaces between any mapped
1135 // regions, or else it would mess up the simple comparison in MetaspaceObj::is_shared().
1136 assert(r->mapped_base() == last_region->mapped_end(), "must have no gaps");
1199 } else if (addr_delta != 0) {
1200 r->set_read_only(false); // Need to patch the pointers
1201 }
1202
1203 if (MetaspaceShared::use_windows_memory_mapping() && rs.is_reserved()) {
1204 // This is the second time we try to map the archive(s). We have already created a ReservedSpace
1205 // that covers all the FileMapRegions to ensure all regions can be mapped. However, Windows
1206 // can't mmap into a ReservedSpace, so we just ::read() the data. We're going to patch all the
1207 // regions anyway, so there's no benefit for mmap anyway.
1208 if (!read_region(i, requested_addr, size, /* do_commit = */ true)) {
1209 log_info(cds)("Failed to read %s shared space into reserved space at " INTPTR_FORMAT,
1210 shared_region_name[i], p2i(requested_addr));
1211 return MAP_ARCHIVE_OTHER_FAILURE; // oom or I/O error.
1212 } else {
1213 assert(r->mapped_base() != nullptr, "must be initialized");
1214 }
1215 } else {
1216 // Note that this may either be a "fresh" mapping into unreserved address
1217 // space (Windows, first mapping attempt), or a mapping into pre-reserved
1218 // space (Posix). See also comment in MetaspaceShared::map_archives().
1219 char* base = map_memory(_fd, _full_path, r->file_offset(),
1220 requested_addr, size, r->read_only(),
1221 r->allow_exec(), mtClassShared);
1222 if (base != requested_addr) {
1223 log_info(cds)("Unable to map %s shared space at " INTPTR_FORMAT,
1224 shared_region_name[i], p2i(requested_addr));
1225 _memory_mapping_failed = true;
1226 return MAP_ARCHIVE_MMAP_FAILURE;
1227 }
1228
1229 if (VerifySharedSpaces && !r->check_region_crc(requested_addr)) {
1230 return MAP_ARCHIVE_OTHER_FAILURE;
1231 }
1232
1233 r->set_mapped_from_file(true);
1234 r->set_mapped_base(requested_addr);
1235 }
1236
1237 if (rs.is_reserved()) {
1238 char* mapped_base = r->mapped_base();
1239 assert(rs.base() <= mapped_base && mapped_base + size <= rs.end(),
1240 PTR_FORMAT " <= " PTR_FORMAT " < " PTR_FORMAT " <= " PTR_FORMAT,
1259 return nullptr;
1260 }
1261
1262 if (VerifySharedSpaces && !r->check_region_crc(bitmap_base)) {
1263 log_error(cds)("relocation bitmap CRC error");
1264 if (!os::unmap_memory(bitmap_base, r->used_aligned())) {
1265 fatal("os::unmap_memory of relocation bitmap failed");
1266 }
1267 return nullptr;
1268 }
1269
1270 r->set_mapped_from_file(true);
1271 r->set_mapped_base(bitmap_base);
1272 log_info(cds)("Mapped %s region #%d at base " INTPTR_FORMAT " top " INTPTR_FORMAT " (%s)",
1273 is_static() ? "static " : "dynamic",
1274 MetaspaceShared::bm, p2i(r->mapped_base()), p2i(r->mapped_end()),
1275 shared_region_name[MetaspaceShared::bm]);
1276 return bitmap_base;
1277 }
1278
1279 class SharedDataRelocationTask : public ArchiveWorkerTask {
1280 private:
1281 BitMapView* const _rw_bm;
1282 BitMapView* const _ro_bm;
1283 SharedDataRelocator* const _rw_reloc;
1284 SharedDataRelocator* const _ro_reloc;
1285
1286 public:
1287 SharedDataRelocationTask(BitMapView* rw_bm, BitMapView* ro_bm, SharedDataRelocator* rw_reloc, SharedDataRelocator* ro_reloc) :
1288 ArchiveWorkerTask("Shared Data Relocation"),
1289 _rw_bm(rw_bm), _ro_bm(ro_bm), _rw_reloc(rw_reloc), _ro_reloc(ro_reloc) {}
1290
1291 void work(int chunk, int max_chunks) override {
1292 work_on(chunk, max_chunks, _rw_bm, _rw_reloc);
1293 work_on(chunk, max_chunks, _ro_bm, _ro_reloc);
1294 }
1295
1296 void work_on(int chunk, int max_chunks, BitMapView* bm, SharedDataRelocator* reloc) {
1297 BitMap::idx_t size = bm->size();
1298 BitMap::idx_t start = MIN2(size, size * chunk / max_chunks);
1408 }
1409
1410 void FileMapInfo::map_or_load_heap_region() {
1411 bool success = false;
1412
1413 if (can_use_heap_region()) {
1414 if (ArchiveHeapLoader::can_map()) {
1415 success = map_heap_region();
1416 } else if (ArchiveHeapLoader::can_load()) {
1417 success = ArchiveHeapLoader::load_heap_region(this);
1418 } else {
1419 if (!UseCompressedOops && !ArchiveHeapLoader::can_map()) {
1420 log_info(cds)("Cannot use CDS heap data. Selected GC not compatible -XX:-UseCompressedOops");
1421 } else {
1422 log_info(cds)("Cannot use CDS heap data. UseEpsilonGC, UseG1GC, UseSerialGC, UseParallelGC, or UseShenandoahGC are required.");
1423 }
1424 }
1425 }
1426
1427 if (!success) {
1428 if (CDSConfig::is_using_aot_linked_classes()) {
1429 // It's too late to recover -- we have already committed to use the archived metaspace objects, but
1430 // the archived heap objects cannot be loaded, so we don't have the archived FMG to guarantee that
1431 // all AOT-linked classes are visible.
1432 //
1433 // We get here because the heap is too small. The app will fail anyway. So let's quit.
1434 MetaspaceShared::unrecoverable_loading_error("CDS archive has aot-linked classes but the archived "
1435 "heap objects cannot be loaded. Try increasing your heap size.");
1436 }
1437 CDSConfig::stop_using_full_module_graph("archive heap loading failed");
1438 }
1439 }
1440
1441 bool FileMapInfo::can_use_heap_region() {
1442 if (!has_heap_region()) {
1443 return false;
1444 }
1445 if (JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::has_early_class_hook_env()) {
1446 ShouldNotReachHere(); // CDS should have been disabled.
1447 // The archived objects are mapped at JVM start-up, but we don't know if
1448 // j.l.String or j.l.Class might be replaced by the ClassFileLoadHook,
1787 return false;
1788 }
1789 }
1790
1791 return true;
1792 }
1793
1794 bool FileMapInfo::validate_aot_class_linking() {
1795 // These checks need to be done after FileMapInfo::initialize(), which gets called before Universe::heap()
1796 // is available.
1797 if (header()->has_aot_linked_classes()) {
1798 CDSConfig::set_has_aot_linked_classes(true);
1799 if (JvmtiExport::should_post_class_file_load_hook()) {
1800 log_error(cds)("CDS archive has aot-linked classes. It cannot be used when JVMTI ClassFileLoadHook is in use.");
1801 return false;
1802 }
1803 if (JvmtiExport::has_early_vmstart_env()) {
1804 log_error(cds)("CDS archive has aot-linked classes. It cannot be used when JVMTI early vm start is in use.");
1805 return false;
1806 }
1807 if (!CDSConfig::is_using_full_module_graph()) {
1808 log_error(cds)("CDS archive has aot-linked classes. It cannot be used when archived full module graph is not used.");
1809 return false;
1810 }
1811
1812 const char* prop = Arguments::get_property("java.security.manager");
1813 if (prop != nullptr && strcmp(prop, "disallow") != 0) {
1814 log_error(cds)("CDS archive has aot-linked classes. It cannot be used with -Djava.security.manager=%s.", prop);
1815 return false;
1816 }
1817
1818 #if INCLUDE_JVMTI
1819 if (Arguments::has_jdwp_agent()) {
1820 log_error(cds)("CDS archive has aot-linked classes. It cannot be used with JDWP agent");
1821 return false;
1822 }
1823 #endif
1824 }
1825
1826 return true;
1827 }
1828
1829 // The 2 core spaces are RW->RO
1830 FileMapRegion* FileMapInfo::first_core_region() const {
1831 return region_at(MetaspaceShared::rw);
1832 }
1833
1834 FileMapRegion* FileMapInfo::last_core_region() const {
1835 return region_at(MetaspaceShared::ro);
1836 }
1837
1937 " does not equal the current UseCompactObjectHeaders setting (%s).", file_type, file_type,
1938 _compact_headers ? "enabled" : "disabled",
1939 UseCompactObjectHeaders ? "enabled" : "disabled");
1940 return false;
1941 }
1942
1943 if (!_use_optimized_module_handling && !CDSConfig::is_dumping_final_static_archive()) {
1944 CDSConfig::stop_using_optimized_module_handling();
1945 log_info(cds)("optimized module handling: disabled because archive was created without optimized module handling");
1946 }
1947
1948 if (is_static()) {
1949 // Only the static archive can contain the full module graph.
1950 if (!_has_full_module_graph) {
1951 CDSConfig::stop_using_full_module_graph("archive was created without full module graph");
1952 }
1953
1954 if (_has_archived_invokedynamic) {
1955 CDSConfig::set_has_archived_invokedynamic();
1956 }
1957 }
1958
1959 return true;
1960 }
1961
1962 bool FileMapInfo::validate_header() {
1963 if (!header()->validate()) {
1964 return false;
1965 }
1966 if (_is_static) {
1967 return true;
1968 } else {
1969 return DynamicArchive::validate(this);
1970 }
1971 }
1972
1973 #if INCLUDE_JVMTI
1974 ClassPathEntry** FileMapInfo::_classpath_entries_for_jvmti = nullptr;
1975
1976 ClassPathEntry* FileMapInfo::get_classpath_entry_for_jvmti(int i, TRAPS) {
|
218 if (CDSConfig::is_dumping_heap()) {
219 _narrow_oop_mode = CompressedOops::mode();
220 _narrow_oop_base = CompressedOops::base();
221 _narrow_oop_shift = CompressedOops::shift();
222 }
223 _compressed_oops = UseCompressedOops;
224 _compressed_class_ptrs = UseCompressedClassPointers;
225 if (UseCompressedClassPointers) {
226 #ifdef _LP64
227 _narrow_klass_pointer_bits = CompressedKlassPointers::narrow_klass_pointer_bits();
228 _narrow_klass_shift = ArchiveBuilder::precomputed_narrow_klass_shift();
229 #endif
230 } else {
231 _narrow_klass_pointer_bits = _narrow_klass_shift = -1;
232 }
233 _max_heap_size = MaxHeapSize;
234 _use_optimized_module_handling = CDSConfig::is_using_optimized_module_handling();
235 _has_aot_linked_classes = CDSConfig::is_dumping_aot_linked_classes();
236 _has_full_module_graph = CDSConfig::is_dumping_full_module_graph();
237 _has_archived_invokedynamic = CDSConfig::is_dumping_invokedynamic();
238 _has_archived_packages = CDSConfig::is_dumping_packages();
239 _has_archived_protection_domains = CDSConfig::is_dumping_protection_domains();
240 _gc_kind = (int)Universe::heap()->kind();
241 jio_snprintf(_gc_name, sizeof(_gc_name), Universe::heap()->name());
242
243 // The following fields are for sanity checks for whether this archive
244 // will function correctly with this JVM and the bootclasspath it's
245 // invoked with.
246
247 // JVM version string ... changes on each build.
248 get_header_version(_jvm_ident);
249
250 _verify_local = BytecodeVerificationLocal;
251 _verify_remote = BytecodeVerificationRemote;
252 _has_platform_or_app_classes = AOTClassLocationConfig::dumptime()->has_platform_or_app_classes();
253 _requested_base_address = (char*)SharedBaseAddress;
254 _mapped_base_address = (char*)SharedBaseAddress;
255 _allow_archiving_with_java_agent = AllowArchivingWithJavaAgent;
256 }
257
258 void FileMapHeader::copy_base_archive_name(const char* archive) {
259 assert(base_archive_name_size() != 0, "_base_archive_name_size not set");
260 assert(base_archive_name_offset() != 0, "_base_archive_name_offset not set");
261 assert(header_size() > sizeof(*this), "_base_archive_name_size not included in header size?");
297 st->print_cr("- class_location_config_offset: 0x%zx", _class_location_config_offset);
298 st->print_cr("- verify_local: %d", _verify_local);
299 st->print_cr("- verify_remote: %d", _verify_remote);
300 st->print_cr("- has_platform_or_app_classes: %d", _has_platform_or_app_classes);
301 st->print_cr("- requested_base_address: " INTPTR_FORMAT, p2i(_requested_base_address));
302 st->print_cr("- mapped_base_address: " INTPTR_FORMAT, p2i(_mapped_base_address));
303 st->print_cr("- heap_root_segments.roots_count: %d" , _heap_root_segments.roots_count());
304 st->print_cr("- heap_root_segments.base_offset: 0x%zx", _heap_root_segments.base_offset());
305 st->print_cr("- heap_root_segments.count: %zu", _heap_root_segments.count());
306 st->print_cr("- heap_root_segments.max_size_elems: %d", _heap_root_segments.max_size_in_elems());
307 st->print_cr("- heap_root_segments.max_size_bytes: %d", _heap_root_segments.max_size_in_bytes());
308 st->print_cr("- _heap_oopmap_start_pos: %zu", _heap_oopmap_start_pos);
309 st->print_cr("- _heap_ptrmap_start_pos: %zu", _heap_ptrmap_start_pos);
310 st->print_cr("- _rw_ptrmap_start_pos: %zu", _rw_ptrmap_start_pos);
311 st->print_cr("- _ro_ptrmap_start_pos: %zu", _ro_ptrmap_start_pos);
312 st->print_cr("- allow_archiving_with_java_agent:%d", _allow_archiving_with_java_agent);
313 st->print_cr("- use_optimized_module_handling: %d", _use_optimized_module_handling);
314 st->print_cr("- has_full_module_graph %d", _has_full_module_graph);
315 st->print_cr("- has_aot_linked_classes %d", _has_aot_linked_classes);
316 st->print_cr("- has_archived_invokedynamic %d", _has_archived_invokedynamic);
317 st->print_cr("- has_archived_packages %d", _has_archived_packages);
318 st->print_cr("- has_archived_protection_domains %d", _has_archived_protection_domains);
319 st->print_cr("- ptrmap_size_in_bits: %zu", _ptrmap_size_in_bits);
320 }
321
322 bool FileMapInfo::validate_class_location() {
323 assert(CDSConfig::is_using_archive(), "runtime only");
324
325 AOTClassLocationConfig* config = header()->class_location_config();
326 bool has_extra_module_paths = false;
327 if (!config->validate(header()->has_aot_linked_classes(), &has_extra_module_paths)) {
328 if (PrintSharedArchiveAndExit) {
329 MetaspaceShared::set_archive_loading_failed();
330 return true;
331 } else {
332 return false;
333 }
334 }
335
336 if (header()->has_full_module_graph() && has_extra_module_paths) {
337 CDSConfig::stop_using_optimized_module_handling();
338 log_info(cds)("optimized module handling: disabled because extra module path(s) are specified");
339 }
816 bool FileMapRegion::check_region_crc(char* base) const {
817 // This function should be called after the region has been properly
818 // loaded into memory via FileMapInfo::map_region() or FileMapInfo::read_region().
819 // I.e., this->mapped_base() must be valid.
820 size_t sz = used();
821 if (sz == 0) {
822 return true;
823 }
824
825 assert(base != nullptr, "must be initialized");
826 int crc = ClassLoader::crc32(0, base, (jint)sz);
827 if (crc != this->crc()) {
828 log_warning(cds)("Checksum verification failed.");
829 return false;
830 }
831 return true;
832 }
833
834 static const char* region_name(int region_index) {
835 static const char* names[] = {
836 "rw", "ro", "bm", "hp", "cc",
837 };
838 const int num_regions = sizeof(names)/sizeof(names[0]);
839 assert(0 <= region_index && region_index < num_regions, "sanity");
840
841 return names[region_index];
842 }
843
844 BitMapView FileMapInfo::bitmap_view(int region_index, bool is_oopmap) {
845 FileMapRegion* r = region_at(region_index);
846 char* bitmap_base = is_static() ? FileMapInfo::current_info()->map_bitmap_region() : FileMapInfo::dynamic_info()->map_bitmap_region();
847 bitmap_base += is_oopmap ? r->oopmap_offset() : r->ptrmap_offset();
848 size_t size_in_bits = is_oopmap ? r->oopmap_size_in_bits() : r->ptrmap_size_in_bits();
849
850 log_debug(cds, reloc)("mapped %s relocation %smap @ " INTPTR_FORMAT " (%zu bits)",
851 region_name(region_index), is_oopmap ? "oop" : "ptr",
852 p2i(bitmap_base), size_in_bits);
853
854 return BitMapView((BitMap::bm_word_t*)(bitmap_base), size_in_bits);
855 }
856
902 mapping_offset = (size_t)((address)requested_base - CompressedOops::base());
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 log_info(cds)("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 log_info(cds)("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,
959 CHeapBitMap* cc_ptrmap,
960 ArchiveHeapInfo* heap_info,
961 size_t &size_in_bytes) {
962 size_t removed_rw_leading_zeros = remove_bitmap_zeros(rw_ptrmap);
963 size_t removed_ro_leading_zeros = remove_bitmap_zeros(ro_ptrmap);
964 header()->set_rw_ptrmap_start_pos(removed_rw_leading_zeros);
965 header()->set_ro_ptrmap_start_pos(removed_ro_leading_zeros);
966 size_in_bytes = rw_ptrmap->size_in_bytes() + ro_ptrmap->size_in_bytes() + cc_ptrmap->size_in_bytes();
967
968 if (heap_info->is_used()) {
969 // Remove leading and trailing zeros
970 size_t removed_oop_leading_zeros = remove_bitmap_zeros(heap_info->oopmap());
971 size_t removed_ptr_leading_zeros = remove_bitmap_zeros(heap_info->ptrmap());
972 header()->set_heap_oopmap_start_pos(removed_oop_leading_zeros);
973 header()->set_heap_ptrmap_start_pos(removed_ptr_leading_zeros);
974
975 size_in_bytes += heap_info->oopmap()->size_in_bytes();
976 size_in_bytes += heap_info->ptrmap()->size_in_bytes();
977 }
978
979 // The bitmap region contains up to 4 parts:
980 // rw_ptrmap: metaspace pointers inside the read-write region
981 // ro_ptrmap: metaspace pointers inside the read-only region
982 // heap_info->oopmap(): Java oop pointers in the heap region
983 // heap_info->ptrmap(): metaspace pointers in the heap region
984 char* buffer = NEW_C_HEAP_ARRAY(char, size_in_bytes, mtClassShared);
985 size_t written = 0;
986
987 region_at(MetaspaceShared::rw)->init_ptrmap(0, rw_ptrmap->size());
988 written = write_bitmap(rw_ptrmap, buffer, written);
989
990 region_at(MetaspaceShared::ro)->init_ptrmap(written, ro_ptrmap->size());
991 written = write_bitmap(ro_ptrmap, buffer, written);
992
993 region_at(MetaspaceShared::cc)->init_ptrmap(written, cc_ptrmap->size());
994 written = write_bitmap(cc_ptrmap, buffer, written);
995
996 if (heap_info->is_used()) {
997 FileMapRegion* r = region_at(MetaspaceShared::hp);
998
999 r->init_oopmap(written, heap_info->oopmap()->size());
1000 written = write_bitmap(heap_info->oopmap(), buffer, written);
1001
1002 r->init_ptrmap(written, heap_info->ptrmap()->size());
1003 written = write_bitmap(heap_info->ptrmap(), buffer, written);
1004 }
1005
1006 write_region(MetaspaceShared::bm, (char*)buffer, size_in_bytes, /*read_only=*/true, /*allow_exec=*/false);
1007 return buffer;
1008 }
1009
1010 size_t FileMapInfo::write_heap_region(ArchiveHeapInfo* heap_info) {
1011 char* buffer_start = heap_info->buffer_start();
1012 size_t buffer_size = heap_info->buffer_byte_size();
1013 write_region(MetaspaceShared::hp, buffer_start, buffer_size, false, false);
1014 header()->set_heap_root_segments(heap_info->heap_root_segments());
1015 return buffer_size;
1111 assert(WINDOWS_ONLY(false) NOT_WINDOWS(true), "Don't call on Windows");
1112 // Replace old mapping with new one that is writable.
1113 char *base = os::map_memory(_fd, _full_path, r->file_offset(),
1114 addr, size, false /* !read_only */,
1115 r->allow_exec());
1116 close();
1117 // These have to be errors because the shared region is now unmapped.
1118 if (base == nullptr) {
1119 log_error(cds)("Unable to remap shared readonly space (errno=%d).", errno);
1120 vm_exit(1);
1121 }
1122 if (base != addr) {
1123 log_error(cds)("Unable to remap shared readonly space (errno=%d).", errno);
1124 vm_exit(1);
1125 }
1126 r->set_read_only(false);
1127 return true;
1128 }
1129
1130 // Memory map a region in the address space.
1131 static const char* shared_region_name[] = { "ReadWrite", "ReadOnly", "Bitmap", "Heap", "Code" };
1132
1133 MapArchiveResult FileMapInfo::map_regions(int regions[], int num_regions, char* mapped_base_address, ReservedSpace rs) {
1134 DEBUG_ONLY(FileMapRegion* last_region = nullptr);
1135 intx addr_delta = mapped_base_address - header()->requested_base_address();
1136
1137 // Make sure we don't attempt to use header()->mapped_base_address() unless
1138 // it's been successfully mapped.
1139 DEBUG_ONLY(header()->set_mapped_base_address((char*)(uintptr_t)0xdeadbeef);)
1140
1141 for (int i = 0; i < num_regions; i++) {
1142 int idx = regions[i];
1143 MapArchiveResult result = map_region(idx, addr_delta, mapped_base_address, rs);
1144 if (result != MAP_ARCHIVE_SUCCESS) {
1145 return result;
1146 }
1147 FileMapRegion* r = region_at(idx);
1148 DEBUG_ONLY(if (last_region != nullptr) {
1149 // Ensure that the OS won't be able to allocate new memory spaces between any mapped
1150 // regions, or else it would mess up the simple comparison in MetaspaceObj::is_shared().
1151 assert(r->mapped_base() == last_region->mapped_end(), "must have no gaps");
1214 } else if (addr_delta != 0) {
1215 r->set_read_only(false); // Need to patch the pointers
1216 }
1217
1218 if (MetaspaceShared::use_windows_memory_mapping() && rs.is_reserved()) {
1219 // This is the second time we try to map the archive(s). We have already created a ReservedSpace
1220 // that covers all the FileMapRegions to ensure all regions can be mapped. However, Windows
1221 // can't mmap into a ReservedSpace, so we just ::read() the data. We're going to patch all the
1222 // regions anyway, so there's no benefit for mmap anyway.
1223 if (!read_region(i, requested_addr, size, /* do_commit = */ true)) {
1224 log_info(cds)("Failed to read %s shared space into reserved space at " INTPTR_FORMAT,
1225 shared_region_name[i], p2i(requested_addr));
1226 return MAP_ARCHIVE_OTHER_FAILURE; // oom or I/O error.
1227 } else {
1228 assert(r->mapped_base() != nullptr, "must be initialized");
1229 }
1230 } else {
1231 // Note that this may either be a "fresh" mapping into unreserved address
1232 // space (Windows, first mapping attempt), or a mapping into pre-reserved
1233 // space (Posix). See also comment in MetaspaceShared::map_archives().
1234 bool read_only = r->read_only() && !CDSConfig::is_dumping_final_static_archive();
1235 char* base = map_memory(_fd, _full_path, r->file_offset(),
1236 requested_addr, size, read_only,
1237 r->allow_exec(), mtClassShared);
1238 if (base != requested_addr) {
1239 log_info(cds)("Unable to map %s shared space at " INTPTR_FORMAT,
1240 shared_region_name[i], p2i(requested_addr));
1241 _memory_mapping_failed = true;
1242 return MAP_ARCHIVE_MMAP_FAILURE;
1243 }
1244
1245 if (VerifySharedSpaces && !r->check_region_crc(requested_addr)) {
1246 return MAP_ARCHIVE_OTHER_FAILURE;
1247 }
1248
1249 r->set_mapped_from_file(true);
1250 r->set_mapped_base(requested_addr);
1251 }
1252
1253 if (rs.is_reserved()) {
1254 char* mapped_base = r->mapped_base();
1255 assert(rs.base() <= mapped_base && mapped_base + size <= rs.end(),
1256 PTR_FORMAT " <= " PTR_FORMAT " < " PTR_FORMAT " <= " PTR_FORMAT,
1275 return nullptr;
1276 }
1277
1278 if (VerifySharedSpaces && !r->check_region_crc(bitmap_base)) {
1279 log_error(cds)("relocation bitmap CRC error");
1280 if (!os::unmap_memory(bitmap_base, r->used_aligned())) {
1281 fatal("os::unmap_memory of relocation bitmap failed");
1282 }
1283 return nullptr;
1284 }
1285
1286 r->set_mapped_from_file(true);
1287 r->set_mapped_base(bitmap_base);
1288 log_info(cds)("Mapped %s region #%d at base " INTPTR_FORMAT " top " INTPTR_FORMAT " (%s)",
1289 is_static() ? "static " : "dynamic",
1290 MetaspaceShared::bm, p2i(r->mapped_base()), p2i(r->mapped_end()),
1291 shared_region_name[MetaspaceShared::bm]);
1292 return bitmap_base;
1293 }
1294
1295 bool FileMapInfo::map_cached_code_region(ReservedSpace rs) {
1296 FileMapRegion* r = region_at(MetaspaceShared::cc);
1297 assert(r->used() > 0 && r->used_aligned() == rs.size(), "must be");
1298
1299 char* requested_base = rs.base();
1300 assert(requested_base != nullptr, "should be inside code cache");
1301
1302 char* mapped_base;
1303 if (MetaspaceShared::use_windows_memory_mapping()) {
1304 if (!read_region(MetaspaceShared::cc, requested_base, r->used_aligned(), /* do_commit = */ true)) {
1305 log_info(cds)("Failed to read cc shared space into reserved space at " INTPTR_FORMAT,
1306 p2i(requested_base));
1307 return false;
1308 }
1309 mapped_base = requested_base;
1310 } else {
1311 bool read_only = false, allow_exec = false;
1312 mapped_base = map_memory(_fd, _full_path, r->file_offset(),
1313 requested_base, r->used_aligned(), read_only, allow_exec, mtClassShared);
1314 }
1315 if (mapped_base == nullptr) {
1316 log_info(cds)("failed to map cached code region");
1317 return false;
1318 } else {
1319 assert(mapped_base == requested_base, "must be");
1320 r->set_mapped_from_file(true);
1321 r->set_mapped_base(mapped_base);
1322 relocate_pointers_in_cached_code_region();
1323 log_info(cds)("Mapped static region #%d at base " INTPTR_FORMAT " top " INTPTR_FORMAT " (%s)",
1324 MetaspaceShared::cc, p2i(r->mapped_base()), p2i(r->mapped_end()),
1325 shared_region_name[MetaspaceShared::cc]);
1326 return true;
1327 }
1328 }
1329
1330 class CachedCodeRelocator: public BitMapClosure {
1331 address _code_requested_base;
1332 address* _patch_base;
1333 intx _code_delta;
1334 intx _metadata_delta;
1335
1336 public:
1337 CachedCodeRelocator(address code_requested_base, address code_mapped_base,
1338 intx metadata_delta) {
1339 _code_requested_base = code_requested_base;
1340 _patch_base = (address*)code_mapped_base;
1341 _code_delta = code_mapped_base - code_requested_base;
1342 _metadata_delta = metadata_delta;
1343 }
1344
1345 bool do_bit(size_t offset) {
1346 address* p = _patch_base + offset;
1347 address requested_ptr = *p;
1348 if (requested_ptr < _code_requested_base) {
1349 *p = requested_ptr + _metadata_delta;
1350 } else {
1351 *p = requested_ptr + _code_delta;
1352 }
1353 return true; // keep iterating
1354 }
1355 };
1356
1357 void FileMapInfo::relocate_pointers_in_cached_code_region() {
1358 FileMapRegion* r = region_at(MetaspaceShared::cc);
1359 char* bitmap_base = map_bitmap_region();
1360
1361 BitMapView cc_ptrmap = ptrmap_view(MetaspaceShared::cc);
1362 if (cc_ptrmap.size() == 0) {
1363 return;
1364 }
1365
1366 address core_regions_requested_base = (address)header()->requested_base_address();
1367 address core_regions_mapped_base = (address)header()->mapped_base_address();
1368 address cc_region_requested_base = core_regions_requested_base + r->mapping_offset();
1369 address cc_region_mapped_base = (address)r->mapped_base();
1370
1371 size_t max_bits_for_core_regions = pointer_delta(mapped_end(), mapped_base(), // FIXME - renamed to core_regions_mapped_base(), etc
1372 sizeof(address));
1373
1374 CachedCodeRelocator patcher(cc_region_requested_base, cc_region_mapped_base,
1375 core_regions_mapped_base - core_regions_requested_base);
1376 cc_ptrmap.iterate(&patcher);
1377 }
1378
1379 class SharedDataRelocationTask : public ArchiveWorkerTask {
1380 private:
1381 BitMapView* const _rw_bm;
1382 BitMapView* const _ro_bm;
1383 SharedDataRelocator* const _rw_reloc;
1384 SharedDataRelocator* const _ro_reloc;
1385
1386 public:
1387 SharedDataRelocationTask(BitMapView* rw_bm, BitMapView* ro_bm, SharedDataRelocator* rw_reloc, SharedDataRelocator* ro_reloc) :
1388 ArchiveWorkerTask("Shared Data Relocation"),
1389 _rw_bm(rw_bm), _ro_bm(ro_bm), _rw_reloc(rw_reloc), _ro_reloc(ro_reloc) {}
1390
1391 void work(int chunk, int max_chunks) override {
1392 work_on(chunk, max_chunks, _rw_bm, _rw_reloc);
1393 work_on(chunk, max_chunks, _ro_bm, _ro_reloc);
1394 }
1395
1396 void work_on(int chunk, int max_chunks, BitMapView* bm, SharedDataRelocator* reloc) {
1397 BitMap::idx_t size = bm->size();
1398 BitMap::idx_t start = MIN2(size, size * chunk / max_chunks);
1508 }
1509
1510 void FileMapInfo::map_or_load_heap_region() {
1511 bool success = false;
1512
1513 if (can_use_heap_region()) {
1514 if (ArchiveHeapLoader::can_map()) {
1515 success = map_heap_region();
1516 } else if (ArchiveHeapLoader::can_load()) {
1517 success = ArchiveHeapLoader::load_heap_region(this);
1518 } else {
1519 if (!UseCompressedOops && !ArchiveHeapLoader::can_map()) {
1520 log_info(cds)("Cannot use CDS heap data. Selected GC not compatible -XX:-UseCompressedOops");
1521 } else {
1522 log_info(cds)("Cannot use CDS heap data. UseEpsilonGC, UseG1GC, UseSerialGC, UseParallelGC, or UseShenandoahGC are required.");
1523 }
1524 }
1525 }
1526
1527 if (!success) {
1528 if (CDSConfig::is_using_aot_linked_classes() && !CDSConfig::is_dumping_final_static_archive()) {
1529 // It's too late to recover -- we have already committed to use the archived metaspace objects, but
1530 // the archived heap objects cannot be loaded, so we don't have the archived FMG to guarantee that
1531 // all AOT-linked classes are visible.
1532 //
1533 // We get here because the heap is too small. The app will fail anyway. So let's quit.
1534 MetaspaceShared::unrecoverable_loading_error("CDS archive has aot-linked classes but the archived "
1535 "heap objects cannot be loaded. Try increasing your heap size.");
1536 }
1537 CDSConfig::stop_using_full_module_graph("archive heap loading failed");
1538 }
1539 }
1540
1541 bool FileMapInfo::can_use_heap_region() {
1542 if (!has_heap_region()) {
1543 return false;
1544 }
1545 if (JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::has_early_class_hook_env()) {
1546 ShouldNotReachHere(); // CDS should have been disabled.
1547 // The archived objects are mapped at JVM start-up, but we don't know if
1548 // j.l.String or j.l.Class might be replaced by the ClassFileLoadHook,
1887 return false;
1888 }
1889 }
1890
1891 return true;
1892 }
1893
1894 bool FileMapInfo::validate_aot_class_linking() {
1895 // These checks need to be done after FileMapInfo::initialize(), which gets called before Universe::heap()
1896 // is available.
1897 if (header()->has_aot_linked_classes()) {
1898 CDSConfig::set_has_aot_linked_classes(true);
1899 if (JvmtiExport::should_post_class_file_load_hook()) {
1900 log_error(cds)("CDS archive has aot-linked classes. It cannot be used when JVMTI ClassFileLoadHook is in use.");
1901 return false;
1902 }
1903 if (JvmtiExport::has_early_vmstart_env()) {
1904 log_error(cds)("CDS archive has aot-linked classes. It cannot be used when JVMTI early vm start is in use.");
1905 return false;
1906 }
1907 if (!CDSConfig::is_using_full_module_graph() && !CDSConfig::is_dumping_final_static_archive()) {
1908 log_error(cds)("CDS archive has aot-linked classes. It cannot be used when archived full module graph is not used.");
1909 return false;
1910 }
1911
1912 const char* prop = Arguments::get_property("java.security.manager");
1913 if (prop != nullptr && strcmp(prop, "disallow") != 0) {
1914 log_error(cds)("CDS archive has aot-linked classes. It cannot be used with -Djava.security.manager=%s.", prop);
1915 return false;
1916 }
1917
1918 if (header()->gc_kind() != (int)Universe::heap()->kind()) {
1919 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)",
1920 header()->gc_name(), Universe::heap()->name());
1921 return false;
1922 }
1923
1924 #if INCLUDE_JVMTI
1925 if (Arguments::has_jdwp_agent()) {
1926 log_error(cds)("CDS archive has aot-linked classes. It cannot be used with JDWP agent");
1927 return false;
1928 }
1929 #endif
1930 }
1931
1932 return true;
1933 }
1934
1935 // The 2 core spaces are RW->RO
1936 FileMapRegion* FileMapInfo::first_core_region() const {
1937 return region_at(MetaspaceShared::rw);
1938 }
1939
1940 FileMapRegion* FileMapInfo::last_core_region() const {
1941 return region_at(MetaspaceShared::ro);
1942 }
1943
2043 " does not equal the current UseCompactObjectHeaders setting (%s).", file_type, file_type,
2044 _compact_headers ? "enabled" : "disabled",
2045 UseCompactObjectHeaders ? "enabled" : "disabled");
2046 return false;
2047 }
2048
2049 if (!_use_optimized_module_handling && !CDSConfig::is_dumping_final_static_archive()) {
2050 CDSConfig::stop_using_optimized_module_handling();
2051 log_info(cds)("optimized module handling: disabled because archive was created without optimized module handling");
2052 }
2053
2054 if (is_static()) {
2055 // Only the static archive can contain the full module graph.
2056 if (!_has_full_module_graph) {
2057 CDSConfig::stop_using_full_module_graph("archive was created without full module graph");
2058 }
2059
2060 if (_has_archived_invokedynamic) {
2061 CDSConfig::set_has_archived_invokedynamic();
2062 }
2063 if (_has_archived_packages) {
2064 CDSConfig::set_is_loading_packages();
2065 }
2066 if (_has_archived_protection_domains) {
2067 CDSConfig::set_is_loading_protection_domains();
2068 }
2069 }
2070
2071 return true;
2072 }
2073
2074 bool FileMapInfo::validate_header() {
2075 if (!header()->validate()) {
2076 return false;
2077 }
2078 if (_is_static) {
2079 return true;
2080 } else {
2081 return DynamicArchive::validate(this);
2082 }
2083 }
2084
2085 #if INCLUDE_JVMTI
2086 ClassPathEntry** FileMapInfo::_classpath_entries_for_jvmti = nullptr;
2087
2088 ClassPathEntry* FileMapInfo::get_classpath_entry_for_jvmti(int i, TRAPS) {
|