< prev index next >

src/hotspot/share/cds/filemap.cpp

Print this page
@@ -128,10 +128,75 @@
      }
    }
    va_end(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.
  //

@@ -246,10 +311,11 @@
    _mapped_base_address = (char*)SharedBaseAddress;
    _allow_archiving_with_java_agent = AllowArchivingWithJavaAgent;
    // the following 2 fields will be set in write_header for dynamic archive header
    _base_archive_name_size = 0;
    _base_archive_is_default = false;
+   _must_match.init();
  
    if (!DynamicDumpSharedSpaces) {
      set_shared_path_table(mapinfo->_shared_path_table);
      CDS_JAVA_HEAP_ONLY(_heap_obj_roots = CompressedOops::encode(HeapShared::roots());)
    }

@@ -300,10 +366,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);

@@ -1181,10 +1248,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 (lseek(_fd, (long)pos, SEEK_SET) < 0) {
< prev index next >