< prev index next >

src/hotspot/share/cds/filemap.cpp

Print this page
*** 83,10 ***
--- 83,75 ---
  
  #ifndef O_BINARY       // if defined (Win32) use binary files.
  #define O_BINARY 0     // otherwise do nothing.
  #endif
  
+ 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("%zd", v);
+ }
+ 
+ inline void CDSMustMatchFlags::do_print(outputStream* st, uintx v) {
+   st->print("%zu", v);
+ }
+ 
+ inline void CDSMustMatchFlags::do_print(outputStream* st, double v) {
+   st->print("%f", v);
+ }
+ 
+ void CDSMustMatchFlags::init() {
+   assert(CDSConfig::is_dumping_archive(), "sanity");
+   _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(")"); \
+     log_info(cds)("%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.
  //

*** 232,10 ***
--- 297,11 ---
    }
    _max_heap_size = MaxHeapSize;
    _use_optimized_module_handling = CDSConfig::is_using_optimized_module_handling();
    _has_aot_linked_classes = CDSConfig::is_dumping_aot_linked_classes();
    _has_full_module_graph = CDSConfig::is_dumping_full_module_graph();
+   _has_valhalla_patched_classes = CDSConfig::is_valhalla_preview();
  
    // The following fields are for sanity checks for whether this archive
    // will function correctly with this JVM and the bootclasspath it's
    // invoked with.
  

*** 246,10 ***
--- 312,11 ---
    _verify_remote = BytecodeVerificationRemote;
    _has_platform_or_app_classes = AOTClassLocationConfig::dumptime()->has_platform_or_app_classes();
    _requested_base_address = (char*)SharedBaseAddress;
    _mapped_base_address = (char*)SharedBaseAddress;
    _allow_archiving_with_java_agent = AllowArchivingWithJavaAgent;
+   _must_match.init();
  }
  
  void FileMapHeader::copy_base_archive_name(const char* archive) {
    assert(base_archive_name_size() != 0, "_base_archive_name_size not set");
    assert(base_archive_name_offset() != 0, "_base_archive_name_offset not set");

*** 305,10 ***
--- 372,12 ---
    st->print_cr("- _rw_ptrmap_start_pos:           %zu", _rw_ptrmap_start_pos);
    st->print_cr("- _ro_ptrmap_start_pos:           %zu", _ro_ptrmap_start_pos);
    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("- has_full_module_graph           %d", _has_full_module_graph);
+   st->print_cr("- has_valhalla_patched_classes    %d", _has_valhalla_patched_classes);
+   _must_match.print(st);
    st->print_cr("- has_aot_linked_classes          %d", _has_aot_linked_classes);
  }
  
  bool FileMapInfo::validate_class_location() {
    assert(CDSConfig::is_using_archive(), "runtime only");

*** 688,10 ***
--- 757,14 ---
        log_warning(cds)("The %s has been truncated.", file_type);
        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) {

*** 1928,10 ***
--- 2001,28 ---
      log_warning(cds)("Unable to use %s.\nThe saved state of UseCompressedOops and UseCompressedClassPointers is "
                                 "different from runtime, CDS will be disabled.", file_type);
      return false;
    }
  
+   if (is_static()) {
+     const char* err = nullptr;
+     if (CDSConfig::is_valhalla_preview()) {
+       if (!_has_valhalla_patched_classes) {
+         err = "not created";
+       }
+     } else {
+       if (_has_valhalla_patched_classes) {
+         err = "created";
+       }
+     }
+     if (err != nullptr) {
+       log_warning(cds)("This archive was %s with --enable-preview -XX:+EnableValhalla. It is "
+                          "incompatible with the current JVM setting", err);
+       return false;
+     }
+   }
+ 
    if (compact_headers() != UseCompactObjectHeaders) {
      log_warning(cds)("Unable to use %s.\nThe %s's UseCompactObjectHeaders setting (%s)"
                       " does not equal the current UseCompactObjectHeaders setting (%s).", file_type, file_type,
                       _compact_headers          ? "enabled" : "disabled",
                       UseCompactObjectHeaders   ? "enabled" : "disabled");
< prev index next >