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 AOTMappedHeapInfo* mapped_heap_info,
978 AOTStreamedHeapInfo* 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,
1354 if (!read_region(AOTMetaspace::ac, requested_base, r->used_aligned(), /* do_commit = */ true)) {
1355 AOTMetaspace::report_loading_error("Failed to read aot code shared space into reserved space at " INTPTR_FORMAT,
1356 p2i(requested_base));
1357 return false;
1358 }
1359 mapped_base = requested_base;
1360 } else {
1361 // We do not execute in-place in the AOT code region.
1362 // AOT code is copied to the CodeCache for execution.
1363 bool read_only = false, allow_exec = false;
1364 mapped_base = map_memory(_fd, _full_path, r->file_offset(),
1365 requested_base, r->used_aligned(), read_only, allow_exec, mtClassShared);
1366 }
1367 if (mapped_base == nullptr) {
1368 AOTMetaspace::report_loading_error("failed to map aot code region");
1369 return false;
1370 } else {
1371 assert(mapped_base == requested_base, "must be");
1372 r->set_mapped_from_file(true);
1373 r->set_mapped_base(mapped_base);
1374 aot_log_info(aot)("Mapped static region #%d at base " INTPTR_FORMAT " top " INTPTR_FORMAT " (%s)",
1375 AOTMetaspace::ac, p2i(r->mapped_base()), p2i(r->mapped_end()),
1376 shared_region_name[AOTMetaspace::ac]);
1377 return true;
1378 }
1379 }
1380
1381 class SharedDataRelocationTask : public ArchiveWorkerTask {
1382 private:
1383 BitMapView* const _rw_bm;
1384 BitMapView* const _ro_bm;
1385 SharedDataRelocator* const _rw_reloc;
1386 SharedDataRelocator* const _ro_reloc;
1387
1388 public:
1389 SharedDataRelocationTask(BitMapView* rw_bm, BitMapView* ro_bm, SharedDataRelocator* rw_reloc, SharedDataRelocator* ro_reloc) :
1390 ArchiveWorkerTask("Shared Data Relocation"),
1391 _rw_bm(rw_bm), _ro_bm(ro_bm), _rw_reloc(rw_reloc), _ro_reloc(ro_reloc) {}
1392
1393 void work(int chunk, int max_chunks) override {
1394 work_on(chunk, max_chunks, _rw_bm, _rw_reloc);
1395 work_on(chunk, max_chunks, _ro_bm, _ro_reloc);
1396 }
1397
1398 void work_on(int chunk, int max_chunks, BitMapView* bm, SharedDataRelocator* reloc) {
1399 BitMap::idx_t size = bm->size();
1400 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
|
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 AOTMappedHeapInfo* mapped_heap_info,
982 AOTStreamedHeapInfo* 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,
1366 if (!read_region(AOTMetaspace::ac, requested_base, r->used_aligned(), /* do_commit = */ true)) {
1367 AOTMetaspace::report_loading_error("Failed to read aot code shared space into reserved space at " INTPTR_FORMAT,
1368 p2i(requested_base));
1369 return false;
1370 }
1371 mapped_base = requested_base;
1372 } else {
1373 // We do not execute in-place in the AOT code region.
1374 // AOT code is copied to the CodeCache for execution.
1375 bool read_only = false, allow_exec = false;
1376 mapped_base = map_memory(_fd, _full_path, r->file_offset(),
1377 requested_base, r->used_aligned(), read_only, allow_exec, mtClassShared);
1378 }
1379 if (mapped_base == nullptr) {
1380 AOTMetaspace::report_loading_error("failed to map aot code region");
1381 return false;
1382 } else {
1383 assert(mapped_base == requested_base, "must be");
1384 r->set_mapped_from_file(true);
1385 r->set_mapped_base(mapped_base);
1386 relocate_pointers_in_aot_code_region();
1387 aot_log_info(aot)("Mapped static region #%d at base " INTPTR_FORMAT " top " INTPTR_FORMAT " (%s)",
1388 AOTMetaspace::ac, p2i(r->mapped_base()), p2i(r->mapped_end()),
1389 shared_region_name[AOTMetaspace::ac]);
1390 return true;
1391 }
1392 }
1393
1394 class CachedCodeRelocator: public BitMapClosure {
1395 address _code_requested_base;
1396 address* _patch_base;
1397 intx _code_delta;
1398 intx _metadata_delta;
1399
1400 public:
1401 CachedCodeRelocator(address code_requested_base, address code_mapped_base,
1402 intx metadata_delta) {
1403 _code_requested_base = code_requested_base;
1404 _patch_base = (address*)code_mapped_base;
1405 _code_delta = code_mapped_base - code_requested_base;
1406 _metadata_delta = metadata_delta;
1407 }
1408
1409 bool do_bit(size_t offset) {
1410 address* p = _patch_base + offset;
1411 address requested_ptr = *p;
1412 if (requested_ptr < _code_requested_base) {
1413 *p = requested_ptr + _metadata_delta;
1414 } else {
1415 *p = requested_ptr + _code_delta;
1416 }
1417 return true; // keep iterating
1418 }
1419 };
1420
1421 void FileMapInfo::relocate_pointers_in_aot_code_region() {
1422 FileMapRegion* r = region_at(AOTMetaspace::ac);
1423 char* bitmap_base = map_bitmap_region();
1424
1425 BitMapView ac_ptrmap = ptrmap_view(AOTMetaspace::ac);
1426 if (ac_ptrmap.size() == 0) {
1427 return;
1428 }
1429
1430 address core_regions_requested_base = (address)header()->requested_base_address();
1431 address core_regions_mapped_base = (address)header()->mapped_base_address();
1432 address ac_region_requested_base = core_regions_requested_base + r->mapping_offset();
1433 address ac_region_mapped_base = (address)r->mapped_base();
1434
1435 size_t max_bits_for_core_regions = pointer_delta(mapped_end(), mapped_base(), // FIXME - renamed to core_regions_mapped_base(), etc
1436 sizeof(address));
1437
1438 CachedCodeRelocator patcher(ac_region_requested_base, ac_region_mapped_base,
1439 core_regions_mapped_base - core_regions_requested_base);
1440 ac_ptrmap.iterate(&patcher);
1441 }
1442
1443 class SharedDataRelocationTask : public ArchiveWorkerTask {
1444 private:
1445 BitMapView* const _rw_bm;
1446 BitMapView* const _ro_bm;
1447 SharedDataRelocator* const _rw_reloc;
1448 SharedDataRelocator* const _ro_reloc;
1449
1450 public:
1451 SharedDataRelocationTask(BitMapView* rw_bm, BitMapView* ro_bm, SharedDataRelocator* rw_reloc, SharedDataRelocator* ro_reloc) :
1452 ArchiveWorkerTask("Shared Data Relocation"),
1453 _rw_bm(rw_bm), _ro_bm(ro_bm), _rw_reloc(rw_reloc), _ro_reloc(ro_reloc) {}
1454
1455 void work(int chunk, int max_chunks) override {
1456 work_on(chunk, max_chunks, _rw_bm, _rw_reloc);
1457 work_on(chunk, max_chunks, _ro_bm, _ro_reloc);
1458 }
1459
1460 void work_on(int chunk, int max_chunks, BitMapView* bm, SharedDataRelocator* reloc) {
1461 BitMap::idx_t size = bm->size();
1462 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
|