From 137d97131bc044fa090b88eab767913d690bb2e2 Mon Sep 17 00:00:00 2001 From: Vladimir Kozlov Date: Fri, 20 Mar 2026 20:18:12 +0000 Subject: [PATCH] 8378935: C2 crash in PhaseOutput::fill_buffer: wrong size of mach node Reviewed-by: iklam, asmehra --- src/hotspot/share/cds/aotMetaspace.cpp | 4 +-- src/hotspot/share/cds/cdsConfig.cpp | 4 +-- src/hotspot/share/code/aotCodeCache.cpp | 45 +++---------------------- src/hotspot/share/code/aotCodeCache.hpp | 9 ++--- 4 files changed, 10 insertions(+), 52 deletions(-) diff --git a/src/hotspot/share/cds/aotMetaspace.cpp b/src/hotspot/share/cds/aotMetaspace.cpp index b75d7628aa9..5e75cd72778 100644 --- a/src/hotspot/share/cds/aotMetaspace.cpp +++ b/src/hotspot/share/cds/aotMetaspace.cpp @@ -1187,8 +1187,8 @@ void AOTMetaspace::dump_static_archive_impl(StaticArchiveBuilder& builder, TRAPS CDSConfig::enable_dumping_aot_code(); { builder.start_ac_region(); - // Write the contents to AOT code region and close AOTCodeCache before packing the region - AOTCodeCache::close(); + // Write the contents to AOT code region before packing the region + AOTCodeCache::dump(); builder.end_ac_region(); } CDSConfig::disable_dumping_aot_code(); diff --git a/src/hotspot/share/cds/cdsConfig.cpp b/src/hotspot/share/cds/cdsConfig.cpp index f4ef3c66f7a..d8ae50517fe 100644 --- a/src/hotspot/share/cds/cdsConfig.cpp +++ b/src/hotspot/share/cds/cdsConfig.cpp @@ -108,6 +108,8 @@ void CDSConfig::ergo_initialize() { } AOTMapLogger::ergo_initialize(); + + setup_compiler_args(); } const char* CDSConfig::default_archive_path() { @@ -635,8 +637,6 @@ bool CDSConfig::check_vm_args_consistency(bool patch_mod_javabase, bool mode_fla FLAG_SET_ERGO_IF_DEFAULT(AOTClassLinking, true); } - setup_compiler_args(); - if (AOTClassLinking) { // If AOTClassLinking is specified, enable all AOT optimizations by default. FLAG_SET_ERGO_IF_DEFAULT(AOTInvokeDynamicLinking, true); diff --git a/src/hotspot/share/code/aotCodeCache.cpp b/src/hotspot/share/code/aotCodeCache.cpp index e5f68afc51d..b29cf906736 100644 --- a/src/hotspot/share/code/aotCodeCache.cpp +++ b/src/hotspot/share/code/aotCodeCache.cpp @@ -284,11 +284,11 @@ bool AOTCodeCache::open_cache(bool is_dumping, bool is_using) { return true; } -void AOTCodeCache::close() { +void AOTCodeCache::dump() { if (is_on()) { - delete _cache; // Free memory - _cache = nullptr; - opened_cache = nullptr; + assert(is_on_for_dump(), "should be called only when dumping AOT code"); + MutexLocker ml(Compile_lock); + _cache->finish_write(); } } @@ -304,7 +304,6 @@ AOTCodeCache::AOTCodeCache(bool is_dumping, bool is_using) : _store_size(0), _for_use(is_using), _for_dump(is_dumping), - _closing(false), _failed(false), _lookup_failed(false), _table(nullptr), @@ -381,30 +380,6 @@ void AOTCodeCache::init_early_c1_table() { } } -AOTCodeCache::~AOTCodeCache() { - if (_closing) { - return; // Already closed - } - // Stop any further access to cache. - _closing = true; - - MutexLocker ml(Compile_lock); - if (for_dump()) { // Finalize cache - finish_write(); - } - _load_buffer = nullptr; - if (_C_store_buffer != nullptr) { - FREE_C_HEAP_ARRAY(char, _C_store_buffer); - _C_store_buffer = nullptr; - _store_buffer = nullptr; - } - if (_table != nullptr) { - MutexLocker ml(AOTCodeCStrings_lock, Mutex::_no_safepoint_check_flag); - delete _table; - _table = nullptr; - } -} - void AOTCodeCache::Config::record(uint cpu_features_offset) { _flags = 0; #ifdef ASSERT @@ -1545,18 +1520,6 @@ void AOTCodeAddressTable::init_early_c1() { #undef SET_ADDRESS -AOTCodeAddressTable::~AOTCodeAddressTable() { - if (_extrs_addr != nullptr) { - FREE_C_HEAP_ARRAY(address, _extrs_addr); - } - if (_stubs_addr != nullptr) { - FREE_C_HEAP_ARRAY(address, _stubs_addr); - } - if (_shared_blobs_addr != nullptr) { - FREE_C_HEAP_ARRAY(address, _shared_blobs_addr); - } -} - #ifdef PRODUCT #define MAX_STR_COUNT 200 #else diff --git a/src/hotspot/share/code/aotCodeCache.hpp b/src/hotspot/share/code/aotCodeCache.hpp index 85f8b47920f..bd8721fea8c 100644 --- a/src/hotspot/share/code/aotCodeCache.hpp +++ b/src/hotspot/share/code/aotCodeCache.hpp @@ -152,7 +152,6 @@ public: _early_c1_complete(false), _complete(false) { } - ~AOTCodeAddressTable(); void init_extrs(); void init_early_stubs(); void init_shared_blobs(); @@ -260,7 +259,6 @@ private: uint _store_size; // Used when writing cache bool _for_use; // AOT cache is open for using AOT code bool _for_dump; // AOT cache is open for dumping AOT code - bool _closing; // Closing cache file bool _failed; // Failed read/write to/from cache (cache is broken?) bool _lookup_failed; // Failed to lookup for info (skip only this code load) @@ -290,7 +288,6 @@ private: public: AOTCodeCache(bool is_dumping, bool is_using); - ~AOTCodeCache(); const char* cache_buffer() const { return _load_buffer; } bool failed() const { return _failed; } @@ -314,8 +311,6 @@ public: bool for_use() const { return _for_use && !_failed; } bool for_dump() const { return _for_dump && !_failed; } - bool closing() const { return _closing; } - AOTCodeEntry* add_entry() { _store_entries_cnt++; _store_entries -= 1; @@ -375,8 +370,8 @@ public: static AOTCodeCache* cache() { assert(_passed_init2, "Too early to ask"); return _cache; } static void initialize() NOT_CDS_RETURN; static void init2() NOT_CDS_RETURN; - static void close() NOT_CDS_RETURN; - static bool is_on() CDS_ONLY({ return cache() != nullptr && !_cache->closing(); }) NOT_CDS_RETURN_(false); + static void dump() NOT_CDS_RETURN; + static bool is_on() CDS_ONLY({ return cache() != nullptr; }) NOT_CDS_RETURN_(false); static bool is_on_for_use() CDS_ONLY({ return is_on() && _cache->for_use(); }) NOT_CDS_RETURN_(false); static bool is_on_for_dump() CDS_ONLY({ return is_on() && _cache->for_dump(); }) NOT_CDS_RETURN_(false); static bool is_dumping_stub() NOT_CDS_RETURN_(false);