From 8152b3b2d0d16b5f1bfe72c5212f5d00aa51c6d9 Mon Sep 17 00:00:00 2001 From: Boris Ulasevich Date: Fri, 23 Jan 2026 14:15:19 -0300 Subject: [PATCH] Move runtime image check to early VM init Suggested-by: Ioi Lam --- src/hotspot/share/cds/aotClassLocation.cpp | 7 +------ src/hotspot/share/classfile/classLoader.cpp | 4 ++++ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/hotspot/share/cds/aotClassLocation.cpp b/src/hotspot/share/cds/aotClassLocation.cpp index 62fc491a0dd..f77aac3540c 100644 --- a/src/hotspot/share/cds/aotClassLocation.cpp +++ b/src/hotspot/share/cds/aotClassLocation.cpp @@ -965,12 +965,7 @@ bool AOTClassLocationConfig::validate(const char* cache_filename, bool has_aot_l log_locations(cache_filename, /*is_write=*/false); - ClassPathEntry* jrt_entry = ClassLoader::get_jrt_entry(); - if (jrt_entry == nullptr) { - log_warning(class, path)("Runtime image (modules) is unreadable or missing - validation failed"); - return false; - } - const char* jrt = jrt_entry->name(); + const char* jrt = ClassLoader::get_jrt_entry()->name(); log_info(class, path)("Checking [0] (modules image)"); bool success = class_location_at(0)->check(jrt, has_aot_linked_classes); log_info(class, path)("Modules image %s validation: %s", jrt, success ? "passed" : "failed"); diff --git a/src/hotspot/share/classfile/classLoader.cpp b/src/hotspot/share/classfile/classLoader.cpp index 12fbda899b9..f6bba6d9d3e 100644 --- a/src/hotspot/share/classfile/classLoader.cpp +++ b/src/hotspot/share/classfile/classLoader.cpp @@ -1418,6 +1418,10 @@ char* ClassLoader::lookup_vm_options() { jio_snprintf(modules_path, JVM_MAXPATHLEN, "%s%slib%smodules", Arguments::get_java_home(), fileSep, fileSep); JImage_file =(*JImageOpen)(modules_path, &error); if (JImage_file == nullptr) { + if (Arguments::has_jimage()) { + // The modules file exists but is unreadable or corrupt + vm_exit_during_initialization(err_msg("Unable to load %s", modules_path)); + } return nullptr; }