< prev index next >

src/hotspot/share/cds/filemap.cpp

Print this page

 196   set_common_app_classpath_prefix_size((unsigned int)common_app_classpath_prefix_size);
 197   set_magic(CDSConfig::is_dumping_dynamic_archive() ? CDS_DYNAMIC_ARCHIVE_MAGIC : CDS_ARCHIVE_MAGIC);
 198   set_version(CURRENT_CDS_ARCHIVE_VERSION);
 199 
 200   if (!info->is_static() && base_archive_name_size != 0) {
 201     // copy base archive name
 202     copy_base_archive_name(CDSConfig::static_archive_path());
 203   }
 204   _core_region_alignment = core_region_alignment;
 205   _obj_alignment = ObjectAlignmentInBytes;
 206   _compact_strings = CompactStrings;
 207   if (CDSConfig::is_dumping_heap()) {
 208     _narrow_oop_mode = CompressedOops::mode();
 209     _narrow_oop_base = CompressedOops::base();
 210     _narrow_oop_shift = CompressedOops::shift();
 211   }
 212   _compressed_oops = UseCompressedOops;
 213   _compressed_class_ptrs = UseCompressedClassPointers;
 214   _max_heap_size = MaxHeapSize;
 215   _use_optimized_module_handling = MetaspaceShared::use_optimized_module_handling();

 216   _has_full_module_graph = CDSConfig::is_dumping_full_module_graph();

 217 
 218   // The following fields are for sanity checks for whether this archive
 219   // will function correctly with this JVM and the bootclasspath it's
 220   // invoked with.
 221 
 222   // JVM version string ... changes on each build.
 223   get_header_version(_jvm_ident);
 224 
 225   _app_class_paths_start_index = ClassLoaderExt::app_class_paths_start_index();
 226   _app_module_paths_start_index = ClassLoaderExt::app_module_paths_start_index();
 227   _max_used_path_index = ClassLoaderExt::max_used_path_index();
 228   _num_module_paths = ClassLoader::num_module_path_entries();
 229 
 230   _verify_local = BytecodeVerificationLocal;
 231   _verify_remote = BytecodeVerificationRemote;
 232   _has_platform_or_app_classes = ClassLoaderExt::has_platform_or_app_classes();
 233   _has_non_jar_in_classpath = ClassLoaderExt::has_non_jar_in_classpath();
 234   _requested_base_address = (char*)SharedBaseAddress;
 235   _mapped_base_address = (char*)SharedBaseAddress;
 236   _allow_archiving_with_java_agent = AllowArchivingWithJavaAgent;

 275   st->print_cr("- compressed_oops:                %d", _compressed_oops);
 276   st->print_cr("- compressed_class_ptrs:          %d", _compressed_class_ptrs);
 277   st->print_cr("- cloned_vtables_offset:          " SIZE_FORMAT_X, _cloned_vtables_offset);
 278   st->print_cr("- serialized_data_offset:         " SIZE_FORMAT_X, _serialized_data_offset);
 279   st->print_cr("- jvm_ident:                      %s", _jvm_ident);
 280   st->print_cr("- shared_path_table_offset:       " SIZE_FORMAT_X, _shared_path_table_offset);
 281   st->print_cr("- app_class_paths_start_index:    %d", _app_class_paths_start_index);
 282   st->print_cr("- app_module_paths_start_index:   %d", _app_module_paths_start_index);
 283   st->print_cr("- num_module_paths:               %d", _num_module_paths);
 284   st->print_cr("- max_used_path_index:            %d", _max_used_path_index);
 285   st->print_cr("- verify_local:                   %d", _verify_local);
 286   st->print_cr("- verify_remote:                  %d", _verify_remote);
 287   st->print_cr("- has_platform_or_app_classes:    %d", _has_platform_or_app_classes);
 288   st->print_cr("- has_non_jar_in_classpath:       %d", _has_non_jar_in_classpath);
 289   st->print_cr("- requested_base_address:         " INTPTR_FORMAT, p2i(_requested_base_address));
 290   st->print_cr("- mapped_base_address:            " INTPTR_FORMAT, p2i(_mapped_base_address));
 291   st->print_cr("- heap_roots_offset:              " SIZE_FORMAT, _heap_roots_offset);
 292   st->print_cr("- allow_archiving_with_java_agent:%d", _allow_archiving_with_java_agent);
 293   st->print_cr("- use_optimized_module_handling:  %d", _use_optimized_module_handling);
 294   st->print_cr("- has_full_module_graph           %d", _has_full_module_graph);

 295   st->print_cr("- ptrmap_size_in_bits:            " SIZE_FORMAT, _ptrmap_size_in_bits);
 296 }
 297 
 298 void SharedClassPathEntry::init_as_non_existent(const char* path, TRAPS) {
 299   _type = non_existent_entry;
 300   set_name(path, CHECK);
 301 }
 302 
 303 void SharedClassPathEntry::init(bool is_modules_image,
 304                                 bool is_module_path,
 305                                 ClassPathEntry* cpe, TRAPS) {
 306   assert(CDSConfig::is_dumping_archive(), "sanity");
 307   _timestamp = 0;
 308   _filesize  = 0;
 309   _from_class_path_attr = false;
 310 
 311   struct stat st;
 312   if (os::stat(cpe->name(), &st) == 0) {
 313     if ((st.st_mode & S_IFMT) == S_IFDIR) {
 314       _type = dir_entry;

 540 
 541 void FileMapInfo::record_non_existent_class_path_entry(const char* path) {
 542   assert(CDSConfig::is_dumping_archive(), "sanity");
 543   log_info(class, path)("non-existent Class-Path entry %s", path);
 544   if (_non_existent_class_paths == nullptr) {
 545     _non_existent_class_paths = new (mtClass) GrowableArray<const char*>(10, mtClass);
 546   }
 547   _non_existent_class_paths->append(os::strdup(path));
 548 }
 549 
 550 int FileMapInfo::num_non_existent_class_paths() {
 551   assert(CDSConfig::is_dumping_archive(), "sanity");
 552   if (_non_existent_class_paths != nullptr) {
 553     return _non_existent_class_paths->length();
 554   } else {
 555     return 0;
 556   }
 557 }
 558 
 559 int FileMapInfo::get_module_shared_path_index(Symbol* location) {



 560   if (location->starts_with("jrt:", 4) && get_number_of_shared_paths() > 0) {
 561     assert(shared_path(0)->is_modules_image(), "first shared_path must be the modules image");
 562     return 0;
 563   }
 564 
 565   if (ClassLoaderExt::app_module_paths_start_index() >= get_number_of_shared_paths()) {
 566     // The archive(s) were created without --module-path option
 567     return -1;
 568   }
 569 
 570   if (!location->starts_with("file:", 5)) {
 571     return -1;
 572   }
 573 
 574   // skip_uri_protocol was also called during dump time -- see ClassLoaderExt::process_module_table()
 575   ResourceMark rm;
 576   const char* file = ClassLoader::skip_uri_protocol(location->as_C_string());
 577   for (int i = ClassLoaderExt::app_module_paths_start_index(); i < get_number_of_shared_paths(); i++) {
 578     SharedClassPathEntry* ent = shared_path(i);
 579     if (!ent->is_non_existent()) {

1470 bool FileMapRegion::check_region_crc(char* base) const {
1471   // This function should be called after the region has been properly
1472   // loaded into memory via FileMapInfo::map_region() or FileMapInfo::read_region().
1473   // I.e., this->mapped_base() must be valid.
1474   size_t sz = used();
1475   if (sz == 0) {
1476     return true;
1477   }
1478 
1479   assert(base != nullptr, "must be initialized");
1480   int crc = ClassLoader::crc32(0, base, (jint)sz);
1481   if (crc != this->crc()) {
1482     log_warning(cds)("Checksum verification failed.");
1483     return false;
1484   }
1485   return true;
1486 }
1487 
1488 static const char* region_name(int region_index) {
1489   static const char* names[] = {
1490     "rw", "ro", "bm", "hp"
1491   };
1492   const int num_regions = sizeof(names)/sizeof(names[0]);
1493   assert(0 <= region_index && region_index < num_regions, "sanity");
1494 
1495   return names[region_index];
1496 }
1497 
1498 void FileMapRegion::print(outputStream* st, int region_index) {
1499   st->print_cr("============ region ============= %d \"%s\"", region_index, region_name(region_index));
1500   st->print_cr("- crc:                            0x%08x", _crc);
1501   st->print_cr("- read_only:                      %d", _read_only);
1502   st->print_cr("- allow_exec:                     %d", _allow_exec);
1503   st->print_cr("- is_heap_region:                 %d", _is_heap_region);
1504   st->print_cr("- is_bitmap_region:               %d", _is_bitmap_region);
1505   st->print_cr("- mapped_from_file:               %d", _mapped_from_file);
1506   st->print_cr("- file_offset:                    " SIZE_FORMAT_X, _file_offset);
1507   st->print_cr("- mapping_offset:                 " SIZE_FORMAT_X, _mapping_offset);
1508   st->print_cr("- used:                           " SIZE_FORMAT, _used);
1509   st->print_cr("- oopmap_offset:                  " SIZE_FORMAT_X, _oopmap_offset);
1510   st->print_cr("- oopmap_size_in_bits:            " SIZE_FORMAT, _oopmap_size_in_bits);

1533       mapping_offset = (size_t)((address)requested_base - CompressedOops::base());
1534       assert((mapping_offset >> CompressedOops::shift()) << CompressedOops::shift() == mapping_offset, "must be");
1535     } else {
1536       mapping_offset = 0; // not used with !UseCompressedOops
1537     }
1538 #endif // INCLUDE_CDS_JAVA_HEAP
1539   } else {
1540     char* requested_SharedBaseAddress = (char*)MetaspaceShared::requested_base_address();
1541     requested_base = ArchiveBuilder::current()->to_requested(base);
1542     assert(requested_base >= requested_SharedBaseAddress, "must be");
1543     mapping_offset = requested_base - requested_SharedBaseAddress;
1544   }
1545 
1546   r->set_file_offset(_file_offset);
1547   int crc = ClassLoader::crc32(0, base, (jint)size);
1548   if (size > 0) {
1549     log_info(cds)("Shared file region (%s) %d: " SIZE_FORMAT_W(8)
1550                    " bytes, addr " INTPTR_FORMAT " file offset 0x%08" PRIxPTR
1551                    " crc 0x%08x",
1552                    region_name(region), region, size, p2i(requested_base), _file_offset, crc);



1553   }
1554 
1555   r->init(region, mapping_offset, size, read_only, allow_exec, crc);
1556 
1557   if (base != nullptr) {
1558     write_bytes_aligned(base, size);
1559   }
1560 }
1561 
1562 static size_t write_bitmap(const CHeapBitMap* map, char* output, size_t offset) {
1563   size_t size_in_bytes = map->size_in_bytes();
1564   map->write_to((BitMap::bm_word_t*)(output + offset), size_in_bytes);
1565   return offset + size_in_bytes;
1566 }
1567 
1568 char* FileMapInfo::write_bitmap_region(const CHeapBitMap* ptrmap, ArchiveHeapInfo* heap_info,
1569                                        size_t &size_in_bytes) {
1570   size_in_bytes = ptrmap->size_in_bytes();
1571 
1572   if (heap_info->is_used()) {

1694   assert(WINDOWS_ONLY(false) NOT_WINDOWS(true), "Don't call on Windows");
1695   // Replace old mapping with new one that is writable.
1696   char *base = os::map_memory(_fd, _full_path, r->file_offset(),
1697                               addr, size, false /* !read_only */,
1698                               r->allow_exec());
1699   close();
1700   // These have to be errors because the shared region is now unmapped.
1701   if (base == nullptr) {
1702     log_error(cds)("Unable to remap shared readonly space (errno=%d).", errno);
1703     vm_exit(1);
1704   }
1705   if (base != addr) {
1706     log_error(cds)("Unable to remap shared readonly space (errno=%d).", errno);
1707     vm_exit(1);
1708   }
1709   r->set_read_only(false);
1710   return true;
1711 }
1712 
1713 // Memory map a region in the address space.
1714 static const char* shared_region_name[] = { "ReadWrite", "ReadOnly", "Bitmap", "Heap" };
1715 
1716 MapArchiveResult FileMapInfo::map_regions(int regions[], int num_regions, char* mapped_base_address, ReservedSpace rs) {
1717   DEBUG_ONLY(FileMapRegion* last_region = nullptr);
1718   intx addr_delta = mapped_base_address - header()->requested_base_address();
1719 
1720   // Make sure we don't attempt to use header()->mapped_base_address() unless
1721   // it's been successfully mapped.
1722   DEBUG_ONLY(header()->set_mapped_base_address((char*)(uintptr_t)0xdeadbeef);)
1723 
1724   for (int i = 0; i < num_regions; i++) {
1725     int idx = regions[i];
1726     MapArchiveResult result = map_region(idx, addr_delta, mapped_base_address, rs);
1727     if (result != MAP_ARCHIVE_SUCCESS) {
1728       return result;
1729     }
1730     FileMapRegion* r = region_at(idx);
1731     DEBUG_ONLY(if (last_region != nullptr) {
1732         // Ensure that the OS won't be able to allocate new memory spaces between any mapped
1733         // regions, or else it would mess up the simple comparison in MetaspaceObj::is_shared().
1734         assert(r->mapped_base() == last_region->mapped_end(), "must have no gaps");

1797     r->set_read_only(false); // Need to patch the pointers
1798   }
1799 
1800   if (MetaspaceShared::use_windows_memory_mapping() && rs.is_reserved()) {
1801     // This is the second time we try to map the archive(s). We have already created a ReservedSpace
1802     // that covers all the FileMapRegions to ensure all regions can be mapped. However, Windows
1803     // can't mmap into a ReservedSpace, so we just ::read() the data. We're going to patch all the
1804     // regions anyway, so there's no benefit for mmap anyway.
1805     if (!read_region(i, requested_addr, size, /* do_commit = */ true)) {
1806       log_info(cds)("Failed to read %s shared space into reserved space at " INTPTR_FORMAT,
1807                     shared_region_name[i], p2i(requested_addr));
1808       return MAP_ARCHIVE_OTHER_FAILURE; // oom or I/O error.
1809     } else {
1810       assert(r->mapped_base() != nullptr, "must be initialized");
1811       return MAP_ARCHIVE_SUCCESS;
1812     }
1813   } else {
1814     // Note that this may either be a "fresh" mapping into unreserved address
1815     // space (Windows, first mapping attempt), or a mapping into pre-reserved
1816     // space (Posix). See also comment in MetaspaceShared::map_archives().

1817     char* base = map_memory(_fd, _full_path, r->file_offset(),
1818                             requested_addr, size, r->read_only(),
1819                             r->allow_exec(), mtClassShared);
1820     if (base != requested_addr) {
1821       log_info(cds)("Unable to map %s shared space at " INTPTR_FORMAT,
1822                     shared_region_name[i], p2i(requested_addr));
1823       _memory_mapping_failed = true;
1824       return MAP_ARCHIVE_MMAP_FAILURE;
1825     }
1826 
1827     if (VerifySharedSpaces && !r->check_region_crc(requested_addr)) {
1828       return MAP_ARCHIVE_OTHER_FAILURE;
1829     }
1830 
1831     r->set_mapped_from_file(true);
1832     r->set_mapped_base(requested_addr);
1833 
1834     return MAP_ARCHIVE_SUCCESS;
1835   }
1836 }
1837 
1838 // The return value is the location of the archive relocation bitmap.

1850     return nullptr;
1851   }
1852 
1853   if (VerifySharedSpaces && !r->check_region_crc(bitmap_base)) {
1854     log_error(cds)("relocation bitmap CRC error");
1855     if (!os::unmap_memory(bitmap_base, r->used_aligned())) {
1856       fatal("os::unmap_memory of relocation bitmap failed");
1857     }
1858     return nullptr;
1859   }
1860 
1861   r->set_mapped_from_file(true);
1862   r->set_mapped_base(bitmap_base);
1863   log_info(cds)("Mapped %s region #%d at base " INTPTR_FORMAT " top " INTPTR_FORMAT " (%s)",
1864                 is_static() ? "static " : "dynamic",
1865                 MetaspaceShared::bm, p2i(r->mapped_base()), p2i(r->mapped_end()),
1866                 shared_region_name[MetaspaceShared::bm]);
1867   return bitmap_base;
1868 }
1869 
















































































1870 // This is called when we cannot map the archive at the requested[ base address (usually 0x800000000).
1871 // We relocate all pointers in the 2 core regions (ro, rw).
1872 bool FileMapInfo::relocate_pointers_in_core_regions(intx addr_delta) {
1873   log_debug(cds, reloc)("runtime archive relocation start");
1874   char* bitmap_base = map_bitmap_region();
1875 
1876   if (bitmap_base == nullptr) {
1877     return false; // OOM, or CRC check failure
1878   } else {
1879     size_t ptrmap_size_in_bits = header()->ptrmap_size_in_bits();
1880     log_debug(cds, reloc)("mapped relocation bitmap @ " INTPTR_FORMAT " (" SIZE_FORMAT " bits)",
1881                           p2i(bitmap_base), ptrmap_size_in_bits);
1882 
1883     BitMapView ptrmap((BitMap::bm_word_t*)bitmap_base, ptrmap_size_in_bits);
1884 
1885     // Patch all pointers in the mapped region that are marked by ptrmap.
1886     address patch_base = (address)mapped_base();
1887     address patch_end  = (address)mapped_end();
1888 




1889     // the current value of the pointers to be patched must be within this
1890     // range (i.e., must be between the requested base address and the address of the current archive).
1891     // Note: top archive may point to objects in the base archive, but not the other way around.
1892     address valid_old_base = (address)header()->requested_base_address();
1893     address valid_old_end  = valid_old_base + mapping_end_offset();
1894 
1895     // after patching, the pointers must point inside this range
1896     // (the requested location of the archive, as mapped at runtime).
1897     address valid_new_base = (address)header()->mapped_base_address();
1898     address valid_new_end  = (address)mapped_end();
1899 




1900     SharedDataRelocator patcher((address*)patch_base, (address*)patch_end, valid_old_base, valid_old_end,
1901                                 valid_new_base, valid_new_end, addr_delta);
1902     ptrmap.iterate(&patcher);
1903 
1904     // The MetaspaceShared::bm region will be unmapped in MetaspaceShared::initialize_shared_spaces().
1905 
1906     log_debug(cds, reloc)("runtime archive relocation done");
1907     return true;
1908   }
1909 }
1910 
1911 size_t FileMapInfo::read_bytes(void* buffer, size_t count) {
1912   assert(_file_open, "Archive file is not open");
1913   size_t n = ::read(_fd, buffer, (unsigned int)count);
1914   if (n != count) {
1915     // Close the file if there's a problem reading it.
1916     close();
1917     return 0;
1918   }
1919   _file_offset += count;

1960 
1961 void FileMapInfo::map_or_load_heap_region() {
1962   bool success = false;
1963 
1964   if (can_use_heap_region()) {
1965     if (ArchiveHeapLoader::can_map()) {
1966       success = map_heap_region();
1967     } else if (ArchiveHeapLoader::can_load()) {
1968       success = ArchiveHeapLoader::load_heap_region(this);
1969     } else {
1970       if (!UseCompressedOops && !ArchiveHeapLoader::can_map()) {
1971         // TODO - remove implicit knowledge of G1
1972         log_info(cds)("Cannot use CDS heap data. UseG1GC is required for -XX:-UseCompressedOops");
1973       } else {
1974         log_info(cds)("Cannot use CDS heap data. UseEpsilonGC, UseG1GC, UseSerialGC or UseParallelGC are required.");
1975       }
1976     }
1977   }
1978 
1979   if (!success) {
1980     CDSConfig::disable_loading_full_module_graph();
1981   }
1982 }
1983 
1984 bool FileMapInfo::can_use_heap_region() {
1985   if (!has_heap_region()) {
1986     return false;
1987   }
1988   if (JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::has_early_class_hook_env()) {
1989     ShouldNotReachHere(); // CDS should have been disabled.
1990     // The archived objects are mapped at JVM start-up, but we don't know if
1991     // j.l.String or j.l.Class might be replaced by the ClassFileLoadHook,
1992     // which would make the archived String or mirror objects invalid. Let's be safe and not
1993     // use the archived objects. These 2 classes are loaded during the JVMTI "early" stage.
1994     //
1995     // If JvmtiExport::has_early_class_hook_env() is false, the classes of some objects
1996     // in the archived subgraphs may be replaced by the ClassFileLoadHook. But that's OK
1997     // because we won't install an archived object subgraph if the klass of any of the
1998     // referenced objects are replaced. See HeapShared::initialize_from_archived_subgraph().
1999   }
2000 

2272     // during the JVMTI "early" stage, so we can still use CDS if
2273     // JvmtiExport::has_early_class_hook_env() is false.
2274     log_info(cds)("CDS is disabled because early JVMTI ClassFileLoadHook is in use.");
2275     return false;
2276   }
2277 
2278   if (!open_for_read() || !init_from_file(_fd) || !validate_header()) {
2279     if (_is_static) {
2280       log_info(cds)("Initialize static archive failed.");
2281       return false;
2282     } else {
2283       log_info(cds)("Initialize dynamic archive failed.");
2284       if (AutoCreateSharedArchive) {
2285         CDSConfig::enable_dumping_dynamic_archive();
2286         ArchiveClassesAtExit = CDSConfig::dynamic_archive_path();
2287       }
2288       return false;
2289     }
2290   }
2291 











2292   return true;
2293 }
2294 
2295 // The 2 core spaces are RW->RO
2296 FileMapRegion* FileMapInfo::first_core_region() const {
2297   return region_at(MetaspaceShared::rw);
2298 }
2299 
2300 FileMapRegion* FileMapInfo::last_core_region() const {
2301   return region_at(MetaspaceShared::ro);
2302 }
2303 
2304 void FileMapInfo::print(outputStream* st) const {
2305   header()->print(st);
2306   if (!is_static()) {
2307     dynamic_header()->print(st);
2308   }
2309 }
2310 
2311 void FileMapHeader::set_as_offset(char* p, size_t *offset) {

2380   }
2381 
2382   if (_allow_archiving_with_java_agent) {
2383     log_warning(cds)("This archive was created with AllowArchivingWithJavaAgent. It should be used "
2384             "for testing purposes only and should not be used in a production environment");
2385   }
2386 
2387   log_info(cds)("Archive was created with UseCompressedOops = %d, UseCompressedClassPointers = %d",
2388                           compressed_oops(), compressed_class_pointers());
2389   if (compressed_oops() != UseCompressedOops || compressed_class_pointers() != UseCompressedClassPointers) {
2390     log_info(cds)("Unable to use shared archive.\nThe saved state of UseCompressedOops and UseCompressedClassPointers is "
2391                                "different from runtime, CDS will be disabled.");
2392     return false;
2393   }
2394 
2395   if (!_use_optimized_module_handling) {
2396     MetaspaceShared::disable_optimized_module_handling();
2397     log_info(cds)("optimized module handling: disabled because archive was created without optimized module handling");
2398   }
2399 
2400   if (is_static() && !_has_full_module_graph) {
2401     // Only the static archive can contain the full module graph.
2402     CDSConfig::disable_loading_full_module_graph("archive was created without full module graph");






2403   }
2404 
2405   return true;
2406 }
2407 
2408 bool FileMapInfo::validate_header() {
2409   if (!header()->validate()) {
2410     return false;
2411   }
2412   if (_is_static) {
2413     return true;
2414   } else {
2415     return DynamicArchive::validate(this);
2416   }
2417 }
2418 
2419 #if INCLUDE_JVMTI
2420 ClassPathEntry** FileMapInfo::_classpath_entries_for_jvmti = nullptr;
2421 
2422 ClassPathEntry* FileMapInfo::get_classpath_entry_for_jvmti(int i, TRAPS) {

 196   set_common_app_classpath_prefix_size((unsigned int)common_app_classpath_prefix_size);
 197   set_magic(CDSConfig::is_dumping_dynamic_archive() ? CDS_DYNAMIC_ARCHIVE_MAGIC : CDS_ARCHIVE_MAGIC);
 198   set_version(CURRENT_CDS_ARCHIVE_VERSION);
 199 
 200   if (!info->is_static() && base_archive_name_size != 0) {
 201     // copy base archive name
 202     copy_base_archive_name(CDSConfig::static_archive_path());
 203   }
 204   _core_region_alignment = core_region_alignment;
 205   _obj_alignment = ObjectAlignmentInBytes;
 206   _compact_strings = CompactStrings;
 207   if (CDSConfig::is_dumping_heap()) {
 208     _narrow_oop_mode = CompressedOops::mode();
 209     _narrow_oop_base = CompressedOops::base();
 210     _narrow_oop_shift = CompressedOops::shift();
 211   }
 212   _compressed_oops = UseCompressedOops;
 213   _compressed_class_ptrs = UseCompressedClassPointers;
 214   _max_heap_size = MaxHeapSize;
 215   _use_optimized_module_handling = MetaspaceShared::use_optimized_module_handling();
 216   _has_preloaded_classes = PreloadSharedClasses;
 217   _has_full_module_graph = CDSConfig::is_dumping_full_module_graph();
 218   _has_archived_invokedynamic = CDSConfig::is_dumping_invokedynamic();
 219 
 220   // The following fields are for sanity checks for whether this archive
 221   // will function correctly with this JVM and the bootclasspath it's
 222   // invoked with.
 223 
 224   // JVM version string ... changes on each build.
 225   get_header_version(_jvm_ident);
 226 
 227   _app_class_paths_start_index = ClassLoaderExt::app_class_paths_start_index();
 228   _app_module_paths_start_index = ClassLoaderExt::app_module_paths_start_index();
 229   _max_used_path_index = ClassLoaderExt::max_used_path_index();
 230   _num_module_paths = ClassLoader::num_module_path_entries();
 231 
 232   _verify_local = BytecodeVerificationLocal;
 233   _verify_remote = BytecodeVerificationRemote;
 234   _has_platform_or_app_classes = ClassLoaderExt::has_platform_or_app_classes();
 235   _has_non_jar_in_classpath = ClassLoaderExt::has_non_jar_in_classpath();
 236   _requested_base_address = (char*)SharedBaseAddress;
 237   _mapped_base_address = (char*)SharedBaseAddress;
 238   _allow_archiving_with_java_agent = AllowArchivingWithJavaAgent;

 277   st->print_cr("- compressed_oops:                %d", _compressed_oops);
 278   st->print_cr("- compressed_class_ptrs:          %d", _compressed_class_ptrs);
 279   st->print_cr("- cloned_vtables_offset:          " SIZE_FORMAT_X, _cloned_vtables_offset);
 280   st->print_cr("- serialized_data_offset:         " SIZE_FORMAT_X, _serialized_data_offset);
 281   st->print_cr("- jvm_ident:                      %s", _jvm_ident);
 282   st->print_cr("- shared_path_table_offset:       " SIZE_FORMAT_X, _shared_path_table_offset);
 283   st->print_cr("- app_class_paths_start_index:    %d", _app_class_paths_start_index);
 284   st->print_cr("- app_module_paths_start_index:   %d", _app_module_paths_start_index);
 285   st->print_cr("- num_module_paths:               %d", _num_module_paths);
 286   st->print_cr("- max_used_path_index:            %d", _max_used_path_index);
 287   st->print_cr("- verify_local:                   %d", _verify_local);
 288   st->print_cr("- verify_remote:                  %d", _verify_remote);
 289   st->print_cr("- has_platform_or_app_classes:    %d", _has_platform_or_app_classes);
 290   st->print_cr("- has_non_jar_in_classpath:       %d", _has_non_jar_in_classpath);
 291   st->print_cr("- requested_base_address:         " INTPTR_FORMAT, p2i(_requested_base_address));
 292   st->print_cr("- mapped_base_address:            " INTPTR_FORMAT, p2i(_mapped_base_address));
 293   st->print_cr("- heap_roots_offset:              " SIZE_FORMAT, _heap_roots_offset);
 294   st->print_cr("- allow_archiving_with_java_agent:%d", _allow_archiving_with_java_agent);
 295   st->print_cr("- use_optimized_module_handling:  %d", _use_optimized_module_handling);
 296   st->print_cr("- has_full_module_graph           %d", _has_full_module_graph);
 297   st->print_cr("- has_archived_invokedynamic      %d", _has_archived_invokedynamic);
 298   st->print_cr("- ptrmap_size_in_bits:            " SIZE_FORMAT, _ptrmap_size_in_bits);
 299 }
 300 
 301 void SharedClassPathEntry::init_as_non_existent(const char* path, TRAPS) {
 302   _type = non_existent_entry;
 303   set_name(path, CHECK);
 304 }
 305 
 306 void SharedClassPathEntry::init(bool is_modules_image,
 307                                 bool is_module_path,
 308                                 ClassPathEntry* cpe, TRAPS) {
 309   assert(CDSConfig::is_dumping_archive(), "sanity");
 310   _timestamp = 0;
 311   _filesize  = 0;
 312   _from_class_path_attr = false;
 313 
 314   struct stat st;
 315   if (os::stat(cpe->name(), &st) == 0) {
 316     if ((st.st_mode & S_IFMT) == S_IFDIR) {
 317       _type = dir_entry;

 543 
 544 void FileMapInfo::record_non_existent_class_path_entry(const char* path) {
 545   assert(CDSConfig::is_dumping_archive(), "sanity");
 546   log_info(class, path)("non-existent Class-Path entry %s", path);
 547   if (_non_existent_class_paths == nullptr) {
 548     _non_existent_class_paths = new (mtClass) GrowableArray<const char*>(10, mtClass);
 549   }
 550   _non_existent_class_paths->append(os::strdup(path));
 551 }
 552 
 553 int FileMapInfo::num_non_existent_class_paths() {
 554   assert(CDSConfig::is_dumping_archive(), "sanity");
 555   if (_non_existent_class_paths != nullptr) {
 556     return _non_existent_class_paths->length();
 557   } else {
 558     return 0;
 559   }
 560 }
 561 
 562 int FileMapInfo::get_module_shared_path_index(Symbol* location) {
 563   if (location == nullptr) {
 564     return 0; // Used by java/lang/reflect/Proxy$ProxyBuilder
 565   }
 566   if (location->starts_with("jrt:", 4) && get_number_of_shared_paths() > 0) {
 567     assert(shared_path(0)->is_modules_image(), "first shared_path must be the modules image");
 568     return 0;
 569   }
 570 
 571   if (ClassLoaderExt::app_module_paths_start_index() >= get_number_of_shared_paths()) {
 572     // The archive(s) were created without --module-path option
 573     return -1;
 574   }
 575 
 576   if (!location->starts_with("file:", 5)) {
 577     return -1;
 578   }
 579 
 580   // skip_uri_protocol was also called during dump time -- see ClassLoaderExt::process_module_table()
 581   ResourceMark rm;
 582   const char* file = ClassLoader::skip_uri_protocol(location->as_C_string());
 583   for (int i = ClassLoaderExt::app_module_paths_start_index(); i < get_number_of_shared_paths(); i++) {
 584     SharedClassPathEntry* ent = shared_path(i);
 585     if (!ent->is_non_existent()) {

1476 bool FileMapRegion::check_region_crc(char* base) const {
1477   // This function should be called after the region has been properly
1478   // loaded into memory via FileMapInfo::map_region() or FileMapInfo::read_region().
1479   // I.e., this->mapped_base() must be valid.
1480   size_t sz = used();
1481   if (sz == 0) {
1482     return true;
1483   }
1484 
1485   assert(base != nullptr, "must be initialized");
1486   int crc = ClassLoader::crc32(0, base, (jint)sz);
1487   if (crc != this->crc()) {
1488     log_warning(cds)("Checksum verification failed.");
1489     return false;
1490   }
1491   return true;
1492 }
1493 
1494 static const char* region_name(int region_index) {
1495   static const char* names[] = {
1496     "rw", "ro", "bm", "hp", "cc",
1497   };
1498   const int num_regions = sizeof(names)/sizeof(names[0]);
1499   assert(0 <= region_index && region_index < num_regions, "sanity");
1500 
1501   return names[region_index];
1502 }
1503 
1504 void FileMapRegion::print(outputStream* st, int region_index) {
1505   st->print_cr("============ region ============= %d \"%s\"", region_index, region_name(region_index));
1506   st->print_cr("- crc:                            0x%08x", _crc);
1507   st->print_cr("- read_only:                      %d", _read_only);
1508   st->print_cr("- allow_exec:                     %d", _allow_exec);
1509   st->print_cr("- is_heap_region:                 %d", _is_heap_region);
1510   st->print_cr("- is_bitmap_region:               %d", _is_bitmap_region);
1511   st->print_cr("- mapped_from_file:               %d", _mapped_from_file);
1512   st->print_cr("- file_offset:                    " SIZE_FORMAT_X, _file_offset);
1513   st->print_cr("- mapping_offset:                 " SIZE_FORMAT_X, _mapping_offset);
1514   st->print_cr("- used:                           " SIZE_FORMAT, _used);
1515   st->print_cr("- oopmap_offset:                  " SIZE_FORMAT_X, _oopmap_offset);
1516   st->print_cr("- oopmap_size_in_bits:            " SIZE_FORMAT, _oopmap_size_in_bits);

1539       mapping_offset = (size_t)((address)requested_base - CompressedOops::base());
1540       assert((mapping_offset >> CompressedOops::shift()) << CompressedOops::shift() == mapping_offset, "must be");
1541     } else {
1542       mapping_offset = 0; // not used with !UseCompressedOops
1543     }
1544 #endif // INCLUDE_CDS_JAVA_HEAP
1545   } else {
1546     char* requested_SharedBaseAddress = (char*)MetaspaceShared::requested_base_address();
1547     requested_base = ArchiveBuilder::current()->to_requested(base);
1548     assert(requested_base >= requested_SharedBaseAddress, "must be");
1549     mapping_offset = requested_base - requested_SharedBaseAddress;
1550   }
1551 
1552   r->set_file_offset(_file_offset);
1553   int crc = ClassLoader::crc32(0, base, (jint)size);
1554   if (size > 0) {
1555     log_info(cds)("Shared file region (%s) %d: " SIZE_FORMAT_W(8)
1556                    " bytes, addr " INTPTR_FORMAT " file offset 0x%08" PRIxPTR
1557                    " crc 0x%08x",
1558                    region_name(region), region, size, p2i(requested_base), _file_offset, crc);
1559   } else {
1560     log_info(cds)("Shared file region (%s) %d: " SIZE_FORMAT_W(8)
1561                   " bytes", region_name(region), region, size);
1562   }
1563 
1564   r->init(region, mapping_offset, size, read_only, allow_exec, crc);
1565 
1566   if (base != nullptr) {
1567     write_bytes_aligned(base, size);
1568   }
1569 }
1570 
1571 static size_t write_bitmap(const CHeapBitMap* map, char* output, size_t offset) {
1572   size_t size_in_bytes = map->size_in_bytes();
1573   map->write_to((BitMap::bm_word_t*)(output + offset), size_in_bytes);
1574   return offset + size_in_bytes;
1575 }
1576 
1577 char* FileMapInfo::write_bitmap_region(const CHeapBitMap* ptrmap, ArchiveHeapInfo* heap_info,
1578                                        size_t &size_in_bytes) {
1579   size_in_bytes = ptrmap->size_in_bytes();
1580 
1581   if (heap_info->is_used()) {

1703   assert(WINDOWS_ONLY(false) NOT_WINDOWS(true), "Don't call on Windows");
1704   // Replace old mapping with new one that is writable.
1705   char *base = os::map_memory(_fd, _full_path, r->file_offset(),
1706                               addr, size, false /* !read_only */,
1707                               r->allow_exec());
1708   close();
1709   // These have to be errors because the shared region is now unmapped.
1710   if (base == nullptr) {
1711     log_error(cds)("Unable to remap shared readonly space (errno=%d).", errno);
1712     vm_exit(1);
1713   }
1714   if (base != addr) {
1715     log_error(cds)("Unable to remap shared readonly space (errno=%d).", errno);
1716     vm_exit(1);
1717   }
1718   r->set_read_only(false);
1719   return true;
1720 }
1721 
1722 // Memory map a region in the address space.
1723 static const char* shared_region_name[] = { "ReadWrite", "ReadOnly", "Bitmap", "Heap", "Code" };
1724 
1725 MapArchiveResult FileMapInfo::map_regions(int regions[], int num_regions, char* mapped_base_address, ReservedSpace rs) {
1726   DEBUG_ONLY(FileMapRegion* last_region = nullptr);
1727   intx addr_delta = mapped_base_address - header()->requested_base_address();
1728 
1729   // Make sure we don't attempt to use header()->mapped_base_address() unless
1730   // it's been successfully mapped.
1731   DEBUG_ONLY(header()->set_mapped_base_address((char*)(uintptr_t)0xdeadbeef);)
1732 
1733   for (int i = 0; i < num_regions; i++) {
1734     int idx = regions[i];
1735     MapArchiveResult result = map_region(idx, addr_delta, mapped_base_address, rs);
1736     if (result != MAP_ARCHIVE_SUCCESS) {
1737       return result;
1738     }
1739     FileMapRegion* r = region_at(idx);
1740     DEBUG_ONLY(if (last_region != nullptr) {
1741         // Ensure that the OS won't be able to allocate new memory spaces between any mapped
1742         // regions, or else it would mess up the simple comparison in MetaspaceObj::is_shared().
1743         assert(r->mapped_base() == last_region->mapped_end(), "must have no gaps");

1806     r->set_read_only(false); // Need to patch the pointers
1807   }
1808 
1809   if (MetaspaceShared::use_windows_memory_mapping() && rs.is_reserved()) {
1810     // This is the second time we try to map the archive(s). We have already created a ReservedSpace
1811     // that covers all the FileMapRegions to ensure all regions can be mapped. However, Windows
1812     // can't mmap into a ReservedSpace, so we just ::read() the data. We're going to patch all the
1813     // regions anyway, so there's no benefit for mmap anyway.
1814     if (!read_region(i, requested_addr, size, /* do_commit = */ true)) {
1815       log_info(cds)("Failed to read %s shared space into reserved space at " INTPTR_FORMAT,
1816                     shared_region_name[i], p2i(requested_addr));
1817       return MAP_ARCHIVE_OTHER_FAILURE; // oom or I/O error.
1818     } else {
1819       assert(r->mapped_base() != nullptr, "must be initialized");
1820       return MAP_ARCHIVE_SUCCESS;
1821     }
1822   } else {
1823     // Note that this may either be a "fresh" mapping into unreserved address
1824     // space (Windows, first mapping attempt), or a mapping into pre-reserved
1825     // space (Posix). See also comment in MetaspaceShared::map_archives().
1826     bool read_only = r->read_only() && !CDSConfig::is_dumping_final_static_archive();
1827     char* base = map_memory(_fd, _full_path, r->file_offset(),
1828                             requested_addr, size, read_only,
1829                             r->allow_exec(), mtClassShared);
1830     if (base != requested_addr) {
1831       log_info(cds)("Unable to map %s shared space at " INTPTR_FORMAT,
1832                     shared_region_name[i], p2i(requested_addr));
1833       _memory_mapping_failed = true;
1834       return MAP_ARCHIVE_MMAP_FAILURE;
1835     }
1836 
1837     if (VerifySharedSpaces && !r->check_region_crc(requested_addr)) {
1838       return MAP_ARCHIVE_OTHER_FAILURE;
1839     }
1840 
1841     r->set_mapped_from_file(true);
1842     r->set_mapped_base(requested_addr);
1843 
1844     return MAP_ARCHIVE_SUCCESS;
1845   }
1846 }
1847 
1848 // The return value is the location of the archive relocation bitmap.

1860     return nullptr;
1861   }
1862 
1863   if (VerifySharedSpaces && !r->check_region_crc(bitmap_base)) {
1864     log_error(cds)("relocation bitmap CRC error");
1865     if (!os::unmap_memory(bitmap_base, r->used_aligned())) {
1866       fatal("os::unmap_memory of relocation bitmap failed");
1867     }
1868     return nullptr;
1869   }
1870 
1871   r->set_mapped_from_file(true);
1872   r->set_mapped_base(bitmap_base);
1873   log_info(cds)("Mapped %s region #%d at base " INTPTR_FORMAT " top " INTPTR_FORMAT " (%s)",
1874                 is_static() ? "static " : "dynamic",
1875                 MetaspaceShared::bm, p2i(r->mapped_base()), p2i(r->mapped_end()),
1876                 shared_region_name[MetaspaceShared::bm]);
1877   return bitmap_base;
1878 }
1879 
1880 bool FileMapInfo::map_cached_code_region(ReservedSpace rs) {
1881   FileMapRegion* r = region_at(MetaspaceShared::cc);
1882   assert(r->used() > 0 && rs.size(), "must be");
1883 
1884   bool read_only = false, allow_exec = true;
1885   char* requested_base = rs.base();
1886   char* mapped_base = map_memory(_fd, _full_path, r->file_offset(),
1887                                  requested_base, r->used_aligned(), read_only, allow_exec, mtClassShared);
1888   if (mapped_base == nullptr) {
1889     log_info(cds)("failed to map cached code region");
1890     return false;
1891   } else {
1892     assert(mapped_base == requested_base, "must be");
1893     r->set_mapped_from_file(true);
1894     r->set_mapped_base(mapped_base);
1895     relocate_pointers_in_cached_code_region();
1896     log_info(cds)("Mapped static region #%d at base " INTPTR_FORMAT " top " INTPTR_FORMAT " (%s)",
1897                   MetaspaceShared::bm, p2i(r->mapped_base()), p2i(r->mapped_end()),
1898                   shared_region_name[MetaspaceShared::cc]);
1899     return true;
1900   }
1901 }
1902 
1903 class CachedCodeRelocator: public BitMapClosure {
1904   address _code_requested_base;
1905   address* _patch_base;
1906   intx _code_delta;
1907   intx _metadata_delta;
1908 
1909 public:
1910   CachedCodeRelocator(address code_requested_base, address code_mapped_base,
1911                       intx metadata_delta) {
1912     _code_requested_base = code_requested_base;
1913     _patch_base = (address*)code_mapped_base;
1914     _code_delta = code_mapped_base - code_requested_base;
1915     _metadata_delta = metadata_delta;
1916   }
1917   
1918   bool do_bit(size_t offset) {
1919     address* p = _patch_base + offset;
1920     address requested_ptr = *p;
1921     if (requested_ptr < _code_requested_base) {
1922       *p = requested_ptr + _metadata_delta;
1923     } else {
1924       *p = requested_ptr + _code_delta;
1925     }
1926     return true; // keep iterating
1927   }
1928 };
1929 
1930 void FileMapInfo::relocate_pointers_in_cached_code_region() {
1931   FileMapRegion* r = region_at(MetaspaceShared::cc);
1932   char* bitmap_base = map_bitmap_region();
1933 
1934   address core_regions_requested_base = (address)header()->requested_base_address();
1935   address core_regions_mapped_base = (address)header()->mapped_base_address();
1936   address cc_region_requested_base = core_regions_requested_base + r->mapping_offset();
1937   address cc_region_mapped_base = (address)r->mapped_base();
1938 
1939   size_t max_bits_for_core_regions = pointer_delta(mapped_end(), mapped_base(), // FIXME - renamed to core_regions_mapped_base(), etc
1940                                                    sizeof(address));
1941   size_t ptrmap_size_in_bits = header()->ptrmap_size_in_bits();
1942   if (ptrmap_size_in_bits <= max_bits_for_core_regions) {
1943     // No relocation inside the cached code region??
1944     return;
1945   }
1946 
1947   ptrmap_size_in_bits -= max_bits_for_core_regions;
1948   assert((max_bits_for_core_regions % 8) == 0, "must be aligned");
1949   bitmap_base += max_bits_for_core_regions / 8;
1950   BitMapView ptrmap((BitMap::bm_word_t*)bitmap_base, ptrmap_size_in_bits);
1951 
1952   log_debug(cds, reloc)("cached code bitmap @ " INTPTR_FORMAT " (" SIZE_FORMAT " bits)",
1953                         p2i(bitmap_base), ptrmap_size_in_bits);
1954 
1955   CachedCodeRelocator patcher(cc_region_requested_base, cc_region_mapped_base,
1956                               core_regions_mapped_base - core_regions_requested_base);
1957   ptrmap.iterate(&patcher);
1958 }
1959 
1960 // This is called when we cannot map the archive at the requested[ base address (usually 0x800000000).
1961 // We relocate all pointers in the 2 core regions (ro, rw).
1962 bool FileMapInfo::relocate_pointers_in_core_regions(intx addr_delta) {
1963   log_debug(cds, reloc)("runtime archive relocation start");
1964   char* bitmap_base = map_bitmap_region();
1965 
1966   if (bitmap_base == nullptr) {
1967     return false; // OOM, or CRC check failure
1968   } else {






1969     // Patch all pointers in the mapped region that are marked by ptrmap.
1970     address patch_base = (address)mapped_base();
1971     address patch_end  = (address)mapped_end();
1972 
1973     // Exclude the bits used for the code_cache region (if it exists)
1974     size_t max_bits_for_core_regions = pointer_delta(patch_end, patch_base, sizeof(address));
1975     size_t ptrmap_size_in_bits = MIN2(header()->ptrmap_size_in_bits(), max_bits_for_core_regions);
1976 
1977     // the current value of the pointers to be patched must be within this
1978     // range (i.e., must be between the requested base address and the address of the current archive).
1979     // Note: top archive may point to objects in the base archive, but not the other way around.
1980     address valid_old_base = (address)header()->requested_base_address();
1981     address valid_old_end  = valid_old_base + mapping_end_offset();
1982 
1983     // after patching, the pointers must point inside this range
1984     // (the requested location of the archive, as mapped at runtime).
1985     address valid_new_base = (address)header()->mapped_base_address();
1986     address valid_new_end  = (address)mapped_end();
1987 
1988     log_debug(cds, reloc)("mapped relocation bitmap @ " INTPTR_FORMAT " (" SIZE_FORMAT " bits)",
1989                           p2i(bitmap_base), ptrmap_size_in_bits);
1990     BitMapView ptrmap((BitMap::bm_word_t*)bitmap_base, ptrmap_size_in_bits);
1991 
1992     SharedDataRelocator patcher((address*)patch_base, (address*)patch_end, valid_old_base, valid_old_end,
1993                                 valid_new_base, valid_new_end, addr_delta);
1994     ptrmap.iterate(&patcher);
1995 
1996     // The MetaspaceShared::bm region will be unmapped in MetaspaceShared::initialize_shared_spaces().
1997 
1998     log_debug(cds, reloc)("runtime archive relocation done");
1999     return true;
2000   }
2001 }
2002 
2003 size_t FileMapInfo::read_bytes(void* buffer, size_t count) {
2004   assert(_file_open, "Archive file is not open");
2005   size_t n = ::read(_fd, buffer, (unsigned int)count);
2006   if (n != count) {
2007     // Close the file if there's a problem reading it.
2008     close();
2009     return 0;
2010   }
2011   _file_offset += count;

2052 
2053 void FileMapInfo::map_or_load_heap_region() {
2054   bool success = false;
2055 
2056   if (can_use_heap_region()) {
2057     if (ArchiveHeapLoader::can_map()) {
2058       success = map_heap_region();
2059     } else if (ArchiveHeapLoader::can_load()) {
2060       success = ArchiveHeapLoader::load_heap_region(this);
2061     } else {
2062       if (!UseCompressedOops && !ArchiveHeapLoader::can_map()) {
2063         // TODO - remove implicit knowledge of G1
2064         log_info(cds)("Cannot use CDS heap data. UseG1GC is required for -XX:-UseCompressedOops");
2065       } else {
2066         log_info(cds)("Cannot use CDS heap data. UseEpsilonGC, UseG1GC, UseSerialGC or UseParallelGC are required.");
2067       }
2068     }
2069   }
2070 
2071   if (!success) {
2072     CDSConfig::disable_loading_full_module_graph("archive heap loading failed");
2073   }
2074 }
2075 
2076 bool FileMapInfo::can_use_heap_region() {
2077   if (!has_heap_region()) {
2078     return false;
2079   }
2080   if (JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::has_early_class_hook_env()) {
2081     ShouldNotReachHere(); // CDS should have been disabled.
2082     // The archived objects are mapped at JVM start-up, but we don't know if
2083     // j.l.String or j.l.Class might be replaced by the ClassFileLoadHook,
2084     // which would make the archived String or mirror objects invalid. Let's be safe and not
2085     // use the archived objects. These 2 classes are loaded during the JVMTI "early" stage.
2086     //
2087     // If JvmtiExport::has_early_class_hook_env() is false, the classes of some objects
2088     // in the archived subgraphs may be replaced by the ClassFileLoadHook. But that's OK
2089     // because we won't install an archived object subgraph if the klass of any of the
2090     // referenced objects are replaced. See HeapShared::initialize_from_archived_subgraph().
2091   }
2092 

2364     // during the JVMTI "early" stage, so we can still use CDS if
2365     // JvmtiExport::has_early_class_hook_env() is false.
2366     log_info(cds)("CDS is disabled because early JVMTI ClassFileLoadHook is in use.");
2367     return false;
2368   }
2369 
2370   if (!open_for_read() || !init_from_file(_fd) || !validate_header()) {
2371     if (_is_static) {
2372       log_info(cds)("Initialize static archive failed.");
2373       return false;
2374     } else {
2375       log_info(cds)("Initialize dynamic archive failed.");
2376       if (AutoCreateSharedArchive) {
2377         CDSConfig::enable_dumping_dynamic_archive();
2378         ArchiveClassesAtExit = CDSConfig::dynamic_archive_path();
2379       }
2380       return false;
2381     }
2382   }
2383 
2384   if (header()->has_preloaded_classes()) {
2385     if (JvmtiExport::should_post_class_file_load_hook()) {
2386       log_info(cds)("CDS archive has preloaded classes. It cannot be used when JVMTI ClassFileLoadHook is in use.");
2387       return false;
2388     }
2389     if (JvmtiExport::has_early_vmstart_env()) {
2390       log_info(cds)("CDS archive has preloaded classes. It cannot be used when JVMTI early vm start is in use.");
2391       return false;
2392     }
2393   }
2394 
2395   return true;
2396 }
2397 
2398 // The 2 core spaces are RW->RO
2399 FileMapRegion* FileMapInfo::first_core_region() const {
2400   return region_at(MetaspaceShared::rw);
2401 }
2402 
2403 FileMapRegion* FileMapInfo::last_core_region() const {
2404   return region_at(MetaspaceShared::ro);
2405 }
2406 
2407 void FileMapInfo::print(outputStream* st) const {
2408   header()->print(st);
2409   if (!is_static()) {
2410     dynamic_header()->print(st);
2411   }
2412 }
2413 
2414 void FileMapHeader::set_as_offset(char* p, size_t *offset) {

2483   }
2484 
2485   if (_allow_archiving_with_java_agent) {
2486     log_warning(cds)("This archive was created with AllowArchivingWithJavaAgent. It should be used "
2487             "for testing purposes only and should not be used in a production environment");
2488   }
2489 
2490   log_info(cds)("Archive was created with UseCompressedOops = %d, UseCompressedClassPointers = %d",
2491                           compressed_oops(), compressed_class_pointers());
2492   if (compressed_oops() != UseCompressedOops || compressed_class_pointers() != UseCompressedClassPointers) {
2493     log_info(cds)("Unable to use shared archive.\nThe saved state of UseCompressedOops and UseCompressedClassPointers is "
2494                                "different from runtime, CDS will be disabled.");
2495     return false;
2496   }
2497 
2498   if (!_use_optimized_module_handling) {
2499     MetaspaceShared::disable_optimized_module_handling();
2500     log_info(cds)("optimized module handling: disabled because archive was created without optimized module handling");
2501   }
2502 
2503   if (is_static()) {
2504     // Only the static archive can contain the full module graph.
2505     if (!_has_full_module_graph) {
2506       CDSConfig::disable_loading_full_module_graph("archive was created without full module graph");
2507     }
2508 
2509     if (_has_archived_invokedynamic) {
2510       CDSConfig::set_is_loading_invokedynamic();
2511     }
2512   }
2513 
2514   return true;
2515 }
2516 
2517 bool FileMapInfo::validate_header() {
2518   if (!header()->validate()) {
2519     return false;
2520   }
2521   if (_is_static) {
2522     return true;
2523   } else {
2524     return DynamicArchive::validate(this);
2525   }
2526 }
2527 
2528 #if INCLUDE_JVMTI
2529 ClassPathEntry** FileMapInfo::_classpath_entries_for_jvmti = nullptr;
2530 
2531 ClassPathEntry* FileMapInfo::get_classpath_entry_for_jvmti(int i, TRAPS) {
< prev index next >