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