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

Produce events in the JDK without a dependency on jdk.jfr



    • jfr
    • b18



        It's not possible to define a JFR event class in java.base since it would create a dependency on the jdk.jfr module at compile time. One way to avoid this is to add an event class with the same method signature as jdk.jfr.Event to an internal package of java.base.

        The methods will be empty, just like they are for jdk.jfr.Event, but when the subclass is loaded the JVM, or code in jdk.jfr module, will add the bytecode needed to write that event into the JFR buffers. Labels, descriptions etc. for the event that require a dependency on annotation classes in jdk.jfr can be defined in a mirror class in jdk.jfr.events package. Example,

        -------------------------- java.base -----------------------------------------------
        package jdk.internal.events;

        class HelloWorld extends jdk.internal.events.Event {
           public String message;
        -------------------------- jdk.jfr -----------------------------------------------
        package jdk.jfr.events;

        @Label("Hell World")
        @Description("Helps the programmer getting started");
        class HelloWorld extends jdk.jfr.Event {
          @Description("A fine message")
          public message;

        To ensure that fields are matching, there will be a check when the event is registered. if they don't match, an InternalError will be thrown to ensure such code is never checked in.

        If other JDK modules in the future would run into similar problems, it would be possible to export the java,base/jdk.internal.events package to that module and they could also avoid the dependency on the JFR module. Since the methods of jdk.internal.events.Event are empty, all traces of JFR will be eliminated by the JIT if JFR is not present.


          Issue Links



                egahlin Erik Gahlin
                egahlin Erik Gahlin
                0 Vote for this issue
                5 Start watching this issue