6. Agenda
• History in nutshell
• JMC and Flight Recorder in bullet points
• JFR under the hood
• JFR in Action and Examples
• Power of Data Visualisation
• What about JDK improvements and upcoming features?
• Q/A
7. History in nutshell
• 1998 Appeal Virtual Machines (AVM) - JRockit JVM
• 2002 AVM acquired by BEA
• 2008 acquired by Oracle
• 2012 JDK 7u4 update: Oracle integrated JFR into the HotSpot
• 2017 JDK 9 : Public APIs for creating and consuming data
• 2018 JDK 11: JMC/JFR announced to be fully Open-Sourced
8. JFR in bullets
• Part of Java Mission Control project
• Java Flight Recorder is an event based tracing framework
• Build directly into the Java Virtual Machine
• Provides access to all internal events
• Allows to create custom events
• Tries to achieve a goal 1% overhead
10. Profiling with JFR
• Observability allows to measure a system based on provided data metrics
(local, on-prem or cloud)
• each application may have di
ff
erent telemetry, di
ff
erent assumptions
• hardware, container, end-points, libraries….
• Monitoring -> keeping yes on sampled data
• Pro
fi
ling -> recording and analysing “real” data
https://www.hippopx.com/en/camera-security-monitoring-big-brother-control-surveillance-camera-video-surveillance-81117
11. Common Usage of JFR
• Micros-Services, Distributes and Stand-Alone applications
• helps in root-cause analysis
• application understanding, bottlenecks
• solution correctes
• testing
• monitoring
Let’s split
More Pods there…
12. Java Mission Control Project
Current release 8.3
Release Milestone Date
========== =========== ==========
8.2.0 GA 2022-01-19
8.2.1 GA 2022-06-16
8.3 EA 2022-10-11
8.1 : New Allocation Events for JDK 16,
• JMC Agent, JMC Agent Plugin
• Performance Improvements : Perser, Rules
8.2: Minor release
• JFR: Heat-Map View, WebSocket-API
8.3: Minor release
• JMC Core: Parser improvements
• JFR: Dependency view, Graph Pruning, JFR: Selectable attributes,
• Agent: bug
fi
xing
13. Java Mission Control Project
Current release 8.3
Dependency View
Graph pruning View
Flameview Selectable Attributes
14. Java Flight Recorder
under the hood
Java Event API
JVM Events
Thread Local
Buffers
Events
Global Bu
ff
ers
Repository
per 1s
JFR Event Streaming (JEP 349): Continual Monitoring
15. JFR under the hood: Event - fundamental element
• Import “jdk.jfr.Event”
• Basic Element that caries valuable information
EventID:
Timestamp : when event was taken
Duration: not always
Thread ID: Thread where event has occurred
StackTrace ID: It’s optional referst to the StackTrace, default depth 64
Payload: custom information
16. Import jdk.jfr.Event;
public class SampleEvent extends Event {
//internal logic
String message;
}
…
void someAdvanceLogic() {
SampleEvent e = new SampleEvent();
e.message = “Important Information”;
e.begin();
// advanced logic
e.end();
e.commit();
}
…
JFR under the hood: Event
17. JFR under the hood: : Tuning up an Event
Annotations: https://docs.oracle.com/en/java/javase/19/docs/api/jdk.jfr/jdk/jfr/class-use/MetadataDe
fi
nition.html
Annotation Description Default
@Name
Automatically Set, Recommended pattern: org.com…
Event
Full path with Name:
openvalue.SampleEvent
@Label Short descriptive information
@Category Category is present to the user
@Threshold
Default min duration fo the event to be included in the
recording
0ns
@StackTrace Include a stack-trace to the event TRUE
@Enabled Is Event enabled by default con
fi
guration
18. JFR under the hood: : Tuning up an Event
import jdk.jfr.Event
import jdk.jfr.Label
import jdk.jdf.Name
@Name(“com.openvalue.events.SampleEvent”)
@Label(“Sample Event”)
class SampleEvent extends Event {
@Label(“Message”)
String name;
@Label(“Value”)
int value;
}
Annotations: https://docs.oracle.com/en/java/javase/19/docs/api/jdk.jfr/jdk/jfr/class-use/MetadataDe
fi
nition.html
19. JFR under the hood: Performance
• Usage of Thread Local Bu
ff
ers
• Java Platform Optimisation
• Methods: INLINING, CODE ELIMINATION, SCALARIZATION
• What happens when event is enabled / disabled
-XX:StartFlightRecording=filename=<RECORDING_FILE>.jfr,dumponexit=true,settings=profile
20. void someAdvanceLogic() {
SampleEvent e = new SampleEvent();
e.message = “Important Information”;
e.begin();
// advanced logic
e.commit();
}
void commit() {
// IF it’s not enabled -> NOT INTERESTING
if(isEnabled()){
//now() reads CPU clock register, cheap check
long duration = now() - startTime;
if(duration > THRESHOLD) {
if (shouldCommit()) {
// Cheap - Thread local writes
actuallyCommit();
}
}
}
Mikeal Vidstedt presented quite neat pseudo-code that helps to understand to the commit()
JFR under the hood: Event in Action
21. void someAdvanceLogic(){
// allocating event
SampleEvent e = new SampleEvent();
e.begin(); -> INLINING => e.startTime = now(); -> e.startTime = <JVM intrinsic>
// advanced logic
// timestamp, likewise INLINING, implicit end()
e.commit();
// JFR ENABLED STATE
if(e.isEnabled()){
// perform additional checks and maybe actuallyCommit()
}
}
JFR under the hood: Enabled
22. JFR under the hood: Disabled - part 1
void someAdvanceLogic() {
SampleEvent e = new SampleEvent();
// INLINING from the previous slide
e.startTime = <JVM intrinsic>;
// advanced logic
//INLINING
if(false) { // result e.isEnabled()
//perform additional checks
//CODE ELIMINATION -> will be removed
}
}
23. JFR under the hood: Disabled - part 2
void someAdvanceLogic() {
SampleEvent e = new SampleEvent(); // SCALARIZATION -> REMOVAL
e.begin()
1. initial state: e.begin();
2. INLINING => e.startTime = <JVM intrinsic>;
3. INLINING => long startTime = <JVM intrisic>;
4. CODE ELIMINATION => long startTime = <JVM intrisic>; REMOVAL
//business logic
}
24. JFR under the hood: Disabled - part 3
void someAdvanceLogic() {
//business logic
}
25. JFR: Start Recording
# Starting a recording
$ java -XX:StartFlightRecording …
# Starting Recording and Storing into the file
$ java -XX:StartFlightRecording=filename=<FILE_NAME>.jfr
# Starting Recording and dump on exit
$ java -XX:StartFlightRecording=filename=<FILE_NAME>.jfr,dumponexit-true,settings=profile
# Using jcmd command via PID to start recording
$ jcmd <PID> JFR.start duration=30s filename=hotmethods_jcmd.jfr
26. JFR: Data Visualisation
• Command line tool avaliable from JDK 11 => jfr
$jfr summary <JFR_file>
$jfr print —json <JFR_FILE>
• JFR GUI. (DEMO)
• Automated analysis
• Java Application => Thread, Memory, etc.
• Event Browser