< prev index next >

src/hotspot/share/cds/cdsConfig.cpp

Print this page
@@ -1,7 +1,7 @@
  /*
-  * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+  * Copyright (c) 2023, 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.

@@ -29,10 +29,11 @@
  #include "classfile/classLoaderDataShared.hpp"
  #include "classfile/moduleEntry.hpp"
  #include "include/jvm_io.h"
  #include "logging/log.hpp"
  #include "runtime/arguments.hpp"
+ #include "runtime/globals.hpp"
  #include "runtime/java.hpp"
  #include "utilities/defaultStream.hpp"
  
  bool CDSConfig::_is_dumping_static_archive = false;
  bool CDSConfig::_is_dumping_dynamic_archive = false;

@@ -41,10 +42,18 @@
  // is_dumping_full_module_graph(), but can be unconditionally disabled by
  // _dumping_full_module_graph_disabled. (Ditto for loading the FMG).
  bool CDSConfig::_dumping_full_module_graph_disabled = false;
  bool CDSConfig::_loading_full_module_graph_disabled = false;
  
+ bool CDSConfig::_module_patching_disables_cds = false;
+ bool CDSConfig::_java_base_module_patching_disables_cds = false;
+ 
+ bool CDSConfig::is_valhalla_preview() {
+   return Arguments::enable_preview() && EnableValhalla;
+ }
+ 
+ 
  char* CDSConfig::_default_archive_path = nullptr;
  char* CDSConfig::_static_archive_path = nullptr;
  char* CDSConfig::_dynamic_archive_path = nullptr;
  
  void CDSConfig::initialize() {

@@ -70,15 +79,19 @@
      os::jvm_path(jvm_path, sizeof(jvm_path));
      char *end = strrchr(jvm_path, *os::file_separator());
      if (end != nullptr) *end = '\0';
      size_t jvm_path_len = strlen(jvm_path);
      size_t file_sep_len = strlen(os::file_separator());
-     const size_t len = jvm_path_len + file_sep_len + 20;
+     const size_t len = jvm_path_len + file_sep_len + strlen("classes_nocoops_valhalla.jsa") + 1;
      _default_archive_path = NEW_C_HEAP_ARRAY(char, len, mtArguments);
-     jio_snprintf(_default_archive_path, len,
-                 LP64_ONLY(!UseCompressedOops ? "%s%sclasses_nocoops.jsa":) "%s%sclasses.jsa",
-                 jvm_path, os::file_separator());
+     LP64_ONLY(bool nocoops = !UseCompressedOops);
+     NOT_LP64(bool nocoops = false);
+     bool valhalla = is_valhalla_preview();
+     jio_snprintf(_default_archive_path, len, "%s%sclasses%s%s.jsa",
+                 jvm_path, os::file_separator(),
+                  nocoops ? "_nocoops" : "",
+                  valhalla ? "_valhalla" : "");
    }
    return _default_archive_path;
  }
  
  int CDSConfig::num_archives(const char* archive_path) {

@@ -238,16 +251,14 @@
  }
  
  static const char* unsupported_properties[] = {
    "jdk.module.limitmods",
    "jdk.module.upgrade.path",
-   "jdk.module.patch.0"
  };
  static const char* unsupported_options[] = {
    "--limit-modules",
    "--upgrade-module-path",
-   "--patch-module"
  };
  
  void CDSConfig::check_unsupported_dumping_properties() {
    assert(is_dumping_archive(), "this function is only used with CDS dump time");
    assert(ARRAY_SIZE(unsupported_properties) == ARRAY_SIZE(unsupported_options), "must be");

@@ -261,10 +272,16 @@
        }
      }
      sp = sp->next();
    }
  
+   if (module_patching_disables_cds()) {
+     vm_exit_during_initialization(
+             "Cannot use the following option when dumping the shared archive", "--patch-module");
+   }
+ 
+ 
    // Check for an exploded module build in use with -Xshare:dump.
    if (!Arguments::has_jimage()) {
      vm_exit_during_initialization("Dumping the shared archive is not supported with an exploded module build");
    }
  }

@@ -287,14 +304,24 @@
          log_info(cds)("CDS is disabled when the %s option is specified.", unsupported_options[i]);
        }
        return true;
      }
    }
+ 
+   if (module_patching_disables_cds()) {
+     if (RequireSharedSpaces) {
+       warning("CDS is disabled when the %s option is specified.", "--patch-module");
+     } else {
+       log_info(cds)("CDS is disabled when the %s option is specified.", "--patch-module");
+     }
+     return true;
+   }
+ 
    return false;
  }
  
- bool CDSConfig::check_vm_args_consistency(bool patch_mod_javabase,  bool mode_flag_cmd_line) {
+ bool CDSConfig::check_vm_args_consistency(bool mode_flag_cmd_line) {
    if (is_dumping_static_archive()) {
      if (!mode_flag_cmd_line) {
        // By default, -Xshare:dump runs in interpreter-only mode, which is required for deterministic archive.
        //
        // If your classlist is large and you don't care about deterministic dumping, you can use

@@ -335,11 +362,11 @@
        log_warning(cds)("-XX:+AutoCreateSharedArchive does not work with ArchiveClassesAtExit");
        return false;
      }
    }
  
-   if (UseSharedSpaces && patch_mod_javabase) {
+   if (UseSharedSpaces && java_base_module_patching_disables_cds() && module_patching_disables_cds()) {
      Arguments::no_shared_spaces("CDS is disabled when " JAVA_BASE_NAME " module is patched.");
    }
    if (UseSharedSpaces && check_unsupported_cds_runtime_properties()) {
      UseSharedSpaces = false;
    }

@@ -355,10 +382,14 @@
    return true;
  }
  
  #if INCLUDE_CDS_JAVA_HEAP
  bool CDSConfig::is_dumping_heap() {
+   if (is_valhalla_preview()) {
+     // Not working yet -- e.g., HeapShared::oop_hash() needs to be implemented for value oops
+     return false;
+   }
    // heap dump is not supported in dynamic dump
    return is_dumping_static_archive() && HeapShared::can_write();
  }
  
  bool CDSConfig::is_dumping_full_module_graph() {
< prev index next >