From 3a8c8e5b7a0ad3b96a3399ec47578921841d663a Mon Sep 17 00:00:00 2001 From: Vladimir Kozlov Date: Thu, 12 Jun 2025 07:17:26 -0700 Subject: [PATCH] 8358738: AOT cache created without graal jit should not be used with graal jit --- src/hotspot/share/cds/filemap.cpp | 35 +++++++++++++++++++++++++++++++ src/hotspot/share/cds/filemap.hpp | 1 + 2 files changed, 36 insertions(+) diff --git a/src/hotspot/share/cds/filemap.cpp b/src/hotspot/share/cds/filemap.cpp index a413aa2d8e8..df2e48a274b 100644 --- a/src/hotspot/share/cds/filemap.cpp +++ b/src/hotspot/share/cds/filemap.cpp @@ -44,6 +44,7 @@ #include "classfile/systemDictionaryShared.hpp" #include "classfile/vmClasses.hpp" #include "classfile/vmSymbols.hpp" +#include "compiler/compilerDefinitions.inline.hpp" #include "jvm.h" #include "logging/log.hpp" #include "logging/logMessage.hpp" @@ -232,6 +233,15 @@ void FileMapHeader::populate(FileMapInfo *info, size_t core_region_alignment, } else { _narrow_klass_pointer_bits = _narrow_klass_shift = -1; } + // Which JIT compier is used + _compiler_type = (u1)CompilerType::compiler_none; // Interpreter only + if (CompilerConfig::is_c2_enabled()) { + _compiler_type = (u1)CompilerType::compiler_c2; + } else if (CompilerConfig::is_jvmci_compiler_enabled()) { + _compiler_type = (u1)CompilerType::compiler_jvmci; + } else if (CompilerConfig::is_c1_enabled()) { + _compiler_type = (u1)CompilerType::compiler_c1; + } _type_profile_level = TypeProfileLevel; _type_profile_args_limit = TypeProfileArgsLimit; _type_profile_parms_limit = TypeProfileParmsLimit; @@ -1935,6 +1945,31 @@ bool FileMapHeader::validate() { CompactStrings ? "enabled" : "disabled"); return false; } + bool jvmci_compiler_is_enabled = CompilerConfig::is_jvmci_compiler_enabled(); + CompilerType compiler_type = CompilerType::compiler_none; // Interpreter only + if (CompilerConfig::is_c2_enabled()) { + compiler_type = CompilerType::compiler_c2; + } else if (jvmci_compiler_is_enabled) { + compiler_type = CompilerType::compiler_jvmci; + } else if (CompilerConfig::is_c1_enabled()) { + compiler_type = CompilerType::compiler_c1; + } + CompilerType archive_compiler_type = CompilerType(_compiler_type); + // JVMCI compiler loads additional jdk.internal.vm.ci module, + // does different type profiling settigns and generate + // different code. We can't use archive which was produced + // without it and reverse. + // Only allow mix when JIT compilation is disabled. + // Interpreter is used by default when dumping archive. + bool intepreter_is_used = (archive_compiler_type == CompilerType::compiler_none) || + (compiler_type == CompilerType::compiler_none); + if (!intepreter_is_used && + jvmci_compiler_is_enabled != (archive_compiler_type == CompilerType::compiler_jvmci)) { + MetaspaceShared::report_loading_error("The %s's JIT compiler setting (%s)" + " does not equal the current setting (%s).", file_type, + compilertype2name(archive_compiler_type), compilertype2name(compiler_type)); + return false; + } if (TrainingData::have_data()) { if (_type_profile_level != TypeProfileLevel) { MetaspaceShared::report_loading_error("The %s's TypeProfileLevel setting (%d)" diff --git a/src/hotspot/share/cds/filemap.hpp b/src/hotspot/share/cds/filemap.hpp index e0b33fc8245..02390874f39 100644 --- a/src/hotspot/share/cds/filemap.hpp +++ b/src/hotspot/share/cds/filemap.hpp @@ -147,6 +147,7 @@ private: size_t _ro_ptrmap_start_pos; // The first bit in the ptrmap corresponds to this position in the ro region // The following are parameters that affect MethodData layout. + u1 _compiler_type; uint _type_profile_level; int _type_profile_args_limit; int _type_profile_parms_limit;