On Tue, 18 Jun 2024 13:41:05 GMT, Erik Österlund <eosterl...@openjdk.org> wrote:
>> src/hotspot/share/prims/jvmtiGetLoadedClasses.cpp line 108: >> >>> 106: // and collect them using the LoadedClassesClosure >>> 107: MutexLocker mcld(ClassLoaderDataGraph_lock); >>> 108: ClassLoaderDataGraph::loaded_classes_do_keepalive(&closure); >> >> This one looks like it might not be safe to exposes without keeping the >> classes alive. > > Looks like we fetch the mirror with Klass::java_mirror() and not > Klass::java_mirror_no_keepalive(). Its tempting to think that java_mirror > will, unlike its evil twin function, keep the mirror alive. However, this > maps to _java_mirror.resolve() vs _java_mirror.peek(). The difference between > these was only a thing in single generation ZGC as the _java_mirror is an > OopHandle with strong references. Single generation ZGC was the only > collector that needed to keep oops alive with strong reference loads - no > other collector does that. > > In summary, unless you use single generation ZGC, we don't seem to keep the > mirrors alive that we expose from here. `ClassLoaderDataGraph::loaded_classes_do_keepalive` is a `keepalive` iteration. That is it will load the holder of the CLD. https://github.com/openjdk/jdk/blob/08366b1244775e5892bbbb184660821e8774f37a/src/hotspot/share/classfile/classLoaderDataGraph.cpp#L328-L335 ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/19769#discussion_r1644738502