< prev index next >

src/hotspot/share/cds/filemap.cpp

Print this page
*** 1,7 ***
  /*
!  * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.
--- 1,7 ---
  /*
!  * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.

*** 79,10 ***
--- 79,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(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() {
+   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.
  //

*** 212,11 ***
    _compressed_oops = UseCompressedOops;
    _compressed_class_ptrs = UseCompressedClassPointers;
    _max_heap_size = MaxHeapSize;
    _use_optimized_module_handling = MetaspaceShared::use_optimized_module_handling();
    _has_full_module_graph = CDSConfig::is_dumping_full_module_graph();
! 
    // The following fields are for sanity checks for whether this archive
    // will function correctly with this JVM and the bootclasspath it's
    // invoked with.
  
    // JVM version string ... changes on each build.
--- 277,11 ---
    _compressed_oops = UseCompressedOops;
    _compressed_class_ptrs = UseCompressedClassPointers;
    _max_heap_size = MaxHeapSize;
    _use_optimized_module_handling = MetaspaceShared::use_optimized_module_handling();
    _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.
  
    // JVM version string ... changes on each build.

*** 232,10 ***
--- 297,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 (!CDSConfig::is_dumping_dynamic_archive()) {
      set_shared_path_table(info->_shared_path_table);
    }
  }

*** 290,11 ***
--- 356,13 ---
    st->print_cr("- mapped_base_address:            " INTPTR_FORMAT, p2i(_mapped_base_address));
    st->print_cr("- heap_roots_offset:              " SIZE_FORMAT, _heap_roots_offset);
    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);
    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);

*** 1341,10 ***
--- 1409,14 ---
        log_warning(cds)("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) {

*** 2380,10 ***
--- 2452,28 ---
      log_info(cds)("Unable to use shared archive.\nThe saved state of UseCompressedOops and UseCompressedClassPointers is "
                                 "different from runtime, CDS will be disabled.");
      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 (!_use_optimized_module_handling) {
      MetaspaceShared::disable_optimized_module_handling();
      log_info(cds)("optimized module handling: disabled because archive was created without optimized module handling");
    }
  
< prev index next >