RFR: 8353225: Add a way to iterate Klass inside the loaded CDS archive

Leonid Mesnik lmesnik at openjdk.org
Thu Apr 3 22:04:51 UTC 2025


On Sat, 29 Mar 2025 07:53:37 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:

> Please consider.
> 
> This patch adds a way to iterate all Klass structures in the loaded CDS archive (`SystemDictionaryShared::iterate_klasses_in_shared_archive(ConstKlassClosure* klassClosure, bool is_static);`). This uses the same mechanism that `PrintSharedArchiveAndExit` uses. I  need this mechanism for some future GC work.
> 
> Then, it re-implements `PrintSharedArchiveAndExit` to reuse the new iteration API instead. This also serves as a way to test, since there are pre-existing tests for this flag.
> 
> It also adds a new, rather basic, gtest.
> 
> Finally, the new gtest picked up a small pre-existing bug in the implementation of `PrintSharedArchiveAndExit`: it prints all array classes of all InstanceKlass inside the archive, for all dimensions, without testing if that array class is part of the archive. The array class may have been created dynamically, however. The patch fixes that.
> 
> ----
> 
> Testing:
> - I ensured that the output of `PrintSharedArchiveAndExit`, before and after this patch, are identical apart from the small error fix concerning array classes
> - I ran all runtime/cds tests on Linux x64
> - GHAs

Changes requested by lmesnik (Reviewer).

test/hotspot/gtest/cds/test_klass_iteration.cpp line 57:

> 55:   ASSERT_GT(cl_static._c, 0);
> 56: 
> 57:   SystemDictionaryShared::iterate_klasses_in_shared_archive(&cl_static, false);

Shouldn't it be cl_dynamic here? Can it be zero or assertion is missed ?

-------------

PR Review: https://git.openjdk.org/jdk/pull/24311#pullrequestreview-2741286330
PR Review Comment: https://git.openjdk.org/jdk/pull/24311#discussion_r2027805073


More information about the hotspot-runtime-dev mailing list