JDK-8193210 : [JVMCI/Graal] add JFR compiler phase/inlining events
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 9,10
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2017-12-07
  • Updated: 2020-04-30
  • Resolved: 2020-03-27
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 15
15 b17Fixed
Related Reports
Blocks :  
Relates :  
Relates :  
Description
HotSpot JFR Events support for Graal Compiler

**

This enhancement adds jvmci supports that is required for extending existing phase/inlining events support in graal compilers.

In this process all event generation code are moved to compiler/compilerEvent.hpp/ .cpp

Graal use these events via jvmc  JFR.java helper class, which uses c2v interface to post and get information from hotspot

Overview of functionalities exposed by JFR. java

registerCompilerPhase, to register compiler phases at compiler creation, called only for singleton object.

Ticks, for getting current jfr counter/ time stamp. used for getting start of events by Graal compiler.

CompilerPhaseEvent for posting phase event to hotspot JFR.

CompilerInlininingEvent for posting inlininig events.


Detailed Design

Note: This covers the JFR Provider and JVMCI part of the design only. Most other parts of event generation in Graal simply mimic DebugContext and dump handling code.

This change introduces JFRProvider in Graal to notify a provider of JFR compilation events. The HotSpot-specific implementation of this provider is in HotSpotJFRProvider. HotSpotJFRProvider uses HotSpot-specific JVMCI API (JFR) to describe events.

There are two compiler events defined by JFRProvider:

JFRProvider.CompilerPhaseEvent
JFRProvider.CompilerInliningEvent
Both compiler events provide a write() method.

HotSpotJFRProvider implements the above provider using the JVMCI JFR class to translate the events to EventCompilerPhase and EventCompilerInlining events in the HotSpot JFR C++ implementation.

The JFR helper class provides helper classes/methods to access HotSpot JFR features required to implement HotSpotJFRProvider. Each HotSpot feature is implemented as nested class.

Overview of features in JFR class.

JFR.registerCompilerPhases, used for registering compiler phases on compiler create(used only for singleton object)

JFR.Ticks class is used to access the current JFR time stamp.

Each HotSpot JFR compiler event defined in src/share/jfr/metadata/metadata.xml  has corresponding class at the Java level

JFR.CompilerPhaseEvent
JFR.CompilerInliningEvent
These helper classes are used to notify events via C2V interface

JFR.CompilerPhaseEvent requires phaseToId mapping in TYPE_COMPILERPHASETYPE.

This is maintained as a growable array in compiler/compilerEvent.hpp  and a cached copy in JFR.CompilerPhaseEvent.

Comparison with earlier C2 implementation:

In earlier C2 implementation idToPhase/phaseToId mapping is maintained in opto/phasetype.hpp. This is the compile time constant enum and a helper class. with JVMCI it is maintained as a growable array in compiler/compilerEvent.hpp and its cached copy maintained in JFR.CompilerPhaseEvent

JFR Changes 
Extended the current content type TYPE_COMPILERPHASETYPE, to support Graal phases.

CompilerPhaseEvent extends and use TYPE_COMPILERPHASETYPE content type for phase events

CompilerEvent::PhaseType::register_phases is used for registering phases. This function is usually called on compiler singleton object creation. It is also called lazily if phases are not known beforehand.

Testing
All tests in jdk/jdk/jfr were run. There were a few unrelated failures

There are no new tests added for this enhancement as it uses exisiting native events, and tests in jdk/jfr covers it.


1) Execution failed: `main' threw exception: java.lang.NoClassDefFoundError: jdk/test/lib/Utils

jdk/jfr/javaagent/TestLoadedAgent.java: Tests emitting events in a dynamically loaded Java agent

jdk/jfr/javaagent/TestPremainAgent.java: Tests emitting event before main using a Java agent

Ran this separately, it passes

2) Execution failed: `main' threw exception: java.lang.RuntimeException: Expected to get exit value of [0]

jdk/jfr/event/io/TestInstrumentation.java: Test that will instrument the same classes that JFR will also instrument.

Fails with other compilers.

jdk/jfr/jvm/TestJfrJavaBase.java: verify that jfr can not be used when JVM is executed only with java.base

Execution failed: `main' threw exception: java.lang.RuntimeException: Wrong shouldCommit(): expected false to equal true

Fails with other compilers.

jdk/jfr/api/event/TestShouldCommit.java: Test enable/disable event and verify recording has expected events.

Fails with other compilers.

Program `/mnt/Work/OpenGrok/source/graal_latest/graal/compiler/mxbuild/linux-amd64/graaljdks/jdk14-cmp/bin/java' timed out (timeout set to 120000ms, elapsed time including timeout handling was 120274ms).

jdk/jfr/event/io/EvilInstrument.java: This test runs JFR with a javaagent that reads/writes files and sockets during every class definition.

Timeouts with other compilers.

 

Entire JVMCI changes :http://cr.openjdk.java.net/~jcm/8193210/webrev/


Comments
URL: https://hg.openjdk.java.net/jdk/jdk/rev/a51657b8d389 User: jcm Date: 2020-03-27 17:07:59 +0000
27-03-2020

[~egahlin] i missed this comment. - Do you plan to implement the events in native, or as Java events? i am planning to implement the events in native. Thanks a lot for the comments and inputs. - I'm asking to make sure we end up with a design that will integrate nicely with JFR and JMC. sure, i will send out a document capturing the design information for your inputs.
04-12-2019

I have few questions: - Do you plan to implement the events in native, or as Java events? - If Java events, will you use java.base/jdk.internal.event.Event or jdk.jfr.Event as a base class? - How are you going to handle method ids, as there is no way to provide metadata for them in Java? I'm asking to make sure we end up with a design that will integrate nicely with JFR and JMC. The service provioder solution was removed in JDK 9 and we later added event support in java.base to work around modularity issues.
25-11-2019

dropped plan of adding additional intefaces. jvmci provider wil be directly used for phases and inlining events(as embedded in DebugContext)
15-08-2019

two tasks: enable events for inlining and compilation phases.
12-07-2019

This is something that doesn't require deep Graal knowledge so I'm requesting it be re-assigned to a compiler engineer. Or push it out to 12.
16-05-2018

Thank you Doug!
11-04-2018

[~hirt], I've myrecording.jfr which was produced by applying http://cr.openjdk.java.net/~dnsimon/8193210/ and running: java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler -XX:+BootstrapJVMCI -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=duration=60s,filename=myrecording.jfr -version
10-04-2018

Yes, but the problem is not only opening JFR but adding it to modules tree by default. But looking on closed/make/common/Modules.gmk it is already linked to boot modules in closed builds: # jdk.jfr is linked in in non-commercial build BOOT_MODULES += \ jdk.jfr \ So it may be not a problem. [~mchung] Mandy what is your opinion here? Thanks!
02-02-2018

From what I understand, JFR will be open sourced. This issue is therefore somewhat blocked until it is.
31-01-2018

I think the requirement for this RFE is to produce *at least* the same events as C2 compiler if possible.
30-01-2018

Next will not work because JFR module is present only in closed builds: module jdk.internal.vm.ci { + requires jdk.jfr;
30-01-2018

http://cr.openjdk.java.net/~dnsimon/8193210/
29-01-2018