JDK-8203629 : Produce events in the JDK without a dependency on jdk.jfr
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: jfr
  • Affected Version: 11,12
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2018-05-22
  • Updated: 2020-01-15
  • Resolved: 2018-10-31
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 12
11.0.5-oracleFixed 12 b18Fixed
Related Reports
Blocks :  
Relates :  
Relates :  
Relates :  
Relates :  
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.
Comments
Fix request: This fix is part of a series of JFR patches that Oracle have integrated into their 11.0.5 update. The series consists of JDK-8203629, JDK-8213172, JDK-8214161 and JDK-8148188. They all apply (in that order, with a little fuzz for JDK-8148188 in src/java.base/share/classes/java/security/Security.java) and tests at the SAP test system show no regressions. So requesting backport approval for 11u.
08-06-2019

JDK-8148188 review looking healthy[1] . Now waiting on JDK-8203629 [1] http://mail.openjdk.java.net/pipermail/security-dev/2018-June/017488.html
28-06-2018

Fix is ready and sent out for review, but awaiting JDK-8148188 before checking it in.
25-06-2018