1383 idx, p2i(si->mapped_base()), p2i(si->mapped_end()), |
1383 idx, p2i(si->mapped_base()), p2i(si->mapped_end()), |
1384 shared_region_name[idx]); |
1384 shared_region_name[idx]); |
1385 |
1385 |
1386 } |
1386 } |
1387 |
1387 |
1388 DEBUG_ONLY(if (addr_delta == 0 && ArchiveRelocationMode == 1) { |
|
1389 // This is for simulating mmap failures at the requested address. We do it here (instead |
|
1390 // of MetaspaceShared::map_archives) so we can thoroughly test the code for failure handling |
|
1391 // (releasing all allocated resource, etc). |
|
1392 log_info(cds)("ArchiveRelocationMode == 1: always map archive(s) at an alternative address"); |
|
1393 return MAP_ARCHIVE_MMAP_FAILURE; |
|
1394 }); |
|
1395 |
|
1396 header()->set_mapped_base_address(header()->requested_base_address() + addr_delta); |
1388 header()->set_mapped_base_address(header()->requested_base_address() + addr_delta); |
1397 if (addr_delta != 0 && !relocate_pointers(addr_delta)) { |
1389 if (addr_delta != 0 && !relocate_pointers(addr_delta)) { |
1398 return MAP_ARCHIVE_OTHER_FAILURE; |
1390 return MAP_ARCHIVE_OTHER_FAILURE; |
1399 } |
1391 } |
1400 |
1392 |
1444 if (rs.is_reserved()) { |
1436 if (rs.is_reserved()) { |
1445 assert(rs.contains(requested_addr) && rs.contains(requested_addr + size - 1), "must be"); |
1437 assert(rs.contains(requested_addr) && rs.contains(requested_addr + size - 1), "must be"); |
1446 MemTracker::record_virtual_memory_type((address)requested_addr, mtClassShared); |
1438 MemTracker::record_virtual_memory_type((address)requested_addr, mtClassShared); |
1447 } |
1439 } |
1448 |
1440 |
1449 if (MetaspaceShared::use_windows_memory_mapping() && addr_delta != 0) { |
1441 if (MetaspaceShared::use_windows_memory_mapping() && rs.is_reserved()) { |
1450 // This is the second time we try to map the archive(s). We have already created a ReservedSpace |
1442 // This is the second time we try to map the archive(s). We have already created a ReservedSpace |
1451 // that covers all the FileMapRegions to ensure all regions can be mapped. However, Windows |
1443 // that covers all the FileMapRegions to ensure all regions can be mapped. However, Windows |
1452 // can't mmap into a ReservedSpace, so we just os::read() the data. We're going to patch all the |
1444 // can't mmap into a ReservedSpace, so we just os::read() the data. We're going to patch all the |
1453 // regions anyway, so there's no benefit for mmap anyway. |
1445 // regions anyway, so there's no benefit for mmap anyway. |
1454 if (!read_region(i, requested_addr, size)) { |
1446 if (!read_region(i, requested_addr, size)) { |
|
1447 log_info(cds)("Failed to read %s shared space into reserved space at " INTPTR_FORMAT, |
|
1448 shared_region_name[i], p2i(requested_addr)); |
1455 return MAP_ARCHIVE_OTHER_FAILURE; // oom or I/O error. |
1449 return MAP_ARCHIVE_OTHER_FAILURE; // oom or I/O error. |
1456 } |
1450 } |
1457 } else { |
1451 } else { |
1458 char* base = os::map_memory(_fd, _full_path, si->file_offset(), |
1452 char* base = os::map_memory(_fd, _full_path, si->file_offset(), |
1459 requested_addr, size, si->read_only(), |
1453 requested_addr, size, si->read_only(), |
1460 si->allow_exec()); |
1454 si->allow_exec()); |
1461 if (base != requested_addr) { |
1455 if (base != requested_addr) { |
1462 log_info(cds)("Unable to map %s shared space at required address.", shared_region_name[i]); |
1456 log_info(cds)("Unable to map %s shared space at " INTPTR_FORMAT, |
|
1457 shared_region_name[i], p2i(requested_addr)); |
1463 _memory_mapping_failed = true; |
1458 _memory_mapping_failed = true; |
1464 return MAP_ARCHIVE_MMAP_FAILURE; |
1459 return MAP_ARCHIVE_MMAP_FAILURE; |
1465 } |
1460 } |
1466 si->set_mapped_from_file(true); |
1461 si->set_mapped_from_file(true); |
1467 } |
1462 } |
1468 si->set_mapped_base(requested_addr); |
1463 si->set_mapped_base(requested_addr); |
1469 |
1464 |
1470 if (!rs.is_reserved()) { |
1465 if (!rs.is_reserved()) { |
1471 // When mapping on Windows with (addr_delta == 0), we don't reserve the address space for the regions |
1466 // When mapping on Windows for the first attempt, we don't reserve the address space for the regions |
1472 // (Windows can't mmap into a ReservedSpace). In this case, NMT requires we call it after |
1467 // (Windows can't mmap into a ReservedSpace). In this case, NMT requires we call it after |
1473 // os::map_memory has succeeded. |
1468 // os::map_memory has succeeded. |
1474 assert(MetaspaceShared::use_windows_memory_mapping(), "Windows memory mapping only"); |
1469 assert(MetaspaceShared::use_windows_memory_mapping(), "Windows memory mapping only"); |
1475 MemTracker::record_virtual_memory_type((address)requested_addr, mtClassShared); |
1470 MemTracker::record_virtual_memory_type((address)requested_addr, mtClassShared); |
1476 } |
1471 } |