As of JDK 21, jdk.jfr.internal.TypeLibrary#initialize() unconditionally initializes TypeLibary. If TypeLibary is initialized more than once, there is the potential for things to break. This is because initialization results in adding elements to jdk.jfr.internal.Type#fields which may have already been changed to an unmodifiableList after the initial initialization of TypeLibrary. (see attached stacktrace). This suggests that TypeLibrary is only intended to be initialized once.
This is of concern for JFR support in GraalVM Native Image. Specifically, multiple initializations of TypeLibrary breaks the ability to use JFR at native image built time. This is because, if JFR is used at image build time, the data of a few of the JFR singletons such as MetadataRepository must be re-initialized for runtime recordings to start with a "clean-slate". However, re-initializing MetadataRepository, also has the effect of calling TypeLibrary#initialize() which unconditionally attempts to initialize TypeRepository, resulting in errors.
It would be good if the previous behavior of TypeLibrary#initialize() could be re-implemented. A simple check whether the TypeLibrary is already initialized should be enough to fix the problem.
This is of concern for JFR support in GraalVM Native Image. Specifically, multiple initializations of TypeLibrary breaks the ability to use JFR at native image built time. This is because, if JFR is used at image build time, the data of a few of the JFR singletons such as MetadataRepository must be re-initialized for runtime recordings to start with a "clean-slate". However, re-initializing MetadataRepository, also has the effect of calling TypeLibrary#initialize() which unconditionally attempts to initialize TypeRepository, resulting in errors.
It would be good if the previous behavior of TypeLibrary#initialize() could be re-implemented. A simple check whether the TypeLibrary is already initialized should be enough to fix the problem.
- relates to
-
JDK-8303674 JFR: TypeLibrary class not thread safe
- Resolved