@@ -138,10 +138,75 @@ lm.vwrite(level, msg, ap); } } } + inline void CDSMustMatchFlags::do_print(outputStream* st, bool v) { + st->print("%s", v ? "true" : "false"); + } + + inline void CDSMustMatchFlags::do_print(outputStream* st, intx v) { + st->print(INTX_FORMAT, v); + } + + inline void CDSMustMatchFlags::do_print(outputStream* st, uintx v) { + st->print(UINTX_FORMAT, v); + } + + inline void CDSMustMatchFlags::do_print(outputStream* st, double v) { + st->print("%f", v); + } + + void CDSMustMatchFlags::init() { + Arguments::assert_is_dumping_archive(); + _max_name_width = 0; + + #define INIT_CDS_MUST_MATCH_FLAG(n) \ + _v_##n = n; \ + _max_name_width = MAX2(_max_name_width,strlen(#n)); + CDS_MUST_MATCH_FLAGS_DO(INIT_CDS_MUST_MATCH_FLAG); + #undef INIT_CDS_MUST_MATCH_FLAG + } + + bool CDSMustMatchFlags::runtime_check() const { + #define CHECK_CDS_MUST_MATCH_FLAG(n) \ + if (_v_##n != n) { \ + ResourceMark rm; \ + stringStream ss; \ + ss.print("VM option %s is different between dumptime (", #n); \ + do_print(&ss, _v_ ## n); \ + ss.print(") and runtime ("); \ + do_print(&ss, n); \ + ss.print(")"); \ + FileMapInfo::fail_continue("%s", ss.as_string()); \ + return false; \ + } + CDS_MUST_MATCH_FLAGS_DO(CHECK_CDS_MUST_MATCH_FLAG); + #undef CHECK_CDS_MUST_MATCH_FLAG + + return true; + } + + void CDSMustMatchFlags::print_info() const { + LogTarget(Info, cds) lt; + if (lt.is_enabled()) { + LogStream ls(lt); + ls.print_cr("Recorded VM flags during dumptime:"); + print(&ls); + } + } + + void CDSMustMatchFlags::print(outputStream* st) const { + #define PRINT_CDS_MUST_MATCH_FLAG(n) \ + st->print("- %-s ", #n); \ + st->sp(int(_max_name_width - strlen(#n))); \ + do_print(st, _v_##n); \ + st->cr(); + CDS_MUST_MATCH_FLAGS_DO(PRINT_CDS_MUST_MATCH_FLAG); + #undef PRINT_CDS_MUST_MATCH_FLAG + } + // Fill in the fileMapInfo structure with data about this VM instance. // This method copies the vm version info into header_version. If the version is too // long then a truncated version, which has a hash code appended to it, is copied. //
@@ -304,10 +369,11 @@ _has_platform_or_app_classes = ClassLoaderExt::has_platform_or_app_classes(); _has_non_jar_in_classpath = ClassLoaderExt::has_non_jar_in_classpath(); _requested_base_address = (char*)SharedBaseAddress; _mapped_base_address = (char*)SharedBaseAddress; _allow_archiving_with_java_agent = AllowArchivingWithJavaAgent; + _must_match.init(); if (!DynamicDumpSharedSpaces) { set_shared_path_table(info->_shared_path_table); } }
@@ -366,10 +432,11 @@ st->print_cr("- mapped_base_address: " INTPTR_FORMAT, p2i(_mapped_base_address)); st->print_cr("- allow_archiving_with_java_agent:%d", _allow_archiving_with_java_agent); st->print_cr("- use_optimized_module_handling: %d", _use_optimized_module_handling); st->print_cr("- use_full_module_graph %d", _use_full_module_graph); st->print_cr("- ptrmap_size_in_bits: " SIZE_FORMAT, _ptrmap_size_in_bits); + _must_match.print(st); } void SharedClassPathEntry::init_as_non_existent(const char* path, TRAPS) { _type = non_existent_entry; set_name(path, CHECK);
@@ -1474,10 +1541,14 @@ fail_continue("The shared archive file has been truncated."); return false; } } + if (!header()->check_must_match_flags()) { + return false; + } + return true; } void FileMapInfo::seek_to_position(size_t pos) { if (os::lseek(_fd, (long)pos, SEEK_SET) < 0) {