From bf3f844a9732bbdb775fd24e98bb0cc5782ba377 Mon Sep 17 00:00:00 2001 From: Matias Saavedra Silva Date: Wed, 8 Apr 2026 12:32:50 -0400 Subject: [PATCH 1/4] Archive growable arrays --- src/hotspot/share/cds/aotGrowableArray.cpp | 34 --------- src/hotspot/share/cds/aotGrowableArray.hpp | 76 ------------------- src/hotspot/share/cds/cppVtables.cpp | 6 +- src/hotspot/share/classfile/moduleEntry.cpp | 4 +- src/hotspot/share/classfile/moduleEntry.hpp | 7 +- src/hotspot/share/classfile/packageEntry.cpp | 4 +- src/hotspot/share/classfile/packageEntry.hpp | 3 +- src/hotspot/share/memory/metaspaceClosure.cpp | 6 +- src/hotspot/share/memory/metaspaceClosure.hpp | 19 +++-- .../share/memory/metaspaceClosureType.hpp | 1 + src/hotspot/share/runtime/sharedRuntime.cpp | 5 ++ src/hotspot/share/runtime/sharedRuntime.hpp | 6 +- src/hotspot/share/runtime/signature.hpp | 8 ++ src/hotspot/share/utilities/growableArray.cpp | 7 +- src/hotspot/share/utilities/growableArray.hpp | 11 ++- .../growableArray.inline.hpp} | 12 +-- .../gtest/utilities/test_metaspaceClosure.cpp | 14 ++-- 17 files changed, 68 insertions(+), 155 deletions(-) delete mode 100644 src/hotspot/share/cds/aotGrowableArray.cpp delete mode 100644 src/hotspot/share/cds/aotGrowableArray.hpp rename src/hotspot/share/{cds/aotGrowableArray.inline.hpp => utilities/growableArray.inline.hpp} (76%) diff --git a/src/hotspot/share/cds/aotGrowableArray.cpp b/src/hotspot/share/cds/aotGrowableArray.cpp deleted file mode 100644 index ec63e7aa57f..00000000000 --- a/src/hotspot/share/cds/aotGrowableArray.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2026, 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. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ - -#include "cds/aotGrowableArray.hpp" -#include "cds/aotMetaspace.hpp" -#include "memory/allocation.inline.hpp" -#include "utilities/growableArray.hpp" - -void AOTGrowableArrayHelper::deallocate(void* mem) { - if (!AOTMetaspace::in_aot_cache(mem)) { - GrowableArrayCHeapAllocator::deallocate(mem); - } -} diff --git a/src/hotspot/share/cds/aotGrowableArray.hpp b/src/hotspot/share/cds/aotGrowableArray.hpp deleted file mode 100644 index 0a0c137ed07..00000000000 --- a/src/hotspot/share/cds/aotGrowableArray.hpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2026, 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. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ - -#ifndef SHARE_AOT_AOTGROWABLEARRAY_HPP -#define SHARE_AOT_AOTGROWABLEARRAY_HPP - -#include -#include - -class AOTGrowableArrayHelper { -public: - static void deallocate(void* mem); -}; - -// An AOTGrowableArray provides the same functionality as a GrowableArray that -// uses the C heap allocator. In addition, AOTGrowableArray can be iterated with -// MetaspaceClosure. This type should be used for growable arrays that need to be -// stored in the AOT cache. See ModuleEntry::_reads for an example. -template -class AOTGrowableArray : public GrowableArrayWithAllocator> { - friend class VMStructs; - friend class GrowableArrayWithAllocator; - - static E* allocate(int max, MemTag mem_tag) { - return (E*)GrowableArrayCHeapAllocator::allocate(max, sizeof(E), mem_tag); - } - - E* allocate() { - return allocate(this->_capacity, mtClass); - } - - void deallocate(E* mem) { -#if INCLUDE_CDS - AOTGrowableArrayHelper::deallocate(mem); -#else - GrowableArrayCHeapAllocator::deallocate(mem); -#endif - } - -public: - AOTGrowableArray(int initial_capacity, MemTag mem_tag) : - GrowableArrayWithAllocator( - allocate(initial_capacity, mem_tag), - initial_capacity) {} - - AOTGrowableArray() : AOTGrowableArray(0, mtClassShared) {} - - // methods required by MetaspaceClosure - void metaspace_pointers_do(MetaspaceClosure* it); - int size_in_heapwords() const { return (int)heap_word_size(sizeof(*this)); } - MetaspaceClosureType type() const { return MetaspaceClosureType::GrowableArrayType; } - static bool is_read_only_by_default() { return false; } -}; - -#endif // SHARE_AOT_AOTGROWABLEARRAY_HPP diff --git a/src/hotspot/share/cds/cppVtables.cpp b/src/hotspot/share/cds/cppVtables.cpp index 0bbc28edb4d..64f50327798 100644 --- a/src/hotspot/share/cds/cppVtables.cpp +++ b/src/hotspot/share/cds/cppVtables.cpp @@ -22,7 +22,6 @@ * */ -#include "cds/aotGrowableArray.hpp" #include "cds/aotMetaspace.hpp" #include "cds/archiveBuilder.hpp" #include "cds/archiveUtils.hpp" @@ -45,6 +44,7 @@ #include "oops/typeArrayKlass.hpp" #include "runtime/arguments.hpp" #include "utilities/globalDefinitions.hpp" +#include "utilities/growableArray.hpp" // Objects of the Metadata types (such as Klass and ConstantPool) have C++ vtables. // (In GCC this is the field ::_vptr, i.e., first word in the object.) @@ -62,10 +62,10 @@ #ifndef PRODUCT -// AOTGrowableArray has a vtable only when in non-product builds (due to +// GrowableArray has a vtable only when in non-product builds (due to // the virtual printing functions in AnyObj). -using GrowableArray_ModuleEntry_ptr = AOTGrowableArray; +using GrowableArray_ModuleEntry_ptr = GrowableArray; #define DEBUG_CPP_VTABLE_TYPES_DO(f) \ f(GrowableArray_ModuleEntry_ptr) \ diff --git a/src/hotspot/share/classfile/moduleEntry.cpp b/src/hotspot/share/classfile/moduleEntry.cpp index b5b8aa4ef55..79dd93c4b7e 100644 --- a/src/hotspot/share/classfile/moduleEntry.cpp +++ b/src/hotspot/share/classfile/moduleEntry.cpp @@ -23,7 +23,6 @@ */ #include "cds/aotClassLocation.hpp" -#include "cds/aotGrowableArray.inline.hpp" #include "cds/archiveBuilder.hpp" #include "cds/archiveUtils.hpp" #include "cds/cdsConfig.hpp" @@ -46,6 +45,7 @@ #include "runtime/handles.inline.hpp" #include "runtime/safepoint.hpp" #include "utilities/events.hpp" +#include "utilities/growableArray.inline.hpp" #include "utilities/hashTable.hpp" #include "utilities/ostream.hpp" #include "utilities/quickSort.hpp" @@ -168,7 +168,7 @@ void ModuleEntry::add_read(ModuleEntry* m) { } else { if (reads() == nullptr) { // Lazily create a module's reads list - AOTGrowableArray* new_reads = new (mtModule) AOTGrowableArray(MODULE_READS_SIZE, mtModule); + GrowableArray* new_reads = new (mtModule) GrowableArray(MODULE_READS_SIZE, mtModule); set_reads(new_reads); } diff --git a/src/hotspot/share/classfile/moduleEntry.hpp b/src/hotspot/share/classfile/moduleEntry.hpp index 1a0251a2c2a..10dec73e9fa 100644 --- a/src/hotspot/share/classfile/moduleEntry.hpp +++ b/src/hotspot/share/classfile/moduleEntry.hpp @@ -25,7 +25,6 @@ #ifndef SHARE_CLASSFILE_MODULEENTRY_HPP #define SHARE_CLASSFILE_MODULEENTRY_HPP -#include "cds/aotGrowableArray.hpp" #include "jni.h" #include "memory/metaspaceClosureType.hpp" #include "oops/oopHandle.hpp" @@ -70,7 +69,7 @@ class ModuleEntry : public CHeapObj { // for shared classes from this module Symbol* _name; // name of this module ClassLoaderData* _loader_data; - AOTGrowableArray* _reads; // list of modules that are readable by this module + GrowableArray* _reads; // list of modules that are readable by this module Symbol* _version; // module version number Symbol* _location; // module location @@ -118,10 +117,10 @@ class ModuleEntry : public CHeapObj { bool can_read(ModuleEntry* m) const; bool has_reads_list() const; - AOTGrowableArray* reads() const { + GrowableArray* reads() const { return _reads; } - void set_reads(AOTGrowableArray* r) { + void set_reads(GrowableArray* r) { _reads = r; } void pack_reads() { diff --git a/src/hotspot/share/classfile/packageEntry.cpp b/src/hotspot/share/classfile/packageEntry.cpp index 3e61f2e3a3e..f96d3e92b01 100644 --- a/src/hotspot/share/classfile/packageEntry.cpp +++ b/src/hotspot/share/classfile/packageEntry.cpp @@ -22,7 +22,6 @@ * */ -#include "cds/aotGrowableArray.inline.hpp" #include "cds/aotMetaspace.hpp" #include "cds/archiveBuilder.hpp" #include "cds/archiveUtils.hpp" @@ -40,6 +39,7 @@ #include "runtime/handles.inline.hpp" #include "runtime/java.hpp" #include "utilities/events.hpp" +#include "utilities/growableArray.inline.hpp" #include "utilities/hashTable.hpp" #include "utilities/ostream.hpp" #include "utilities/quickSort.hpp" @@ -83,7 +83,7 @@ void PackageEntry::add_qexport(ModuleEntry* m) { if (!has_qual_exports_list()) { // Lazily create a package's qualified exports list. // Initial size is small, do not anticipate export lists to be large. - _qualified_exports = new (mtModule) AOTGrowableArray(QUAL_EXP_SIZE, mtModule); + _qualified_exports = new (mtModule) GrowableArray(QUAL_EXP_SIZE, mtModule); } // Determine, based on this newly established export to module m, diff --git a/src/hotspot/share/classfile/packageEntry.hpp b/src/hotspot/share/classfile/packageEntry.hpp index 7b174a92287..e064e53b263 100644 --- a/src/hotspot/share/classfile/packageEntry.hpp +++ b/src/hotspot/share/classfile/packageEntry.hpp @@ -25,7 +25,6 @@ #ifndef SHARE_CLASSFILE_PACKAGEENTRY_HPP #define SHARE_CLASSFILE_PACKAGEENTRY_HPP -#include "cds/aotGrowableArray.hpp" #include "classfile/moduleEntry.hpp" #include "memory/metaspaceClosureType.hpp" #include "oops/symbol.hpp" @@ -116,7 +115,7 @@ class PackageEntry : public CHeapObj { bool _must_walk_exports; // Contains list of modules this package is qualifiedly exported to. Access // to this list is protected by the Module_lock. - AOTGrowableArray* _qualified_exports; + GrowableArray* _qualified_exports; JFR_ONLY(DEFINE_TRACE_ID_FIELD;) // Initial size of a package entry's list of qualified exports. diff --git a/src/hotspot/share/memory/metaspaceClosure.cpp b/src/hotspot/share/memory/metaspaceClosure.cpp index 0239eadf692..c2c6c6d762c 100644 --- a/src/hotspot/share/memory/metaspaceClosure.cpp +++ b/src/hotspot/share/memory/metaspaceClosure.cpp @@ -22,11 +22,11 @@ * */ -#include "cds/aotGrowableArray.hpp" #include "classfile/packageEntry.hpp" #include "memory/metaspaceClosure.hpp" #include "oops/array.hpp" #include "oops/instanceKlass.hpp" +#include "utilities/growableArray.hpp" // Sanity checks static_assert(!HAS_METASPACE_POINTERS_DO(int)); @@ -35,8 +35,8 @@ static_assert(HAS_METASPACE_POINTERS_DO(Array)); static_assert(HAS_METASPACE_POINTERS_DO(Array)); static_assert(HAS_METASPACE_POINTERS_DO(InstanceKlass)); static_assert(HAS_METASPACE_POINTERS_DO(PackageEntry)); -static_assert(HAS_METASPACE_POINTERS_DO(AOTGrowableArray)); -static_assert(HAS_METASPACE_POINTERS_DO(AOTGrowableArray)); +static_assert(HAS_METASPACE_POINTERS_DO(GrowableArray)); +static_assert(HAS_METASPACE_POINTERS_DO(GrowableArray)); void MetaspaceClosure::push_impl(MetaspaceClosure::Ref* ref) { if (_enclosing_ref != nullptr) { diff --git a/src/hotspot/share/memory/metaspaceClosure.hpp b/src/hotspot/share/memory/metaspaceClosure.hpp index b6ba69d6f63..b05366d2423 100644 --- a/src/hotspot/share/memory/metaspaceClosure.hpp +++ b/src/hotspot/share/memory/metaspaceClosure.hpp @@ -25,7 +25,6 @@ #ifndef SHARE_MEMORY_METASPACECLOSURE_HPP #define SHARE_MEMORY_METASPACECLOSURE_HPP -#include "cds/aotGrowableArray.hpp" #include "cppstdlib/type_traits.hpp" #include "logging/log.hpp" #include "memory/allocation.hpp" @@ -303,11 +302,11 @@ class MetaspaceClosure { }; //-------------------------------- - // Support for AOTGrowableArray + // Support for GrowableArray //-------------------------------- // Abstract base class for MSOCArrayRef, MSOPointerCArrayRef and OtherCArrayRef. - // These are used for iterating the buffer held by AOTGrowableArray. + // These are used for iterating the buffer held by GrowableArray. template class CArrayRef : public Ref { T** _mpp; int _num_elems; // Number of elements @@ -354,7 +353,7 @@ class MetaspaceClosure { // MSOCArrayRef -- iterate a C array of type T, where T has metaspace_pointer_do(). // We recursively call T::metaspace_pointers_do() for each element in this array. - // This is for supporting AOTGrowableArray. + // This is for supporting GrowableArray. // // E.g., PackageEntry* _pkg_entry_pointers[2]; // a buffer that has 2 PackageEntry objects // ... @@ -377,7 +376,7 @@ class MetaspaceClosure { // MSOPointerCArrayRef -- iterate a C array of type T*, where T has metaspace_pointer_do(). // We recursively call MetaspaceClosure::push() for each pointer in this array. - // This is for supporting AOTGrowableArray. + // This is for supporting GrowableArray. // // E.g., PackageEntry** _pkg_entry_pointers[2]; // a buffer that has 2 PackageEntry pointers // ... @@ -440,11 +439,11 @@ class MetaspaceClosure { // Array*>* a4 = ...; it->push(&a4); => MSOPointerArrayRef // Array* a5 = ...; it->push(&a5); => MSOPointerArrayRef // - // AOTGrowableArrays have a separate "C array" buffer, so they are scanned in two steps: + // GrowableArrays have a separate "C array" buffer, so they are scanned in two steps: // - // AOTGrowableArray* ga1 = ...; it->push(&ga1); => MSORef => OtherCArrayRef - // AOTGrowableArray* ga2 = ...; it->push(&ga2); => MSORef => MSOCArrayRef - // AOTGrowableArray* ga3 = ...; it->push(&ga3); => MSORef => MSOPointerCArrayRef + // GrowableArray* ga1 = ...; it->push(&ga1); => MSORef => OtherCArrayRef + // GrowableArray* ga2 = ...; it->push(&ga2); => MSORef => MSOCArrayRef + // GrowableArray* ga3 = ...; it->push(&ga3); => MSORef => MSOPointerCArrayRef // // Note that the following will fail to compile: // @@ -476,7 +475,7 @@ class MetaspaceClosure { push_with_ref>(mpp, w); } - // --- The buffer of AOTGrowableArray + // --- The buffer of GrowableArray template void push_c_array(T** mpp, int num_elems, Writability w = _default) { push_impl(new OtherCArrayRef(mpp, num_elems, w)); diff --git a/src/hotspot/share/memory/metaspaceClosureType.hpp b/src/hotspot/share/memory/metaspaceClosureType.hpp index adf6805521b..c2c1b500b82 100644 --- a/src/hotspot/share/memory/metaspaceClosureType.hpp +++ b/src/hotspot/share/memory/metaspaceClosureType.hpp @@ -34,6 +34,7 @@ f(GrowableArray) \ f(ModuleEntry) \ f(PackageEntry) \ + f(SigEntry) \ #define METASPACE_CLOSURE_TYPE_DECLARE(name) name ## Type, diff --git a/src/hotspot/share/runtime/sharedRuntime.cpp b/src/hotspot/share/runtime/sharedRuntime.cpp index f3ddedbe98b..6a4f86613c0 100644 --- a/src/hotspot/share/runtime/sharedRuntime.cpp +++ b/src/hotspot/share/runtime/sharedRuntime.cpp @@ -3600,6 +3600,7 @@ void AdapterHandlerEntry::metaspace_pointers_do(MetaspaceClosure* it) { lsh.cr(); } it->push(&_fingerprint); + it->push(&_sig_cc); } AdapterHandlerEntry::~AdapterHandlerEntry() { @@ -4316,3 +4317,7 @@ JRT_BLOCK_ENTRY(void, SharedRuntime::store_inline_type_fields_to_buf(JavaThread* JRT_BLOCK_END; } JRT_END + +void SigEntry::metaspace_pointers_do(MetaspaceClosure* it) { + it->push(&_name); +} diff --git a/src/hotspot/share/runtime/sharedRuntime.hpp b/src/hotspot/share/runtime/sharedRuntime.hpp index d204fd9eb4d..cc64c6abdcb 100644 --- a/src/hotspot/share/runtime/sharedRuntime.hpp +++ b/src/hotspot/share/runtime/sharedRuntime.hpp @@ -734,7 +734,7 @@ class AdapterHandlerEntry : public MetaspaceObj { static const char *_entry_names[]; // Support for scalarized inline type calling convention - const GrowableArray* _sig_cc; + GrowableArray* _sig_cc; #ifdef ASSERT // Captures code and signature used to generate this adapter when @@ -848,8 +848,8 @@ class AdapterHandlerEntry : public MetaspaceObj { bool is_linked() const { return _linked; } // Support for scalarized inline type calling convention - void set_sig_cc(const GrowableArray* sig) { _sig_cc = sig; } - const GrowableArray* get_sig_cc() const { return _sig_cc; } + void set_sig_cc(GrowableArray* sig) { _sig_cc = sig; } + GrowableArray* get_sig_cc() const { return _sig_cc; } uint id() const { return _id; } AdapterFingerPrint* fingerprint() const { return _fingerprint; } diff --git a/src/hotspot/share/runtime/signature.hpp b/src/hotspot/share/runtime/signature.hpp index 20154c9e1f9..3975a288047 100644 --- a/src/hotspot/share/runtime/signature.hpp +++ b/src/hotspot/share/runtime/signature.hpp @@ -28,8 +28,11 @@ #include "classfile/symbolTable.hpp" #include "memory/allocation.hpp" +#include "memory/metaspaceClosureType.hpp" #include "oops/method.hpp" +class MetaspaceClosure; + // Static routines and parsing loops for processing field and method // descriptors. In the HotSpot sources we call them "signatures". // @@ -595,6 +598,11 @@ class SigEntry { static int fill_sig_bt(const GrowableArray* sig, BasicType* sig_bt); static TempNewSymbol create_symbol(const GrowableArray* sig); + void metaspace_pointers_do(MetaspaceClosure* it); + int size_in_heapwords() const { return (int)heap_word_size(sizeof(SigEntry)); } + MetaspaceClosureType type() const { return MetaspaceClosureType::SigEntryType; } + static bool is_read_only_by_default() { return true; } + void print_on(outputStream* st) const; }; diff --git a/src/hotspot/share/utilities/growableArray.cpp b/src/hotspot/share/utilities/growableArray.cpp index 6a1cb0b0414..9cc0813a1f6 100644 --- a/src/hotspot/share/utilities/growableArray.cpp +++ b/src/hotspot/share/utilities/growableArray.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2026, 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 @@ -22,6 +22,7 @@ * */ +#include "cds/aotMetaspace.hpp" #include "memory/allocation.inline.hpp" #include "memory/resourceArea.hpp" #include "runtime/javaThread.hpp" @@ -56,7 +57,9 @@ void* GrowableArrayCHeapAllocator::allocate(int max, int element_size, MemTag me } void GrowableArrayCHeapAllocator::deallocate(void* elements) { - FreeHeap(elements); + if (!AOTMetaspace::in_aot_cache(elements)) { + FreeHeap(elements); + } } #ifdef ASSERT diff --git a/src/hotspot/share/utilities/growableArray.hpp b/src/hotspot/share/utilities/growableArray.hpp index 6a577de111e..798db0da103 100644 --- a/src/hotspot/share/utilities/growableArray.hpp +++ b/src/hotspot/share/utilities/growableArray.hpp @@ -27,6 +27,7 @@ #include "memory/allocation.hpp" #include "memory/iterator.hpp" +#include "memory/metaspaceClosureType.hpp" #include "oops/array.hpp" #include "oops/oop.hpp" #include "utilities/debug.hpp" @@ -34,6 +35,8 @@ #include "utilities/ostream.hpp" #include "utilities/powerOfTwo.hpp" +class MetaspaceClosure; + // A growable array. /*************************************************************************/ @@ -120,7 +123,7 @@ class GrowableArrayView : public GrowableArrayBase { ~GrowableArrayView() {} protected: - // Used by AOTGrowableArray for MetaspaceClosure support. + // Used by GrowableArray for MetaspaceClosure support. E** data_addr() { return &_data; } @@ -830,6 +833,12 @@ class GrowableArray : public GrowableArrayWithAllocator> { this->clear_and_deallocate(); } } + + // methods required by MetaspaceClosure + void metaspace_pointers_do(MetaspaceClosure* it); + int size_in_heapwords() const { return (int)heap_word_size(sizeof(*this)); } + MetaspaceClosureType type() const { return MetaspaceClosureType::GrowableArrayType; } + static bool is_read_only_by_default() { return false; } }; // Leaner GrowableArray for CHeap backed data arrays, with compile-time decided MemTag. diff --git a/src/hotspot/share/cds/aotGrowableArray.inline.hpp b/src/hotspot/share/utilities/growableArray.inline.hpp similarity index 76% rename from src/hotspot/share/cds/aotGrowableArray.inline.hpp rename to src/hotspot/share/utilities/growableArray.inline.hpp index 8c6e8cb6503..70cdc7383d7 100644 --- a/src/hotspot/share/cds/aotGrowableArray.inline.hpp +++ b/src/hotspot/share/utilities/growableArray.inline.hpp @@ -22,16 +22,16 @@ * */ -#ifndef SHARE_CDS_AOTGROWABLEARRAY_INLINE_HPP -#define SHARE_CDS_AOTGROWABLEARRAY_INLINE_HPP +#ifndef SHARE_UTILITIES_GROWABLEARRAY_INLINE_HPP +#define SHARE_UTILITIES_GROWABLEARRAY_INLINE_HPP -#include "cds/aotGrowableArray.hpp" +#include "utilities/growableArray.hpp" #include "memory/metaspaceClosure.hpp" template -void AOTGrowableArray::metaspace_pointers_do(MetaspaceClosure* it) { - it->push_c_array(AOTGrowableArray::data_addr(), AOTGrowableArray::capacity()); +void GrowableArray::metaspace_pointers_do(MetaspaceClosure* it) { + it->push_c_array(GrowableArray::data_addr(), GrowableArray::capacity()); } -#endif // SHARE_CDS_AOTGROWABLEARRAY_INLINE_HPP +#endif // SHARE_UTILITIES_GROWABLEARRAY_INLINE_HPP diff --git a/test/hotspot/gtest/utilities/test_metaspaceClosure.cpp b/test/hotspot/gtest/utilities/test_metaspaceClosure.cpp index c98b38b8c3c..b310daed633 100644 --- a/test/hotspot/gtest/utilities/test_metaspaceClosure.cpp +++ b/test/hotspot/gtest/utilities/test_metaspaceClosure.cpp @@ -21,13 +21,13 @@ * questions. */ -#include "cds/aotGrowableArray.inline.hpp" #include "memory/allocation.hpp" #include "memory/metadataFactory.hpp" #include "memory/metaspaceClosure.hpp" #include "oops/array.hpp" #include "oops/metadata.hpp" #include "runtime/javaThread.hpp" +#include "utilities/growableArray.inline.hpp" #include "unittest.hpp" class MyMetaData : public MetaspaceObj { @@ -168,9 +168,9 @@ TEST_VM(MetaspaceClosure, OtherArrayRef) { EXPECT_TRUE(closure.has_visited(array)) << "must be"; } -// iterate an AOTGrowableArray +// iterate an GrowableArray TEST_VM(MetaspaceClosure, GrowableArray_MSOPointer) { - AOTGrowableArray* array = new(mtClass) AOTGrowableArray(2, mtClass); + GrowableArray* array = new(mtClass) GrowableArray(2, mtClass); MyMetaData x; MyMetaData y; @@ -190,9 +190,9 @@ TEST_VM(MetaspaceClosure, GrowableArray_MSOPointer) { EXPECT_TRUE(closure.has_visited(&z)) << "must be"; } -// iterate an AOTGrowableArray +// iterate an GrowableArray TEST_VM(MetaspaceClosure, GrowableArray_MSO) { - AOTGrowableArray* array = new(mtClass) AOTGrowableArray(4, mtClass); + GrowableArray* array = new(mtClass) GrowableArray(4, mtClass); for (int i = 0; i < array->length(); i++) { EXPECT_TRUE(array->at(i)._a == nullptr) << "should be initialized to null"; @@ -218,9 +218,9 @@ TEST_VM(MetaspaceClosure, GrowableArray_MSO) { EXPECT_TRUE(closure.has_visited(&z)) << "must be"; } -// iterate an AOTGrowableArray +// iterate an GrowableArray TEST_VM(MetaspaceClosure, GrowableArray_jlong) { - AOTGrowableArray* array = new(mtClass) AOTGrowableArray(4, mtClass); + GrowableArray* array = new(mtClass) GrowableArray(4, mtClass); MyUniqueMetaspaceClosure closure; closure.push(&array); From d2435f3f18cbee3a41db553faf0a173125c3b2b3 Mon Sep 17 00:00:00 2001 From: Matias Saavedra Silva Date: Wed, 8 Apr 2026 16:06:28 -0400 Subject: [PATCH 2/4] Archive sig_cc --- src/hotspot/share/cds/cppVtables.cpp | 2 ++ src/hotspot/share/runtime/sharedRuntime.cpp | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/hotspot/share/cds/cppVtables.cpp b/src/hotspot/share/cds/cppVtables.cpp index 64f50327798..7905b4d938b 100644 --- a/src/hotspot/share/cds/cppVtables.cpp +++ b/src/hotspot/share/cds/cppVtables.cpp @@ -66,9 +66,11 @@ // the virtual printing functions in AnyObj). using GrowableArray_ModuleEntry_ptr = GrowableArray; +using GrowableArray_SigEntry = GrowableArray; #define DEBUG_CPP_VTABLE_TYPES_DO(f) \ f(GrowableArray_ModuleEntry_ptr) \ + f(GrowableArray_SigEntry) \ #endif diff --git a/src/hotspot/share/runtime/sharedRuntime.cpp b/src/hotspot/share/runtime/sharedRuntime.cpp index 6a4f86613c0..742d1fbc68b 100644 --- a/src/hotspot/share/runtime/sharedRuntime.cpp +++ b/src/hotspot/share/runtime/sharedRuntime.cpp @@ -90,6 +90,7 @@ #include "utilities/events.hpp" #include "utilities/exceptions.hpp" #include "utilities/globalDefinitions.hpp" +#include "utilities/growableArray.inline.hpp" #include "utilities/hashTable.hpp" #include "utilities/macros.hpp" #include "utilities/xmlstream.hpp" @@ -3415,7 +3416,6 @@ void AdapterHandlerEntry::remove_unshareable_info() { #endif // ASSERT _adapter_blob = nullptr; _linked = false; - _sig_cc = nullptr; } class CopyAdapterTableToArchive : StackObj { @@ -3503,6 +3503,7 @@ void AdapterHandlerEntry::link() { CompiledEntrySignature ces; ces.initialize_from_fingerprint(_fingerprint); if (ces.has_scalarized_args()) { + fatal("Calling conventions should have been archived"); // Save a C heap allocated version of the scalarized signature and store it in the adapter GrowableArray* heap_sig = new (mtInternal) GrowableArray(ces.sig_cc()->length(), mtInternal); heap_sig->appendAll(ces.sig_cc()); From fd81dd272e6bb24dc15195cae76b9232a4c041b9 Mon Sep 17 00:00:00 2001 From: Matias Saavedra Silva Date: Mon, 20 Apr 2026 17:45:51 -0400 Subject: [PATCH 3/4] Merge conflict --- src/hotspot/share/classfile/moduleEntry.cpp | 1 - src/hotspot/share/classfile/packageEntry.cpp | 1 - src/hotspot/share/utilities/growableArray.hpp | 9 ---- .../share/utilities/growableArray.inline.hpp | 45 ------------------- test/setup_aot/HelloWorld.java | 16 ------- 5 files changed, 72 deletions(-) delete mode 100644 src/hotspot/share/utilities/growableArray.inline.hpp diff --git a/src/hotspot/share/classfile/moduleEntry.cpp b/src/hotspot/share/classfile/moduleEntry.cpp index 79dd93c4b7e..c7fadeaea9b 100644 --- a/src/hotspot/share/classfile/moduleEntry.cpp +++ b/src/hotspot/share/classfile/moduleEntry.cpp @@ -45,7 +45,6 @@ #include "runtime/handles.inline.hpp" #include "runtime/safepoint.hpp" #include "utilities/events.hpp" -#include "utilities/growableArray.inline.hpp" #include "utilities/hashTable.hpp" #include "utilities/ostream.hpp" #include "utilities/quickSort.hpp" diff --git a/src/hotspot/share/classfile/packageEntry.cpp b/src/hotspot/share/classfile/packageEntry.cpp index f96d3e92b01..3eb50fcb5a7 100644 --- a/src/hotspot/share/classfile/packageEntry.cpp +++ b/src/hotspot/share/classfile/packageEntry.cpp @@ -39,7 +39,6 @@ #include "runtime/handles.inline.hpp" #include "runtime/java.hpp" #include "utilities/events.hpp" -#include "utilities/growableArray.inline.hpp" #include "utilities/hashTable.hpp" #include "utilities/ostream.hpp" #include "utilities/quickSort.hpp" diff --git a/src/hotspot/share/utilities/growableArray.hpp b/src/hotspot/share/utilities/growableArray.hpp index f04fc30b7ef..c97114347ac 100644 --- a/src/hotspot/share/utilities/growableArray.hpp +++ b/src/hotspot/share/utilities/growableArray.hpp @@ -27,7 +27,6 @@ #include "memory/allocation.hpp" #include "memory/iterator.hpp" -#include "memory/metaspaceClosureType.hpp" #include "oops/array.hpp" #include "oops/oop.hpp" #include "utilities/debug.hpp" @@ -35,8 +34,6 @@ #include "utilities/ostream.hpp" #include "utilities/powerOfTwo.hpp" -class MetaspaceClosure; - // A growable array. /*************************************************************************/ @@ -122,12 +119,6 @@ class GrowableArrayView : public GrowableArrayBase { ~GrowableArrayView() {} -protected: - // Used by GrowableArray for MetaspaceClosure support. - E** data_addr() { - return &_data; - } - public: bool operator==(const GrowableArrayView& rhs) const { if (_len != rhs._len) diff --git a/src/hotspot/share/utilities/growableArray.inline.hpp b/src/hotspot/share/utilities/growableArray.inline.hpp deleted file mode 100644 index 53ef6bcad41..00000000000 --- a/src/hotspot/share/utilities/growableArray.inline.hpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2026, 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. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ - -<<<<<<<< HEAD:src/hotspot/share/utilities/growableArray.inline.hpp -#ifndef SHARE_UTILITIES_GROWABLEARRAY_INLINE_HPP -#define SHARE_UTILITIES_GROWABLEARRAY_INLINE_HPP - -#include "utilities/growableArray.hpp" - -#include "memory/metaspaceClosure.hpp" - -template -void GrowableArray::metaspace_pointers_do(MetaspaceClosure* it) { - it->push_c_array(GrowableArray::data_addr(), GrowableArray::capacity()); -} - -#endif // SHARE_UTILITIES_GROWABLEARRAY_INLINE_HPP -======== -public class HelloWorld { - public static void main(String args[]) { - System.out.println("HelloWorld"); - } -} ->>>>>>>> 00f5e960c8d0862d102f9011496b33f332596e4b:test/setup_aot/HelloWorld.java diff --git a/test/setup_aot/HelloWorld.java b/test/setup_aot/HelloWorld.java index 53ef6bcad41..e243dfb4e8e 100644 --- a/test/setup_aot/HelloWorld.java +++ b/test/setup_aot/HelloWorld.java @@ -22,24 +22,8 @@ * */ -<<<<<<<< HEAD:src/hotspot/share/utilities/growableArray.inline.hpp -#ifndef SHARE_UTILITIES_GROWABLEARRAY_INLINE_HPP -#define SHARE_UTILITIES_GROWABLEARRAY_INLINE_HPP - -#include "utilities/growableArray.hpp" - -#include "memory/metaspaceClosure.hpp" - -template -void GrowableArray::metaspace_pointers_do(MetaspaceClosure* it) { - it->push_c_array(GrowableArray::data_addr(), GrowableArray::capacity()); -} - -#endif // SHARE_UTILITIES_GROWABLEARRAY_INLINE_HPP -======== public class HelloWorld { public static void main(String args[]) { System.out.println("HelloWorld"); } } ->>>>>>>> 00f5e960c8d0862d102f9011496b33f332596e4b:test/setup_aot/HelloWorld.java From 1e4c4d761b1cfea6bb4c11972007942352ac2856 Mon Sep 17 00:00:00 2001 From: Matias Saavedra Silva Date: Tue, 21 Apr 2026 11:34:01 -0400 Subject: [PATCH 4/4] Removed calling convention recalculation --- src/hotspot/share/runtime/sharedRuntime.cpp | 21 +------------------ src/hotspot/share/runtime/sharedRuntime.hpp | 10 ++++----- .../gtest/utilities/test_metaspaceClosure.cpp | 1 - 3 files changed, 6 insertions(+), 26 deletions(-) diff --git a/src/hotspot/share/runtime/sharedRuntime.cpp b/src/hotspot/share/runtime/sharedRuntime.cpp index aa56718f3a8..36f7b89637b 100644 --- a/src/hotspot/share/runtime/sharedRuntime.cpp +++ b/src/hotspot/share/runtime/sharedRuntime.cpp @@ -90,7 +90,6 @@ #include "utilities/events.hpp" #include "utilities/exceptions.hpp" #include "utilities/globalDefinitions.hpp" -#include "utilities/growableArray.inline.hpp" #include "utilities/hashTable.hpp" #include "utilities/macros.hpp" #include "utilities/xmlstream.hpp" @@ -3425,7 +3424,6 @@ void AdapterHandlerEntry::remove_unshareable_info() { #endif // ASSERT _adapter_blob = nullptr; _linked = false; - _sig_cc_ro = nullptr; } class CopyAdapterTableToArchive : StackObj { @@ -3505,24 +3503,6 @@ void AdapterHandlerEntry::link() { log_warning(aot)("Failed to link AdapterHandlerEntry (fp=%s) to its code in the AOT code cache", _fingerprint->as_basic_args_string()); generate_code = true; } - - if (get_sig_cc() == nullptr) { - // Calling conventions have to be regenerated at runtime and are accessed through method adapters, - // which are archived in the AOT code cache. If the adapters are not regenerated, the - // calling conventions should be regenerated here. - CompiledEntrySignature ces; - ces.initialize_from_fingerprint(_fingerprint); - if (ces.has_scalarized_args()) { - fatal("Calling conventions should have been archived"); - // Save a C heap allocated version of the scalarized signature and store it in the adapter - GrowableArray* heap_sig = new (mtInternal) GrowableArray(ces.sig_cc()->length(), mtInternal); - heap_sig->appendAll(ces.sig_cc()); - set_sig_cc(heap_sig); - heap_sig = new (mtInternal) GrowableArray(ces.sig_cc_ro()->length(), mtInternal); - heap_sig->appendAll(ces.sig_cc_ro()); - set_sig_cc_ro(heap_sig); - } - } } else { generate_code = true; } @@ -3615,6 +3595,7 @@ void AdapterHandlerEntry::metaspace_pointers_do(MetaspaceClosure* it) { } it->push(&_fingerprint); it->push(&_sig_cc); + it->push(&_sig_cc_ro); } AdapterHandlerEntry::~AdapterHandlerEntry() { diff --git a/src/hotspot/share/runtime/sharedRuntime.hpp b/src/hotspot/share/runtime/sharedRuntime.hpp index 04034f96953..2b1919bd890 100644 --- a/src/hotspot/share/runtime/sharedRuntime.hpp +++ b/src/hotspot/share/runtime/sharedRuntime.hpp @@ -735,7 +735,7 @@ class AdapterHandlerEntry : public MetaspaceObj { // Support for scalarized inline type calling convention GrowableArray* _sig_cc; - const GrowableArray* _sig_cc_ro; + GrowableArray* _sig_cc_ro; #ifdef ASSERT // Captures code and signature used to generate this adapter when @@ -850,16 +850,16 @@ class AdapterHandlerEntry : public MetaspaceObj { bool is_linked() const { return _linked; } // Support for scalarized inline type calling convention - void set_sig_cc(const GrowableArray* sig) { + void set_sig_cc(GrowableArray* sig) { assert(_sig_cc == nullptr, "Already initialized"); _sig_cc = sig; } - const GrowableArray* get_sig_cc() const { return _sig_cc; } - void set_sig_cc_ro(const GrowableArray* sig) { + GrowableArray* get_sig_cc() const { return _sig_cc; } + void set_sig_cc_ro(GrowableArray* sig) { assert(_sig_cc_ro == nullptr, "Already initialized"); _sig_cc_ro = sig; } - const GrowableArray* get_sig_cc_ro() const { return _sig_cc_ro; } + GrowableArray* get_sig_cc_ro() const { return _sig_cc_ro; } uint id() const { return _id; } AdapterFingerPrint* fingerprint() const { return _fingerprint; } diff --git a/test/hotspot/gtest/utilities/test_metaspaceClosure.cpp b/test/hotspot/gtest/utilities/test_metaspaceClosure.cpp index b310daed633..091767cc273 100644 --- a/test/hotspot/gtest/utilities/test_metaspaceClosure.cpp +++ b/test/hotspot/gtest/utilities/test_metaspaceClosure.cpp @@ -27,7 +27,6 @@ #include "oops/array.hpp" #include "oops/metadata.hpp" #include "runtime/javaThread.hpp" -#include "utilities/growableArray.inline.hpp" #include "unittest.hpp" class MyMetaData : public MetaspaceObj {