< prev index next >

src/hotspot/share/cds/filemap.cpp

Print this page

 115     // If we are doing PrintSharedArchiveAndExit and some of the classpath entries
 116     // do not validate, we can still continue "limping" to validate the remaining
 117     // entries. No need to quit.
 118     tty->print("[");
 119     tty->vprint(msg, ap);
 120     tty->print_cr("]");
 121   } else {
 122     if (RequireSharedSpaces) {
 123       fail_exit(msg, ap);
 124     } else {
 125       if (log_is_enabled(Info, cds)) {
 126         LogStream ls(Log(cds)::info());
 127         ls.print("UseSharedSpaces: ");
 128         ls.vprint_cr(msg, ap);
 129       }
 130     }
 131   }
 132   va_end(ap);
 133 }
 134 

































































 135 // Fill in the fileMapInfo structure with data about this VM instance.
 136 
 137 // This method copies the vm version info into header_version.  If the version is too
 138 // long then a truncated version, which has a hash code appended to it, is copied.
 139 //
 140 // Using a template enables this method to verify that header_version is an array of
 141 // length JVM_IDENT_MAX.  This ensures that the code that writes to the CDS file and
 142 // the code that reads the CDS file will both use the same size buffer.  Hence, will
 143 // use identical truncation.  This is necessary for matching of truncated versions.
 144 template <int N> static void get_header_version(char (&header_version) [N]) {
 145   assert(N == JVM_IDENT_MAX, "Bad header_version size");
 146 
 147   const char *vm_version = VM_Version::internal_vm_info_string();
 148   const int version_len = (int)strlen(vm_version);
 149 
 150   memset(header_version, 0, JVM_IDENT_MAX);
 151 
 152   if (version_len < (JVM_IDENT_MAX-1)) {
 153     strcpy(header_version, vm_version);
 154 

 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   _num_module_paths = ClassLoader::num_module_path_entries();
 292   _max_used_path_index = ClassLoaderExt::max_used_path_index();
 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 
 302   if (!DynamicDumpSharedSpaces) {
 303     set_shared_path_table(info->_shared_path_table);
 304   }
 305 }
 306 
 307 void FileMapHeader::copy_base_archive_name(const char* archive) {
 308   assert(base_archive_name_size() != 0, "_base_archive_name_size not set");
 309   assert(base_archive_name_offset() != 0, "_base_archive_name_offset not set");
 310   assert(header_size() > sizeof(*this), "_base_archive_name_size not included in header size?");
 311   memcpy((char*)this + base_archive_name_offset(), archive, base_archive_name_size());
 312 }
 313 
 314 void FileMapHeader::print(outputStream* st) {
 315   ResourceMark rm;
 316 
 317   st->print_cr("- magic:                          0x%08x", magic());
 318   st->print_cr("- crc:                            0x%08x", crc());
 319   st->print_cr("- version:                        0x%x", version());
 320   st->print_cr("- header_size:                    " UINT32_FORMAT, header_size());

 343   st->print_cr("- serialized_data_offset:         " SIZE_FORMAT_X, _serialized_data_offset);
 344   st->print_cr("- heap_begin:                     " INTPTR_FORMAT, p2i(_heap_begin));
 345   st->print_cr("- heap_end:                       " INTPTR_FORMAT, p2i(_heap_end));
 346   st->print_cr("- jvm_ident:                      %s", _jvm_ident);
 347   st->print_cr("- shared_path_table_offset:       " SIZE_FORMAT_X, _shared_path_table_offset);
 348   st->print_cr("- shared_path_table_size:         %d", _shared_path_table_size);
 349   st->print_cr("- app_class_paths_start_index:    %d", _app_class_paths_start_index);
 350   st->print_cr("- app_module_paths_start_index:   %d", _app_module_paths_start_index);
 351   st->print_cr("- num_module_paths:               %d", _num_module_paths);
 352   st->print_cr("- max_used_path_index:            %d", _max_used_path_index);
 353   st->print_cr("- verify_local:                   %d", _verify_local);
 354   st->print_cr("- verify_remote:                  %d", _verify_remote);
 355   st->print_cr("- has_platform_or_app_classes:    %d", _has_platform_or_app_classes);
 356   st->print_cr("- has_non_jar_in_classpath:       %d", _has_non_jar_in_classpath);
 357   st->print_cr("- requested_base_address:         " INTPTR_FORMAT, p2i(_requested_base_address));
 358   st->print_cr("- mapped_base_address:            " INTPTR_FORMAT, p2i(_mapped_base_address));
 359   st->print_cr("- allow_archiving_with_java_agent:%d", _allow_archiving_with_java_agent);
 360   st->print_cr("- use_optimized_module_handling:  %d", _use_optimized_module_handling);
 361   st->print_cr("- use_full_module_graph           %d", _use_full_module_graph);
 362   st->print_cr("- ptrmap_size_in_bits:            " SIZE_FORMAT, _ptrmap_size_in_bits);

 363 }
 364 
 365 void SharedClassPathEntry::init_as_non_existent(const char* path, TRAPS) {
 366   _type = non_existent_entry;
 367   set_name(path, CHECK);
 368 }
 369 
 370 void SharedClassPathEntry::init(bool is_modules_image,
 371                                 bool is_module_path,
 372                                 ClassPathEntry* cpe, TRAPS) {
 373   Arguments::assert_is_dumping_archive();
 374   _timestamp = 0;
 375   _filesize  = 0;
 376   _from_class_path_attr = false;
 377 
 378   struct stat st;
 379   if (os::stat(cpe->name(), &st) == 0) {
 380     if ((st.st_mode & S_IFMT) == S_IFDIR) {
 381       _type = dir_entry;
 382     } else {

1453   if (strncmp(actual_ident, expected_ident, JVM_IDENT_MAX-1) != 0) {
1454     log_info(cds)("_jvm_ident expected: %s", expected_ident);
1455     log_info(cds)("             actual: %s", actual_ident);
1456     FileMapInfo::fail_continue("The shared archive file was created by a different"
1457                   " version or build of HotSpot");
1458     return false;
1459   }
1460 
1461   _file_offset = header()->header_size(); // accounts for the size of _base_archive_name
1462 
1463   size_t len = os::lseek(fd, 0, SEEK_END);
1464 
1465   for (int i = 0; i <= MetaspaceShared::last_valid_region; i++) {
1466     FileMapRegion* si = space_at(i);
1467     if (si->file_offset() > len || len - si->file_offset() < si->used()) {
1468       fail_continue("The shared archive file has been truncated.");
1469       return false;
1470     }
1471   }
1472 




1473   return true;
1474 }
1475 
1476 void FileMapInfo::seek_to_position(size_t pos) {
1477   if (os::lseek(_fd, (long)pos, SEEK_SET) < 0) {
1478     fail_stop("Unable to seek to position " SIZE_FORMAT, pos);
1479   }
1480 }
1481 
1482 // Read the FileMapInfo information from the file.
1483 bool FileMapInfo::open_for_read() {
1484   if (_file_open) {
1485     return true;
1486   }
1487   log_info(cds)("trying to map %s", _full_path);
1488   int fd = os::open(_full_path, O_RDONLY | O_BINARY, 0);
1489   if (fd < 0) {
1490     if (errno == ENOENT) {
1491       fail_continue("Specified shared archive not found (%s)", _full_path);
1492     } else {

 115     // If we are doing PrintSharedArchiveAndExit and some of the classpath entries
 116     // do not validate, we can still continue "limping" to validate the remaining
 117     // entries. No need to quit.
 118     tty->print("[");
 119     tty->vprint(msg, ap);
 120     tty->print_cr("]");
 121   } else {
 122     if (RequireSharedSpaces) {
 123       fail_exit(msg, ap);
 124     } else {
 125       if (log_is_enabled(Info, cds)) {
 126         LogStream ls(Log(cds)::info());
 127         ls.print("UseSharedSpaces: ");
 128         ls.vprint_cr(msg, ap);
 129       }
 130     }
 131   }
 132   va_end(ap);
 133 }
 134 
 135 inline void CDSMustMatchFlags::do_print(outputStream* st, bool v) {
 136   st->print("%s", v ? "true" : "false");
 137 }
 138 
 139 inline void CDSMustMatchFlags::do_print(outputStream* st, intx v) {
 140   st->print(INTX_FORMAT, v);
 141 }
 142 
 143 inline void CDSMustMatchFlags::do_print(outputStream* st, uintx v) {
 144   st->print(UINTX_FORMAT, v);
 145 }
 146 
 147 inline void CDSMustMatchFlags::do_print(outputStream* st, double v) {
 148   st->print("%f", v);
 149 }
 150 
 151 void CDSMustMatchFlags::init() {
 152   Arguments::assert_is_dumping_archive();
 153   _max_name_width = 0;
 154 
 155 #define INIT_CDS_MUST_MATCH_FLAG(n) \
 156   _v_##n = n; \
 157   _max_name_width = MAX2(_max_name_width,strlen(#n));
 158   CDS_MUST_MATCH_FLAGS_DO(INIT_CDS_MUST_MATCH_FLAG);
 159 #undef INIT_CDS_MUST_MATCH_FLAG
 160 }
 161 
 162 bool CDSMustMatchFlags::runtime_check() const {
 163 #define CHECK_CDS_MUST_MATCH_FLAG(n) \
 164   if (_v_##n != n) { \
 165     ResourceMark rm; \
 166     stringStream ss; \
 167     ss.print("VM option %s is different between dumptime (", #n);  \
 168     do_print(&ss, _v_ ## n); \
 169     ss.print(") and runtime ("); \
 170     do_print(&ss, n); \
 171     ss.print(")"); \
 172     FileMapInfo::fail_continue("%s", ss.as_string()); \
 173     return false; \
 174   }
 175   CDS_MUST_MATCH_FLAGS_DO(CHECK_CDS_MUST_MATCH_FLAG);
 176 #undef CHECK_CDS_MUST_MATCH_FLAG
 177 
 178   return true;
 179 }
 180 
 181 void CDSMustMatchFlags::print_info() const {
 182   LogTarget(Info, cds) lt;
 183   if (lt.is_enabled()) {
 184     LogStream ls(lt);
 185     ls.print_cr("Recorded VM flags during dumptime:");
 186     print(&ls);
 187   }
 188 }
 189 
 190 void CDSMustMatchFlags::print(outputStream* st) const {
 191 #define PRINT_CDS_MUST_MATCH_FLAG(n) \
 192   st->print("- %-s ", #n);                   \
 193   st->sp(int(_max_name_width - strlen(#n))); \
 194   do_print(st, _v_##n);                      \
 195   st->cr();
 196   CDS_MUST_MATCH_FLAGS_DO(PRINT_CDS_MUST_MATCH_FLAG);
 197 #undef PRINT_CDS_MUST_MATCH_FLAG
 198 }
 199 
 200 // Fill in the fileMapInfo structure with data about this VM instance.
 201 
 202 // This method copies the vm version info into header_version.  If the version is too
 203 // long then a truncated version, which has a hash code appended to it, is copied.
 204 //
 205 // Using a template enables this method to verify that header_version is an array of
 206 // length JVM_IDENT_MAX.  This ensures that the code that writes to the CDS file and
 207 // the code that reads the CDS file will both use the same size buffer.  Hence, will
 208 // use identical truncation.  This is necessary for matching of truncated versions.
 209 template <int N> static void get_header_version(char (&header_version) [N]) {
 210   assert(N == JVM_IDENT_MAX, "Bad header_version size");
 211 
 212   const char *vm_version = VM_Version::internal_vm_info_string();
 213   const int version_len = (int)strlen(vm_version);
 214 
 215   memset(header_version, 0, JVM_IDENT_MAX);
 216 
 217   if (version_len < (JVM_IDENT_MAX-1)) {
 218     strcpy(header_version, vm_version);
 219 

 346 
 347   // The following fields are for sanity checks for whether this archive
 348   // will function correctly with this JVM and the bootclasspath it's
 349   // invoked with.
 350 
 351   // JVM version string ... changes on each build.
 352   get_header_version(_jvm_ident);
 353 
 354   _app_class_paths_start_index = ClassLoaderExt::app_class_paths_start_index();
 355   _app_module_paths_start_index = ClassLoaderExt::app_module_paths_start_index();
 356   _num_module_paths = ClassLoader::num_module_path_entries();
 357   _max_used_path_index = ClassLoaderExt::max_used_path_index();
 358 
 359   _verify_local = BytecodeVerificationLocal;
 360   _verify_remote = BytecodeVerificationRemote;
 361   _has_platform_or_app_classes = ClassLoaderExt::has_platform_or_app_classes();
 362   _has_non_jar_in_classpath = ClassLoaderExt::has_non_jar_in_classpath();
 363   _requested_base_address = (char*)SharedBaseAddress;
 364   _mapped_base_address = (char*)SharedBaseAddress;
 365   _allow_archiving_with_java_agent = AllowArchivingWithJavaAgent;
 366   _must_match.init();
 367 
 368   if (!DynamicDumpSharedSpaces) {
 369     set_shared_path_table(info->_shared_path_table);
 370   }
 371 }
 372 
 373 void FileMapHeader::copy_base_archive_name(const char* archive) {
 374   assert(base_archive_name_size() != 0, "_base_archive_name_size not set");
 375   assert(base_archive_name_offset() != 0, "_base_archive_name_offset not set");
 376   assert(header_size() > sizeof(*this), "_base_archive_name_size not included in header size?");
 377   memcpy((char*)this + base_archive_name_offset(), archive, base_archive_name_size());
 378 }
 379 
 380 void FileMapHeader::print(outputStream* st) {
 381   ResourceMark rm;
 382 
 383   st->print_cr("- magic:                          0x%08x", magic());
 384   st->print_cr("- crc:                            0x%08x", crc());
 385   st->print_cr("- version:                        0x%x", version());
 386   st->print_cr("- header_size:                    " UINT32_FORMAT, header_size());

 409   st->print_cr("- serialized_data_offset:         " SIZE_FORMAT_X, _serialized_data_offset);
 410   st->print_cr("- heap_begin:                     " INTPTR_FORMAT, p2i(_heap_begin));
 411   st->print_cr("- heap_end:                       " INTPTR_FORMAT, p2i(_heap_end));
 412   st->print_cr("- jvm_ident:                      %s", _jvm_ident);
 413   st->print_cr("- shared_path_table_offset:       " SIZE_FORMAT_X, _shared_path_table_offset);
 414   st->print_cr("- shared_path_table_size:         %d", _shared_path_table_size);
 415   st->print_cr("- app_class_paths_start_index:    %d", _app_class_paths_start_index);
 416   st->print_cr("- app_module_paths_start_index:   %d", _app_module_paths_start_index);
 417   st->print_cr("- num_module_paths:               %d", _num_module_paths);
 418   st->print_cr("- max_used_path_index:            %d", _max_used_path_index);
 419   st->print_cr("- verify_local:                   %d", _verify_local);
 420   st->print_cr("- verify_remote:                  %d", _verify_remote);
 421   st->print_cr("- has_platform_or_app_classes:    %d", _has_platform_or_app_classes);
 422   st->print_cr("- has_non_jar_in_classpath:       %d", _has_non_jar_in_classpath);
 423   st->print_cr("- requested_base_address:         " INTPTR_FORMAT, p2i(_requested_base_address));
 424   st->print_cr("- mapped_base_address:            " INTPTR_FORMAT, p2i(_mapped_base_address));
 425   st->print_cr("- allow_archiving_with_java_agent:%d", _allow_archiving_with_java_agent);
 426   st->print_cr("- use_optimized_module_handling:  %d", _use_optimized_module_handling);
 427   st->print_cr("- use_full_module_graph           %d", _use_full_module_graph);
 428   st->print_cr("- ptrmap_size_in_bits:            " SIZE_FORMAT, _ptrmap_size_in_bits);
 429   _must_match.print(st);
 430 }
 431 
 432 void SharedClassPathEntry::init_as_non_existent(const char* path, TRAPS) {
 433   _type = non_existent_entry;
 434   set_name(path, CHECK);
 435 }
 436 
 437 void SharedClassPathEntry::init(bool is_modules_image,
 438                                 bool is_module_path,
 439                                 ClassPathEntry* cpe, TRAPS) {
 440   Arguments::assert_is_dumping_archive();
 441   _timestamp = 0;
 442   _filesize  = 0;
 443   _from_class_path_attr = false;
 444 
 445   struct stat st;
 446   if (os::stat(cpe->name(), &st) == 0) {
 447     if ((st.st_mode & S_IFMT) == S_IFDIR) {
 448       _type = dir_entry;
 449     } else {

1520   if (strncmp(actual_ident, expected_ident, JVM_IDENT_MAX-1) != 0) {
1521     log_info(cds)("_jvm_ident expected: %s", expected_ident);
1522     log_info(cds)("             actual: %s", actual_ident);
1523     FileMapInfo::fail_continue("The shared archive file was created by a different"
1524                   " version or build of HotSpot");
1525     return false;
1526   }
1527 
1528   _file_offset = header()->header_size(); // accounts for the size of _base_archive_name
1529 
1530   size_t len = os::lseek(fd, 0, SEEK_END);
1531 
1532   for (int i = 0; i <= MetaspaceShared::last_valid_region; i++) {
1533     FileMapRegion* si = space_at(i);
1534     if (si->file_offset() > len || len - si->file_offset() < si->used()) {
1535       fail_continue("The shared archive file has been truncated.");
1536       return false;
1537     }
1538   }
1539 
1540   if (!header()->check_must_match_flags()) {
1541     return false;
1542   }
1543 
1544   return true;
1545 }
1546 
1547 void FileMapInfo::seek_to_position(size_t pos) {
1548   if (os::lseek(_fd, (long)pos, SEEK_SET) < 0) {
1549     fail_stop("Unable to seek to position " SIZE_FORMAT, pos);
1550   }
1551 }
1552 
1553 // Read the FileMapInfo information from the file.
1554 bool FileMapInfo::open_for_read() {
1555   if (_file_open) {
1556     return true;
1557   }
1558   log_info(cds)("trying to map %s", _full_path);
1559   int fd = os::open(_full_path, O_RDONLY | O_BINARY, 0);
1560   if (fd < 0) {
1561     if (errno == ENOENT) {
1562       fail_continue("Specified shared archive not found (%s)", _full_path);
1563     } else {
< prev index next >