< prev index next >

src/hotspot/share/cds/filemap.cpp

Print this page

  42 #include "classfile/symbolTable.hpp"
  43 #include "classfile/systemDictionaryShared.hpp"
  44 #include "classfile/vmClasses.hpp"
  45 #include "classfile/vmSymbols.hpp"
  46 #include "jvm.h"
  47 #include "logging/log.hpp"
  48 #include "logging/logMessage.hpp"
  49 #include "logging/logStream.hpp"
  50 #include "memory/iterator.inline.hpp"
  51 #include "memory/metadataFactory.hpp"
  52 #include "memory/metaspaceClosure.hpp"
  53 #include "memory/oopFactory.hpp"
  54 #include "memory/universe.hpp"
  55 #include "nmt/memTracker.hpp"
  56 #include "oops/access.hpp"
  57 #include "oops/compressedOops.hpp"
  58 #include "oops/compressedOops.inline.hpp"
  59 #include "oops/compressedKlass.hpp"
  60 #include "oops/objArrayOop.hpp"
  61 #include "oops/oop.inline.hpp"

  62 #include "oops/typeArrayKlass.hpp"
  63 #include "prims/jvmtiExport.hpp"
  64 #include "runtime/arguments.hpp"
  65 #include "runtime/globals_extension.hpp"
  66 #include "runtime/java.hpp"
  67 #include "runtime/javaCalls.hpp"
  68 #include "runtime/mutexLocker.hpp"
  69 #include "runtime/os.hpp"
  70 #include "runtime/vm_version.hpp"
  71 #include "utilities/align.hpp"
  72 #include "utilities/bitMap.inline.hpp"
  73 #include "utilities/classpathStream.hpp"
  74 #include "utilities/defaultStream.hpp"
  75 #include "utilities/ostream.hpp"
  76 #if INCLUDE_G1GC
  77 #include "gc/g1/g1CollectedHeap.hpp"
  78 #include "gc/g1/g1HeapRegion.hpp"
  79 #endif
  80 
  81 # include <sys/stat.h>

 213   }
 214   _core_region_alignment = core_region_alignment;
 215   _obj_alignment = ObjectAlignmentInBytes;
 216   _compact_strings = CompactStrings;
 217   _compact_headers = UseCompactObjectHeaders;
 218   if (CDSConfig::is_dumping_heap()) {
 219     _narrow_oop_mode = CompressedOops::mode();
 220     _narrow_oop_base = CompressedOops::base();
 221     _narrow_oop_shift = CompressedOops::shift();
 222   }
 223   _compressed_oops = UseCompressedOops;
 224   _compressed_class_ptrs = UseCompressedClassPointers;
 225   if (UseCompressedClassPointers) {
 226 #ifdef _LP64
 227     _narrow_klass_pointer_bits = CompressedKlassPointers::narrow_klass_pointer_bits();
 228     _narrow_klass_shift = ArchiveBuilder::precomputed_narrow_klass_shift();
 229 #endif
 230   } else {
 231     _narrow_klass_pointer_bits = _narrow_klass_shift = -1;
 232   }





 233   _max_heap_size = MaxHeapSize;
 234   _use_optimized_module_handling = CDSConfig::is_using_optimized_module_handling();
 235   _has_aot_linked_classes = CDSConfig::is_dumping_aot_linked_classes();
 236   _has_full_module_graph = CDSConfig::is_dumping_full_module_graph();




 237 
 238   // The following fields are for sanity checks for whether this archive
 239   // will function correctly with this JVM and the bootclasspath it's
 240   // invoked with.
 241 
 242   // JVM version string ... changes on each build.
 243   get_header_version(_jvm_ident);
 244 
 245   _verify_local = BytecodeVerificationLocal;
 246   _verify_remote = BytecodeVerificationRemote;
 247   _has_platform_or_app_classes = AOTClassLocationConfig::dumptime()->has_platform_or_app_classes();
 248   _requested_base_address = (char*)SharedBaseAddress;
 249   _mapped_base_address = (char*)SharedBaseAddress;
 250   _allow_archiving_with_java_agent = AllowArchivingWithJavaAgent;
 251 }
 252 
 253 void FileMapHeader::copy_base_archive_name(const char* archive) {
 254   assert(base_archive_name_size() != 0, "_base_archive_name_size not set");
 255   assert(base_archive_name_offset() != 0, "_base_archive_name_offset not set");
 256   assert(header_size() > sizeof(*this), "_base_archive_name_size not included in header size?");

 291   st->print_cr("- jvm_ident:                      %s", _jvm_ident);
 292   st->print_cr("- class_location_config_offset:   0x%zx", _class_location_config_offset);
 293   st->print_cr("- verify_local:                   %d", _verify_local);
 294   st->print_cr("- verify_remote:                  %d", _verify_remote);
 295   st->print_cr("- has_platform_or_app_classes:    %d", _has_platform_or_app_classes);
 296   st->print_cr("- requested_base_address:         " INTPTR_FORMAT, p2i(_requested_base_address));
 297   st->print_cr("- mapped_base_address:            " INTPTR_FORMAT, p2i(_mapped_base_address));
 298   st->print_cr("- heap_root_segments.roots_count: %d" , _heap_root_segments.roots_count());
 299   st->print_cr("- heap_root_segments.base_offset: 0x%zx", _heap_root_segments.base_offset());
 300   st->print_cr("- heap_root_segments.count:       %zu", _heap_root_segments.count());
 301   st->print_cr("- heap_root_segments.max_size_elems: %d", _heap_root_segments.max_size_in_elems());
 302   st->print_cr("- heap_root_segments.max_size_bytes: %d", _heap_root_segments.max_size_in_bytes());
 303   st->print_cr("- _heap_oopmap_start_pos:         %zu", _heap_oopmap_start_pos);
 304   st->print_cr("- _heap_ptrmap_start_pos:         %zu", _heap_ptrmap_start_pos);
 305   st->print_cr("- _rw_ptrmap_start_pos:           %zu", _rw_ptrmap_start_pos);
 306   st->print_cr("- _ro_ptrmap_start_pos:           %zu", _ro_ptrmap_start_pos);
 307   st->print_cr("- allow_archiving_with_java_agent:%d", _allow_archiving_with_java_agent);
 308   st->print_cr("- use_optimized_module_handling:  %d", _use_optimized_module_handling);
 309   st->print_cr("- has_full_module_graph           %d", _has_full_module_graph);
 310   st->print_cr("- has_aot_linked_classes          %d", _has_aot_linked_classes);



 311 }
 312 
 313 bool FileMapInfo::validate_class_location() {
 314   assert(CDSConfig::is_using_archive(), "runtime only");
 315 
 316   AOTClassLocationConfig* config = header()->class_location_config();
 317   bool has_extra_module_paths = false;
 318   if (!config->validate(header()->has_aot_linked_classes(), &has_extra_module_paths)) {
 319     if (PrintSharedArchiveAndExit) {
 320       MetaspaceShared::set_archive_loading_failed();
 321       return true;
 322     } else {
 323       return false;
 324     }
 325   }
 326 
 327   if (header()->has_full_module_graph() && has_extra_module_paths) {
 328     CDSConfig::stop_using_optimized_module_handling();
 329     log_info(cds)("optimized module handling: disabled because extra module path(s) are specified");
 330   }

 894       assert((mapping_offset >> CompressedOops::shift()) << CompressedOops::shift() == mapping_offset, "must be");
 895     } else {
 896       mapping_offset = 0; // not used with !UseCompressedOops
 897     }
 898 #endif // INCLUDE_CDS_JAVA_HEAP
 899   } else {
 900     char* requested_SharedBaseAddress = (char*)MetaspaceShared::requested_base_address();
 901     requested_base = ArchiveBuilder::current()->to_requested(base);
 902     assert(requested_base >= requested_SharedBaseAddress, "must be");
 903     mapping_offset = requested_base - requested_SharedBaseAddress;
 904   }
 905 
 906   r->set_file_offset(_file_offset);
 907   int crc = ClassLoader::crc32(0, base, (jint)size);
 908   if (size > 0) {
 909     log_info(cds)("Shared file region (%s) %d: %8zu"
 910                    " bytes, addr " INTPTR_FORMAT " file offset 0x%08" PRIxPTR
 911                    " crc 0x%08x",
 912                    region_name(region), region, size, p2i(requested_base), _file_offset, crc);
 913   } else {
 914      log_info(cds)("Shared file region (%s) %d: %8zu"
 915                    " bytes", region_name(region), region, size);
 916   }
 917 
 918   r->init(region, mapping_offset, size, read_only, allow_exec, crc);
 919 
 920   if (base != nullptr) {
 921     write_bytes_aligned(base, size);
 922   }
 923 }
 924 
 925 static size_t write_bitmap(const CHeapBitMap* map, char* output, size_t offset) {
 926   size_t size_in_bytes = map->size_in_bytes();
 927   map->write_to((BitMap::bm_word_t*)(output + offset), size_in_bytes);
 928   return offset + size_in_bytes;
 929 }
 930 
 931 // The sorting code groups the objects with non-null oop/ptrs together.
 932 // Relevant bitmaps then have lots of leading and trailing zeros, which
 933 // we do not have to store.
 934 size_t FileMapInfo::remove_bitmap_zeros(CHeapBitMap* map) {
 935   BitMap::idx_t first_set = map->find_first_set_bit(0);
 936   BitMap::idx_t last_set  = map->find_last_set_bit(0);
 937   size_t old_size = map->size();
 938 
 939   // Slice and resize bitmap
 940   map->truncate(first_set, last_set + 1);
 941 
 942   assert(map->at(0), "First bit should be set");
 943   assert(map->at(map->size() - 1), "Last bit should be set");
 944   assert(map->size() <= old_size, "sanity");
 945 
 946   return first_set;
 947 }
 948 
 949 char* FileMapInfo::write_bitmap_region(CHeapBitMap* rw_ptrmap, CHeapBitMap* ro_ptrmap, ArchiveHeapInfo* heap_info,


 950                                        size_t &size_in_bytes) {
 951   size_t removed_rw_leading_zeros = remove_bitmap_zeros(rw_ptrmap);
 952   size_t removed_ro_leading_zeros = remove_bitmap_zeros(ro_ptrmap);
 953   header()->set_rw_ptrmap_start_pos(removed_rw_leading_zeros);
 954   header()->set_ro_ptrmap_start_pos(removed_ro_leading_zeros);
 955   size_in_bytes = rw_ptrmap->size_in_bytes() + ro_ptrmap->size_in_bytes();
 956 
 957   if (heap_info->is_used()) {
 958     // Remove leading and trailing zeros
 959     size_t removed_oop_leading_zeros = remove_bitmap_zeros(heap_info->oopmap());
 960     size_t removed_ptr_leading_zeros = remove_bitmap_zeros(heap_info->ptrmap());
 961     header()->set_heap_oopmap_start_pos(removed_oop_leading_zeros);
 962     header()->set_heap_ptrmap_start_pos(removed_ptr_leading_zeros);
 963 
 964     size_in_bytes += heap_info->oopmap()->size_in_bytes();
 965     size_in_bytes += heap_info->ptrmap()->size_in_bytes();
 966   }
 967 
 968   // The bitmap region contains up to 4 parts:
 969   // rw_ptrmap:           metaspace pointers inside the read-write region
 970   // ro_ptrmap:           metaspace pointers inside the read-only region
 971   // heap_info->oopmap(): Java oop pointers in the heap region
 972   // heap_info->ptrmap(): metaspace pointers in the heap region
 973   char* buffer = NEW_C_HEAP_ARRAY(char, size_in_bytes, mtClassShared);
 974   size_t written = 0;
 975 
 976   region_at(MetaspaceShared::rw)->init_ptrmap(0, rw_ptrmap->size());
 977   written = write_bitmap(rw_ptrmap, buffer, written);
 978 
 979   region_at(MetaspaceShared::ro)->init_ptrmap(written, ro_ptrmap->size());
 980   written = write_bitmap(ro_ptrmap, buffer, written);
 981 



 982   if (heap_info->is_used()) {
 983     FileMapRegion* r = region_at(MetaspaceShared::hp);
 984 
 985     r->init_oopmap(written, heap_info->oopmap()->size());
 986     written = write_bitmap(heap_info->oopmap(), buffer, written);
 987 
 988     r->init_ptrmap(written, heap_info->ptrmap()->size());
 989     written = write_bitmap(heap_info->ptrmap(), buffer, written);
 990   }
 991 
 992   write_region(MetaspaceShared::bm, (char*)buffer, size_in_bytes, /*read_only=*/true, /*allow_exec=*/false);
 993   return buffer;
 994 }
 995 
 996 size_t FileMapInfo::write_heap_region(ArchiveHeapInfo* heap_info) {
 997   char* buffer_start = heap_info->buffer_start();
 998   size_t buffer_size = heap_info->buffer_byte_size();
 999   write_region(MetaspaceShared::hp, buffer_start, buffer_size, false, false);
1000   header()->set_heap_root_segments(heap_info->heap_root_segments());
1001   return buffer_size;

1200   } else if (addr_delta != 0) {
1201     r->set_read_only(false); // Need to patch the pointers
1202   }
1203 
1204   if (MetaspaceShared::use_windows_memory_mapping() && rs.is_reserved()) {
1205     // This is the second time we try to map the archive(s). We have already created a ReservedSpace
1206     // that covers all the FileMapRegions to ensure all regions can be mapped. However, Windows
1207     // can't mmap into a ReservedSpace, so we just ::read() the data. We're going to patch all the
1208     // regions anyway, so there's no benefit for mmap anyway.
1209     if (!read_region(i, requested_addr, size, /* do_commit = */ true)) {
1210       log_info(cds)("Failed to read %s shared space into reserved space at " INTPTR_FORMAT,
1211                     shared_region_name[i], p2i(requested_addr));
1212       return MAP_ARCHIVE_OTHER_FAILURE; // oom or I/O error.
1213     } else {
1214       assert(r->mapped_base() != nullptr, "must be initialized");
1215     }
1216   } else {
1217     // Note that this may either be a "fresh" mapping into unreserved address
1218     // space (Windows, first mapping attempt), or a mapping into pre-reserved
1219     // space (Posix). See also comment in MetaspaceShared::map_archives().

1220     char* base = map_memory(_fd, _full_path, r->file_offset(),
1221                             requested_addr, size, r->read_only(),
1222                             r->allow_exec(), mtClassShared);
1223     if (base != requested_addr) {
1224       log_info(cds)("Unable to map %s shared space at " INTPTR_FORMAT,
1225                     shared_region_name[i], p2i(requested_addr));
1226       _memory_mapping_failed = true;
1227       return MAP_ARCHIVE_MMAP_FAILURE;
1228     }
1229 
1230     if (VerifySharedSpaces && !r->check_region_crc(requested_addr)) {
1231       return MAP_ARCHIVE_OTHER_FAILURE;
1232     }
1233 
1234     r->set_mapped_from_file(true);
1235     r->set_mapped_base(requested_addr);
1236   }
1237 
1238   if (rs.is_reserved()) {
1239     char* mapped_base = r->mapped_base();
1240     assert(rs.base() <= mapped_base && mapped_base + size <= rs.end(),
1241            PTR_FORMAT " <= " PTR_FORMAT " < " PTR_FORMAT " <= " PTR_FORMAT,

1289     if (!read_region(MetaspaceShared::ac, requested_base, r->used_aligned(), /* do_commit = */ true)) {
1290       log_info(cds)("Failed to read aot code shared space into reserved space at " INTPTR_FORMAT,
1291                     p2i(requested_base));
1292       return false;
1293     }
1294     mapped_base = requested_base;
1295   } else {
1296     // We do not execute in-place in the AOT code region.
1297     // AOT code is copied to the CodeCache for execution.
1298     bool read_only = false, allow_exec = false;
1299     mapped_base = map_memory(_fd, _full_path, r->file_offset(),
1300                              requested_base, r->used_aligned(), read_only, allow_exec, mtClassShared);
1301   }
1302   if (mapped_base == nullptr) {
1303     log_info(cds)("failed to map aot code region");
1304     return false;
1305   } else {
1306     assert(mapped_base == requested_base, "must be");
1307     r->set_mapped_from_file(true);
1308     r->set_mapped_base(mapped_base);

1309     log_info(cds)("Mapped static  region #%d at base " INTPTR_FORMAT " top " INTPTR_FORMAT " (%s)",
1310                   MetaspaceShared::ac, p2i(r->mapped_base()), p2i(r->mapped_end()),
1311                   shared_region_name[MetaspaceShared::ac]);
1312     return true;
1313   }
1314 }
1315 

















































1316 class SharedDataRelocationTask : public ArchiveWorkerTask {
1317 private:
1318   BitMapView* const _rw_bm;
1319   BitMapView* const _ro_bm;
1320   SharedDataRelocator* const _rw_reloc;
1321   SharedDataRelocator* const _ro_reloc;
1322 
1323 public:
1324   SharedDataRelocationTask(BitMapView* rw_bm, BitMapView* ro_bm, SharedDataRelocator* rw_reloc, SharedDataRelocator* ro_reloc) :
1325                            ArchiveWorkerTask("Shared Data Relocation"),
1326                            _rw_bm(rw_bm), _ro_bm(ro_bm), _rw_reloc(rw_reloc), _ro_reloc(ro_reloc) {}
1327 
1328   void work(int chunk, int max_chunks) override {
1329     work_on(chunk, max_chunks, _rw_bm, _rw_reloc);
1330     work_on(chunk, max_chunks, _ro_bm, _ro_reloc);
1331   }
1332 
1333   void work_on(int chunk, int max_chunks, BitMapView* bm, SharedDataRelocator* reloc) {
1334     BitMap::idx_t size  = bm->size();
1335     BitMap::idx_t start = MIN2(size, size * chunk / max_chunks);

1445 }
1446 
1447 void FileMapInfo::map_or_load_heap_region() {
1448   bool success = false;
1449 
1450   if (can_use_heap_region()) {
1451     if (ArchiveHeapLoader::can_map()) {
1452       success = map_heap_region();
1453     } else if (ArchiveHeapLoader::can_load()) {
1454       success = ArchiveHeapLoader::load_heap_region(this);
1455     } else {
1456       if (!UseCompressedOops && !ArchiveHeapLoader::can_map()) {
1457         log_info(cds)("Cannot use CDS heap data. Selected GC not compatible -XX:-UseCompressedOops");
1458       } else {
1459         log_info(cds)("Cannot use CDS heap data. UseEpsilonGC, UseG1GC, UseSerialGC, UseParallelGC, or UseShenandoahGC are required.");
1460       }
1461     }
1462   }
1463 
1464   if (!success) {
1465     if (CDSConfig::is_using_aot_linked_classes()) {
1466       // It's too late to recover -- we have already committed to use the archived metaspace objects, but
1467       // the archived heap objects cannot be loaded, so we don't have the archived FMG to guarantee that
1468       // all AOT-linked classes are visible.
1469       //
1470       // We get here because the heap is too small. The app will fail anyway. So let's quit.
1471       MetaspaceShared::unrecoverable_loading_error("CDS archive has aot-linked classes but the archived "
1472                                                    "heap objects cannot be loaded. Try increasing your heap size.");
1473     }
1474     CDSConfig::stop_using_full_module_graph("archive heap loading failed");
1475   }
1476 }
1477 
1478 bool FileMapInfo::can_use_heap_region() {
1479   if (!has_heap_region()) {
1480     return false;
1481   }
1482   if (JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::has_early_class_hook_env()) {
1483     ShouldNotReachHere(); // CDS should have been disabled.
1484     // The archived objects are mapped at JVM start-up, but we don't know if
1485     // j.l.String or j.l.Class might be replaced by the ClassFileLoadHook,

1823       return false;
1824     }
1825   }
1826 
1827   return true;
1828 }
1829 
1830 bool FileMapInfo::validate_aot_class_linking() {
1831   // These checks need to be done after FileMapInfo::initialize(), which gets called before Universe::heap()
1832   // is available.
1833   if (header()->has_aot_linked_classes()) {
1834     CDSConfig::set_has_aot_linked_classes(true);
1835     if (JvmtiExport::should_post_class_file_load_hook()) {
1836       log_error(cds)("CDS archive has aot-linked classes. It cannot be used when JVMTI ClassFileLoadHook is in use.");
1837       return false;
1838     }
1839     if (JvmtiExport::has_early_vmstart_env()) {
1840       log_error(cds)("CDS archive has aot-linked classes. It cannot be used when JVMTI early vm start is in use.");
1841       return false;
1842     }
1843     if (!CDSConfig::is_using_full_module_graph()) {
1844       log_error(cds)("CDS archive has aot-linked classes. It cannot be used when archived full module graph is not used.");
1845       return false;
1846     }
1847 
1848     const char* prop = Arguments::get_property("java.security.manager");
1849     if (prop != nullptr && strcmp(prop, "disallow") != 0) {
1850       log_error(cds)("CDS archive has aot-linked classes. It cannot be used with -Djava.security.manager=%s.", prop);
1851       return false;
1852     }
1853 






1854 #if INCLUDE_JVMTI
1855     if (Arguments::has_jdwp_agent()) {
1856       log_error(cds)("CDS archive has aot-linked classes. It cannot be used with JDWP agent");
1857       return false;
1858     }
1859 #endif
1860   }
1861 
1862   return true;
1863 }
1864 
1865 // The 2 core spaces are RW->RO
1866 FileMapRegion* FileMapInfo::first_core_region() const {
1867   return region_at(MetaspaceShared::rw);
1868 }
1869 
1870 FileMapRegion* FileMapInfo::last_core_region() const {
1871   return region_at(MetaspaceShared::ro);
1872 }
1873 

1890   int crc = ClassLoader::crc32(0, buf, (jint)sz);
1891   return crc;
1892 }
1893 
1894 // This function should only be called during run time with UseSharedSpaces enabled.
1895 bool FileMapHeader::validate() {
1896   const char* file_type = CDSConfig::type_of_archive_being_loaded();
1897   if (_obj_alignment != ObjectAlignmentInBytes) {
1898     log_info(cds)("The %s's ObjectAlignmentInBytes of %d"
1899                   " does not equal the current ObjectAlignmentInBytes of %d.",
1900                   file_type, _obj_alignment, ObjectAlignmentInBytes);
1901     return false;
1902   }
1903   if (_compact_strings != CompactStrings) {
1904     log_info(cds)("The %s's CompactStrings setting (%s)"
1905                   " does not equal the current CompactStrings setting (%s).", file_type,
1906                   _compact_strings ? "enabled" : "disabled",
1907                   CompactStrings   ? "enabled" : "disabled");
1908     return false;
1909   }




































1910 
1911   // This must be done after header validation because it might change the
1912   // header data
1913   const char* prop = Arguments::get_property("java.system.class.loader");
1914   if (prop != nullptr) {
1915     if (has_aot_linked_classes()) {
1916       log_error(cds)("CDS archive has aot-linked classes. It cannot be used when the "
1917                      "java.system.class.loader property is specified.");
1918       return false;
1919     }
1920     log_warning(cds)("Archived non-system classes are disabled because the "
1921             "java.system.class.loader property is specified (value = \"%s\"). "
1922             "To use archived non-system classes, this property must not be set", prop);
1923     _has_platform_or_app_classes = false;
1924   }
1925 
1926 
1927   if (!_verify_local && BytecodeVerificationLocal) {
1928     //  we cannot load boot classes, so there's no point of using the CDS archive
1929     log_info(cds)("The %s's BytecodeVerificationLocal setting (%s)"

1969   }
1970 
1971   if (compact_headers() != UseCompactObjectHeaders) {
1972     log_warning(cds)("Unable to use %s.\nThe %s's UseCompactObjectHeaders setting (%s)"
1973                      " does not equal the current UseCompactObjectHeaders setting (%s).", file_type, file_type,
1974                      _compact_headers          ? "enabled" : "disabled",
1975                      UseCompactObjectHeaders   ? "enabled" : "disabled");
1976     return false;
1977   }
1978 
1979   if (!_use_optimized_module_handling && !CDSConfig::is_dumping_final_static_archive()) {
1980     CDSConfig::stop_using_optimized_module_handling();
1981     log_info(cds)("optimized module handling: disabled because archive was created without optimized module handling");
1982   }
1983 
1984   if (is_static()) {
1985     // Only the static archive can contain the full module graph.
1986     if (!_has_full_module_graph) {
1987       CDSConfig::stop_using_full_module_graph("archive was created without full module graph");
1988     }







1989   }
1990 
1991   return true;
1992 }
1993 
1994 bool FileMapInfo::validate_header() {
1995   if (!header()->validate()) {
1996     return false;
1997   }
1998   if (_is_static) {
1999     return true;
2000   } else {
2001     return DynamicArchive::validate(this);
2002   }
2003 }
2004 
2005 #if INCLUDE_JVMTI
2006 ClassPathEntry** FileMapInfo::_classpath_entries_for_jvmti = nullptr;
2007 
2008 ClassPathEntry* FileMapInfo::get_classpath_entry_for_jvmti(int i, TRAPS) {

  42 #include "classfile/symbolTable.hpp"
  43 #include "classfile/systemDictionaryShared.hpp"
  44 #include "classfile/vmClasses.hpp"
  45 #include "classfile/vmSymbols.hpp"
  46 #include "jvm.h"
  47 #include "logging/log.hpp"
  48 #include "logging/logMessage.hpp"
  49 #include "logging/logStream.hpp"
  50 #include "memory/iterator.inline.hpp"
  51 #include "memory/metadataFactory.hpp"
  52 #include "memory/metaspaceClosure.hpp"
  53 #include "memory/oopFactory.hpp"
  54 #include "memory/universe.hpp"
  55 #include "nmt/memTracker.hpp"
  56 #include "oops/access.hpp"
  57 #include "oops/compressedOops.hpp"
  58 #include "oops/compressedOops.inline.hpp"
  59 #include "oops/compressedKlass.hpp"
  60 #include "oops/objArrayOop.hpp"
  61 #include "oops/oop.inline.hpp"
  62 #include "oops/trainingData.hpp"
  63 #include "oops/typeArrayKlass.hpp"
  64 #include "prims/jvmtiExport.hpp"
  65 #include "runtime/arguments.hpp"
  66 #include "runtime/globals_extension.hpp"
  67 #include "runtime/java.hpp"
  68 #include "runtime/javaCalls.hpp"
  69 #include "runtime/mutexLocker.hpp"
  70 #include "runtime/os.hpp"
  71 #include "runtime/vm_version.hpp"
  72 #include "utilities/align.hpp"
  73 #include "utilities/bitMap.inline.hpp"
  74 #include "utilities/classpathStream.hpp"
  75 #include "utilities/defaultStream.hpp"
  76 #include "utilities/ostream.hpp"
  77 #if INCLUDE_G1GC
  78 #include "gc/g1/g1CollectedHeap.hpp"
  79 #include "gc/g1/g1HeapRegion.hpp"
  80 #endif
  81 
  82 # include <sys/stat.h>

 214   }
 215   _core_region_alignment = core_region_alignment;
 216   _obj_alignment = ObjectAlignmentInBytes;
 217   _compact_strings = CompactStrings;
 218   _compact_headers = UseCompactObjectHeaders;
 219   if (CDSConfig::is_dumping_heap()) {
 220     _narrow_oop_mode = CompressedOops::mode();
 221     _narrow_oop_base = CompressedOops::base();
 222     _narrow_oop_shift = CompressedOops::shift();
 223   }
 224   _compressed_oops = UseCompressedOops;
 225   _compressed_class_ptrs = UseCompressedClassPointers;
 226   if (UseCompressedClassPointers) {
 227 #ifdef _LP64
 228     _narrow_klass_pointer_bits = CompressedKlassPointers::narrow_klass_pointer_bits();
 229     _narrow_klass_shift = ArchiveBuilder::precomputed_narrow_klass_shift();
 230 #endif
 231   } else {
 232     _narrow_klass_pointer_bits = _narrow_klass_shift = -1;
 233   }
 234   _type_profile_level = TypeProfileLevel;
 235   _type_profile_width = TypeProfileWidth;
 236   _bci_profile_width = BciProfileWidth;
 237   _profile_traps = ProfileTraps;
 238   _spec_trap_limit_extra_entries = SpecTrapLimitExtraEntries;
 239   _max_heap_size = MaxHeapSize;
 240   _use_optimized_module_handling = CDSConfig::is_using_optimized_module_handling();
 241   _has_aot_linked_classes = CDSConfig::is_dumping_aot_linked_classes();
 242   _has_full_module_graph = CDSConfig::is_dumping_full_module_graph();
 243   _has_archived_packages = CDSConfig::is_dumping_packages();
 244   _has_archived_protection_domains = CDSConfig::is_dumping_protection_domains();
 245   _gc_kind = (int)Universe::heap()->kind();
 246   jio_snprintf(_gc_name, sizeof(_gc_name), Universe::heap()->name());
 247 
 248   // The following fields are for sanity checks for whether this archive
 249   // will function correctly with this JVM and the bootclasspath it's
 250   // invoked with.
 251 
 252   // JVM version string ... changes on each build.
 253   get_header_version(_jvm_ident);
 254 
 255   _verify_local = BytecodeVerificationLocal;
 256   _verify_remote = BytecodeVerificationRemote;
 257   _has_platform_or_app_classes = AOTClassLocationConfig::dumptime()->has_platform_or_app_classes();
 258   _requested_base_address = (char*)SharedBaseAddress;
 259   _mapped_base_address = (char*)SharedBaseAddress;
 260   _allow_archiving_with_java_agent = AllowArchivingWithJavaAgent;
 261 }
 262 
 263 void FileMapHeader::copy_base_archive_name(const char* archive) {
 264   assert(base_archive_name_size() != 0, "_base_archive_name_size not set");
 265   assert(base_archive_name_offset() != 0, "_base_archive_name_offset not set");
 266   assert(header_size() > sizeof(*this), "_base_archive_name_size not included in header size?");

 301   st->print_cr("- jvm_ident:                      %s", _jvm_ident);
 302   st->print_cr("- class_location_config_offset:   0x%zx", _class_location_config_offset);
 303   st->print_cr("- verify_local:                   %d", _verify_local);
 304   st->print_cr("- verify_remote:                  %d", _verify_remote);
 305   st->print_cr("- has_platform_or_app_classes:    %d", _has_platform_or_app_classes);
 306   st->print_cr("- requested_base_address:         " INTPTR_FORMAT, p2i(_requested_base_address));
 307   st->print_cr("- mapped_base_address:            " INTPTR_FORMAT, p2i(_mapped_base_address));
 308   st->print_cr("- heap_root_segments.roots_count: %d" , _heap_root_segments.roots_count());
 309   st->print_cr("- heap_root_segments.base_offset: 0x%zx", _heap_root_segments.base_offset());
 310   st->print_cr("- heap_root_segments.count:       %zu", _heap_root_segments.count());
 311   st->print_cr("- heap_root_segments.max_size_elems: %d", _heap_root_segments.max_size_in_elems());
 312   st->print_cr("- heap_root_segments.max_size_bytes: %d", _heap_root_segments.max_size_in_bytes());
 313   st->print_cr("- _heap_oopmap_start_pos:         %zu", _heap_oopmap_start_pos);
 314   st->print_cr("- _heap_ptrmap_start_pos:         %zu", _heap_ptrmap_start_pos);
 315   st->print_cr("- _rw_ptrmap_start_pos:           %zu", _rw_ptrmap_start_pos);
 316   st->print_cr("- _ro_ptrmap_start_pos:           %zu", _ro_ptrmap_start_pos);
 317   st->print_cr("- allow_archiving_with_java_agent:%d", _allow_archiving_with_java_agent);
 318   st->print_cr("- use_optimized_module_handling:  %d", _use_optimized_module_handling);
 319   st->print_cr("- has_full_module_graph           %d", _has_full_module_graph);
 320   st->print_cr("- has_aot_linked_classes          %d", _has_aot_linked_classes);
 321   st->print_cr("- has_archived_packages           %d", _has_archived_packages);
 322   st->print_cr("- has_archived_protection_domains %d", _has_archived_protection_domains);
 323   st->print_cr("- ptrmap_size_in_bits:            %zu", _ptrmap_size_in_bits);
 324 }
 325 
 326 bool FileMapInfo::validate_class_location() {
 327   assert(CDSConfig::is_using_archive(), "runtime only");
 328 
 329   AOTClassLocationConfig* config = header()->class_location_config();
 330   bool has_extra_module_paths = false;
 331   if (!config->validate(header()->has_aot_linked_classes(), &has_extra_module_paths)) {
 332     if (PrintSharedArchiveAndExit) {
 333       MetaspaceShared::set_archive_loading_failed();
 334       return true;
 335     } else {
 336       return false;
 337     }
 338   }
 339 
 340   if (header()->has_full_module_graph() && has_extra_module_paths) {
 341     CDSConfig::stop_using_optimized_module_handling();
 342     log_info(cds)("optimized module handling: disabled because extra module path(s) are specified");
 343   }

 907       assert((mapping_offset >> CompressedOops::shift()) << CompressedOops::shift() == mapping_offset, "must be");
 908     } else {
 909       mapping_offset = 0; // not used with !UseCompressedOops
 910     }
 911 #endif // INCLUDE_CDS_JAVA_HEAP
 912   } else {
 913     char* requested_SharedBaseAddress = (char*)MetaspaceShared::requested_base_address();
 914     requested_base = ArchiveBuilder::current()->to_requested(base);
 915     assert(requested_base >= requested_SharedBaseAddress, "must be");
 916     mapping_offset = requested_base - requested_SharedBaseAddress;
 917   }
 918 
 919   r->set_file_offset(_file_offset);
 920   int crc = ClassLoader::crc32(0, base, (jint)size);
 921   if (size > 0) {
 922     log_info(cds)("Shared file region (%s) %d: %8zu"
 923                    " bytes, addr " INTPTR_FORMAT " file offset 0x%08" PRIxPTR
 924                    " crc 0x%08x",
 925                    region_name(region), region, size, p2i(requested_base), _file_offset, crc);
 926   } else {
 927     log_info(cds)("Shared file region (%s) %d: %8zu"
 928                    " bytes", region_name(region), region, size);
 929   }
 930 
 931   r->init(region, mapping_offset, size, read_only, allow_exec, crc);
 932 
 933   if (base != nullptr) {
 934     write_bytes_aligned(base, size);
 935   }
 936 }
 937 
 938 static size_t write_bitmap(const CHeapBitMap* map, char* output, size_t offset) {
 939   size_t size_in_bytes = map->size_in_bytes();
 940   map->write_to((BitMap::bm_word_t*)(output + offset), size_in_bytes);
 941   return offset + size_in_bytes;
 942 }
 943 
 944 // The sorting code groups the objects with non-null oop/ptrs together.
 945 // Relevant bitmaps then have lots of leading and trailing zeros, which
 946 // we do not have to store.
 947 size_t FileMapInfo::remove_bitmap_zeros(CHeapBitMap* map) {
 948   BitMap::idx_t first_set = map->find_first_set_bit(0);
 949   BitMap::idx_t last_set  = map->find_last_set_bit(0);
 950   size_t old_size = map->size();
 951 
 952   // Slice and resize bitmap
 953   map->truncate(first_set, last_set + 1);
 954 
 955   assert(map->at(0), "First bit should be set");
 956   assert(map->at(map->size() - 1), "Last bit should be set");
 957   assert(map->size() <= old_size, "sanity");
 958 
 959   return first_set;
 960 }
 961 
 962 char* FileMapInfo::write_bitmap_region(CHeapBitMap* rw_ptrmap, CHeapBitMap* ro_ptrmap,
 963                                        CHeapBitMap* ac_ptrmap,
 964                                        ArchiveHeapInfo* heap_info,
 965                                        size_t &size_in_bytes) {
 966   size_t removed_rw_leading_zeros = remove_bitmap_zeros(rw_ptrmap);
 967   size_t removed_ro_leading_zeros = remove_bitmap_zeros(ro_ptrmap);
 968   header()->set_rw_ptrmap_start_pos(removed_rw_leading_zeros);
 969   header()->set_ro_ptrmap_start_pos(removed_ro_leading_zeros);
 970   size_in_bytes = rw_ptrmap->size_in_bytes() + ro_ptrmap->size_in_bytes() + ac_ptrmap->size_in_bytes();
 971 
 972   if (heap_info->is_used()) {
 973     // Remove leading and trailing zeros
 974     size_t removed_oop_leading_zeros = remove_bitmap_zeros(heap_info->oopmap());
 975     size_t removed_ptr_leading_zeros = remove_bitmap_zeros(heap_info->ptrmap());
 976     header()->set_heap_oopmap_start_pos(removed_oop_leading_zeros);
 977     header()->set_heap_ptrmap_start_pos(removed_ptr_leading_zeros);
 978 
 979     size_in_bytes += heap_info->oopmap()->size_in_bytes();
 980     size_in_bytes += heap_info->ptrmap()->size_in_bytes();
 981   }
 982 
 983   // The bitmap region contains up to 4 parts:
 984   // rw_ptrmap:           metaspace pointers inside the read-write region
 985   // ro_ptrmap:           metaspace pointers inside the read-only region
 986   // heap_info->oopmap(): Java oop pointers in the heap region
 987   // heap_info->ptrmap(): metaspace pointers in the heap region
 988   char* buffer = NEW_C_HEAP_ARRAY(char, size_in_bytes, mtClassShared);
 989   size_t written = 0;
 990 
 991   region_at(MetaspaceShared::rw)->init_ptrmap(0, rw_ptrmap->size());
 992   written = write_bitmap(rw_ptrmap, buffer, written);
 993 
 994   region_at(MetaspaceShared::ro)->init_ptrmap(written, ro_ptrmap->size());
 995   written = write_bitmap(ro_ptrmap, buffer, written);
 996 
 997   region_at(MetaspaceShared::ac)->init_ptrmap(written, ac_ptrmap->size());
 998   written = write_bitmap(ac_ptrmap, buffer, written);
 999 
1000   if (heap_info->is_used()) {
1001     FileMapRegion* r = region_at(MetaspaceShared::hp);
1002 
1003     r->init_oopmap(written, heap_info->oopmap()->size());
1004     written = write_bitmap(heap_info->oopmap(), buffer, written);
1005 
1006     r->init_ptrmap(written, heap_info->ptrmap()->size());
1007     written = write_bitmap(heap_info->ptrmap(), buffer, written);
1008   }
1009 
1010   write_region(MetaspaceShared::bm, (char*)buffer, size_in_bytes, /*read_only=*/true, /*allow_exec=*/false);
1011   return buffer;
1012 }
1013 
1014 size_t FileMapInfo::write_heap_region(ArchiveHeapInfo* heap_info) {
1015   char* buffer_start = heap_info->buffer_start();
1016   size_t buffer_size = heap_info->buffer_byte_size();
1017   write_region(MetaspaceShared::hp, buffer_start, buffer_size, false, false);
1018   header()->set_heap_root_segments(heap_info->heap_root_segments());
1019   return buffer_size;

1218   } else if (addr_delta != 0) {
1219     r->set_read_only(false); // Need to patch the pointers
1220   }
1221 
1222   if (MetaspaceShared::use_windows_memory_mapping() && rs.is_reserved()) {
1223     // This is the second time we try to map the archive(s). We have already created a ReservedSpace
1224     // that covers all the FileMapRegions to ensure all regions can be mapped. However, Windows
1225     // can't mmap into a ReservedSpace, so we just ::read() the data. We're going to patch all the
1226     // regions anyway, so there's no benefit for mmap anyway.
1227     if (!read_region(i, requested_addr, size, /* do_commit = */ true)) {
1228       log_info(cds)("Failed to read %s shared space into reserved space at " INTPTR_FORMAT,
1229                     shared_region_name[i], p2i(requested_addr));
1230       return MAP_ARCHIVE_OTHER_FAILURE; // oom or I/O error.
1231     } else {
1232       assert(r->mapped_base() != nullptr, "must be initialized");
1233     }
1234   } else {
1235     // Note that this may either be a "fresh" mapping into unreserved address
1236     // space (Windows, first mapping attempt), or a mapping into pre-reserved
1237     // space (Posix). See also comment in MetaspaceShared::map_archives().
1238     bool read_only = r->read_only() && !CDSConfig::is_dumping_final_static_archive();
1239     char* base = map_memory(_fd, _full_path, r->file_offset(),
1240                             requested_addr, size, read_only,
1241                             r->allow_exec(), mtClassShared);
1242     if (base != requested_addr) {
1243       log_info(cds)("Unable to map %s shared space at " INTPTR_FORMAT,
1244                     shared_region_name[i], p2i(requested_addr));
1245       _memory_mapping_failed = true;
1246       return MAP_ARCHIVE_MMAP_FAILURE;
1247     }
1248 
1249     if (VerifySharedSpaces && !r->check_region_crc(requested_addr)) {
1250       return MAP_ARCHIVE_OTHER_FAILURE;
1251     }
1252 
1253     r->set_mapped_from_file(true);
1254     r->set_mapped_base(requested_addr);
1255   }
1256 
1257   if (rs.is_reserved()) {
1258     char* mapped_base = r->mapped_base();
1259     assert(rs.base() <= mapped_base && mapped_base + size <= rs.end(),
1260            PTR_FORMAT " <= " PTR_FORMAT " < " PTR_FORMAT " <= " PTR_FORMAT,

1308     if (!read_region(MetaspaceShared::ac, requested_base, r->used_aligned(), /* do_commit = */ true)) {
1309       log_info(cds)("Failed to read aot code shared space into reserved space at " INTPTR_FORMAT,
1310                     p2i(requested_base));
1311       return false;
1312     }
1313     mapped_base = requested_base;
1314   } else {
1315     // We do not execute in-place in the AOT code region.
1316     // AOT code is copied to the CodeCache for execution.
1317     bool read_only = false, allow_exec = false;
1318     mapped_base = map_memory(_fd, _full_path, r->file_offset(),
1319                              requested_base, r->used_aligned(), read_only, allow_exec, mtClassShared);
1320   }
1321   if (mapped_base == nullptr) {
1322     log_info(cds)("failed to map aot code region");
1323     return false;
1324   } else {
1325     assert(mapped_base == requested_base, "must be");
1326     r->set_mapped_from_file(true);
1327     r->set_mapped_base(mapped_base);
1328     relocate_pointers_in_aot_code_region();
1329     log_info(cds)("Mapped static  region #%d at base " INTPTR_FORMAT " top " INTPTR_FORMAT " (%s)",
1330                   MetaspaceShared::ac, p2i(r->mapped_base()), p2i(r->mapped_end()),
1331                   shared_region_name[MetaspaceShared::ac]);
1332     return true;
1333   }
1334 }
1335 
1336 class CachedCodeRelocator: public BitMapClosure {
1337   address _code_requested_base;
1338   address* _patch_base;
1339   intx _code_delta;
1340   intx _metadata_delta;
1341 
1342 public:
1343   CachedCodeRelocator(address code_requested_base, address code_mapped_base,
1344                       intx metadata_delta) {
1345     _code_requested_base = code_requested_base;
1346     _patch_base = (address*)code_mapped_base;
1347     _code_delta = code_mapped_base - code_requested_base;
1348     _metadata_delta = metadata_delta;
1349   }
1350 
1351   bool do_bit(size_t offset) {
1352     address* p = _patch_base + offset;
1353     address requested_ptr = *p;
1354     if (requested_ptr < _code_requested_base) {
1355       *p = requested_ptr + _metadata_delta;
1356     } else {
1357       *p = requested_ptr + _code_delta;
1358     }
1359     return true; // keep iterating
1360   }
1361 };
1362 
1363 void FileMapInfo::relocate_pointers_in_aot_code_region() {
1364   FileMapRegion* r = region_at(MetaspaceShared::ac);
1365   char* bitmap_base = map_bitmap_region();
1366 
1367   BitMapView ac_ptrmap = ptrmap_view(MetaspaceShared::ac);
1368   if (ac_ptrmap.size() == 0) {
1369     return;
1370   }
1371 
1372   address core_regions_requested_base = (address)header()->requested_base_address();
1373   address core_regions_mapped_base = (address)header()->mapped_base_address();
1374   address ac_region_requested_base = core_regions_requested_base + r->mapping_offset();
1375   address ac_region_mapped_base = (address)r->mapped_base();
1376 
1377   size_t max_bits_for_core_regions = pointer_delta(mapped_end(), mapped_base(), // FIXME - renamed to core_regions_mapped_base(), etc
1378                                                    sizeof(address));
1379 
1380   CachedCodeRelocator patcher(ac_region_requested_base, ac_region_mapped_base,
1381                               core_regions_mapped_base - core_regions_requested_base);
1382   ac_ptrmap.iterate(&patcher);
1383 }
1384 
1385 class SharedDataRelocationTask : public ArchiveWorkerTask {
1386 private:
1387   BitMapView* const _rw_bm;
1388   BitMapView* const _ro_bm;
1389   SharedDataRelocator* const _rw_reloc;
1390   SharedDataRelocator* const _ro_reloc;
1391 
1392 public:
1393   SharedDataRelocationTask(BitMapView* rw_bm, BitMapView* ro_bm, SharedDataRelocator* rw_reloc, SharedDataRelocator* ro_reloc) :
1394                            ArchiveWorkerTask("Shared Data Relocation"),
1395                            _rw_bm(rw_bm), _ro_bm(ro_bm), _rw_reloc(rw_reloc), _ro_reloc(ro_reloc) {}
1396 
1397   void work(int chunk, int max_chunks) override {
1398     work_on(chunk, max_chunks, _rw_bm, _rw_reloc);
1399     work_on(chunk, max_chunks, _ro_bm, _ro_reloc);
1400   }
1401 
1402   void work_on(int chunk, int max_chunks, BitMapView* bm, SharedDataRelocator* reloc) {
1403     BitMap::idx_t size  = bm->size();
1404     BitMap::idx_t start = MIN2(size, size * chunk / max_chunks);

1514 }
1515 
1516 void FileMapInfo::map_or_load_heap_region() {
1517   bool success = false;
1518 
1519   if (can_use_heap_region()) {
1520     if (ArchiveHeapLoader::can_map()) {
1521       success = map_heap_region();
1522     } else if (ArchiveHeapLoader::can_load()) {
1523       success = ArchiveHeapLoader::load_heap_region(this);
1524     } else {
1525       if (!UseCompressedOops && !ArchiveHeapLoader::can_map()) {
1526         log_info(cds)("Cannot use CDS heap data. Selected GC not compatible -XX:-UseCompressedOops");
1527       } else {
1528         log_info(cds)("Cannot use CDS heap data. UseEpsilonGC, UseG1GC, UseSerialGC, UseParallelGC, or UseShenandoahGC are required.");
1529       }
1530     }
1531   }
1532 
1533   if (!success) {
1534     if (CDSConfig::is_using_aot_linked_classes() && !CDSConfig::is_dumping_final_static_archive()) {
1535       // It's too late to recover -- we have already committed to use the archived metaspace objects, but
1536       // the archived heap objects cannot be loaded, so we don't have the archived FMG to guarantee that
1537       // all AOT-linked classes are visible.
1538       //
1539       // We get here because the heap is too small. The app will fail anyway. So let's quit.
1540       MetaspaceShared::unrecoverable_loading_error("CDS archive has aot-linked classes but the archived "
1541                                                    "heap objects cannot be loaded. Try increasing your heap size.");
1542     }
1543     CDSConfig::stop_using_full_module_graph("archive heap loading failed");
1544   }
1545 }
1546 
1547 bool FileMapInfo::can_use_heap_region() {
1548   if (!has_heap_region()) {
1549     return false;
1550   }
1551   if (JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::has_early_class_hook_env()) {
1552     ShouldNotReachHere(); // CDS should have been disabled.
1553     // The archived objects are mapped at JVM start-up, but we don't know if
1554     // j.l.String or j.l.Class might be replaced by the ClassFileLoadHook,

1892       return false;
1893     }
1894   }
1895 
1896   return true;
1897 }
1898 
1899 bool FileMapInfo::validate_aot_class_linking() {
1900   // These checks need to be done after FileMapInfo::initialize(), which gets called before Universe::heap()
1901   // is available.
1902   if (header()->has_aot_linked_classes()) {
1903     CDSConfig::set_has_aot_linked_classes(true);
1904     if (JvmtiExport::should_post_class_file_load_hook()) {
1905       log_error(cds)("CDS archive has aot-linked classes. It cannot be used when JVMTI ClassFileLoadHook is in use.");
1906       return false;
1907     }
1908     if (JvmtiExport::has_early_vmstart_env()) {
1909       log_error(cds)("CDS archive has aot-linked classes. It cannot be used when JVMTI early vm start is in use.");
1910       return false;
1911     }
1912     if (!CDSConfig::is_using_full_module_graph() && !CDSConfig::is_dumping_final_static_archive()) {
1913       log_error(cds)("CDS archive has aot-linked classes. It cannot be used when archived full module graph is not used.");
1914       return false;
1915     }
1916 
1917     const char* prop = Arguments::get_property("java.security.manager");
1918     if (prop != nullptr && strcmp(prop, "disallow") != 0) {
1919       log_error(cds)("CDS archive has aot-linked classes. It cannot be used with -Djava.security.manager=%s.", prop);
1920       return false;
1921     }
1922 
1923     if (header()->gc_kind() != (int)Universe::heap()->kind()) {
1924       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)",
1925                      header()->gc_name(), Universe::heap()->name());
1926       return false;
1927     }
1928 
1929 #if INCLUDE_JVMTI
1930     if (Arguments::has_jdwp_agent()) {
1931       log_error(cds)("CDS archive has aot-linked classes. It cannot be used with JDWP agent");
1932       return false;
1933     }
1934 #endif
1935   }
1936 
1937   return true;
1938 }
1939 
1940 // The 2 core spaces are RW->RO
1941 FileMapRegion* FileMapInfo::first_core_region() const {
1942   return region_at(MetaspaceShared::rw);
1943 }
1944 
1945 FileMapRegion* FileMapInfo::last_core_region() const {
1946   return region_at(MetaspaceShared::ro);
1947 }
1948 

1965   int crc = ClassLoader::crc32(0, buf, (jint)sz);
1966   return crc;
1967 }
1968 
1969 // This function should only be called during run time with UseSharedSpaces enabled.
1970 bool FileMapHeader::validate() {
1971   const char* file_type = CDSConfig::type_of_archive_being_loaded();
1972   if (_obj_alignment != ObjectAlignmentInBytes) {
1973     log_info(cds)("The %s's ObjectAlignmentInBytes of %d"
1974                   " does not equal the current ObjectAlignmentInBytes of %d.",
1975                   file_type, _obj_alignment, ObjectAlignmentInBytes);
1976     return false;
1977   }
1978   if (_compact_strings != CompactStrings) {
1979     log_info(cds)("The %s's CompactStrings setting (%s)"
1980                   " does not equal the current CompactStrings setting (%s).", file_type,
1981                   _compact_strings ? "enabled" : "disabled",
1982                   CompactStrings   ? "enabled" : "disabled");
1983     return false;
1984   }
1985   if (TrainingData::have_data()) {
1986     if (_type_profile_level != TypeProfileLevel) {
1987       log_info(cds)("The %s's TypeProfileLevel setting (%d)"
1988                     " does not equal the current TypeProfileLevel setting (%d).", file_type,
1989                     _type_profile_level, TypeProfileLevel);
1990       return false;
1991     }
1992     if (_type_profile_width != TypeProfileWidth) {
1993       log_info(cds)("The %s's TypeProfileWidth setting (%d)"
1994                     " does not equal the current TypeProfileWidth setting (%d).", file_type,
1995                     (int)_type_profile_width, (int)TypeProfileWidth);
1996       return false;
1997 
1998     }
1999     if (_bci_profile_width != BciProfileWidth) {
2000       log_info(cds)("The %s's BciProfileWidth setting (%d)"
2001                     " does not equal the current BciProfileWidth setting (%d).", file_type,
2002                     (int)_bci_profile_width, (int)BciProfileWidth);
2003       return false;
2004     }
2005     if (_profile_traps != ProfileTraps) {
2006       log_info(cds)("The %s's ProfileTraps setting (%s)"
2007                     " does not equal the current ProfileTraps setting (%s).", file_type,
2008                     _profile_traps ? "enabled" : "disabled",
2009                     ProfileTraps   ? "enabled" : "disabled");
2010 
2011       return false;
2012     }
2013     if (_spec_trap_limit_extra_entries != SpecTrapLimitExtraEntries) {
2014       log_info(cds)("The %s's SpecTrapLimitExtraEntries setting (%d)"
2015                     " does not equal the current SpecTrapLimitExtraEntries setting (%d).", file_type,
2016                     _spec_trap_limit_extra_entries, SpecTrapLimitExtraEntries);
2017       return false;
2018 
2019     }
2020   }
2021 
2022   // This must be done after header validation because it might change the
2023   // header data
2024   const char* prop = Arguments::get_property("java.system.class.loader");
2025   if (prop != nullptr) {
2026     if (has_aot_linked_classes()) {
2027       log_error(cds)("CDS archive has aot-linked classes. It cannot be used when the "
2028                      "java.system.class.loader property is specified.");
2029       return false;
2030     }
2031     log_warning(cds)("Archived non-system classes are disabled because the "
2032             "java.system.class.loader property is specified (value = \"%s\"). "
2033             "To use archived non-system classes, this property must not be set", prop);
2034     _has_platform_or_app_classes = false;
2035   }
2036 
2037 
2038   if (!_verify_local && BytecodeVerificationLocal) {
2039     //  we cannot load boot classes, so there's no point of using the CDS archive
2040     log_info(cds)("The %s's BytecodeVerificationLocal setting (%s)"

2080   }
2081 
2082   if (compact_headers() != UseCompactObjectHeaders) {
2083     log_warning(cds)("Unable to use %s.\nThe %s's UseCompactObjectHeaders setting (%s)"
2084                      " does not equal the current UseCompactObjectHeaders setting (%s).", file_type, file_type,
2085                      _compact_headers          ? "enabled" : "disabled",
2086                      UseCompactObjectHeaders   ? "enabled" : "disabled");
2087     return false;
2088   }
2089 
2090   if (!_use_optimized_module_handling && !CDSConfig::is_dumping_final_static_archive()) {
2091     CDSConfig::stop_using_optimized_module_handling();
2092     log_info(cds)("optimized module handling: disabled because archive was created without optimized module handling");
2093   }
2094 
2095   if (is_static()) {
2096     // Only the static archive can contain the full module graph.
2097     if (!_has_full_module_graph) {
2098       CDSConfig::stop_using_full_module_graph("archive was created without full module graph");
2099     }
2100 
2101     if (_has_archived_packages) {
2102       CDSConfig::set_is_loading_packages();
2103     }
2104     if (_has_archived_protection_domains) {
2105       CDSConfig::set_is_loading_protection_domains();
2106     }
2107   }
2108 
2109   return true;
2110 }
2111 
2112 bool FileMapInfo::validate_header() {
2113   if (!header()->validate()) {
2114     return false;
2115   }
2116   if (_is_static) {
2117     return true;
2118   } else {
2119     return DynamicArchive::validate(this);
2120   }
2121 }
2122 
2123 #if INCLUDE_JVMTI
2124 ClassPathEntry** FileMapInfo::_classpath_entries_for_jvmti = nullptr;
2125 
2126 ClassPathEntry* FileMapInfo::get_classpath_entry_for_jvmti(int i, TRAPS) {
< prev index next >