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

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

    Details

    • Subcomponent:
      jfr
    • Resolved In Build:
      b18

      Backports

        Description

        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;

        @Name("jdk.HelloWorld")
        @Label("Hell World")
        @Description("Helps the programmer getting started");
        @StackTrace(false)
        @Enabled(false)
        @MirrorEvent(className="jdk.internal.events.HelloWorld")
        class HelloWorld extends jdk.jfr.Event {
          @Label("Message)"
          @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.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  egahlin Erik Gahlin
                  Reporter:
                  egahlin Erik Gahlin
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  5 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: