< prev index next >

src/hotspot/share/cds/filemap.cpp

Print this page

   1 /*
   2  * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *

  64 #include "runtime/mutexLocker.hpp"
  65 #include "runtime/os.hpp"
  66 #include "runtime/vm_version.hpp"
  67 #include "utilities/align.hpp"
  68 #include "utilities/bitMap.inline.hpp"
  69 #include "utilities/classpathStream.hpp"
  70 #include "utilities/defaultStream.hpp"
  71 #include "utilities/ostream.hpp"
  72 #if INCLUDE_G1GC
  73 #include "gc/g1/g1CollectedHeap.hpp"
  74 #include "gc/g1/heapRegion.hpp"
  75 #endif
  76 
  77 # include <sys/stat.h>
  78 # include <errno.h>
  79 
  80 #ifndef O_BINARY       // if defined (Win32) use binary files.
  81 #define O_BINARY 0     // otherwise do nothing.
  82 #endif
  83 

































































  84 // Fill in the fileMapInfo structure with data about this VM instance.
  85 
  86 // This method copies the vm version info into header_version.  If the version is too
  87 // long then a truncated version, which has a hash code appended to it, is copied.
  88 //
  89 // Using a template enables this method to verify that header_version is an array of
  90 // length JVM_IDENT_MAX.  This ensures that the code that writes to the CDS file and
  91 // the code that reads the CDS file will both use the same size buffer.  Hence, will
  92 // use identical truncation.  This is necessary for matching of truncated versions.
  93 template <int N> static void get_header_version(char (&header_version) [N]) {
  94   assert(N == JVM_IDENT_MAX, "Bad header_version size");
  95 
  96   const char *vm_version = VM_Version::internal_vm_info_string();
  97   const int version_len = (int)strlen(vm_version);
  98 
  99   memset(header_version, 0, JVM_IDENT_MAX);
 100 
 101   if (version_len < (JVM_IDENT_MAX-1)) {
 102     strcpy(header_version, vm_version);
 103 

 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;

 237 
 238   if (!CDSConfig::is_dumping_dynamic_archive()) {
 239     set_shared_path_table(info->_shared_path_table);
 240   }
 241 }
 242 
 243 void FileMapHeader::copy_base_archive_name(const char* archive) {
 244   assert(base_archive_name_size() != 0, "_base_archive_name_size not set");
 245   assert(base_archive_name_offset() != 0, "_base_archive_name_offset not set");
 246   assert(header_size() > sizeof(*this), "_base_archive_name_size not included in header size?");
 247   memcpy((char*)this + base_archive_name_offset(), archive, base_archive_name_size());
 248 }
 249 
 250 void FileMapHeader::print(outputStream* st) {
 251   ResourceMark rm;
 252 
 253   st->print_cr("- magic:                          0x%08x", magic());
 254   st->print_cr("- crc:                            0x%08x", crc());
 255   st->print_cr("- version:                        0x%x", version());
 256   st->print_cr("- header_size:                    " UINT32_FORMAT, header_size());

 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;
 315     } else {

1328   if (strncmp(actual_ident, expected_ident, JVM_IDENT_MAX-1) != 0) {
1329     log_info(cds)("_jvm_ident expected: %s", expected_ident);
1330     log_info(cds)("             actual: %s", actual_ident);
1331     log_warning(cds)("The shared archive file was created by a different"
1332                   " version or build of HotSpot");
1333     return false;
1334   }
1335 
1336   _file_offset = header()->header_size(); // accounts for the size of _base_archive_name
1337 
1338   size_t len = os::lseek(fd, 0, SEEK_END);
1339 
1340   for (int i = 0; i < MetaspaceShared::n_regions; i++) {
1341     FileMapRegion* r = region_at(i);
1342     if (r->file_offset() > len || len - r->file_offset() < r->used()) {
1343       log_warning(cds)("The shared archive file has been truncated.");
1344       return false;
1345     }
1346   }
1347 




1348   return true;
1349 }
1350 
1351 void FileMapInfo::seek_to_position(size_t pos) {
1352   if (os::lseek(_fd, (long)pos, SEEK_SET) < 0) {
1353     log_error(cds)("Unable to seek to position " SIZE_FORMAT, pos);
1354     MetaspaceShared::unrecoverable_loading_error();
1355   }
1356 }
1357 
1358 // Read the FileMapInfo information from the file.
1359 bool FileMapInfo::open_for_read() {
1360   if (_file_open) {
1361     return true;
1362   }
1363   log_info(cds)("trying to map %s", _full_path);
1364   int fd = os::open(_full_path, O_RDONLY | O_BINARY, 0);
1365   if (fd < 0) {
1366     if (errno == ENOENT) {
1367       log_info(cds)("Specified shared archive not found (%s)", _full_path);

2367   // while AllowArchivingWithJavaAgent is set during the current run.
2368   if (_allow_archiving_with_java_agent && !AllowArchivingWithJavaAgent) {
2369     log_warning(cds)("The setting of the AllowArchivingWithJavaAgent is different "
2370                                "from the setting in the shared archive.");
2371     return false;
2372   }
2373 
2374   if (_allow_archiving_with_java_agent) {
2375     log_warning(cds)("This archive was created with AllowArchivingWithJavaAgent. It should be used "
2376             "for testing purposes only and should not be used in a production environment");
2377   }
2378 
2379   log_info(cds)("Archive was created with UseCompressedOops = %d, UseCompressedClassPointers = %d",
2380                           compressed_oops(), compressed_class_pointers());
2381   if (compressed_oops() != UseCompressedOops || compressed_class_pointers() != UseCompressedClassPointers) {
2382     log_info(cds)("Unable to use shared archive.\nThe saved state of UseCompressedOops and UseCompressedClassPointers is "
2383                                "different from runtime, CDS will be disabled.");
2384     return false;
2385   }
2386 


















2387   if (!_use_optimized_module_handling) {
2388     MetaspaceShared::disable_optimized_module_handling();
2389     log_info(cds)("optimized module handling: disabled because archive was created without optimized module handling");
2390   }
2391 
2392   if (is_static() && !_has_full_module_graph) {
2393     // Only the static archive can contain the full module graph.
2394     CDSConfig::disable_loading_full_module_graph("archive was created without full module graph");
2395   }
2396 
2397   return true;
2398 }
2399 
2400 bool FileMapInfo::validate_header() {
2401   if (!header()->validate()) {
2402     return false;
2403   }
2404   if (_is_static) {
2405     return true;
2406   } else {

   1 /*
   2  * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *

  64 #include "runtime/mutexLocker.hpp"
  65 #include "runtime/os.hpp"
  66 #include "runtime/vm_version.hpp"
  67 #include "utilities/align.hpp"
  68 #include "utilities/bitMap.inline.hpp"
  69 #include "utilities/classpathStream.hpp"
  70 #include "utilities/defaultStream.hpp"
  71 #include "utilities/ostream.hpp"
  72 #if INCLUDE_G1GC
  73 #include "gc/g1/g1CollectedHeap.hpp"
  74 #include "gc/g1/heapRegion.hpp"
  75 #endif
  76 
  77 # include <sys/stat.h>
  78 # include <errno.h>
  79 
  80 #ifndef O_BINARY       // if defined (Win32) use binary files.
  81 #define O_BINARY 0     // otherwise do nothing.
  82 #endif
  83 
  84 inline void CDSMustMatchFlags::do_print(outputStream* st, bool v) {
  85   st->print("%s", v ? "true" : "false");
  86 }
  87 
  88 inline void CDSMustMatchFlags::do_print(outputStream* st, intx v) {
  89   st->print(INTX_FORMAT, v);
  90 }
  91 
  92 inline void CDSMustMatchFlags::do_print(outputStream* st, uintx v) {
  93   st->print(UINTX_FORMAT, v);
  94 }
  95 
  96 inline void CDSMustMatchFlags::do_print(outputStream* st, double v) {
  97   st->print("%f", v);
  98 }
  99 
 100 void CDSMustMatchFlags::init() {
 101   assert(CDSConfig::is_dumping_archive(), "sanity");
 102   _max_name_width = 0;
 103 
 104 #define INIT_CDS_MUST_MATCH_FLAG(n) \
 105   _v_##n = n; \
 106   _max_name_width = MAX2(_max_name_width,strlen(#n));
 107   CDS_MUST_MATCH_FLAGS_DO(INIT_CDS_MUST_MATCH_FLAG);
 108 #undef INIT_CDS_MUST_MATCH_FLAG
 109 }
 110 
 111 bool CDSMustMatchFlags::runtime_check() const {
 112 #define CHECK_CDS_MUST_MATCH_FLAG(n) \
 113   if (_v_##n != n) { \
 114     ResourceMark rm; \
 115     stringStream ss; \
 116     ss.print("VM option %s is different between dumptime (", #n);  \
 117     do_print(&ss, _v_ ## n); \
 118     ss.print(") and runtime ("); \
 119     do_print(&ss, n); \
 120     ss.print(")"); \
 121     log_info(cds)("%s", ss.as_string()); \
 122     return false; \
 123   }
 124   CDS_MUST_MATCH_FLAGS_DO(CHECK_CDS_MUST_MATCH_FLAG);
 125 #undef CHECK_CDS_MUST_MATCH_FLAG
 126 
 127   return true;
 128 }
 129 
 130 void CDSMustMatchFlags::print_info() const {
 131   LogTarget(Info, cds) lt;
 132   if (lt.is_enabled()) {
 133     LogStream ls(lt);
 134     ls.print_cr("Recorded VM flags during dumptime:");
 135     print(&ls);
 136   }
 137 }
 138 
 139 void CDSMustMatchFlags::print(outputStream* st) const {
 140 #define PRINT_CDS_MUST_MATCH_FLAG(n) \
 141   st->print("- %-s ", #n);                   \
 142   st->sp(int(_max_name_width - strlen(#n))); \
 143   do_print(st, _v_##n);                      \
 144   st->cr();
 145   CDS_MUST_MATCH_FLAGS_DO(PRINT_CDS_MUST_MATCH_FLAG);
 146 #undef PRINT_CDS_MUST_MATCH_FLAG
 147 }
 148 
 149 // Fill in the fileMapInfo structure with data about this VM instance.
 150 
 151 // This method copies the vm version info into header_version.  If the version is too
 152 // long then a truncated version, which has a hash code appended to it, is copied.
 153 //
 154 // Using a template enables this method to verify that header_version is an array of
 155 // length JVM_IDENT_MAX.  This ensures that the code that writes to the CDS file and
 156 // the code that reads the CDS file will both use the same size buffer.  Hence, will
 157 // use identical truncation.  This is necessary for matching of truncated versions.
 158 template <int N> static void get_header_version(char (&header_version) [N]) {
 159   assert(N == JVM_IDENT_MAX, "Bad header_version size");
 160 
 161   const char *vm_version = VM_Version::internal_vm_info_string();
 162   const int version_len = (int)strlen(vm_version);
 163 
 164   memset(header_version, 0, JVM_IDENT_MAX);
 165 
 166   if (version_len < (JVM_IDENT_MAX-1)) {
 167     strcpy(header_version, vm_version);
 168 

 262   set_magic(CDSConfig::is_dumping_dynamic_archive() ? CDS_DYNAMIC_ARCHIVE_MAGIC : CDS_ARCHIVE_MAGIC);
 263   set_version(CURRENT_CDS_ARCHIVE_VERSION);
 264 
 265   if (!info->is_static() && base_archive_name_size != 0) {
 266     // copy base archive name
 267     copy_base_archive_name(CDSConfig::static_archive_path());
 268   }
 269   _core_region_alignment = core_region_alignment;
 270   _obj_alignment = ObjectAlignmentInBytes;
 271   _compact_strings = CompactStrings;
 272   if (CDSConfig::is_dumping_heap()) {
 273     _narrow_oop_mode = CompressedOops::mode();
 274     _narrow_oop_base = CompressedOops::base();
 275     _narrow_oop_shift = CompressedOops::shift();
 276   }
 277   _compressed_oops = UseCompressedOops;
 278   _compressed_class_ptrs = UseCompressedClassPointers;
 279   _max_heap_size = MaxHeapSize;
 280   _use_optimized_module_handling = MetaspaceShared::use_optimized_module_handling();
 281   _has_full_module_graph = CDSConfig::is_dumping_full_module_graph();
 282   _has_valhalla_patched_classes = CDSConfig::is_valhalla_preview();
 283   // The following fields are for sanity checks for whether this archive
 284   // will function correctly with this JVM and the bootclasspath it's
 285   // invoked with.
 286 
 287   // JVM version string ... changes on each build.
 288   get_header_version(_jvm_ident);
 289 
 290   _app_class_paths_start_index = ClassLoaderExt::app_class_paths_start_index();
 291   _app_module_paths_start_index = ClassLoaderExt::app_module_paths_start_index();
 292   _max_used_path_index = ClassLoaderExt::max_used_path_index();
 293   _num_module_paths = ClassLoader::num_module_path_entries();
 294 
 295   _verify_local = BytecodeVerificationLocal;
 296   _verify_remote = BytecodeVerificationRemote;
 297   _has_platform_or_app_classes = ClassLoaderExt::has_platform_or_app_classes();
 298   _has_non_jar_in_classpath = ClassLoaderExt::has_non_jar_in_classpath();
 299   _requested_base_address = (char*)SharedBaseAddress;
 300   _mapped_base_address = (char*)SharedBaseAddress;
 301   _allow_archiving_with_java_agent = AllowArchivingWithJavaAgent;
 302   _must_match.init();
 303 
 304   if (!CDSConfig::is_dumping_dynamic_archive()) {
 305     set_shared_path_table(info->_shared_path_table);
 306   }
 307 }
 308 
 309 void FileMapHeader::copy_base_archive_name(const char* archive) {
 310   assert(base_archive_name_size() != 0, "_base_archive_name_size not set");
 311   assert(base_archive_name_offset() != 0, "_base_archive_name_offset not set");
 312   assert(header_size() > sizeof(*this), "_base_archive_name_size not included in header size?");
 313   memcpy((char*)this + base_archive_name_offset(), archive, base_archive_name_size());
 314 }
 315 
 316 void FileMapHeader::print(outputStream* st) {
 317   ResourceMark rm;
 318 
 319   st->print_cr("- magic:                          0x%08x", magic());
 320   st->print_cr("- crc:                            0x%08x", crc());
 321   st->print_cr("- version:                        0x%x", version());
 322   st->print_cr("- header_size:                    " UINT32_FORMAT, header_size());

 341   st->print_cr("- compressed_oops:                %d", _compressed_oops);
 342   st->print_cr("- compressed_class_ptrs:          %d", _compressed_class_ptrs);
 343   st->print_cr("- cloned_vtables_offset:          " SIZE_FORMAT_X, _cloned_vtables_offset);
 344   st->print_cr("- serialized_data_offset:         " SIZE_FORMAT_X, _serialized_data_offset);
 345   st->print_cr("- jvm_ident:                      %s", _jvm_ident);
 346   st->print_cr("- shared_path_table_offset:       " SIZE_FORMAT_X, _shared_path_table_offset);
 347   st->print_cr("- app_class_paths_start_index:    %d", _app_class_paths_start_index);
 348   st->print_cr("- app_module_paths_start_index:   %d", _app_module_paths_start_index);
 349   st->print_cr("- num_module_paths:               %d", _num_module_paths);
 350   st->print_cr("- max_used_path_index:            %d", _max_used_path_index);
 351   st->print_cr("- verify_local:                   %d", _verify_local);
 352   st->print_cr("- verify_remote:                  %d", _verify_remote);
 353   st->print_cr("- has_platform_or_app_classes:    %d", _has_platform_or_app_classes);
 354   st->print_cr("- has_non_jar_in_classpath:       %d", _has_non_jar_in_classpath);
 355   st->print_cr("- requested_base_address:         " INTPTR_FORMAT, p2i(_requested_base_address));
 356   st->print_cr("- mapped_base_address:            " INTPTR_FORMAT, p2i(_mapped_base_address));
 357   st->print_cr("- heap_roots_offset:              " SIZE_FORMAT, _heap_roots_offset);
 358   st->print_cr("- allow_archiving_with_java_agent:%d", _allow_archiving_with_java_agent);
 359   st->print_cr("- use_optimized_module_handling:  %d", _use_optimized_module_handling);
 360   st->print_cr("- has_full_module_graph           %d", _has_full_module_graph);
 361   st->print_cr("- has_valhalla_patched_classes    %d", _has_valhalla_patched_classes);
 362   st->print_cr("- ptrmap_size_in_bits:            " SIZE_FORMAT, _ptrmap_size_in_bits);
 363   _must_match.print(st);
 364 }
 365 
 366 void SharedClassPathEntry::init_as_non_existent(const char* path, TRAPS) {
 367   _type = non_existent_entry;
 368   set_name(path, CHECK);
 369 }
 370 
 371 void SharedClassPathEntry::init(bool is_modules_image,
 372                                 bool is_module_path,
 373                                 ClassPathEntry* cpe, TRAPS) {
 374   assert(CDSConfig::is_dumping_archive(), "sanity");
 375   _timestamp = 0;
 376   _filesize  = 0;
 377   _from_class_path_attr = false;
 378 
 379   struct stat st;
 380   if (os::stat(cpe->name(), &st) == 0) {
 381     if ((st.st_mode & S_IFMT) == S_IFDIR) {
 382       _type = dir_entry;
 383     } else {

1396   if (strncmp(actual_ident, expected_ident, JVM_IDENT_MAX-1) != 0) {
1397     log_info(cds)("_jvm_ident expected: %s", expected_ident);
1398     log_info(cds)("             actual: %s", actual_ident);
1399     log_warning(cds)("The shared archive file was created by a different"
1400                   " version or build of HotSpot");
1401     return false;
1402   }
1403 
1404   _file_offset = header()->header_size(); // accounts for the size of _base_archive_name
1405 
1406   size_t len = os::lseek(fd, 0, SEEK_END);
1407 
1408   for (int i = 0; i < MetaspaceShared::n_regions; i++) {
1409     FileMapRegion* r = region_at(i);
1410     if (r->file_offset() > len || len - r->file_offset() < r->used()) {
1411       log_warning(cds)("The shared archive file has been truncated.");
1412       return false;
1413     }
1414   }
1415 
1416   if (!header()->check_must_match_flags()) {
1417     return false;
1418   }
1419 
1420   return true;
1421 }
1422 
1423 void FileMapInfo::seek_to_position(size_t pos) {
1424   if (os::lseek(_fd, (long)pos, SEEK_SET) < 0) {
1425     log_error(cds)("Unable to seek to position " SIZE_FORMAT, pos);
1426     MetaspaceShared::unrecoverable_loading_error();
1427   }
1428 }
1429 
1430 // Read the FileMapInfo information from the file.
1431 bool FileMapInfo::open_for_read() {
1432   if (_file_open) {
1433     return true;
1434   }
1435   log_info(cds)("trying to map %s", _full_path);
1436   int fd = os::open(_full_path, O_RDONLY | O_BINARY, 0);
1437   if (fd < 0) {
1438     if (errno == ENOENT) {
1439       log_info(cds)("Specified shared archive not found (%s)", _full_path);

2439   // while AllowArchivingWithJavaAgent is set during the current run.
2440   if (_allow_archiving_with_java_agent && !AllowArchivingWithJavaAgent) {
2441     log_warning(cds)("The setting of the AllowArchivingWithJavaAgent is different "
2442                                "from the setting in the shared archive.");
2443     return false;
2444   }
2445 
2446   if (_allow_archiving_with_java_agent) {
2447     log_warning(cds)("This archive was created with AllowArchivingWithJavaAgent. It should be used "
2448             "for testing purposes only and should not be used in a production environment");
2449   }
2450 
2451   log_info(cds)("Archive was created with UseCompressedOops = %d, UseCompressedClassPointers = %d",
2452                           compressed_oops(), compressed_class_pointers());
2453   if (compressed_oops() != UseCompressedOops || compressed_class_pointers() != UseCompressedClassPointers) {
2454     log_info(cds)("Unable to use shared archive.\nThe saved state of UseCompressedOops and UseCompressedClassPointers is "
2455                                "different from runtime, CDS will be disabled.");
2456     return false;
2457   }
2458 
2459   if (is_static()) {
2460     const char* err = nullptr;
2461     if (CDSConfig::is_valhalla_preview()) {
2462       if (!_has_valhalla_patched_classes) {
2463         err = "not created";
2464       }
2465     } else {
2466       if (_has_valhalla_patched_classes) {
2467         err = "created";
2468       }
2469     }
2470     if (err != nullptr) {
2471       log_warning(cds)("This archive was %s with --enable-preview -XX:+EnableValhalla. It is "
2472                          "incompatible with the current JVM setting", err);
2473       return false;
2474     }
2475   }
2476 
2477   if (!_use_optimized_module_handling) {
2478     MetaspaceShared::disable_optimized_module_handling();
2479     log_info(cds)("optimized module handling: disabled because archive was created without optimized module handling");
2480   }
2481 
2482   if (is_static() && !_has_full_module_graph) {
2483     // Only the static archive can contain the full module graph.
2484     CDSConfig::disable_loading_full_module_graph("archive was created without full module graph");
2485   }
2486 
2487   return true;
2488 }
2489 
2490 bool FileMapInfo::validate_header() {
2491   if (!header()->validate()) {
2492     return false;
2493   }
2494   if (_is_static) {
2495     return true;
2496   } else {
< prev index next >