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 // Which JIT compier is used
236 _compiler_type = (u1)CompilerConfig::compiler_type();
237 _type_profile_level = TypeProfileLevel;
238 _type_profile_args_limit = TypeProfileArgsLimit;
239 _type_profile_parms_limit = TypeProfileParmsLimit;
240 _type_profile_width = TypeProfileWidth;
241 _bci_profile_width = BciProfileWidth;
242 _profile_traps = ProfileTraps;
243 _type_profile_casts = TypeProfileCasts;
244 _spec_trap_limit_extra_entries = SpecTrapLimitExtraEntries;
245 _max_heap_size = MaxHeapSize;
246 _use_optimized_module_handling = CDSConfig::is_using_optimized_module_handling();
247 _has_aot_linked_classes = CDSConfig::is_dumping_aot_linked_classes();
248 _has_full_module_graph = CDSConfig::is_dumping_full_module_graph();
249
250 // The following fields are for sanity checks for whether this archive
251 // will function correctly with this JVM and the bootclasspath it's
252 // invoked with.
253
254 // JVM version string ... changes on each build.
255 get_header_version(_jvm_ident);
256
257 _verify_local = BytecodeVerificationLocal;
258 _verify_remote = BytecodeVerificationRemote;
259 _has_platform_or_app_classes = AOTClassLocationConfig::dumptime()->has_platform_or_app_classes();
260 _requested_base_address = (char*)SharedBaseAddress;
261 _mapped_base_address = (char*)SharedBaseAddress;
262 }
263
264 void FileMapHeader::copy_base_archive_name(const char* archive) {
265 assert(base_archive_name_size() != 0, "_base_archive_name_size not set");
266 assert(base_archive_name_offset() != 0, "_base_archive_name_offset not set");
267 assert(header_size() > sizeof(*this), "_base_archive_name_size not included in header size?");
268 memcpy((char*)this + base_archive_name_offset(), archive, base_archive_name_size());
312 st->print_cr(" - root_segments");
313 st->print_cr(" - roots_count: %d", _mapped_heap_header.root_segments().roots_count());
314 st->print_cr(" - base_offset: 0x%zx", _mapped_heap_header.root_segments().base_offset());
315 st->print_cr(" - count: %zu", _mapped_heap_header.root_segments().count());
316 st->print_cr(" - max_size_elems: %d", _mapped_heap_header.root_segments().max_size_in_elems());
317 st->print_cr(" - max_size_bytes: %zu", _mapped_heap_header.root_segments().max_size_in_bytes());
318 st->print_cr(" - oopmap_start_pos: %zu", _mapped_heap_header.oopmap_start_pos());
319 st->print_cr(" - oopmap_ptrmap_pos: %zu", _mapped_heap_header.ptrmap_start_pos());
320 st->print_cr("- streamed_heap_header");
321 st->print_cr(" - forwarding_offset: %zu", _streamed_heap_header.forwarding_offset());
322 st->print_cr(" - roots_offset: %zu", _streamed_heap_header.roots_offset());
323 st->print_cr(" - num_roots: %zu", _streamed_heap_header.num_roots());
324 st->print_cr(" - root_highest_object_index_table_offset: %zu", _streamed_heap_header.root_highest_object_index_table_offset());
325 st->print_cr(" - num_archived_objects: %zu", _streamed_heap_header.num_archived_objects());
326
327 st->print_cr("- _rw_ptrmap_start_pos: %zu", _rw_ptrmap_start_pos);
328 st->print_cr("- _ro_ptrmap_start_pos: %zu", _ro_ptrmap_start_pos);
329 st->print_cr("- use_optimized_module_handling: %d", _use_optimized_module_handling);
330 st->print_cr("- has_full_module_graph %d", _has_full_module_graph);
331 st->print_cr("- has_aot_linked_classes %d", _has_aot_linked_classes);
332 }
333
334 bool FileMapInfo::validate_class_location() {
335 assert(CDSConfig::is_using_archive(), "runtime only");
336
337 AOTClassLocationConfig* config = header()->class_location_config();
338 bool has_extra_module_paths = false;
339 if (!config->validate(full_path(), header()->has_aot_linked_classes(), &has_extra_module_paths)) {
340 if (PrintSharedArchiveAndExit) {
341 AOTMetaspace::set_archive_loading_failed();
342 return true;
343 } else {
344 return false;
345 }
346 }
347
348 if (header()->has_full_module_graph() && has_extra_module_paths) {
349 CDSConfig::stop_using_optimized_module_handling();
350 AOTMetaspace::report_loading_error("optimized module handling: disabled because extra module path(s) are specified");
351 }
953 // The sorting code groups the objects with non-null oop/ptrs together.
954 // Relevant bitmaps then have lots of leading and trailing zeros, which
955 // we do not have to store.
956 size_t FileMapInfo::remove_bitmap_zeros(CHeapBitMap* map) {
957 BitMap::idx_t first_set = map->find_first_set_bit(0);
958 BitMap::idx_t last_set = map->find_last_set_bit(0);
959 size_t old_size = map->size();
960
961 // Slice and resize bitmap
962 map->truncate(first_set, last_set + 1);
963
964 assert(map->at(0), "First bit should be set");
965 assert(map->at(map->size() - 1), "Last bit should be set");
966 assert(map->size() <= old_size, "sanity");
967
968 return first_set;
969 }
970
971 char* FileMapInfo::write_bitmap_region(CHeapBitMap* rw_ptrmap,
972 CHeapBitMap* ro_ptrmap,
973 ArchiveMappedHeapInfo* mapped_heap_info,
974 ArchiveStreamedHeapInfo* streamed_heap_info,
975 size_t &size_in_bytes) {
976 size_t removed_rw_leading_zeros = remove_bitmap_zeros(rw_ptrmap);
977 size_t removed_ro_leading_zeros = remove_bitmap_zeros(ro_ptrmap);
978 header()->set_rw_ptrmap_start_pos(removed_rw_leading_zeros);
979 header()->set_ro_ptrmap_start_pos(removed_ro_leading_zeros);
980 size_in_bytes = rw_ptrmap->size_in_bytes() + ro_ptrmap->size_in_bytes();
981
982 if (mapped_heap_info != nullptr && mapped_heap_info->is_used()) {
983 // Remove leading and trailing zeros
984 assert(HeapShared::is_writing_mapping_mode(), "unexpected dumping mode");
985 size_t removed_oop_leading_zeros = remove_bitmap_zeros(mapped_heap_info->oopmap());
986 size_t removed_ptr_leading_zeros = remove_bitmap_zeros(mapped_heap_info->ptrmap());
987 mapped_heap_info->set_oopmap_start_pos(removed_oop_leading_zeros);
988 mapped_heap_info->set_ptrmap_start_pos(removed_ptr_leading_zeros);
989
990 size_in_bytes += mapped_heap_info->oopmap()->size_in_bytes();
991 size_in_bytes += mapped_heap_info->ptrmap()->size_in_bytes();
992 } else if (streamed_heap_info != nullptr && streamed_heap_info->is_used()) {
993 assert(HeapShared::is_writing_streaming_mode(), "unexpected dumping mode");
994
995 size_in_bytes += streamed_heap_info->oopmap()->size_in_bytes();
996 }
997
998 // The bitmap region contains up to 4 parts:
999 // rw_ptrmap: metaspace pointers inside the read-write region
1000 // ro_ptrmap: metaspace pointers inside the read-only region
1001 // *_heap_info->oopmap(): Java oop pointers in the heap region
1002 // mapped_heap_info->ptrmap(): metaspace pointers in the heap region
1003 char* buffer = NEW_C_HEAP_ARRAY(char, size_in_bytes, mtClassShared);
1004 size_t written = 0;
1005
1006 region_at(AOTMetaspace::rw)->init_ptrmap(0, rw_ptrmap->size());
1007 written = write_bitmap(rw_ptrmap, buffer, written);
1008
1009 region_at(AOTMetaspace::ro)->init_ptrmap(written, ro_ptrmap->size());
1010 written = write_bitmap(ro_ptrmap, buffer, written);
1011
1012 if (mapped_heap_info != nullptr && mapped_heap_info->is_used()) {
1013 assert(HeapShared::is_writing_mapping_mode(), "unexpected dumping mode");
1014 FileMapRegion* r = region_at(AOTMetaspace::hp);
1015
1016 r->init_oopmap(written, mapped_heap_info->oopmap()->size());
1017 written = write_bitmap(mapped_heap_info->oopmap(), buffer, written);
1018
1019 r->init_ptrmap(written, mapped_heap_info->ptrmap()->size());
1020 written = write_bitmap(mapped_heap_info->ptrmap(), buffer, written);
1021 } else if (streamed_heap_info != nullptr && streamed_heap_info->is_used()) {
1022 assert(HeapShared::is_writing_streaming_mode(), "unexpected dumping mode");
1023 FileMapRegion* r = region_at(AOTMetaspace::hp);
1024
1025 r->init_oopmap(written, streamed_heap_info->oopmap()->size());
1026 written = write_bitmap(streamed_heap_info->oopmap(), buffer, written);
1027 }
1028
1029 write_region(AOTMetaspace::bm, (char*)buffer, size_in_bytes, /*read_only=*/true, /*allow_exec=*/false);
1030 return buffer;
1031 }
1258 } else if (addr_delta != 0) {
1259 r->set_read_only(false); // Need to patch the pointers
1260 }
1261
1262 if (AOTMetaspace::use_windows_memory_mapping() && rs.is_reserved()) {
1263 // This is the second time we try to map the archive(s). We have already created a ReservedSpace
1264 // that covers all the FileMapRegions to ensure all regions can be mapped. However, Windows
1265 // can't mmap into a ReservedSpace, so we just ::read() the data. We're going to patch all the
1266 // regions anyway, so there's no benefit for mmap anyway.
1267 if (!read_region(i, requested_addr, size, /* do_commit = */ true)) {
1268 AOTMetaspace::report_loading_error("Failed to read %s shared space into reserved space at " INTPTR_FORMAT,
1269 shared_region_name[i], p2i(requested_addr));
1270 return MAP_ARCHIVE_OTHER_FAILURE; // oom or I/O error.
1271 } else {
1272 assert(r->mapped_base() != nullptr, "must be initialized");
1273 }
1274 } else {
1275 // Note that this may either be a "fresh" mapping into unreserved address
1276 // space (Windows, first mapping attempt), or a mapping into pre-reserved
1277 // space (Posix). See also comment in AOTMetaspace::map_archives().
1278 char* base = map_memory(_fd, _full_path, r->file_offset(),
1279 requested_addr, size, r->read_only(),
1280 r->allow_exec(), mtClassShared);
1281 if (base != requested_addr) {
1282 AOTMetaspace::report_loading_error("Unable to map %s shared space at " INTPTR_FORMAT,
1283 shared_region_name[i], p2i(requested_addr));
1284 _memory_mapping_failed = true;
1285 return MAP_ARCHIVE_MMAP_FAILURE;
1286 }
1287
1288 if (VerifySharedSpaces && !r->check_region_crc(requested_addr)) {
1289 return MAP_ARCHIVE_OTHER_FAILURE;
1290 }
1291
1292 r->set_mapped_from_file(true);
1293 r->set_mapped_base(requested_addr);
1294 }
1295
1296 if (rs.is_reserved()) {
1297 char* mapped_base = r->mapped_base();
1298 assert(rs.base() <= mapped_base && mapped_base + size <= rs.end(),
1299 PTR_FORMAT " <= " PTR_FORMAT " < " PTR_FORMAT " <= " PTR_FORMAT,
1352 if (!read_region(AOTMetaspace::ac, requested_base, r->used_aligned(), /* do_commit = */ true)) {
1353 AOTMetaspace::report_loading_error("Failed to read aot code shared space into reserved space at " INTPTR_FORMAT,
1354 p2i(requested_base));
1355 return false;
1356 }
1357 mapped_base = requested_base;
1358 } else {
1359 // We do not execute in-place in the AOT code region.
1360 // AOT code is copied to the CodeCache for execution.
1361 bool read_only = false, allow_exec = false;
1362 mapped_base = map_memory(_fd, _full_path, r->file_offset(),
1363 requested_base, r->used_aligned(), read_only, allow_exec, mtClassShared);
1364 }
1365 if (mapped_base == nullptr) {
1366 AOTMetaspace::report_loading_error("failed to map aot code region");
1367 return false;
1368 } else {
1369 assert(mapped_base == requested_base, "must be");
1370 r->set_mapped_from_file(true);
1371 r->set_mapped_base(mapped_base);
1372 aot_log_info(aot)("Mapped static region #%d at base " INTPTR_FORMAT " top " INTPTR_FORMAT " (%s)",
1373 AOTMetaspace::ac, p2i(r->mapped_base()), p2i(r->mapped_end()),
1374 shared_region_name[AOTMetaspace::ac]);
1375 return true;
1376 }
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);
1719 return false;
1720 }
1721 if (JvmtiExport::has_early_vmstart_env()) {
1722 aot_log_error(aot)("%s has aot-linked classes. It cannot be used when JVMTI early vm start is in use.",
1723 archive_type);
1724 return false;
1725 }
1726 if (!CDSConfig::is_using_full_module_graph()) {
1727 aot_log_error(aot)("%s has aot-linked classes. It cannot be used when archived full module graph is not used.",
1728 archive_type);
1729 return false;
1730 }
1731
1732 const char* prop = Arguments::get_property("java.security.manager");
1733 if (prop != nullptr && strcmp(prop, "disallow") != 0) {
1734 aot_log_error(aot)("%s has aot-linked classes. It cannot be used with -Djava.security.manager=%s.",
1735 archive_type, prop);
1736 return false;
1737 }
1738
1739 #if INCLUDE_JVMTI
1740 if (Arguments::has_jdwp_agent()) {
1741 aot_log_error(aot)("%s has aot-linked classes. It cannot be used with JDWP agent", archive_type);
1742 return false;
1743 }
1744 #endif
1745 }
1746
1747 return true;
1748 }
1749
1750 // The 2 core spaces are RW->RO
1751 FileMapRegion* FileMapInfo::first_core_region() const {
1752 return region_at(AOTMetaspace::rw);
1753 }
1754
1755 FileMapRegion* FileMapInfo::last_core_region() const {
1756 return region_at(AOTMetaspace::ro);
1757 }
1758
|
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 // Which JIT compier is used
236 _compiler_type = (u1)CompilerConfig::compiler_type();
237 _type_profile_level = TypeProfileLevel;
238 _type_profile_args_limit = TypeProfileArgsLimit;
239 _type_profile_parms_limit = TypeProfileParmsLimit;
240 _type_profile_width = TypeProfileWidth;
241 _bci_profile_width = BciProfileWidth;
242 _profile_traps = ProfileTraps;
243 _type_profile_casts = TypeProfileCasts;
244 _spec_trap_limit_extra_entries = SpecTrapLimitExtraEntries;
245 _max_heap_size = MaxHeapSize;
246 _use_optimized_module_handling = CDSConfig::is_using_optimized_module_handling();
247 _has_aot_linked_classes = CDSConfig::is_dumping_aot_linked_classes();
248 _has_full_module_graph = CDSConfig::is_dumping_full_module_graph();
249 _gc_kind = (int)Universe::heap()->kind();
250 jio_snprintf(_gc_name, sizeof(_gc_name), Universe::heap()->name());
251
252 // The following fields are for sanity checks for whether this archive
253 // will function correctly with this JVM and the bootclasspath it's
254 // invoked with.
255
256 // JVM version string ... changes on each build.
257 get_header_version(_jvm_ident);
258
259 _verify_local = BytecodeVerificationLocal;
260 _verify_remote = BytecodeVerificationRemote;
261 _has_platform_or_app_classes = AOTClassLocationConfig::dumptime()->has_platform_or_app_classes();
262 _requested_base_address = (char*)SharedBaseAddress;
263 _mapped_base_address = (char*)SharedBaseAddress;
264 }
265
266 void FileMapHeader::copy_base_archive_name(const char* archive) {
267 assert(base_archive_name_size() != 0, "_base_archive_name_size not set");
268 assert(base_archive_name_offset() != 0, "_base_archive_name_offset not set");
269 assert(header_size() > sizeof(*this), "_base_archive_name_size not included in header size?");
270 memcpy((char*)this + base_archive_name_offset(), archive, base_archive_name_size());
314 st->print_cr(" - root_segments");
315 st->print_cr(" - roots_count: %d", _mapped_heap_header.root_segments().roots_count());
316 st->print_cr(" - base_offset: 0x%zx", _mapped_heap_header.root_segments().base_offset());
317 st->print_cr(" - count: %zu", _mapped_heap_header.root_segments().count());
318 st->print_cr(" - max_size_elems: %d", _mapped_heap_header.root_segments().max_size_in_elems());
319 st->print_cr(" - max_size_bytes: %zu", _mapped_heap_header.root_segments().max_size_in_bytes());
320 st->print_cr(" - oopmap_start_pos: %zu", _mapped_heap_header.oopmap_start_pos());
321 st->print_cr(" - oopmap_ptrmap_pos: %zu", _mapped_heap_header.ptrmap_start_pos());
322 st->print_cr("- streamed_heap_header");
323 st->print_cr(" - forwarding_offset: %zu", _streamed_heap_header.forwarding_offset());
324 st->print_cr(" - roots_offset: %zu", _streamed_heap_header.roots_offset());
325 st->print_cr(" - num_roots: %zu", _streamed_heap_header.num_roots());
326 st->print_cr(" - root_highest_object_index_table_offset: %zu", _streamed_heap_header.root_highest_object_index_table_offset());
327 st->print_cr(" - num_archived_objects: %zu", _streamed_heap_header.num_archived_objects());
328
329 st->print_cr("- _rw_ptrmap_start_pos: %zu", _rw_ptrmap_start_pos);
330 st->print_cr("- _ro_ptrmap_start_pos: %zu", _ro_ptrmap_start_pos);
331 st->print_cr("- use_optimized_module_handling: %d", _use_optimized_module_handling);
332 st->print_cr("- has_full_module_graph %d", _has_full_module_graph);
333 st->print_cr("- has_aot_linked_classes %d", _has_aot_linked_classes);
334 st->print_cr("- ptrmap_size_in_bits: %zu", _ptrmap_size_in_bits);
335 }
336
337 bool FileMapInfo::validate_class_location() {
338 assert(CDSConfig::is_using_archive(), "runtime only");
339
340 AOTClassLocationConfig* config = header()->class_location_config();
341 bool has_extra_module_paths = false;
342 if (!config->validate(full_path(), header()->has_aot_linked_classes(), &has_extra_module_paths)) {
343 if (PrintSharedArchiveAndExit) {
344 AOTMetaspace::set_archive_loading_failed();
345 return true;
346 } else {
347 return false;
348 }
349 }
350
351 if (header()->has_full_module_graph() && has_extra_module_paths) {
352 CDSConfig::stop_using_optimized_module_handling();
353 AOTMetaspace::report_loading_error("optimized module handling: disabled because extra module path(s) are specified");
354 }
956 // The sorting code groups the objects with non-null oop/ptrs together.
957 // Relevant bitmaps then have lots of leading and trailing zeros, which
958 // we do not have to store.
959 size_t FileMapInfo::remove_bitmap_zeros(CHeapBitMap* map) {
960 BitMap::idx_t first_set = map->find_first_set_bit(0);
961 BitMap::idx_t last_set = map->find_last_set_bit(0);
962 size_t old_size = map->size();
963
964 // Slice and resize bitmap
965 map->truncate(first_set, last_set + 1);
966
967 assert(map->at(0), "First bit should be set");
968 assert(map->at(map->size() - 1), "Last bit should be set");
969 assert(map->size() <= old_size, "sanity");
970
971 return first_set;
972 }
973
974 char* FileMapInfo::write_bitmap_region(CHeapBitMap* rw_ptrmap,
975 CHeapBitMap* ro_ptrmap,
976 CHeapBitMap* ac_ptrmap,
977 ArchiveMappedHeapInfo* mapped_heap_info,
978 ArchiveStreamedHeapInfo* streamed_heap_info,
979 size_t &size_in_bytes) {
980 size_t removed_rw_leading_zeros = remove_bitmap_zeros(rw_ptrmap);
981 size_t removed_ro_leading_zeros = remove_bitmap_zeros(ro_ptrmap);
982 header()->set_rw_ptrmap_start_pos(removed_rw_leading_zeros);
983 header()->set_ro_ptrmap_start_pos(removed_ro_leading_zeros);
984 size_in_bytes = rw_ptrmap->size_in_bytes() + ro_ptrmap->size_in_bytes() + ac_ptrmap->size_in_bytes();
985
986 if (mapped_heap_info != nullptr && mapped_heap_info->is_used()) {
987 // Remove leading and trailing zeros
988 assert(HeapShared::is_writing_mapping_mode(), "unexpected dumping mode");
989 size_t removed_oop_leading_zeros = remove_bitmap_zeros(mapped_heap_info->oopmap());
990 size_t removed_ptr_leading_zeros = remove_bitmap_zeros(mapped_heap_info->ptrmap());
991 mapped_heap_info->set_oopmap_start_pos(removed_oop_leading_zeros);
992 mapped_heap_info->set_ptrmap_start_pos(removed_ptr_leading_zeros);
993
994 size_in_bytes += mapped_heap_info->oopmap()->size_in_bytes();
995 size_in_bytes += mapped_heap_info->ptrmap()->size_in_bytes();
996 } else if (streamed_heap_info != nullptr && streamed_heap_info->is_used()) {
997 assert(HeapShared::is_writing_streaming_mode(), "unexpected dumping mode");
998
999 size_in_bytes += streamed_heap_info->oopmap()->size_in_bytes();
1000 }
1001
1002 // The bitmap region contains up to 5 parts:
1003 // rw_ptrmap: metaspace pointers inside the read-write region
1004 // ro_ptrmap: metaspace pointers inside the read-only region
1005 // ac_ptrmap: metaspace pointers inside the AOT code cache region
1006 // *_heap_info->oopmap(): Java oop pointers in the heap region
1007 // mapped_heap_info->ptrmap(): metaspace pointers in the heap region
1008 char* buffer = NEW_C_HEAP_ARRAY(char, size_in_bytes, mtClassShared);
1009 size_t written = 0;
1010
1011 region_at(AOTMetaspace::rw)->init_ptrmap(0, rw_ptrmap->size());
1012 written = write_bitmap(rw_ptrmap, buffer, written);
1013
1014 region_at(AOTMetaspace::ro)->init_ptrmap(written, ro_ptrmap->size());
1015 written = write_bitmap(ro_ptrmap, buffer, written);
1016
1017 if (ac_ptrmap->size() > 0) {
1018 region_at(AOTMetaspace::ac)->init_ptrmap(written, ac_ptrmap->size());
1019 written = write_bitmap(ac_ptrmap, buffer, written);
1020 }
1021
1022 if (mapped_heap_info != nullptr && mapped_heap_info->is_used()) {
1023 assert(HeapShared::is_writing_mapping_mode(), "unexpected dumping mode");
1024 FileMapRegion* r = region_at(AOTMetaspace::hp);
1025
1026 r->init_oopmap(written, mapped_heap_info->oopmap()->size());
1027 written = write_bitmap(mapped_heap_info->oopmap(), buffer, written);
1028
1029 r->init_ptrmap(written, mapped_heap_info->ptrmap()->size());
1030 written = write_bitmap(mapped_heap_info->ptrmap(), buffer, written);
1031 } else if (streamed_heap_info != nullptr && streamed_heap_info->is_used()) {
1032 assert(HeapShared::is_writing_streaming_mode(), "unexpected dumping mode");
1033 FileMapRegion* r = region_at(AOTMetaspace::hp);
1034
1035 r->init_oopmap(written, streamed_heap_info->oopmap()->size());
1036 written = write_bitmap(streamed_heap_info->oopmap(), buffer, written);
1037 }
1038
1039 write_region(AOTMetaspace::bm, (char*)buffer, size_in_bytes, /*read_only=*/true, /*allow_exec=*/false);
1040 return buffer;
1041 }
1268 } else if (addr_delta != 0) {
1269 r->set_read_only(false); // Need to patch the pointers
1270 }
1271
1272 if (AOTMetaspace::use_windows_memory_mapping() && rs.is_reserved()) {
1273 // This is the second time we try to map the archive(s). We have already created a ReservedSpace
1274 // that covers all the FileMapRegions to ensure all regions can be mapped. However, Windows
1275 // can't mmap into a ReservedSpace, so we just ::read() the data. We're going to patch all the
1276 // regions anyway, so there's no benefit for mmap anyway.
1277 if (!read_region(i, requested_addr, size, /* do_commit = */ true)) {
1278 AOTMetaspace::report_loading_error("Failed to read %s shared space into reserved space at " INTPTR_FORMAT,
1279 shared_region_name[i], p2i(requested_addr));
1280 return MAP_ARCHIVE_OTHER_FAILURE; // oom or I/O error.
1281 } else {
1282 assert(r->mapped_base() != nullptr, "must be initialized");
1283 }
1284 } else {
1285 // Note that this may either be a "fresh" mapping into unreserved address
1286 // space (Windows, first mapping attempt), or a mapping into pre-reserved
1287 // space (Posix). See also comment in AOTMetaspace::map_archives().
1288 bool read_only = r->read_only() && !CDSConfig::is_dumping_final_static_archive();
1289
1290 char* base = map_memory(_fd, _full_path, r->file_offset(),
1291 requested_addr, size, read_only,
1292 r->allow_exec(), mtClassShared);
1293 if (base != requested_addr) {
1294 AOTMetaspace::report_loading_error("Unable to map %s shared space at " INTPTR_FORMAT,
1295 shared_region_name[i], p2i(requested_addr));
1296 _memory_mapping_failed = true;
1297 return MAP_ARCHIVE_MMAP_FAILURE;
1298 }
1299
1300 if (VerifySharedSpaces && !r->check_region_crc(requested_addr)) {
1301 return MAP_ARCHIVE_OTHER_FAILURE;
1302 }
1303
1304 r->set_mapped_from_file(true);
1305 r->set_mapped_base(requested_addr);
1306 }
1307
1308 if (rs.is_reserved()) {
1309 char* mapped_base = r->mapped_base();
1310 assert(rs.base() <= mapped_base && mapped_base + size <= rs.end(),
1311 PTR_FORMAT " <= " PTR_FORMAT " < " PTR_FORMAT " <= " PTR_FORMAT,
1364 if (!read_region(AOTMetaspace::ac, requested_base, r->used_aligned(), /* do_commit = */ true)) {
1365 AOTMetaspace::report_loading_error("Failed to read aot code shared space into reserved space at " INTPTR_FORMAT,
1366 p2i(requested_base));
1367 return false;
1368 }
1369 mapped_base = requested_base;
1370 } else {
1371 // We do not execute in-place in the AOT code region.
1372 // AOT code is copied to the CodeCache for execution.
1373 bool read_only = false, allow_exec = false;
1374 mapped_base = map_memory(_fd, _full_path, r->file_offset(),
1375 requested_base, r->used_aligned(), read_only, allow_exec, mtClassShared);
1376 }
1377 if (mapped_base == nullptr) {
1378 AOTMetaspace::report_loading_error("failed to map aot code region");
1379 return false;
1380 } else {
1381 assert(mapped_base == requested_base, "must be");
1382 r->set_mapped_from_file(true);
1383 r->set_mapped_base(mapped_base);
1384 relocate_pointers_in_aot_code_region();
1385 aot_log_info(aot)("Mapped static region #%d at base " INTPTR_FORMAT " top " INTPTR_FORMAT " (%s)",
1386 AOTMetaspace::ac, p2i(r->mapped_base()), p2i(r->mapped_end()),
1387 shared_region_name[AOTMetaspace::ac]);
1388 return true;
1389 }
1390 }
1391
1392 class CachedCodeRelocator: public BitMapClosure {
1393 address _code_requested_base;
1394 address* _patch_base;
1395 intx _code_delta;
1396 intx _metadata_delta;
1397
1398 public:
1399 CachedCodeRelocator(address code_requested_base, address code_mapped_base,
1400 intx metadata_delta) {
1401 _code_requested_base = code_requested_base;
1402 _patch_base = (address*)code_mapped_base;
1403 _code_delta = code_mapped_base - code_requested_base;
1404 _metadata_delta = metadata_delta;
1405 }
1406
1407 bool do_bit(size_t offset) {
1408 address* p = _patch_base + offset;
1409 address requested_ptr = *p;
1410 if (requested_ptr < _code_requested_base) {
1411 *p = requested_ptr + _metadata_delta;
1412 } else {
1413 *p = requested_ptr + _code_delta;
1414 }
1415 return true; // keep iterating
1416 }
1417 };
1418
1419 void FileMapInfo::relocate_pointers_in_aot_code_region() {
1420 FileMapRegion* r = region_at(AOTMetaspace::ac);
1421 char* bitmap_base = map_bitmap_region();
1422
1423 BitMapView ac_ptrmap = ptrmap_view(AOTMetaspace::ac);
1424 if (ac_ptrmap.size() == 0) {
1425 return;
1426 }
1427
1428 address core_regions_requested_base = (address)header()->requested_base_address();
1429 address core_regions_mapped_base = (address)header()->mapped_base_address();
1430 address ac_region_requested_base = core_regions_requested_base + r->mapping_offset();
1431 address ac_region_mapped_base = (address)r->mapped_base();
1432
1433 size_t max_bits_for_core_regions = pointer_delta(mapped_end(), mapped_base(), // FIXME - renamed to core_regions_mapped_base(), etc
1434 sizeof(address));
1435
1436 CachedCodeRelocator patcher(ac_region_requested_base, ac_region_mapped_base,
1437 core_regions_mapped_base - core_regions_requested_base);
1438 ac_ptrmap.iterate(&patcher);
1439 }
1440
1441 class SharedDataRelocationTask : public ArchiveWorkerTask {
1442 private:
1443 BitMapView* const _rw_bm;
1444 BitMapView* const _ro_bm;
1445 SharedDataRelocator* const _rw_reloc;
1446 SharedDataRelocator* const _ro_reloc;
1447
1448 public:
1449 SharedDataRelocationTask(BitMapView* rw_bm, BitMapView* ro_bm, SharedDataRelocator* rw_reloc, SharedDataRelocator* ro_reloc) :
1450 ArchiveWorkerTask("Shared Data Relocation"),
1451 _rw_bm(rw_bm), _ro_bm(ro_bm), _rw_reloc(rw_reloc), _ro_reloc(ro_reloc) {}
1452
1453 void work(int chunk, int max_chunks) override {
1454 work_on(chunk, max_chunks, _rw_bm, _rw_reloc);
1455 work_on(chunk, max_chunks, _ro_bm, _ro_reloc);
1456 }
1457
1458 void work_on(int chunk, int max_chunks, BitMapView* bm, SharedDataRelocator* reloc) {
1459 BitMap::idx_t size = bm->size();
1460 BitMap::idx_t start = MIN2(size, size * chunk / max_chunks);
1781 return false;
1782 }
1783 if (JvmtiExport::has_early_vmstart_env()) {
1784 aot_log_error(aot)("%s has aot-linked classes. It cannot be used when JVMTI early vm start is in use.",
1785 archive_type);
1786 return false;
1787 }
1788 if (!CDSConfig::is_using_full_module_graph()) {
1789 aot_log_error(aot)("%s has aot-linked classes. It cannot be used when archived full module graph is not used.",
1790 archive_type);
1791 return false;
1792 }
1793
1794 const char* prop = Arguments::get_property("java.security.manager");
1795 if (prop != nullptr && strcmp(prop, "disallow") != 0) {
1796 aot_log_error(aot)("%s has aot-linked classes. It cannot be used with -Djava.security.manager=%s.",
1797 archive_type, prop);
1798 return false;
1799 }
1800
1801 if (header()->gc_kind() != (int)Universe::heap()->kind()) {
1802 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)",
1803 header()->gc_name(), Universe::heap()->name());
1804 return false;
1805 }
1806
1807 #if INCLUDE_JVMTI
1808 if (Arguments::has_jdwp_agent()) {
1809 aot_log_error(aot)("%s has aot-linked classes. It cannot be used with JDWP agent", archive_type);
1810 return false;
1811 }
1812 #endif
1813 }
1814
1815 return true;
1816 }
1817
1818 // The 2 core spaces are RW->RO
1819 FileMapRegion* FileMapInfo::first_core_region() const {
1820 return region_at(AOTMetaspace::rw);
1821 }
1822
1823 FileMapRegion* FileMapInfo::last_core_region() const {
1824 return region_at(AOTMetaspace::ro);
1825 }
1826
|