< prev index next >

src/hotspot/share/cds/filemap.cpp

Print this page

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

































































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

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

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

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

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

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




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

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

 281 
 282   // The following fields are for sanity checks for whether this archive
 283   // will function correctly with this JVM and the bootclasspath it's
 284   // invoked with.
 285 
 286   // JVM version string ... changes on each build.
 287   get_header_version(_jvm_ident);
 288 
 289   _app_class_paths_start_index = ClassLoaderExt::app_class_paths_start_index();
 290   _app_module_paths_start_index = ClassLoaderExt::app_module_paths_start_index();
 291   _max_used_path_index = ClassLoaderExt::max_used_path_index();
 292   _num_module_paths = ClassLoader::num_module_path_entries();
 293 
 294   _verify_local = BytecodeVerificationLocal;
 295   _verify_remote = BytecodeVerificationRemote;
 296   _has_platform_or_app_classes = ClassLoaderExt::has_platform_or_app_classes();
 297   _has_non_jar_in_classpath = ClassLoaderExt::has_non_jar_in_classpath();
 298   _requested_base_address = (char*)SharedBaseAddress;
 299   _mapped_base_address = (char*)SharedBaseAddress;
 300   _allow_archiving_with_java_agent = AllowArchivingWithJavaAgent;
 301   _must_match.init();
 302 
 303   if (!DynamicDumpSharedSpaces) {
 304     set_shared_path_table(info->_shared_path_table);
 305   }
 306 }
 307 
 308 void FileMapHeader::copy_base_archive_name(const char* archive) {
 309   assert(base_archive_name_size() != 0, "_base_archive_name_size not set");
 310   assert(base_archive_name_offset() != 0, "_base_archive_name_offset not set");
 311   assert(header_size() > sizeof(*this), "_base_archive_name_size not included in header size?");
 312   memcpy((char*)this + base_archive_name_offset(), archive, base_archive_name_size());
 313 }
 314 
 315 void FileMapHeader::print(outputStream* st) {
 316   ResourceMark rm;
 317 
 318   st->print_cr("- magic:                          0x%08x", magic());
 319   st->print_cr("- crc:                            0x%08x", crc());
 320   st->print_cr("- version:                        0x%x", version());
 321   st->print_cr("- header_size:                    " UINT32_FORMAT, header_size());

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

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