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