Performance Tuning in Production: James Gough Sadiq Jaffer Kirk Pepperdine Richard Warburton
Performance Tuning in Production: James Gough Sadiq Jaffer Kirk Pepperdine Richard Warburton
James Gough
Sadiq Jaffer
Kirk Pepperdine
Richard Warburton
James Gough
@Jim__Gough
http://jamesgough.net
• Who Am I
• Creating Bytecode
• Classloading
• Profiling Code
• Runtime Optimisations
• JITWatch
JVM
+
JVM
+
=
Java
source
code
JVM
javac
Java
source
code
JVM
.class
file
javac
Java
source
code
Version of Class The minor and major versions of the class file
File Format
Constant Pool Pool of constants for the class
Access Flags For example whether the class is abstract, static, etc.
Attributes Any attributes of the class (e.g. name of the sourcefile, etc.)
M V C A T S I F M A
Magic Version Constant Access This Super Interfaces Fields Methods Attributes
B byte
• Common in javap output
C char
• E.g. D double
• ()Ljava/lang/String; F float
I int
• (I)V
J long
• (Ljava/lang/String;I)J
L<type>; Reference type
S short
Z boolean
[ Array-of
JVM
.class
file classloader
javac
Java
source
code
JVM
.class classloader method cache
file
javac JVM
Interpreter
Java
source
code
• The profiler observes the execution and looks for the best
optimisations
• Configurable
JVM
.Class classloader method cache
file
JIT compiler
Java
source
code
JVM
.Class classloader method cache
file
JIT compiler
javac
Interpreter Profiler Emitter
Java
source
code
Time
Task Method Name (size of compiled code)
Offset
321 40 sun.nio.cs.StreamEncoder::isOpen (5 bytes)
322 41 sun.nio.cs.StreamEncoder::implFlushBuffer (15 bytes)
327 42 sun.nio.cs.StreamEncoder::writeBytes (132 bytes)
331 43 ! java.io.PrintStream::write (69 bytes)
335 44 s java.io.BufferedOutputStream::write (67 bytes)
337 46 java.nio.Buffer::clear (20 bytes)
337 47 java.lang.String::indexOf (7 bytes)
338 48 ! java.io.PrintStream::println (24 bytes)
338 49 java.io.PrintStream::print (13 bytes)
343 50 ! java.io.PrintStream::write (83 bytes)
346 51 ! java.io.PrintStream::newLine (73 bytes)
347 52 java.io.BufferedWriter::newLine (9 bytes)
347 53 % HelloWorld::main @ 2 (23 bytes)
! method has exception handler(s)
s method declared synchronized
n native method (no compilation, generate wrapper)
% on-stack replacement used
• determined at runtime
@Benchmark
public long longStride1()
{
long sum = 0; Benchmark Mode Cnt Score Error Units
for (long l = 0; l < MAX; l++) LoopUnrollingCounter.intStride1 thrpt 200 2423.818 ± 2.547 ops/s
{ LoopUnrollingCounter.longStride1 thrpt 200 1469.833 ± 0.721 ops/s
sum += data[(int) l];
}
return sum;
}
Excerpt From: Benjamin J. Evans, James Gough, and Chris Newland. “Optimizing Java.” iBooks.
• When HotSpot encounters a virtual call site, often only one type
will ever be seen there
• e.g. There's only one implementing class for an interface
JVM
.Class classloader method cache
file
JIT compiler
javac
Interpreter Profiler Emitter
Java
source code cache
code
javac Executing
Interpreter Profiler Emitte Code Quality
Java
source code cache
code