SlideShare a Scribd company logo
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Production-Time Profiling
and Diagnostics on the JVM
Marcus Hirt
Consulting Member of Technical Staff
OMC
October, 2018
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Agenda
• Introduction to various OpenJDK serviceability technologies
• Simple examples
• Pointers and hints
• Examples on using several technologies together
2
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
The JVM…
• Translating our byte code to machine code since 1995
– …is a highly performant piece of technology (JIT)
• Gives us the illusion of infinite memory
– …many GC algorithms to choose from (Parallel, CMS, G1, ZGC)
• But it is so much more!
– Plenty of serviceability technologies!
– Makes running programs on the JVM easier to:
• Monitor
• Manage
• Diagnose
• Profile
3
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Serviceability Technologies available in OpenJDK 11
Disclaimers:
• Not going to talk about all of them
– There are even more of them available, SA etc
• They will all get a shallow treatment – not enough time!
• This talk will provide you with a starting point…
– …with a production time focus
– …with examples to get up and running
– …with a few examples on using them together
4
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Attach
5
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Dynamic Attach (com.sun.tools.attach)
• Attach to locally running JVMs
• Get the system properties
• Load agents (JVMTI, JPLIS)
• Load the (JMX) management agent
• If we downcast to HotSpotVirtualMachine…
– Dump hprof format heap dumps
– Execute Diagnostic Commands (JCMD)…
– …which allows us to control the flight recorder
6
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Attach Example
7
Print system properties
public static void main(String[] args) throws Exception {
String pid = AttachUtils.checkPid(args);
VirtualMachine vm = VirtualMachine.attach(pid);
System.out.println(vm.getSystemProperties());
vm.detach();
}
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Attach Example
8
Start Local Management Agent
public static void main(String[] args) throws Exception {
String pid = AttachUtils.checkPid(args);
VirtualMachine vm = VirtualMachine.attach(pid);
System.out.println(vm.startLocalManagementAgent());
vm.detach();
}
JMX Service URL
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Attach Example
9
Naughty little hobbitses edition
public static void main(String[] args) throws Exception {
…
String pid = AttachUtils.checkPid(args);
VirtualMachine vm = VirtualMachine.attach(pid);
HotSpotVirtualMachine hsvm = (HotSpotVirtualMachine) vm;
String result = AttachUtils.readFromStream(hsvm.dumpHeap(outFileStr));
System.out.println(result);
vm.detach();
}
public static void main(String[] args) throws Exception {
…
HotSpotVirtualMachine hsvm = (HotSpotVirtualMachine) vm;
String result = AttachUtils.readFromStream(hsvm.executeJCmd("Thread.print"));
System.out.println(result);
vm.detach();
}
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
JMX
10
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
JMX
• The platform MBean server / java.lang.management (JSR-174, Java 1.5)
• Access to key metrics in the Java platform
– Memory/GC metrics
– CPU load
• Access to third-party metrics
• Remote access through built in agent
• More info if being naughty little hobbitses
11
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
JMX Code Example
12
In Process
public static void main(String[] args) {
System.out.println(ManagementFactory.getRuntimeMXBean()
.getSystemProperties());
}
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
JMX Code Example
13
Other Process
public static void main(String[] args) throws Exception {
…
JMXConnector connector = JMXConnectorFactory
.connect(jmxServiceUrl);
RuntimeMXBean runtimeMXBean = ManagementFactory
.newPlatformMXBeanProxy(connector.getMBeanServerConnection(),
ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean.class);
System.out.println(runtimeMXBean.getSystemProperties());
}
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
JMX Example
14
Nasty little hobbitses CPU Load
public static void main(String[] args) throws Exception {
…
JMXConnector connector =
JMXConnectorFactory.connect(jmxServiceUrl);
OperatingSystemMXBean osMXBean =
ManagementFactory.newPlatformMXBeanProxy(
connector.getMBeanServerConnection(),
ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME,
com.sun.management.OperatingSystemMXBean.class);
System.out.println("JVM process load: " + osMXBean.getProcessCpuLoad());
System.out.println("System load: " + osMXBean.getSystemCpuLoad());
System.out.println("Process cpu time: " + osMXBean.getProcessCpuTime() /
1000_000.0d + " ms");
}
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 15
Invoking Diagnostic Commands
private final static String DC_OBJECT_NAME = "com.sun.management:type=DiagnosticCommand";
…
MBeanServerConnection connection = connector.getMBeanServerConnection();
String result = (String) connection.invoke(new ObjectName(DC_OBJECT_NAME),
"threadPrint",
new Object[] { new String[0] },
new String[] { String[].class.getName() });
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
JMX Concerns
• Content type for attributes not available
– Units descriptor use not standardized
– Some tooling (JMC) provides it own metadata client side
• Memory pressure/overhead
– Don’t get excessive amounts of data too often
– Marshalling/Unmarshalling to/from CompositeData
– Be wary of stack traces or similar data structures
(no compact representation e.g. a constant pool)
16
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
JMX Fun Facts
• JRockit had the world’s first JVM Management API (JMAPI)
• The funny looking long Base64 encoded JMXServiceURL used to connect to
a locally running JVM -> serialized connection stub
17
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Perf Counters
18
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
The JVM Perf Counters
• Access internal instrumentation buffers maintained by the JVM
• Local access only
– Remote access example later
• Entire API internal and restricted
– Very naughty little hobbitses indeed…
19
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Example Listing all of the Perf Counters
20
public static void main(String[] args) throws IOException {
String pid = AttachUtils.checkPid(args);
Perf p = Perf.getPerf();
ByteBuffer buffer = p.attach(Integer.parseInt(pid), "r");
PerfInstrumentation perfInstrumentation =
new PerfInstrumentation(buffer);
for (Counter counter : perfInstrumentation.getAllCounters()) {
System.out.println(
String.format("%s = %s [Variability: %s, Units: %s]",
counter.getName(),
String.valueOf(counter.getValue()),
counter.getVariability(), counter.getUnits()));
}
}
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Some counter examples
…
sun.cls.appClassBytes = 44119 [Variability: Monotonic, Units: Bytes]
sun.cls.appClassLoadCount = 51 [Variability: Monotonic, Units: Events]
sun.cls.appClassLoadTime = 28404804 [Variability: Monotonic, Units: Ticks]
…
sun.property.sun.boot.library.path = /Library/Java/JavaVirtualMachines/jdk-
11.jdk/Contents/Home/lib [Variability: Constant, Units: String]
…
21
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
JVMTI
22
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
JVMTI (The JVM Tool Interface)
• Is basically the old JVMDI + JVMPI
• Native library interface
– Import a header
– Compile a library/DLL for all supported platforms
– Package it all up (different distributable for different platforms)
23
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Pros and Cons
• On the plus side:
– Agent has access to platform specific (native) APIs
– Powerful general API
• On the negative side:
– Agent needs to be compiled for the various platforms of interest
– User must use a library compiled for the specific platform he is using
– The general API must support all kinds of tooling
-> sometimes harder to find efficient solutions for very specific tasks
– Hard to write correct JVMTI code, JNI code for sure
24
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
JDI
25
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
JDI (Java Debug Interface)
• Java has a comprehensive debugger architecture (JPDA)
• JDI is a Java API for attaching to Java processes as a debugger client
– Socket communication (dt_socket, host & port, over JDWP)
– Local attach (process identrified by PID)
– Shared Memory (Win32 only, dt_shmem, identified by unique name)
• Powerful, for example
– Allows for setting breakpoints
– Allows for accessing contents on the stack (parameters, local variables)
– Allows for executing code in the remote JVM
26
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
JDI Examples
• Three examples provided by Oracle
• Trace
– Displays traces of program execution (< 600 lines)
– Uses most of basic JDI à good starting point
• Jdb
– Command line debugger
• Javadt
– The beginnings of a GUI debugger.
• Simple scaled down Hello World example at the java-svc GitHub repo
27
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Production Time?
• No, not really
– People setting breakpoints in your production code?
– Executing arbitrary code?
– Performance penalties (severe, especially if evaluating expressions in breakpoints)
• Sometimes the one remaining option
– Start a node with dt_socket
– Assumes that you either have direct access (!), or access to establish an SSH bridge
– Attach using your favourite remote debugger in your IDE
28
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Example
java -Xdebug
-Xrunjdwp:transport=dt_socket,
address=9876,
server=y,
suspend=y
MyClass
ssh -L 9876:localhost:9876 <user>@<host> -p <sshd port>
29
For completeness…
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
JPLIS
30
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
JPLIS
• Provides the concept of an Agent
– Agent can have a premain method
– An agent can also have an agentmain method (run when loaded dynamically)
– The agent is a jar, and the manifest specifies the Premain-/Agent-Class
• Provides an interface for manipulating the byte code of a class
– java.lang.Instrumentation
– ClassFileTransformer used when class is loaded/retransformed
• Can be loaded from the command line with –javaagent
• Can be loaded dynamically with attach
31
Java Programming Language Instrumentation Services
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Transforming a Class
32
java HelloWorld
load HelloWorld.class
run HelloWorld.main(…)
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Transforming a Class
33
java -javaagent:myagent.jar HelloWorld
Agent.premain registers Transformer
load HelloWorld.class
byte[] Transformer.transform(transform(ClassLoader loader,
String className,…, byte[] classfileBuffer))
run HelloWorld.main(…)
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Transformation
• The transformation usually is done using a bytecode engineering library
• Multiple to chose from
– ASM
– BCEL
– javassist
– ByteBuddy
– …
• Simple example using ASM in the java-svc repo
– List methods to be instrumented in a text file
– Will time the time spent in the method body for the listed methods and print it out
34
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Manifest decides what is allowed (capabilities)
• Premain-Class: se.hirt.examples.svc.jplis.ExampleAgent
• Agent-Class: se.hirt.examples.svc.jplis.ExampleAgent
• Can-Redefine-Classes: false
• Can-Retransform-Classes: true
• Can-Set-Native-Method-Prefix: false
35
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Example - premain
36
public static void premain(String agentArguments, Instrumentation instrumentation) {
try {
List<TransformDescriptor> probes = readProbes(agentArguments);
instrumentation.addTransformer(new ExampleTransformer(probes));
} catch (IOException e) {
getLogger().log(Level.SEVERE,
"Could not initialize agent! Agent will not be active!", e);
}
}
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Example - ASM
37
private void emitTimingPrologue() {
mv.visitMethodInsn(INVOKESTATIC, "java/lang/System", "nanoTime",
"()J", false);
localVariableIndexTime = newLocal(Type.LONG_TYPE);
mv.visitVarInsn(LSTORE, localVariableIndexTime);
}
private void emitTimingEpilogue() {
mv.visitMethodInsn(INVOKESTATIC, "java/lang/System", "nanoTime",
"()J", false);
mv.visitVarInsn(LLOAD, localVariableIndexTime);
mv.visitInsn(LSUB);
mv.visitVarInsn(LSTORE, localVariableIndexTime);
}
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Be Careful
• Redefinition limitations
– Can’t add/remove methods
– No hierarchy changes
– Can’t change (method/class) modifiers
– Can’t add/remove fields
• You may want to generate classes on the fly
– Defining your generated classes? à sun.misc.Unsafe to the rescue
• Careful not to alter the execution of the original application
– Inadvertedly alter the execution path, e.g. by throwing exceptions
• Deopts!
38
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
JCMD
39
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
JCMD – Java Command
• Sends command to local Java Process
• Retrieves a String response
• Executes Diagnostic Commands (as mentioned in previous examples)
• Launcher usually both forward and backwards compatible
– Use JDK 11 to send commands to JDK 7
– Use JDK 7 to send commands to JDK 11
– Use the help command to find out what commands are available
• Commands available to control the JDK Flight Recorder
40
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Example
$ jcmd
89840 org.codehaus.plexus.classworlds.launcher.Launcher jetty:run
97845 jdk.jcmd/sun.tools.jcmd.JCmd
$ jcmd 89840 help
89840:
The following commands are available:
JFR.stop
JFR.start
JFR.dump
JFR.check
…
41
List all processes
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Example
$ jcmd 89840 help JFR.stop
89840:
JFR.stop
Stops a JFR recording
Impact: Low
Permission: java.lang.management.ManagementPermission(monitor)
Syntax : JFR.stop [options]
Options: (options must be specified using the <key> or <key>=<value>
syntax)
name : [optional] Recording name,.e.g "My Recording" (STRING, no
default value)
recording : [optional] Recording number, see JFR.check for a list of
available recordings (JLONG, -1)
42
Get help
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Note
• Providing the PID 0 will execute the command in all JVMs
• As mentioned, remotable over JMX (DiagnosticCommandMBean)
• Often used to control the JDK Flight Recorder from scripts or from the
command line
• Only for processes with the same effective user as the one running jcmd
43
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
JFR
44
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Production Time Profiling and Diagnostics
45
“The big challenge is no longer really performance. The big
challenge is profiling, and especially profiling in production.”
- Tony Printezis, JVM engineer, Twitter
(Devoxx 2015, ”Life of a Twitter JVM Engineer”, 49:49)
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
"Java Mission Control is the best
profiler by far.“
- T Jake Luciani, PMC Cassandra
“Java Mission Control is my current
favourite profiler for the Oracle JVM."
- Nitsan Wakart, Azul
“… Our real-time messaging products can
publish millions of messages a second to many
thousands of connections - only JMC can keep
up with this level of load."
- Phil Aston, Product Architect, Push Technology
"JMC not only saves time trying to resolve
performance issues and bugs, it can give you a
detailed view on your application you cannot get
with other commercial profilers"
- Peter Lawrey, CEO, Chronicle Software
“Once more @javamissionctrl is saving my day! "
- Michael Nitschinger, SDK Engineer, Couchbase
"For the record: Java Mission Control is the best
profiler ever, I use it daily, and so should you"
- Marcus Lagergren, Lead Architect, Nasdaq
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
"I am ACS engineer since 2008, delivering local Middleware support to several
customers. Since I started to work with Java/JRockit Mission Control, it
became a key tool for my work, helping me to troubleshooting, identifying root
causes and bottlenecks, and also for doing proactive follow up services to
customers. Without it, I would be blind."
- Iratxe Etxebarria, Oracle (ACS)
"In Fusion we create hundreds of thousands of Flight Recordings, and we can
figure out 95% of the issues using nothing but the recordings."
- Joe Albowicz, Oracle (Fusion Application Development)
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Flight Recorder
• High Performance Event Recorder
• Built into the JVM
• Binary recordings
• Chunks
– Self contained
– Self describing
101
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
OpenJDK has Flight Recorder!
• OpenSourced, and available in JDK 11!
• Records information about the JVM and the application running
• Can be extended with custom (contextual) information (Event API)
• Can be controlled from Diagnostic Commands (jcmd)
• Can be controlled from JMX (diagnostic commands and dedicated API)
• Also POJO local Java API for controlling the recorder
49
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Rich Data
• Method profiling (multiple variants)
– asyncGetCalltrace (no need to safepoint)
– New event in JDK 10 for calls out to native
• Allocation profiling
• Latency profiling
• GC information
• Method compilation information
• Old object sampling
– New event in JDK 10 for sorting out memory leaks
50
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Low Overhead
• Access to data already collected in the runtime
• Thread local native buffers
• Invariant TSC for time stamping
• Method profiling data even from outside safe-points
• Faster and more accurate allocation profiling
(scalarization not undone by profiler)
• No overhead when event is turned off (and on the critical path)
51
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 52
Java API Events
JVM Events
Event
Event
Event
Event
ThreadBuffer
Global Buffer
Global Buffer Global Buffer Global Buffer
Global Buffer
Global Buffer Global Buffer Global Buffer
Copied into
JFR File
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Example
53
Adding a custom event
public class HelloJfr {
@Label("Hello World!")
static class HelloWorldEvent extends Event {
@Label("Message")
String message;
}
public static void main(String... args) throws IOException {
HelloWorldEvent event = new HelloWorldEvent();
event.message = "Hello World!";
event.commit();
}
}
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Another Custom Event
54
@Label("Fibonacci")
@Description("An example event")
@Category("Fibonacci")
@Enabled(true)
public final class FibonacciEvent extends Event {
@Label("Fibonacci Number")
@Description("The number in the sequence calculated, i.e. the n:th number")
public int number;
@Label("Fibonacci Sum")
@Description("The value of the n:th number")
public long value;
}
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 55
API for Parsing Flight Recorder Files
public class ParserExample {
public static void main(String[] args) throws IOException {
long maxNanos = Long.MIN_VALUE;
RecordedEvent maxEvent = null;
for (RecordedEvent event : RecordingFile.readAllEvents(Paths.get(args[0]))) {
if (event.getEventType().getName().equals("se.hirt.jfr4junit.TestEvent")) {
long nanos = event.getDuration();
if (nanos > maxNanos) {
maxNanos = nanos;
maxEvent = event;
}
}
}
System.out.printf("Longest running test was: %s for %dsn",
maxEvent.getValue("displayName"), maxNanos / 1_000_000);
System.out.println("Event was:n" + maxEvent);
}
}
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 56
Control API and Parsing Example
public class RecordAndConsume {
public static void main(String[] args) throws IOException {
Path path = Paths.get(args[0]);
try (Recording recording = new Recording()) {
recording.setName("Fibonacci Recording");
recording.start();
recording.enable(FibonacciEvent.class);
for (int n = 0; n < 50; n++) {
FibonacciEvent event = new FibonacciEvent();
event.number = n;
event.begin();
event.value = Fibonacci.fibonacciIterative(n);
event.commit();
}
recording.stop();
recording.dump(path);
for (RecordedEvent event : RecordingFile.readAllEvents(path)) {
int number = event.getValue("number");
long value = event.getValue("value");
System.out.printf("fibonacci(%d) = %d (time: %dns)n", number, value, event.getDuration());
}
}
}
}
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
JMC Core
57
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
JDK Mission Control
• Two parts – the application and the core libraries
• The core libraries contain
– A backwards compatible JFR parser capable of running on JDK 7 and above
– Can parse JFR recordings from Oracle JDK 7u40 and above
– An API for filtering and aggregating data (from, for example JFR)
– An API for working with quantities and units of measurement
– An API for analysing JFR recordings
• See my jmc-jshell repo for examples
58
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Example
59
Calculating the Standard Deviation for Monitor Enter events
public static void main(String[] args) throws Exception {
IItemCollection events = JfrLoaderToolkit.loadEvents(new File(args[0]));
IItemCollection monitorEnterEvents = events.apply(JdkFilters.MONITOR_ENTER);
IQuantity stddev = monitorEnterEvents.getAggregate(
Aggregators.stddev(JfrAttributes.DURATION));
System.out.println(stddev.displayUsing(IDisplayable.AUTO)));
}
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Example
60
Getting an HTML report
public static void main(String[] args) throws Exception {
String report = JfrHtmlRulesReport.createReport(
JfrLoaderToolkit.loadEvents(new File(args[0])));
System.out.println(report);
}
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Putting it together
61
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Some Already Mentioned Examples
• Using JCMD from scripts to control the JDK Flight Recorder
– Dumping already defined recordings at a regular interval, moving them somewhere
and pre-process them/run custom rules on them
– Do a m minute profiling recording every h hours
• Using JMX to remotely to access JCMD
62
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Using JMX + PerfCounters
• Expose the perf counters through a Dynamic MBean
63
https://github.com/thegreystone/java-svc/tree/master/perfcounters
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Using JMX + JPLIS + JFR
• Use JFR to record JMX data directly to JFR
– Stacktraces not interesting, so don’t record them
– Let the user configure what to record
– Use not only the data type, but let the user add content type information
• Build it as a JPLIS agent
– Not really using BCI at all…
– …but can now be loaded on the command line using –javaagent
– …and loaded dynamically into a running process (for example through attach)
• Now have access to e.g. third party information available in JMX, but in the
context of everything else recorded in JFR!
Prototype: https://github.com/thegreystone/jmx2jfr
64
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Using JPLIS + JFR to Inject Events
• Building a JPLIS agent to inject JFR events around methods
– Dynamically adds JFR events to method entries/exits (either or both)
– Method timing using efficient JFR events!
– Selectively records parameters and/or return values
– Optionally records stack traces, again using efficient JFR events
– Ongoing project in the JMC project (jmc agent)
• First prototype available with JMC 7
• Uses ASM to add well defined byte code
• Generates support classes as needed, and defines them using sun.misc.Unsafe…
Prototype here: http://hg.openjdk.java.net/jmc/jmc
(under core/ org.openjdk.jmc.agent)
65
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Summing it all up…
66
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Summary
• Java has a rich and powerful set of serviceability features
• Some of them are rather suited for production use
• Using them together makes them even more useful
• They are rather easy to get started with
• One place to start playing with them is here:
https://github.com/thegreystone/java-svc
67
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Safe Harbor Statement
The preceding is intended to outline our general product direction. It is intended for
information purposes only, and may not be incorporated into any contract. It is not a
commitment to deliver any material, code, or functionality, and should not be relied upon
in making purchasing decisions. The development, release, and timing of any features or
functionality described for Oracle’s products remains at the sole discretion of Oracle.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Other JMC-/JFR-related Presentations
Day Time Title Location
Monday 10:30 Contributing to the Mission Control OpenJDK Project MW 2004
Tuesday 11:30 Three Productive Ways to Use Open Source Java Flight Recorder and
Java Mission Control
MW 2024
Tuesday 12:30 Flight Recorder in OpenJDK MW 2018
Tuesday 14:30 Fast and Furious: Java Flight Recorder and Flame Graphs MW 2020
Wednesday 10:30 Production-Time Profiling and Diagnostics on the JVM MW 2004
Wednesday 12:30 OpenJDK Mission Control: The Hands-on-Lab MW 2001A
Wednesday 16:30 Diagnose Your Microservices: OpenTracing/Oracle APM Cloud MW 2011
Thursday 11:00 Getting Started with the (Open Source) JDK Mission Control MW 2014
69

More Related Content

What's hot

"Quantum" performance effects
"Quantum" performance effects"Quantum" performance effects
"Quantum" performance effects
Sergey Kuksenko
 
Job Managment Portlet
Job Managment PortletJob Managment Portlet
Job Managment Portlet
riround
 
TensorFlow XLA RPC
TensorFlow XLA RPCTensorFlow XLA RPC
TensorFlow XLA RPC
Mr. Vengineer
 
Bridge TensorFlow to run on Intel nGraph backends (v0.4)
Bridge TensorFlow to run on Intel nGraph backends (v0.4)Bridge TensorFlow to run on Intel nGraph backends (v0.4)
Bridge TensorFlow to run on Intel nGraph backends (v0.4)
Mr. Vengineer
 
Virtual platform
Virtual platformVirtual platform
Virtual platformsean chen
 
1 Vampir Overview
1 Vampir Overview1 Vampir Overview
1 Vampir OverviewPTIHPA
 
TensorFlow local Python XLA client
TensorFlow local Python XLA clientTensorFlow local Python XLA client
TensorFlow local Python XLA client
Mr. Vengineer
 
A Future for R: Parallel and Distributed Processing in R for Everyone
A Future for R: Parallel and Distributed Processing in R for EveryoneA Future for R: Parallel and Distributed Processing in R for Everyone
A Future for R: Parallel and Distributed Processing in R for Everyone
inside-BigData.com
 
Better Code: Concurrency
Better Code: ConcurrencyBetter Code: Concurrency
Better Code: Concurrency
Platonov Sergey
 
Improving Java performance at JBCNConf 2015
Improving Java performance at JBCNConf 2015Improving Java performance at JBCNConf 2015
Improving Java performance at JBCNConf 2015
Raimon Ràfols
 
Pythonによるカスタム可能な高位設計技術 (Design Solution Forum 2016@新横浜)
Pythonによるカスタム可能な高位設計技術 (Design Solution Forum 2016@新横浜)Pythonによるカスタム可能な高位設計技術 (Design Solution Forum 2016@新横浜)
Pythonによるカスタム可能な高位設計技術 (Design Solution Forum 2016@新横浜)
Shinya Takamaeda-Y
 
GCC RTL and Machine Description
GCC RTL and Machine DescriptionGCC RTL and Machine Description
GCC RTL and Machine Description
Priyatham Bollimpalli
 
Improving Android Performance at Mobiconf 2014
Improving Android Performance at Mobiconf 2014Improving Android Performance at Mobiconf 2014
Improving Android Performance at Mobiconf 2014
Raimon Ràfols
 
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2 「エッジAIモダン計測制御の世界」オ...
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2  「エッジAIモダン計測制御の世界」オ...Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2  「エッジAIモダン計測制御の世界」オ...
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2 「エッジAIモダン計測制御の世界」オ...
Mr. Vengineer
 
Intel IPP Samples for Windows - error correction
Intel IPP Samples for Windows - error correctionIntel IPP Samples for Windows - error correction
Intel IPP Samples for Windows - error correction
PVS-Studio
 
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres..."The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
Edge AI and Vision Alliance
 
Metrics ekon 14_2_kleiner
Metrics ekon 14_2_kleinerMetrics ekon 14_2_kleiner
Metrics ekon 14_2_kleiner
Max Kleiner
 
Verilog tutorial
Verilog tutorialVerilog tutorial
Verilog tutorial
Maryala Srinivas
 
VLSI Lab manual PDF
VLSI Lab manual PDFVLSI Lab manual PDF
VLSI Lab manual PDF
UR11EC098
 

What's hot (20)

"Quantum" performance effects
"Quantum" performance effects"Quantum" performance effects
"Quantum" performance effects
 
Job Managment Portlet
Job Managment PortletJob Managment Portlet
Job Managment Portlet
 
TensorFlow XLA RPC
TensorFlow XLA RPCTensorFlow XLA RPC
TensorFlow XLA RPC
 
Bridge TensorFlow to run on Intel nGraph backends (v0.4)
Bridge TensorFlow to run on Intel nGraph backends (v0.4)Bridge TensorFlow to run on Intel nGraph backends (v0.4)
Bridge TensorFlow to run on Intel nGraph backends (v0.4)
 
Virtual platform
Virtual platformVirtual platform
Virtual platform
 
1 Vampir Overview
1 Vampir Overview1 Vampir Overview
1 Vampir Overview
 
TensorFlow local Python XLA client
TensorFlow local Python XLA clientTensorFlow local Python XLA client
TensorFlow local Python XLA client
 
A Future for R: Parallel and Distributed Processing in R for Everyone
A Future for R: Parallel and Distributed Processing in R for EveryoneA Future for R: Parallel and Distributed Processing in R for Everyone
A Future for R: Parallel and Distributed Processing in R for Everyone
 
Better Code: Concurrency
Better Code: ConcurrencyBetter Code: Concurrency
Better Code: Concurrency
 
Improving Java performance at JBCNConf 2015
Improving Java performance at JBCNConf 2015Improving Java performance at JBCNConf 2015
Improving Java performance at JBCNConf 2015
 
Pythonによるカスタム可能な高位設計技術 (Design Solution Forum 2016@新横浜)
Pythonによるカスタム可能な高位設計技術 (Design Solution Forum 2016@新横浜)Pythonによるカスタム可能な高位設計技術 (Design Solution Forum 2016@新横浜)
Pythonによるカスタム可能な高位設計技術 (Design Solution Forum 2016@新横浜)
 
GCC RTL and Machine Description
GCC RTL and Machine DescriptionGCC RTL and Machine Description
GCC RTL and Machine Description
 
Improving Android Performance at Mobiconf 2014
Improving Android Performance at Mobiconf 2014Improving Android Performance at Mobiconf 2014
Improving Android Performance at Mobiconf 2014
 
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2 「エッジAIモダン計測制御の世界」オ...
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2  「エッジAIモダン計測制御の世界」オ...Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2  「エッジAIモダン計測制御の世界」オ...
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2 「エッジAIモダン計測制御の世界」オ...
 
Intel IPP Samples for Windows - error correction
Intel IPP Samples for Windows - error correctionIntel IPP Samples for Windows - error correction
Intel IPP Samples for Windows - error correction
 
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres..."The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
"The OpenCV Open Source Computer Vision Library: Latest Developments," a Pres...
 
Metrics ekon 14_2_kleiner
Metrics ekon 14_2_kleinerMetrics ekon 14_2_kleiner
Metrics ekon 14_2_kleiner
 
Syntutic
SyntuticSyntutic
Syntutic
 
Verilog tutorial
Verilog tutorialVerilog tutorial
Verilog tutorial
 
VLSI Lab manual PDF
VLSI Lab manual PDFVLSI Lab manual PDF
VLSI Lab manual PDF
 

Similar to Production Time Profiling and Diagnostics on the JVM

Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, TuningJava 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, TuningCarol McDonald
 
Project Helidon Overview (Japanese)
Project Helidon Overview (Japanese)Project Helidon Overview (Japanese)
Project Helidon Overview (Japanese)
Logico
 
Diagnose Your Microservices
Diagnose Your MicroservicesDiagnose Your Microservices
Diagnose Your Microservices
Marcus Hirt
 
Production Time Profiling Out of the Box
Production Time Profiling Out of the BoxProduction Time Profiling Out of the Box
Production Time Profiling Out of the Box
Marcus Hirt
 
Graal and Truffle: One VM to Rule Them All
Graal and Truffle: One VM to Rule Them AllGraal and Truffle: One VM to Rule Them All
Graal and Truffle: One VM to Rule Them All
Thomas Wuerthinger
 
Java one 2010
Java one 2010Java one 2010
Java one 2010
scdn
 
chapter4.ppt
chapter4.pptchapter4.ppt
chapter4.ppt
MalathyN6
 
P4 Introduction
P4 Introduction P4 Introduction
P4 Introduction
Netronome
 
Ingesting streaming data for analysis in apache ignite (stream sets theme)
Ingesting streaming data for analysis in apache ignite (stream sets theme)Ingesting streaming data for analysis in apache ignite (stream sets theme)
Ingesting streaming data for analysis in apache ignite (stream sets theme)
Tom Diederich
 
Taking Jenkins Pipeline to the Extreme
Taking Jenkins Pipeline to the ExtremeTaking Jenkins Pipeline to the Extreme
Taking Jenkins Pipeline to the Extreme
yinonavraham
 
Aspect-Oriented Programming
Aspect-Oriented ProgrammingAspect-Oriented Programming
Aspect-Oriented ProgrammingAndrey Bratukhin
 
Oleksandr Smoktal "Parallel Seismic Data Processing Using OpenMP"
Oleksandr Smoktal "Parallel Seismic Data Processing Using OpenMP"Oleksandr Smoktal "Parallel Seismic Data Processing Using OpenMP"
Oleksandr Smoktal "Parallel Seismic Data Processing Using OpenMP"
LogeekNightUkraine
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
Tier1 app
 
The value of reactive
The value of reactiveThe value of reactive
The value of reactive
Stéphane Maldini
 
The Value of Reactive
The Value of ReactiveThe Value of Reactive
The Value of Reactive
VMware Tanzu
 
How to lock a Python in a cage? Managing Python environment inside an R project
How to lock a Python in a cage?  Managing Python environment inside an R projectHow to lock a Python in a cage?  Managing Python environment inside an R project
How to lock a Python in a cage? Managing Python environment inside an R project
WLOG Solutions
 
Beyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic AnalysisBeyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic Analysis
Fastly
 
The magic behind your Lyft ride prices: A case study on machine learning and ...
The magic behind your Lyft ride prices: A case study on machine learning and ...The magic behind your Lyft ride prices: A case study on machine learning and ...
The magic behind your Lyft ride prices: A case study on machine learning and ...
Karthik Murugesan
 
HeapStats: Troubleshooting with Serviceability and the New Runtime Monitoring...
HeapStats: Troubleshooting with Serviceability and the New Runtime Monitoring...HeapStats: Troubleshooting with Serviceability and the New Runtime Monitoring...
HeapStats: Troubleshooting with Serviceability and the New Runtime Monitoring...
Yuji Kubota
 

Similar to Production Time Profiling and Diagnostics on the JVM (20)

Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, TuningJava 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
 
Project Helidon Overview (Japanese)
Project Helidon Overview (Japanese)Project Helidon Overview (Japanese)
Project Helidon Overview (Japanese)
 
Diagnose Your Microservices
Diagnose Your MicroservicesDiagnose Your Microservices
Diagnose Your Microservices
 
Production Time Profiling Out of the Box
Production Time Profiling Out of the BoxProduction Time Profiling Out of the Box
Production Time Profiling Out of the Box
 
Graal and Truffle: One VM to Rule Them All
Graal and Truffle: One VM to Rule Them AllGraal and Truffle: One VM to Rule Them All
Graal and Truffle: One VM to Rule Them All
 
Java one 2010
Java one 2010Java one 2010
Java one 2010
 
chapter4.ppt
chapter4.pptchapter4.ppt
chapter4.ppt
 
P4 Introduction
P4 Introduction P4 Introduction
P4 Introduction
 
Beyond Unit Testing
Beyond Unit TestingBeyond Unit Testing
Beyond Unit Testing
 
Ingesting streaming data for analysis in apache ignite (stream sets theme)
Ingesting streaming data for analysis in apache ignite (stream sets theme)Ingesting streaming data for analysis in apache ignite (stream sets theme)
Ingesting streaming data for analysis in apache ignite (stream sets theme)
 
Taking Jenkins Pipeline to the Extreme
Taking Jenkins Pipeline to the ExtremeTaking Jenkins Pipeline to the Extreme
Taking Jenkins Pipeline to the Extreme
 
Aspect-Oriented Programming
Aspect-Oriented ProgrammingAspect-Oriented Programming
Aspect-Oriented Programming
 
Oleksandr Smoktal "Parallel Seismic Data Processing Using OpenMP"
Oleksandr Smoktal "Parallel Seismic Data Processing Using OpenMP"Oleksandr Smoktal "Parallel Seismic Data Processing Using OpenMP"
Oleksandr Smoktal "Parallel Seismic Data Processing Using OpenMP"
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
The value of reactive
The value of reactiveThe value of reactive
The value of reactive
 
The Value of Reactive
The Value of ReactiveThe Value of Reactive
The Value of Reactive
 
How to lock a Python in a cage? Managing Python environment inside an R project
How to lock a Python in a cage?  Managing Python environment inside an R projectHow to lock a Python in a cage?  Managing Python environment inside an R project
How to lock a Python in a cage? Managing Python environment inside an R project
 
Beyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic AnalysisBeyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic Analysis
 
The magic behind your Lyft ride prices: A case study on machine learning and ...
The magic behind your Lyft ride prices: A case study on machine learning and ...The magic behind your Lyft ride prices: A case study on machine learning and ...
The magic behind your Lyft ride prices: A case study on machine learning and ...
 
HeapStats: Troubleshooting with Serviceability and the New Runtime Monitoring...
HeapStats: Troubleshooting with Serviceability and the New Runtime Monitoring...HeapStats: Troubleshooting with Serviceability and the New Runtime Monitoring...
HeapStats: Troubleshooting with Serviceability and the New Runtime Monitoring...
 

Recently uploaded

Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
abdulrafaychaudhry
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
ShamsuddeenMuhammadA
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Enterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptxEnterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptx
QuickwayInfoSystems3
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
abdulrafaychaudhry
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 

Recently uploaded (20)

Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Enterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptxEnterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptx
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 

Production Time Profiling and Diagnostics on the JVM

  • 1. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Production-Time Profiling and Diagnostics on the JVM Marcus Hirt Consulting Member of Technical Staff OMC October, 2018
  • 2. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Agenda • Introduction to various OpenJDK serviceability technologies • Simple examples • Pointers and hints • Examples on using several technologies together 2
  • 3. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. The JVM… • Translating our byte code to machine code since 1995 – …is a highly performant piece of technology (JIT) • Gives us the illusion of infinite memory – …many GC algorithms to choose from (Parallel, CMS, G1, ZGC) • But it is so much more! – Plenty of serviceability technologies! – Makes running programs on the JVM easier to: • Monitor • Manage • Diagnose • Profile 3
  • 4. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Serviceability Technologies available in OpenJDK 11 Disclaimers: • Not going to talk about all of them – There are even more of them available, SA etc • They will all get a shallow treatment – not enough time! • This talk will provide you with a starting point… – …with a production time focus – …with examples to get up and running – …with a few examples on using them together 4
  • 5. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Attach 5
  • 6. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Dynamic Attach (com.sun.tools.attach) • Attach to locally running JVMs • Get the system properties • Load agents (JVMTI, JPLIS) • Load the (JMX) management agent • If we downcast to HotSpotVirtualMachine… – Dump hprof format heap dumps – Execute Diagnostic Commands (JCMD)… – …which allows us to control the flight recorder 6
  • 7. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Attach Example 7 Print system properties public static void main(String[] args) throws Exception { String pid = AttachUtils.checkPid(args); VirtualMachine vm = VirtualMachine.attach(pid); System.out.println(vm.getSystemProperties()); vm.detach(); }
  • 8. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Attach Example 8 Start Local Management Agent public static void main(String[] args) throws Exception { String pid = AttachUtils.checkPid(args); VirtualMachine vm = VirtualMachine.attach(pid); System.out.println(vm.startLocalManagementAgent()); vm.detach(); } JMX Service URL
  • 9. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Attach Example 9 Naughty little hobbitses edition public static void main(String[] args) throws Exception { … String pid = AttachUtils.checkPid(args); VirtualMachine vm = VirtualMachine.attach(pid); HotSpotVirtualMachine hsvm = (HotSpotVirtualMachine) vm; String result = AttachUtils.readFromStream(hsvm.dumpHeap(outFileStr)); System.out.println(result); vm.detach(); } public static void main(String[] args) throws Exception { … HotSpotVirtualMachine hsvm = (HotSpotVirtualMachine) vm; String result = AttachUtils.readFromStream(hsvm.executeJCmd("Thread.print")); System.out.println(result); vm.detach(); }
  • 10. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. JMX 10
  • 11. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. JMX • The platform MBean server / java.lang.management (JSR-174, Java 1.5) • Access to key metrics in the Java platform – Memory/GC metrics – CPU load • Access to third-party metrics • Remote access through built in agent • More info if being naughty little hobbitses 11
  • 12. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. JMX Code Example 12 In Process public static void main(String[] args) { System.out.println(ManagementFactory.getRuntimeMXBean() .getSystemProperties()); }
  • 13. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. JMX Code Example 13 Other Process public static void main(String[] args) throws Exception { … JMXConnector connector = JMXConnectorFactory .connect(jmxServiceUrl); RuntimeMXBean runtimeMXBean = ManagementFactory .newPlatformMXBeanProxy(connector.getMBeanServerConnection(), ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean.class); System.out.println(runtimeMXBean.getSystemProperties()); }
  • 14. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. JMX Example 14 Nasty little hobbitses CPU Load public static void main(String[] args) throws Exception { … JMXConnector connector = JMXConnectorFactory.connect(jmxServiceUrl); OperatingSystemMXBean osMXBean = ManagementFactory.newPlatformMXBeanProxy( connector.getMBeanServerConnection(), ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME, com.sun.management.OperatingSystemMXBean.class); System.out.println("JVM process load: " + osMXBean.getProcessCpuLoad()); System.out.println("System load: " + osMXBean.getSystemCpuLoad()); System.out.println("Process cpu time: " + osMXBean.getProcessCpuTime() / 1000_000.0d + " ms"); }
  • 15. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 15 Invoking Diagnostic Commands private final static String DC_OBJECT_NAME = "com.sun.management:type=DiagnosticCommand"; … MBeanServerConnection connection = connector.getMBeanServerConnection(); String result = (String) connection.invoke(new ObjectName(DC_OBJECT_NAME), "threadPrint", new Object[] { new String[0] }, new String[] { String[].class.getName() });
  • 16. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. JMX Concerns • Content type for attributes not available – Units descriptor use not standardized – Some tooling (JMC) provides it own metadata client side • Memory pressure/overhead – Don’t get excessive amounts of data too often – Marshalling/Unmarshalling to/from CompositeData – Be wary of stack traces or similar data structures (no compact representation e.g. a constant pool) 16
  • 17. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. JMX Fun Facts • JRockit had the world’s first JVM Management API (JMAPI) • The funny looking long Base64 encoded JMXServiceURL used to connect to a locally running JVM -> serialized connection stub 17
  • 18. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Perf Counters 18
  • 19. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. The JVM Perf Counters • Access internal instrumentation buffers maintained by the JVM • Local access only – Remote access example later • Entire API internal and restricted – Very naughty little hobbitses indeed… 19
  • 20. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Example Listing all of the Perf Counters 20 public static void main(String[] args) throws IOException { String pid = AttachUtils.checkPid(args); Perf p = Perf.getPerf(); ByteBuffer buffer = p.attach(Integer.parseInt(pid), "r"); PerfInstrumentation perfInstrumentation = new PerfInstrumentation(buffer); for (Counter counter : perfInstrumentation.getAllCounters()) { System.out.println( String.format("%s = %s [Variability: %s, Units: %s]", counter.getName(), String.valueOf(counter.getValue()), counter.getVariability(), counter.getUnits())); } }
  • 21. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Some counter examples … sun.cls.appClassBytes = 44119 [Variability: Monotonic, Units: Bytes] sun.cls.appClassLoadCount = 51 [Variability: Monotonic, Units: Events] sun.cls.appClassLoadTime = 28404804 [Variability: Monotonic, Units: Ticks] … sun.property.sun.boot.library.path = /Library/Java/JavaVirtualMachines/jdk- 11.jdk/Contents/Home/lib [Variability: Constant, Units: String] … 21
  • 22. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. JVMTI 22
  • 23. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. JVMTI (The JVM Tool Interface) • Is basically the old JVMDI + JVMPI • Native library interface – Import a header – Compile a library/DLL for all supported platforms – Package it all up (different distributable for different platforms) 23
  • 24. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Pros and Cons • On the plus side: – Agent has access to platform specific (native) APIs – Powerful general API • On the negative side: – Agent needs to be compiled for the various platforms of interest – User must use a library compiled for the specific platform he is using – The general API must support all kinds of tooling -> sometimes harder to find efficient solutions for very specific tasks – Hard to write correct JVMTI code, JNI code for sure 24
  • 25. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. JDI 25
  • 26. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. JDI (Java Debug Interface) • Java has a comprehensive debugger architecture (JPDA) • JDI is a Java API for attaching to Java processes as a debugger client – Socket communication (dt_socket, host & port, over JDWP) – Local attach (process identrified by PID) – Shared Memory (Win32 only, dt_shmem, identified by unique name) • Powerful, for example – Allows for setting breakpoints – Allows for accessing contents on the stack (parameters, local variables) – Allows for executing code in the remote JVM 26
  • 27. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. JDI Examples • Three examples provided by Oracle • Trace – Displays traces of program execution (< 600 lines) – Uses most of basic JDI à good starting point • Jdb – Command line debugger • Javadt – The beginnings of a GUI debugger. • Simple scaled down Hello World example at the java-svc GitHub repo 27
  • 28. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Production Time? • No, not really – People setting breakpoints in your production code? – Executing arbitrary code? – Performance penalties (severe, especially if evaluating expressions in breakpoints) • Sometimes the one remaining option – Start a node with dt_socket – Assumes that you either have direct access (!), or access to establish an SSH bridge – Attach using your favourite remote debugger in your IDE 28
  • 29. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Example java -Xdebug -Xrunjdwp:transport=dt_socket, address=9876, server=y, suspend=y MyClass ssh -L 9876:localhost:9876 <user>@<host> -p <sshd port> 29 For completeness…
  • 30. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. JPLIS 30
  • 31. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. JPLIS • Provides the concept of an Agent – Agent can have a premain method – An agent can also have an agentmain method (run when loaded dynamically) – The agent is a jar, and the manifest specifies the Premain-/Agent-Class • Provides an interface for manipulating the byte code of a class – java.lang.Instrumentation – ClassFileTransformer used when class is loaded/retransformed • Can be loaded from the command line with –javaagent • Can be loaded dynamically with attach 31 Java Programming Language Instrumentation Services
  • 32. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Transforming a Class 32 java HelloWorld load HelloWorld.class run HelloWorld.main(…)
  • 33. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Transforming a Class 33 java -javaagent:myagent.jar HelloWorld Agent.premain registers Transformer load HelloWorld.class byte[] Transformer.transform(transform(ClassLoader loader, String className,…, byte[] classfileBuffer)) run HelloWorld.main(…)
  • 34. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Transformation • The transformation usually is done using a bytecode engineering library • Multiple to chose from – ASM – BCEL – javassist – ByteBuddy – … • Simple example using ASM in the java-svc repo – List methods to be instrumented in a text file – Will time the time spent in the method body for the listed methods and print it out 34
  • 35. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Manifest decides what is allowed (capabilities) • Premain-Class: se.hirt.examples.svc.jplis.ExampleAgent • Agent-Class: se.hirt.examples.svc.jplis.ExampleAgent • Can-Redefine-Classes: false • Can-Retransform-Classes: true • Can-Set-Native-Method-Prefix: false 35
  • 36. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Example - premain 36 public static void premain(String agentArguments, Instrumentation instrumentation) { try { List<TransformDescriptor> probes = readProbes(agentArguments); instrumentation.addTransformer(new ExampleTransformer(probes)); } catch (IOException e) { getLogger().log(Level.SEVERE, "Could not initialize agent! Agent will not be active!", e); } }
  • 37. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Example - ASM 37 private void emitTimingPrologue() { mv.visitMethodInsn(INVOKESTATIC, "java/lang/System", "nanoTime", "()J", false); localVariableIndexTime = newLocal(Type.LONG_TYPE); mv.visitVarInsn(LSTORE, localVariableIndexTime); } private void emitTimingEpilogue() { mv.visitMethodInsn(INVOKESTATIC, "java/lang/System", "nanoTime", "()J", false); mv.visitVarInsn(LLOAD, localVariableIndexTime); mv.visitInsn(LSUB); mv.visitVarInsn(LSTORE, localVariableIndexTime); }
  • 38. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Be Careful • Redefinition limitations – Can’t add/remove methods – No hierarchy changes – Can’t change (method/class) modifiers – Can’t add/remove fields • You may want to generate classes on the fly – Defining your generated classes? à sun.misc.Unsafe to the rescue • Careful not to alter the execution of the original application – Inadvertedly alter the execution path, e.g. by throwing exceptions • Deopts! 38
  • 39. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. JCMD 39
  • 40. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. JCMD – Java Command • Sends command to local Java Process • Retrieves a String response • Executes Diagnostic Commands (as mentioned in previous examples) • Launcher usually both forward and backwards compatible – Use JDK 11 to send commands to JDK 7 – Use JDK 7 to send commands to JDK 11 – Use the help command to find out what commands are available • Commands available to control the JDK Flight Recorder 40
  • 41. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Example $ jcmd 89840 org.codehaus.plexus.classworlds.launcher.Launcher jetty:run 97845 jdk.jcmd/sun.tools.jcmd.JCmd $ jcmd 89840 help 89840: The following commands are available: JFR.stop JFR.start JFR.dump JFR.check … 41 List all processes
  • 42. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Example $ jcmd 89840 help JFR.stop 89840: JFR.stop Stops a JFR recording Impact: Low Permission: java.lang.management.ManagementPermission(monitor) Syntax : JFR.stop [options] Options: (options must be specified using the <key> or <key>=<value> syntax) name : [optional] Recording name,.e.g "My Recording" (STRING, no default value) recording : [optional] Recording number, see JFR.check for a list of available recordings (JLONG, -1) 42 Get help
  • 43. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Note • Providing the PID 0 will execute the command in all JVMs • As mentioned, remotable over JMX (DiagnosticCommandMBean) • Often used to control the JDK Flight Recorder from scripts or from the command line • Only for processes with the same effective user as the one running jcmd 43
  • 44. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. JFR 44
  • 45. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Production Time Profiling and Diagnostics 45 “The big challenge is no longer really performance. The big challenge is profiling, and especially profiling in production.” - Tony Printezis, JVM engineer, Twitter (Devoxx 2015, ”Life of a Twitter JVM Engineer”, 49:49)
  • 46. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. "Java Mission Control is the best profiler by far.“ - T Jake Luciani, PMC Cassandra “Java Mission Control is my current favourite profiler for the Oracle JVM." - Nitsan Wakart, Azul “… Our real-time messaging products can publish millions of messages a second to many thousands of connections - only JMC can keep up with this level of load." - Phil Aston, Product Architect, Push Technology "JMC not only saves time trying to resolve performance issues and bugs, it can give you a detailed view on your application you cannot get with other commercial profilers" - Peter Lawrey, CEO, Chronicle Software “Once more @javamissionctrl is saving my day! " - Michael Nitschinger, SDK Engineer, Couchbase "For the record: Java Mission Control is the best profiler ever, I use it daily, and so should you" - Marcus Lagergren, Lead Architect, Nasdaq
  • 47. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. "I am ACS engineer since 2008, delivering local Middleware support to several customers. Since I started to work with Java/JRockit Mission Control, it became a key tool for my work, helping me to troubleshooting, identifying root causes and bottlenecks, and also for doing proactive follow up services to customers. Without it, I would be blind." - Iratxe Etxebarria, Oracle (ACS) "In Fusion we create hundreds of thousands of Flight Recordings, and we can figure out 95% of the issues using nothing but the recordings." - Joe Albowicz, Oracle (Fusion Application Development)
  • 48. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Flight Recorder • High Performance Event Recorder • Built into the JVM • Binary recordings • Chunks – Self contained – Self describing 101
  • 49. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. OpenJDK has Flight Recorder! • OpenSourced, and available in JDK 11! • Records information about the JVM and the application running • Can be extended with custom (contextual) information (Event API) • Can be controlled from Diagnostic Commands (jcmd) • Can be controlled from JMX (diagnostic commands and dedicated API) • Also POJO local Java API for controlling the recorder 49
  • 50. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Rich Data • Method profiling (multiple variants) – asyncGetCalltrace (no need to safepoint) – New event in JDK 10 for calls out to native • Allocation profiling • Latency profiling • GC information • Method compilation information • Old object sampling – New event in JDK 10 for sorting out memory leaks 50
  • 51. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Low Overhead • Access to data already collected in the runtime • Thread local native buffers • Invariant TSC for time stamping • Method profiling data even from outside safe-points • Faster and more accurate allocation profiling (scalarization not undone by profiler) • No overhead when event is turned off (and on the critical path) 51
  • 52. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 52 Java API Events JVM Events Event Event Event Event ThreadBuffer Global Buffer Global Buffer Global Buffer Global Buffer Global Buffer Global Buffer Global Buffer Global Buffer Copied into JFR File
  • 53. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Example 53 Adding a custom event public class HelloJfr { @Label("Hello World!") static class HelloWorldEvent extends Event { @Label("Message") String message; } public static void main(String... args) throws IOException { HelloWorldEvent event = new HelloWorldEvent(); event.message = "Hello World!"; event.commit(); } }
  • 54. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Another Custom Event 54 @Label("Fibonacci") @Description("An example event") @Category("Fibonacci") @Enabled(true) public final class FibonacciEvent extends Event { @Label("Fibonacci Number") @Description("The number in the sequence calculated, i.e. the n:th number") public int number; @Label("Fibonacci Sum") @Description("The value of the n:th number") public long value; }
  • 55. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 55 API for Parsing Flight Recorder Files public class ParserExample { public static void main(String[] args) throws IOException { long maxNanos = Long.MIN_VALUE; RecordedEvent maxEvent = null; for (RecordedEvent event : RecordingFile.readAllEvents(Paths.get(args[0]))) { if (event.getEventType().getName().equals("se.hirt.jfr4junit.TestEvent")) { long nanos = event.getDuration(); if (nanos > maxNanos) { maxNanos = nanos; maxEvent = event; } } } System.out.printf("Longest running test was: %s for %dsn", maxEvent.getValue("displayName"), maxNanos / 1_000_000); System.out.println("Event was:n" + maxEvent); } }
  • 56. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 56 Control API and Parsing Example public class RecordAndConsume { public static void main(String[] args) throws IOException { Path path = Paths.get(args[0]); try (Recording recording = new Recording()) { recording.setName("Fibonacci Recording"); recording.start(); recording.enable(FibonacciEvent.class); for (int n = 0; n < 50; n++) { FibonacciEvent event = new FibonacciEvent(); event.number = n; event.begin(); event.value = Fibonacci.fibonacciIterative(n); event.commit(); } recording.stop(); recording.dump(path); for (RecordedEvent event : RecordingFile.readAllEvents(path)) { int number = event.getValue("number"); long value = event.getValue("value"); System.out.printf("fibonacci(%d) = %d (time: %dns)n", number, value, event.getDuration()); } } } }
  • 57. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. JMC Core 57
  • 58. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. JDK Mission Control • Two parts – the application and the core libraries • The core libraries contain – A backwards compatible JFR parser capable of running on JDK 7 and above – Can parse JFR recordings from Oracle JDK 7u40 and above – An API for filtering and aggregating data (from, for example JFR) – An API for working with quantities and units of measurement – An API for analysing JFR recordings • See my jmc-jshell repo for examples 58
  • 59. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Example 59 Calculating the Standard Deviation for Monitor Enter events public static void main(String[] args) throws Exception { IItemCollection events = JfrLoaderToolkit.loadEvents(new File(args[0])); IItemCollection monitorEnterEvents = events.apply(JdkFilters.MONITOR_ENTER); IQuantity stddev = monitorEnterEvents.getAggregate( Aggregators.stddev(JfrAttributes.DURATION)); System.out.println(stddev.displayUsing(IDisplayable.AUTO))); }
  • 60. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Example 60 Getting an HTML report public static void main(String[] args) throws Exception { String report = JfrHtmlRulesReport.createReport( JfrLoaderToolkit.loadEvents(new File(args[0]))); System.out.println(report); }
  • 61. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Putting it together 61
  • 62. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Some Already Mentioned Examples • Using JCMD from scripts to control the JDK Flight Recorder – Dumping already defined recordings at a regular interval, moving them somewhere and pre-process them/run custom rules on them – Do a m minute profiling recording every h hours • Using JMX to remotely to access JCMD 62
  • 63. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Using JMX + PerfCounters • Expose the perf counters through a Dynamic MBean 63 https://github.com/thegreystone/java-svc/tree/master/perfcounters
  • 64. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Using JMX + JPLIS + JFR • Use JFR to record JMX data directly to JFR – Stacktraces not interesting, so don’t record them – Let the user configure what to record – Use not only the data type, but let the user add content type information • Build it as a JPLIS agent – Not really using BCI at all… – …but can now be loaded on the command line using –javaagent – …and loaded dynamically into a running process (for example through attach) • Now have access to e.g. third party information available in JMX, but in the context of everything else recorded in JFR! Prototype: https://github.com/thegreystone/jmx2jfr 64
  • 65. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Using JPLIS + JFR to Inject Events • Building a JPLIS agent to inject JFR events around methods – Dynamically adds JFR events to method entries/exits (either or both) – Method timing using efficient JFR events! – Selectively records parameters and/or return values – Optionally records stack traces, again using efficient JFR events – Ongoing project in the JMC project (jmc agent) • First prototype available with JMC 7 • Uses ASM to add well defined byte code • Generates support classes as needed, and defines them using sun.misc.Unsafe… Prototype here: http://hg.openjdk.java.net/jmc/jmc (under core/ org.openjdk.jmc.agent) 65
  • 66. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Summing it all up… 66
  • 67. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Summary • Java has a rich and powerful set of serviceability features • Some of them are rather suited for production use • Using them together makes them even more useful • They are rather easy to get started with • One place to start playing with them is here: https://github.com/thegreystone/java-svc 67
  • 68. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Safe Harbor Statement The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.
  • 69. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Other JMC-/JFR-related Presentations Day Time Title Location Monday 10:30 Contributing to the Mission Control OpenJDK Project MW 2004 Tuesday 11:30 Three Productive Ways to Use Open Source Java Flight Recorder and Java Mission Control MW 2024 Tuesday 12:30 Flight Recorder in OpenJDK MW 2018 Tuesday 14:30 Fast and Furious: Java Flight Recorder and Flame Graphs MW 2020 Wednesday 10:30 Production-Time Profiling and Diagnostics on the JVM MW 2004 Wednesday 12:30 OpenJDK Mission Control: The Hands-on-Lab MW 2001A Wednesday 16:30 Diagnose Your Microservices: OpenTracing/Oracle APM Cloud MW 2011 Thursday 11:00 Getting Started with the (Open Source) JDK Mission Control MW 2014 69