We currently keep a reference to the MetaspaceClosure::Ref inside ArchiveBuilder::SourceObjInfo:
https://github.com/openjdk/jdk/blob/6f75dd8741f44b3012c5cab5268e89d09121e4be/src/hotspot/share/cds/archiveBuilder.hpp#L125-L126
ArchiveBuilder uses the Ref::keep_after_pushing() API to tell MetaspaceClosure to keep the Ref alive, even though MetaspaceClosure has finished using it.
This makes the lifecycle convoluted.
The only reason to keep the Ref inside SourceObjInfo is to query Ref::msotype() and Ref::obj(), but we're already cached these values in SourceObjInfo::msotype() and SourceObjInfo::source_addr(). So there's no need to keep the Ref around.
https://github.com/openjdk/jdk/blob/6f75dd8741f44b3012c5cab5268e89d09121e4be/src/hotspot/share/cds/archiveBuilder.hpp#L125-L126
ArchiveBuilder uses the Ref::keep_after_pushing() API to tell MetaspaceClosure to keep the Ref alive, even though MetaspaceClosure has finished using it.
This makes the lifecycle convoluted.
The only reason to keep the Ref inside SourceObjInfo is to query Ref::msotype() and Ref::obj(), but we're already cached these values in SourceObjInfo::msotype() and SourceObjInfo::source_addr(). So there's no need to keep the Ref around.