Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8307298

JFR: Ensure jdk.jfr.internal.TypeLibrary is initialized only once

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 21
    • None
    • hotspot
    • None
    • jfr
    • b23

      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.

            sgehwolf Severin Gehwolf
            rtoyonaga Robert Toyonaga
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: