SlideShare a Scribd company logo
1 of 120
1
THE	
PERFORMANCE	
ENGINEER’S	
GUIDE	TO	
HOTSPOT	
JIT	COMPILATION
Monica	Beckwith	
CODE	KARAM	LLC
2
About Me …
Java/JVM/GC performance person
Current Life:
Consultant who solves Managed Runtime performance issues
Past Life:
Worked with Oracle, Sun, AMD…
- Worked with HotSpot VM: JVM heuristics, JIT compiler, GCs:
Parallel(Old) GC, G1 GC, CMS GC
www.codekaram.com
https://www.linkedin.com/in/monicabeckwith
Tweet @mon_beck
©2016 CodeKaram
Establishing the Characters
and The Plot
• HotSpot Virtual Machine
• Runtime Goal
• Common Compilation Techniques
• C1, C2 & Tiered Compilations
• Adaptive Optimization - The Plot
3
©2016 CodeKaram
The Storyline
• Dynamic Deoptimization
• Inlining
• Intrinsics
4
©2016 CodeKaram
The StoryLine
• Compressed Oops + Compressed Class
Pointers
• Escape Analysis
• Vectorization (Auto and otherwise)
5
6
HotSpot Virtual Machine
©2016 CodeKaram
Let’s Peek Under The Hood
7
Java Application
Java
APIs Execution Engine
Java VM
OS + Hardware
Runtime
©2016 CodeKaram8
Java Application
Java
API
Java VM
OS + HardwareJRE
Execution Engine
Runtime
Java Runtime Environment
©2016 CodeKaram
The Helpers
9
Java VM
Execution Engine
Runtime
©2016 CodeKaram
HotSpot VM
10
Execution Engine
Heap
Management
- Garbage
Collection
JIT Compilation -
Tiered (C1 + C2)
©2016 CodeKaram
HotSpot VM
11
Runtime
VM Class
loading
Interpreter
Bytecode
Verification,
Exception
Handling,
Synchronization
, Thread
Management, ….http://openjdk.java.net/groups/hotspot/
docs/RuntimeOverview.html
©2016 CodeKaram
Runtime Goal
12
Bytecode
Native code
©2016 CodeKaram
HotSpot VM - Template
Interpreter
13
Bytecode 1
Bytecode 2
Template Native Code 1
Template Native Code 2
TemplateTable
©2016 CodeKaram
Common Compilation
Techniques
14
Compilation
Adaptive
Optimization
Ahead
Of
Time
Profile-
guided
Static
©2016 CodeKaram
HotSpot VM
15
Compilation
Adaptive
Optimization
Ahead
Of
Time
Profile-
guided
Static
©2016 CodeKaram
• CompileThreshold
• Identify root of compilation
• Method Compilation or On-stack
replacement (Loop)?
16
Identifying Performance
Critical Methods
17
JIT Optimization - Client
Compiler (C1)
©2016 CodeKaram
• Start in interpreter
• CompileThreshold = 1500
• Compile with client compiler
• Few optimizations
18
Client Compiler
19
JIT Optimization - Server
Compiler (C2)
©2016 CodeKaram
• Start in interpreter
• CompileThreshold = 10000
• Compile with optimized server compiler
• High performance optimizations
20
Server Compiler
21
JIT Optimization - Tiered
Compilation
22
©2016 CodeKaram
• Start in interpreter
• Tiered optimization with client compiler
• Code profiled information
• Enable server compiler
23
Tiered Compilation
©2016 CodeKaram24
Tiered Compilation - Effect
on Code Cache
Tiered
Compilation
Code
Cache
Compiled
Native Code
©2016 CodeKaram
• C1 compilation threshold for tiered is about a 100
invocations
• Tiered Compilation has a lot more profiled information
for C1 compiled methods
• CodeCache needs to be 5x larger than non-tiered
• Default on JDK8 when tiered is enabled (240MB vs
48MB)
• Need more? Use -XX:ReservedCodeCacheSize
25
Tiered Compilation - Effect
on Code Cache
26
Advanced Optimizations -
Adaptive Optimization
©2016 CodeKaram27
The Plot
Startup
(Adaptive) JIT
Optimizations
Profiling of
critical hot-
spots
Interpreter
©2016 CodeKaram28
The Plot
Startup
(Adaptive) JIT
Optimizations
Profiling of
critical hot-
spots
Interpreter
29
Adaptive Optimization:
Dynamic Deoptimization
30
Dynamic Deoptimization
©2016 CodeKaram
• Oopsie!
• dependencies invalidation
• classes unloading and redefinition
• uncommon path in compiled code
• misguided profiled information
31
Dynamic Deoptimization
32
Understanding Adaptive
Optimization -
PrintCompilation
©2016 CodeKaram
PrintCompilation
33
timestamp compilation-id flags tiered-
compilation-level Method <@ osr_bci> code-
size <deoptimization>
©2016 CodeKaram
PrintCompilation
34
Flags:
%: is_osr_method
s: is_synchronized
!: has_exception_handler
b: is_blocking
n: is_native
©2016 CodeKaram
PrintCompilation
35
567 693 % ! 3
org.h2.command.dml.Insert::insertRows @ 76 (513 bytes)
656 797 n 0
java.lang.Object::clone (native)
779 835 s 4
java.lang.StringBuffer::append (13 bytes)
©2016 CodeKaram36
573 704 2
org.h2.table.Table::fireAfterRow (17 bytes)
7963 2223 4
org.h2.table.Table::fireAfterRow (17 bytes)
7964 704 2
org.h2.table.Table::fireAfterRow (17 bytes)
made not entrant
33547 704 2
org.h2.table.Table::fireAfterRow (17 bytes)
made zombie
Dynamic Deoptimization
©2016 CodeKaram37
573 704 2
org.h2.table.Table::fireAfterRow (17 bytes)
7963 2223 4
org.h2.table.Table::fireAfterRow (17 bytes)
7964 704 2
org.h2.table.Table::fireAfterRow (17 bytes)
made not entrant
33547 704 2
org.h2.table.Table::fireAfterRow (17 bytes)
made zombie
Dynamic Deoptimization
©2016 CodeKaram38
573 704 2
org.h2.table.Table::fireAfterRow (17 bytes)
7963 2223 4
org.h2.table.Table::fireAfterRow (17 bytes)
7964 704 2
org.h2.table.Table::fireAfterRow (17 bytes)
made not entrant
33547 704 2
org.h2.table.Table::fireAfterRow (17 bytes)
made zombie
Dynamic Deoptimization
©2016 CodeKaram39
573 704 2
org.h2.table.Table::fireAfterRow (17 bytes)
7963 2223 4
org.h2.table.Table::fireAfterRow (17 bytes)
7964 704 2
org.h2.table.Table::fireAfterRow (17 bytes)
made not entrant
33547 704 2
org.h2.table.Table::fireAfterRow (17 bytes)
made zombie
Dynamic Deoptimization
©2016 CodeKaram40
573 704 2
org.h2.table.Table::fireAfterRow (17 bytes)
7963 2223 4
org.h2.table.Table::fireAfterRow (17 bytes)
7964 704 2
org.h2.table.Table::fireAfterRow (17 bytes)
made not entrant
33547 704 2
org.h2.table.Table::fireAfterRow (17 bytes)
made zombie
Dynamic Deoptimization
41
JIT Optimization - Inlining
©2016 CodeKaram
HotSpot has studied Inlining to it’s max potential!
42
Inlining
©2016 CodeKaram
MinInliningThreshold, MaxFreqInlineSize,
InlineSmallCode, MaxInlineSize, MaxInlineLevel,
DesiredMethodLimit …
43
Inlining
44
Understanding Inlining
Optimization -
PrintInlining
©2016 CodeKaram
PrintInling*
45
@ 76 java.util.zip.Inflater::setInput (74 bytes)
too big
@ 80 java.io.BufferedInputStream::getBufIfOpen (21
bytes) inline (hot)
@ 91 java.lang.System::arraycopy (0 bytes)
(intrinsic)
@ 2 java.lang.ClassLoader::checkName (43 bytes)
callee is too large
* needs -XX:+UnlockDiagnosticVMOptions
©2016 CodeKaram
PrintInling*
46
@ 76 java.util.zip.Inflater::setInput (74 bytes)
too big
@ 80 java.io.BufferedInputStream::getBufIfOpen (21
bytes) inline (hot)
@ 91 java.lang.System::arraycopy (0 bytes)
(intrinsic)
@ 2 java.lang.ClassLoader::checkName (43 bytes)
callee is too large
* needs -XX:+UnlockDiagnosticVMOptions
47
JIT Optimization - Intrinsics
©2016 CodeKaram48
Without Intrinsics
Java Method
JIT Compilation
Execute Generated Code
©2016 CodeKaram49
Intrinsics
Java Method
JIT Compilation
Execute Optimized Code
Call Hand-
Optimized
Assembly Code
©2016 CodeKaram
PrintInling*
50
@ 76 java.util.zip.Inflater::setInput (74 bytes)
too big
@ 80 java.io.BufferedInputStream::getBufIfOpen (21
bytes) inline (hot)
@ 91 java.lang.System::arraycopy (0 bytes)
(intrinsic)
@ 2 java.lang.ClassLoader::checkName (43 bytes)
callee is too large
* needs -XX:+UnlockDiagnosticVMOptions
51
Advanced Optimizations -
Compressed Oops +
Compressed Class Pointers
52
A Java Object
©2016 CodeKaram53
Header Body
©2016 CodeKaram
Objects, Fields & Alignment
• Objects are 8 byte aligned (default).
• Fields:
• are aligned by their type.
• can fill a gap that maybe required for
alignment.
• are accessed using offset from the start of the
object
54
55
Java Object Layout in Memory
©2016 CodeKaram56
-Tool to analyze Java object layout :)
Java Object Layout (JOL)
©2016 CodeKaram
JOL Command Line Options
$ java -jar jol-cli.jar
Usage: jol-cli.jar <mode> [optional arguments]*
Available modes:
estimates: Simulate the class layout in different VM modes.
externals: Show the object externals: the objects reachable
from a given instance.
footprint: Estimate the footprint of all objects reachable
from a given instance
heapdump: Consume the heap dump and estimate the savings
in different layout strategies.
heapdumpstats: Consume the heap dump and print the most
frequent instances.
idealpack: Compute the object footprint under different
field layout strategies.
internals: Show the object internals: field layout and
default contents, object header
shapes: Dump the object shapes present in JAR files or
heap dumps.
string-compress: Consume the heap dumps and figures out the
savings attainable with compressed strings.
57
©2016 CodeKaram
JOL Command Line Options
$ java -jar jol-cli.jar
Usage: jol-cli.jar <mode> [optional arguments]*
Available modes:
estimates: Simulate the class layout in different VM modes.
externals: Show the object externals: the objects reachable from
a given instance.
footprint: Estimate the footprint of all objects reachable from
a given instance
heapdump: Consume the heap dump and estimate the savings in
different layout strategies.
heapdumpstats: Consume the heap dump and print the most frequent
instances.
idealpack: Compute the object footprint under different field
layout strategies.
internals: Show the object internals:
field layout and default contents, object header
shapes: Dump the object shapes present in JAR files or heap
dumps.
string-compress: Consume the heap dumps and figures out the savings
attainable with compressed strings.
58
©2016 CodeKaram
Compressed OOPs and
Compressed Class Pointers
59
# Running 64-bit HotSpot VM.
# Using compressed oop with 3-bit shift.
# Using compressed klass with 3-bit
shift.
©2016 CodeKaram
Compressed OOPs and
Compressed Class Pointers
60
# Running 64-bit HotSpot VM.
# Using compressed oop with 3-bit shift.
# Using compressed klass with 3-bit
shift.
61
A Java Object Header
©2016 CodeKaram
A Java Object Header
62
Header
Klass
Mark
Word
Array
Length
63
Java Object Layout Samples -
Uncompressed
©2016 CodeKaram
JOL: 8 Byte Array
[B object internals:
OFFSET SIZE TYPE DESCRIPTION VALUE
0 4 (object header) 01 00
00 00 (00000001 00000000 00000000 00000000) (1)
4 4 (object header) 00 00
00 00 (00000000 00000000 00000000 00000000) (0)
8 4 (object header) a8 07
c0 34 (10101000 00000111 11000000 00110100) (885000104)
12 4 (object header) 02 00
00 00 (00000010 00000000 00000000 00000000) (2)
16 4 (object header) 08 00
00 00 (00001000 00000000 00000000 00000000) (8)
20 4 (alignment/padding gap) N/A
24 8 byte [B.<elements> N/A
Instance size: 32 bytes
Space losses: 4 bytes internal + 0 bytes external = 4
bytes total
64
©2016 CodeKaram
JOL: 8 Byte Array
[B object internals:
OFFSET SIZE TYPE DESCRIPTION VALUE
0 4 (object header) 01 00
00 00 (00000001 00000000 00000000 00000000) (1)
4 4 (object header) 00 00
00 00 (00000000 00000000 00000000 00000000) (0)
8 4 (object header) a8 07
c0 34 (10101000 00000111 11000000 00110100) (885000104)
12 4 (object header) 02 00
00 00 (00000010 00000000 00000000 00000000) (2)
16 4 (object header) 08 00
00 00 (00001000 00000000 00000000 00000000) (8)
20 4 (alignment/padding gap) N/A
24 8 byte [B.<elements> N/A
Instance size: 32 bytes
Space losses: 4 bytes internal + 0 bytes external = 4
bytes total
65
Mark Word
©2016 CodeKaram
JOL: 8 Byte Array
[B object internals:
OFFSET SIZE TYPE DESCRIPTION VALUE
0 4 (object header) 01 00
00 00 (00000001 00000000 00000000 00000000) (1)
4 4 (object header) 00 00
00 00 (00000000 00000000 00000000 00000000) (0)
8 4 (object header) a8 07
c0 34 (10101000 00000111 11000000 00110100) (885000104)
12 4 (object header) 02 00
00 00 (00000010 00000000 00000000 00000000) (2)
16 4 (object header) 08 00
00 00 (00001000 00000000 00000000 00000000) (8)
20 4 (alignment/padding gap) N/A
24 8 byte [B.<elements> N/A
Instance size: 32 bytes
Space losses: 4 bytes internal + 0 bytes external = 4
bytes total
66
Klass
©2016 CodeKaram
JOL: 8 Byte Array
[B object internals:
OFFSET SIZE TYPE DESCRIPTION VALUE
0 4 (object header) 01 00
00 00 (00000001 00000000 00000000 00000000) (1)
4 4 (object header) 00 00
00 00 (00000000 00000000 00000000 00000000) (0)
8 4 (object header) a8 07
c0 34 (10101000 00000111 11000000 00110100) (885000104)
12 4 (object header) 02 00
00 00 (00000010 00000000 00000000 00000000) (2)
16 4 (object header) 08 00
00 00 (00001000 00000000 00000000 00000000) (8)
20 4 (alignment/padding gap) N/A
24 8 byte [B.<elements> N/A
Instance size: 32 bytes
Space losses: 4 bytes internal + 0 bytes external = 4
bytes total
67
©2016 CodeKaram
JOL: 8 Byte Array
[B object internals:
OFFSET SIZE TYPE DESCRIPTION VALUE
0 4 (object header) 01 00
00 00 (00000001 00000000 00000000 00000000) (1)
4 4 (object header) 00 00
00 00 (00000000 00000000 00000000 00000000) (0)
8 4 (object header) a8 07
c0 34 (10101000 00000111 11000000 00110100) (885000104)
12 4 (object header) 02 00
00 00 (00000010 00000000 00000000 00000000) (2)
16 4 (object header) 08 00
00 00 (00001000 00000000 00000000 00000000) (8)
20 4 (alignment/padding gap) N/A
24 8 byte [B.<elements> N/A
Instance size: 32 bytes
Space losses: 4 bytes internal + 0 bytes external = 4
bytes total
68
Array Length
©2016 CodeKaram
JOL: 8 Byte Array
[B object internals:
OFFSET SIZE TYPE DESCRIPTION VALUE
0 4 (object header) 01 00 00 00
(00000001 00000000 00000000 00000000) (1)
4 4 (object header) 00 00 00 00
(00000000 00000000 00000000 00000000) (0)
8 4 (object header) a8 07 c0 34
(10101000 00000111 11000000 00110100) (885000104)
12 4 (object header) 02 00 00 00
(00000010 00000000 00000000 00000000) (2)
16 4 (object header) 08 00 00 00
(00001000 00000000 00000000 00000000) (8)
20 4 (alignment/padding gap)
N/A
24 8 byte [B.<elements> N/A
Instance size: 32 bytes
Space losses: 4 bytes internal + 0 bytes external = 4 bytes
total
69
©2016 CodeKaram
JOL: 8 Byte Array
[B object internals:
OFFSET SIZE TYPE DESCRIPTION VALUE
0 4 (object header) 01 00 00 00
(00000001 00000000 00000000 00000000) (1)
4 4 (object header) 00 00 00 00
(00000000 00000000 00000000 00000000) (0)
8 4 (object header) a8 07 c0 34
(10101000 00000111 11000000 00110100) (885000104)
12 4 (object header) 02 00 00 00
(00000010 00000000 00000000 00000000) (2)
16 4 (object header) 08 00 00 00
(00001000 00000000 00000000 00000000) (8)
20 4 (alignment/padding gap) N/A
24 8 byte [B.<elements>
N/A
Instance size: 32 bytes
Space losses: 4 bytes internal + 0 bytes external = 4 bytes
total
70
71
Java Object Layout Samples -
Compressed
©2016 CodeKaram
JOL: 8 Byte Array
[B object internals:
OFFSET SIZE TYPE DESCRIPTION
VALUE
0 4 (object header) 01
00 00 00 (00000001 00000000 00000000 00000000) (1)
4 4 (object header) 00
00 00 00 (00000000 00000000 00000000 00000000) (0)
8 4 (object header) f5
00 00 f8 (11110101 00000000 00000000 11111000)
(-134217483)
12 4 (object header) 08
00 00 00 (00001000 00000000 00000000 00000000) (8)
16 8 byte [B.<elements> N/A
Instance size: 24 bytes
Space losses: 0 bytes internal + 0 bytes external = 0
bytes total
72
©2016 CodeKaram
JOL: 8 Byte Array
[B object internals:
OFFSET SIZE TYPE DESCRIPTION
VALUE
0 4 (object header) 01
00 00 00 (00000001 00000000 00000000 00000000) (1)
4 4 (object header) 00
00 00 00 (00000000 00000000 00000000 00000000) (0)
8 4 (object header) f5
00 00 f8 (11110101 00000000 00000000 11111000)
(-134217483)
12 4 (object header) 08
00 00 00 (00001000 00000000 00000000 00000000) (8)
16 8 byte [B.<elements> N/A
Instance size: 24 bytes
Space losses: 0 bytes internal + 0 bytes external = 0
bytes total
73
Mark Word
©2016 CodeKaram
JOL: 8 Byte Array
[B object internals:
OFFSET SIZE TYPE DESCRIPTION
VALUE
0 4 (object header) 01
00 00 00 (00000001 00000000 00000000 00000000) (1)
4 4 (object header) 00
00 00 00 (00000000 00000000 00000000 00000000) (0)
8 4 (object header) f5
00 00 f8 (11110101 00000000 00000000 11111000)
(-134217483)
12 4 (object header) 08
00 00 00 (00001000 00000000 00000000 00000000) (8)
16 8 byte [B.<elements> N/A
Instance size: 24 bytes
Space losses: 0 bytes internal + 0 bytes external = 0
bytes total
74
©2016 CodeKaram
JOL: 8 Byte Array
[B object internals:
OFFSET SIZE TYPE DESCRIPTION
VALUE
0 4 (object header) 01
00 00 00 (00000001 00000000 00000000 00000000) (1)
4 4 (object header) 00
00 00 00 (00000000 00000000 00000000 00000000) (0)
8 4 (object header) f5
00 00 f8 (11110101 00000000 00000000 11111000)
(-134217483)
12 4 (object header) 08
00 00 00 (00001000 00000000 00000000 00000000) (8)
16 8 byte [B.<elements> N/A
Instance size: 24 bytes
Space losses: 0 bytes internal + 0 bytes external = 0
bytes total
75
Klass
©2016 CodeKaram
JOL: 8 Byte Array
[B object internals:
OFFSET SIZE TYPE DESCRIPTION
VALUE
0 4 (object header) 01
00 00 00 (00000001 00000000 00000000 00000000) (1)
4 4 (object header) 00
00 00 00 (00000000 00000000 00000000 00000000) (0)
8 4 (object header) f5
00 00 f8 (11110101 00000000 00000000 11111000)
(-134217483)
12 4 (object header) 08
00 00 00 (00001000 00000000 00000000 00000000) (8)
16 8 byte [B.<elements> N/A
Instance size: 24 bytes
Space losses: 0 bytes internal + 0 bytes external = 0
bytes total
76
©2016 CodeKaram
JOL: 8 Byte Array
[B object internals:
OFFSET SIZE TYPE DESCRIPTION
VALUE
0 4 (object header) 01
00 00 00 (00000001 00000000 00000000 00000000) (1)
4 4 (object header) 00
00 00 00 (00000000 00000000 00000000 00000000) (0)
8 4 (object header) f5
00 00 f8 (11110101 00000000 00000000 11111000)
(-134217483)
12 4 (object header) 08
00 00 00 (00001000 00000000 00000000 00000000) (8)
16 8 byte [B.<elements> N/A
Instance size: 24 bytes
Space losses: 0 bytes internal + 0 bytes external = 0
bytes total
77
Array Length
©2016 CodeKaram
JOL: 8 Byte Array
[B object internals:
OFFSET SIZE TYPE DESCRIPTION VALUE
0 4 (object header) 01 00
00 00 (00000001 00000000 00000000 00000000) (1)
4 4 (object header) 00 00
00 00 (00000000 00000000 00000000 00000000) (0)
8 4 (object header) f5 00
00 f8 (11110101 00000000 00000000 11111000) (-134217483)
12 4 (object header) 08 00
00 00 (00001000 00000000 00000000 00000000) (8)
16 8 byte [B.<elements>
N/A
Instance size: 24 bytes
Space losses: 0 bytes internal + 0 bytes external = 0
bytes total
78
79
Java Object Layout Header
Comparison
©2016 CodeKaram
Compressed vs
Uncompressed
Compressed:
Instance size: 24 bytes
Space losses: 0 bytes internal + 0 bytes
external = 0 bytes total
vs
Uncompressed:
Instance size: 32 bytes
Space losses: 4 bytes internal + 0 bytes
external = 4 bytes total
80
©2016 CodeKaram
Compressed vs
Uncompressed
Compressed:
Instance size: 24 bytes
Space losses: 0 bytes internal + 0 bytes
external = 0 bytes total
vs
Uncompressed:
Instance size: 32 bytes
Space losses: 4 bytes internal + 0 bytes
external = 4 bytes total
81
82
A Java Object
©2016 CodeKaram83
Header Body
©2016 CodeKaram
Compressed OOPs and
Compressed Class Pointers
84
# Running 64-bit HotSpot VM.
# Using compressed oop with 3-bit shift.
# Using compressed klass with 3-bit
shift.
85
Java Object Layout Samples -
UnCompressed
©2016 CodeKaram
JOL: Class
java.lang.Class object internals:
OFFSET SIZE TYPE DESCRIPTION VALUE
0 16 (object header) N/A
16 8 Constructor Class.cachedConstructor N/A
24 8 Class Class.newInstanceCallerCache N/A
32 8 String Class.name N/A
40 8 Module Class.module N/A
48 8 (alignment/padding gap) N/A
56 8 String Class.packageName N/A
64 8 Class Class.componentType N/A
72 8 SoftReference Class.reflectionData N/A
80 8 ClassRepository Class.genericInfo N/A
88 8 Object[] Class.enumConstants N/A
96 8 Map Class.enumConstantDirectory N/A
104 8 AnnotationData Class.annotationData N/A
112 8 AnnotationType Class.annotationType N/A
120 8 ClassValueMap Class.classValueMap N/A
128 32 (alignment/padding gap) N/A
160 4 int Class.classRedefinedCount N/A
164 4 (loss due to the next object alignment)
Instance size: 168 bytes
Space losses: 40 bytes internal + 4 bytes external = 44 bytes total
86
©2016 CodeKaram
java.lang.Class object internals:
OFFSET SIZE TYPE DESCRIPTION VALUE
0 16 (object header)
N/A
16 8 Constructor Class.cachedConstructor N/A
24 8 Class Class.newInstanceCallerCache N/A
32 8 String Class.name N/A
40 8 Module Class.module N/A
48 8 (alignment/padding gap) N/A
56 8 String Class.packageName N/A
64 8 Class Class.componentType N/A
72 8 SoftReference Class.reflectionData N/A
80 8 ClassRepository Class.genericInfo N/A
88 8 Object[] Class.enumConstants N/A
96 8 Map Class.enumConstantDirectory N/A
104 8 AnnotationData Class.annotationData N/A
112 8 AnnotationType Class.annotationType N/A
120 8 ClassValueMap Class.classValueMap N/A
128 32 (alignment/padding gap) N/A
160 4 int Class.classRedefinedCount N/A
164 4 (loss due to the next object alignment)
Instance size: 168 bytes
Space losses: 40 bytes internal + 4 bytes external = 44 bytes total
87
JOL: Class
©2016 CodeKaram
java.lang.Class object internals:
OFFSET SIZE TYPE DESCRIPTION VALUE
0 16 (object header) N/A
16 8 Constructor Class.cachedConstructor N/A
24 8 Class Class.newInstanceCallerCache N/A
32 8 String Class.name N/A
40 8 Module Class.module N/A
48 8 (alignment/padding gap) N/A
56 8 String Class.packageName N/A
64 8 Class Class.componentType N/A
72 8 SoftReference Class.reflectionData N/A
80 8 ClassRepository Class.genericInfo N/A
88 8 Object[] Class.enumConstants N/A
96 8 Map Class.enumConstantDirectory N/A
104 8 AnnotationData Class.annotationData N/A
112 8 AnnotationType Class.annotationType N/A
120 8 ClassValueMap Class.classValueMap N/A
128 32 (alignment/padding gap) N/A
160 4 int Class.classRedefinedCount N/A
164 4 (loss due to the next object alignment)
Instance size: 168 bytes
Space losses: 40 bytes internal + 4 bytes external = 44 bytes total
88
JOL: Class
89
Java Object Layout Samples -
Compressed
©2016 CodeKaram
java.lang.Class object internals:
OFFSET SIZE TYPE DESCRIPTION VALUE
0 12 (object header) N/A
12 4 Constructor Class.cachedConstructor N/A
16 4 Class Class.newInstanceCallerCache N/A
20 4 String Class.name N/A
24 4 Module Class.module N/A
28 4 (alignment/padding gap) N/A
32 4 String Class.packageName N/A
36 4 Class Class.componentType N/A
40 4 SoftReference Class.reflectionData N/A
44 4 ClassRepository Class.genericInfo N/A
48 4 Object[] Class.enumConstants N/A
52 4 Map Class.enumConstantDirectory N/A
56 4 AnnotationData Class.annotationData N/A
60 4 AnnotationType Class.annotationType N/A
64 4 ClassValueMap Class.classValueMap N/A
68 28 (alignment/padding gap) N/A
96 4 int Class.classRedefinedCount N/A
100 4 (loss due to the next object alignment)
90
JOL: Class
©2016 CodeKaram
java.lang.Class object internals:
OFFSET SIZE TYPE DESCRIPTION VALUE
0 12 (object header)
N/A
12 4 Constructor Class.cachedConstructor N/A
16 4 Class Class.newInstanceCallerCache N/A
20 4 String Class.name N/A
24 4 Module Class.module N/A
28 4 (alignment/padding gap) N/A
32 4 String Class.packageName N/A
36 4 Class Class.componentType N/A
40 4 SoftReference Class.reflectionData N/A
44 4 ClassRepository Class.genericInfo N/A
48 4 Object[] Class.enumConstants N/A
52 4 Map Class.enumConstantDirectory N/A
56 4 AnnotationData Class.annotationData N/A
60 4 AnnotationType Class.annotationType N/A
64 4 ClassValueMap Class.classValueMap N/A
68 28 (alignment/padding gap) N/A
96 4 int Class.classRedefinedCount N/A
100 4 (loss due to the next object alignment)
91
JOL: Class
©2016 CodeKaram
java.lang.Class object internals:
OFFSET SIZE TYPE DESCRIPTION VALUE
0 12 (object header) N/A
12 4 Constructor Class.cachedConstructor N/A
16 4 Class Class.newInstanceCallerCache N/A
20 4 String Class.name N/A
24 4 Module Class.module N/A
28 4 (alignment/padding gap) N/A
32 4 String Class.packageName N/A
36 4 Class Class.componentType N/A
40 4 SoftReference Class.reflectionData N/A
44 4 ClassRepository Class.genericInfo N/A
48 4 Object[] Class.enumConstants N/A
52 4 Map Class.enumConstantDirectory N/A
56 4 AnnotationData Class.annotationData N/A
60 4 AnnotationType Class.annotationType N/A
64 4 ClassValueMap Class.classValueMap N/A
68 28 (alignment/padding gap) N/A
96 4 int Class.classRedefinedCount N/A
100 4 (loss due to the next object alignment)
92
JOL: Class
©2016 CodeKaram
Compressed OOPs and
Compressed Class Pointers
93
# Running 64-bit HotSpot VM.
# Using compressed oop with 3-bit shift.
# Using compressed klass with 3-bit
shift.
P
P
94
… but what is the 3-bit shift?
©2016 CodeKaram
Compressed OOPs
95
<wide-oop> = <narrow-oop-base> +
(<narrow-oop> << 3) + <field-offset>
©2016 CodeKaram
Compressed OOPs
96
Heap Size?
<4 GB
(no encoding/
decoding needed)
>4GB; <28GB
(zero-based)
<wide-oop> = <narrow-oop> <narrow-oop> << 3
©2016 CodeKaram
Compressed OOPs
97
Heap Size?
>28 GB; <32 GB
(regular)
>32 GB; <64 GB *
(change alignment)
<wide-oop> =
<narrow-oop-base>
+ (<narrow-oop>
<< 3) + <field-
offset>
<narrow-oop-base>
+ (<narrow-oop>
<< 4) + <field-
offset>
©2016 CodeKaram
Compressed OOPs
98
Heap Size? <4 GB
>4GB;
<28GB
<32GB <64GB
Object
Alignment?
8 bytes 8 bytes 8 bytes 16 bytes
Offset
Required?
No No Yes Yes
Shift by? No shift 3 3 4
99
Other Advanced Optimizations
©2016 CodeKaram
• Fast dynamic type tests for type safety
• Range check elimination
• Loop unrolling
• Escape Analysis
• Vectorization!
100
Other Optimizations
©2016 CodeKaram
• Fast dynamic type tests for type safety
• Range check elimination
• Loop unrolling
• Escape Analysis
• Vectorization!
101
Other Optimizations
102
Advanced Optimization -
Escape Analysis
©2016 CodeKaram
• Entire IR graph
• escaping allocations?
• not stored to a static field or non-static field of
an external object,
• not returned from method,
• not passed as parameter to another method
where it escapes.
103
Escape Analysis
©2016 CodeKaram104
Escape Analysis
allocated object doesn’t
escape the compiled method
allocated object not
passed as a parameter
+
remove allocation and keep field
values in registers
=
©2016 CodeKaram105
Escape Analysis
allocated object is
passed as a parameter
+
remove locks associated with object
and use optimized compare instructions
=
allocated object doesn’t
escape the compiled method
©2016 CodeKaram
• Fast dynamic type tests for type safety
• Range check elimination
• Loop unrolling
• Escape Analysis
• Vectorization!
106
Other JIT Compiler
Optimizations
107
Advanced Optimization -
Vectorization
108
Vectorization in HotSpot
VM??
©2016 CodeKaram
Vectorization
109
• Utilize SIMD (Single Instruction Multiple Data)
instructions offered by the processor.
• Generate assembly stubs
• Get benefits of operating on cache line size data
chunks
110
Advanced Optimization -
Auto-Vectorization
111
Auto-Vectorization in
HotSpot VM??
112
Look Ma, no stubs!!
113
©2016 CodeKaram
SuperWord Level Parallelism
114
http://groups.csail.mit.edu/cag/slp/SLP-PLDI-2000.pdf
©2016 CodeKaram
SuperWord Level Parallelism
115
• Loop Unrolling
• Alignment Analysis
• Pre-Optimization
• Identifying Adjacent Memory References
• Extending the “PackSet”
• Combination and SIMD operation
http://groups.csail.mit.edu/cag/slp/SLP-PLDI-2000.pdf
©2016 CodeKaram
Q & A
116
117
Appendix
©2016 CodeKaram
Compressed Class Pointers
118
• JDK 8 —> Perm Gen Removal —> Class Data outside of
heap
• Compressed class pointer space
• contains class metadata
• is a part of Metaspace
©2016 CodeKaram
Compressed Class Pointers
119
PermGen Removal Overview by Coleen Phillimore + Jon Masamitsu @JavaOne 2013
©2016 CodeKaram120
Mark Word - 32 bit vs 64 bit
Klass - 32 bit vs 64 bit
Array Length - 32 bit on both
boolean, byte, char, float, int, short - 32 bit on both
double, long - 64 bit on both
ILP32 vs. LP64 Field Sizes

More Related Content

What's hot

Lisa12 methodologies
Lisa12 methodologiesLisa12 methodologies
Lisa12 methodologiesBrendan Gregg
 
MacOS memory allocator (libmalloc) Exploitation
MacOS memory allocator (libmalloc) ExploitationMacOS memory allocator (libmalloc) Exploitation
MacOS memory allocator (libmalloc) ExploitationAngel Boy
 
Understanding Android Benchmarks
Understanding Android BenchmarksUnderstanding Android Benchmarks
Understanding Android BenchmarksKoan-Sin Tan
 
Java Performance Analysis on Linux with Flame Graphs
Java Performance Analysis on Linux with Flame GraphsJava Performance Analysis on Linux with Flame Graphs
Java Performance Analysis on Linux with Flame GraphsBrendan Gregg
 
Cloud Native Identity with SPIFFE
Cloud Native Identity with SPIFFECloud Native Identity with SPIFFE
Cloud Native Identity with SPIFFEPrabath Siriwardena
 
Ceph Performance and Sizing Guide
Ceph Performance and Sizing GuideCeph Performance and Sizing Guide
Ceph Performance and Sizing GuideJose De La Rosa
 
[OpenStack Days Korea 2016] Track1 - All flash CEPH 구성 및 최적화
[OpenStack Days Korea 2016] Track1 - All flash CEPH 구성 및 최적화[OpenStack Days Korea 2016] Track1 - All flash CEPH 구성 및 최적화
[OpenStack Days Korea 2016] Track1 - All flash CEPH 구성 및 최적화OpenStack Korea Community
 
Stability Patterns for Microservices
Stability Patterns for MicroservicesStability Patterns for Microservices
Stability Patterns for Microservicespflueras
 
Lessons learned processing 70 billion data points a day using the hybrid cloud
Lessons learned processing 70 billion data points a day using the hybrid cloudLessons learned processing 70 billion data points a day using the hybrid cloud
Lessons learned processing 70 billion data points a day using the hybrid cloudDataWorks Summit
 
Velocity 2015 linux perf tools
Velocity 2015 linux perf toolsVelocity 2015 linux perf tools
Velocity 2015 linux perf toolsBrendan Gregg
 
Elastic Stack Introduction
Elastic Stack IntroductionElastic Stack Introduction
Elastic Stack IntroductionVikram Shinde
 
Blazing Performance with Flame Graphs
Blazing Performance with Flame GraphsBlazing Performance with Flame Graphs
Blazing Performance with Flame GraphsBrendan Gregg
 
It's always sunny with OpenJ9
It's always sunny with OpenJ9It's always sunny with OpenJ9
It's always sunny with OpenJ9DanHeidinga
 
Exploring Thermal Related Stuff in iDevices using Open-Source Tool
Exploring Thermal Related Stuff in iDevices using Open-Source ToolExploring Thermal Related Stuff in iDevices using Open-Source Tool
Exploring Thermal Related Stuff in iDevices using Open-Source ToolKoan-Sin Tan
 
Ceph and Openstack in a Nutshell
Ceph and Openstack in a NutshellCeph and Openstack in a Nutshell
Ceph and Openstack in a NutshellKaran Singh
 
Scylla Summit 2022: Scylla 5.0 New Features, Part 2
Scylla Summit 2022: Scylla 5.0 New Features, Part 2Scylla Summit 2022: Scylla 5.0 New Features, Part 2
Scylla Summit 2022: Scylla 5.0 New Features, Part 2ScyllaDB
 
Find your own iOS kernel bug
Find your own iOS kernel bugFind your own iOS kernel bug
Find your own iOS kernel bugGustavo Martinez
 
Machine Learning and the Elastic Stack
Machine Learning and the Elastic StackMachine Learning and the Elastic Stack
Machine Learning and the Elastic StackYann Cluchey
 

What's hot (20)

Lisa12 methodologies
Lisa12 methodologiesLisa12 methodologies
Lisa12 methodologies
 
Linux Hardening - nullhyd
Linux Hardening - nullhydLinux Hardening - nullhyd
Linux Hardening - nullhyd
 
MacOS memory allocator (libmalloc) Exploitation
MacOS memory allocator (libmalloc) ExploitationMacOS memory allocator (libmalloc) Exploitation
MacOS memory allocator (libmalloc) Exploitation
 
Understanding Android Benchmarks
Understanding Android BenchmarksUnderstanding Android Benchmarks
Understanding Android Benchmarks
 
Java Performance Analysis on Linux with Flame Graphs
Java Performance Analysis on Linux with Flame GraphsJava Performance Analysis on Linux with Flame Graphs
Java Performance Analysis on Linux with Flame Graphs
 
Cloud Native Identity with SPIFFE
Cloud Native Identity with SPIFFECloud Native Identity with SPIFFE
Cloud Native Identity with SPIFFE
 
Ceph Performance and Sizing Guide
Ceph Performance and Sizing GuideCeph Performance and Sizing Guide
Ceph Performance and Sizing Guide
 
[OpenStack Days Korea 2016] Track1 - All flash CEPH 구성 및 최적화
[OpenStack Days Korea 2016] Track1 - All flash CEPH 구성 및 최적화[OpenStack Days Korea 2016] Track1 - All flash CEPH 구성 및 최적화
[OpenStack Days Korea 2016] Track1 - All flash CEPH 구성 및 최적화
 
Stability Patterns for Microservices
Stability Patterns for MicroservicesStability Patterns for Microservices
Stability Patterns for Microservices
 
Lessons learned processing 70 billion data points a day using the hybrid cloud
Lessons learned processing 70 billion data points a day using the hybrid cloudLessons learned processing 70 billion data points a day using the hybrid cloud
Lessons learned processing 70 billion data points a day using the hybrid cloud
 
Velocity 2015 linux perf tools
Velocity 2015 linux perf toolsVelocity 2015 linux perf tools
Velocity 2015 linux perf tools
 
Elastic Stack Introduction
Elastic Stack IntroductionElastic Stack Introduction
Elastic Stack Introduction
 
Blazing Performance with Flame Graphs
Blazing Performance with Flame GraphsBlazing Performance with Flame Graphs
Blazing Performance with Flame Graphs
 
QCon London.pdf
QCon London.pdfQCon London.pdf
QCon London.pdf
 
It's always sunny with OpenJ9
It's always sunny with OpenJ9It's always sunny with OpenJ9
It's always sunny with OpenJ9
 
Exploring Thermal Related Stuff in iDevices using Open-Source Tool
Exploring Thermal Related Stuff in iDevices using Open-Source ToolExploring Thermal Related Stuff in iDevices using Open-Source Tool
Exploring Thermal Related Stuff in iDevices using Open-Source Tool
 
Ceph and Openstack in a Nutshell
Ceph and Openstack in a NutshellCeph and Openstack in a Nutshell
Ceph and Openstack in a Nutshell
 
Scylla Summit 2022: Scylla 5.0 New Features, Part 2
Scylla Summit 2022: Scylla 5.0 New Features, Part 2Scylla Summit 2022: Scylla 5.0 New Features, Part 2
Scylla Summit 2022: Scylla 5.0 New Features, Part 2
 
Find your own iOS kernel bug
Find your own iOS kernel bugFind your own iOS kernel bug
Find your own iOS kernel bug
 
Machine Learning and the Elastic Stack
Machine Learning and the Elastic StackMachine Learning and the Elastic Stack
Machine Learning and the Elastic Stack
 

Viewers also liked

The Performance Engineer's Guide To (OpenJDK) HotSpot Garbage Collection - Th...
The Performance Engineer's Guide To (OpenJDK) HotSpot Garbage Collection - Th...The Performance Engineer's Guide To (OpenJDK) HotSpot Garbage Collection - Th...
The Performance Engineer's Guide To (OpenJDK) HotSpot Garbage Collection - Th...Monica Beckwith
 
Game of Performance: A Song of JIT and GC
Game of Performance: A Song of JIT and GCGame of Performance: A Song of JIT and GC
Game of Performance: A Song of JIT and GCMonica Beckwith
 
GC Tuning Confessions Of A Performance Engineer - Improved :)
GC Tuning Confessions Of A Performance Engineer - Improved :)GC Tuning Confessions Of A Performance Engineer - Improved :)
GC Tuning Confessions Of A Performance Engineer - Improved :)Monica Beckwith
 
JFokus Java 9 contended locking performance
JFokus Java 9 contended locking performanceJFokus Java 9 contended locking performance
JFokus Java 9 contended locking performanceMonica Beckwith
 
Java Performance Engineer's Survival Guide
Java Performance Engineer's Survival GuideJava Performance Engineer's Survival Guide
Java Performance Engineer's Survival GuideMonica Beckwith
 
GC Tuning Confessions Of A Performance Engineer
GC Tuning Confessions Of A Performance EngineerGC Tuning Confessions Of A Performance Engineer
GC Tuning Confessions Of A Performance EngineerMonica Beckwith
 
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...Monica Beckwith
 
Pyjion - a JIT extension system for CPython
Pyjion - a JIT extension system for CPythonPyjion - a JIT extension system for CPython
Pyjion - a JIT extension system for CPythonAnthony Shaw
 
A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]
A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]
A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]Tom Lee
 
Inside Python [OSCON 2012]
Inside Python [OSCON 2012]Inside Python [OSCON 2012]
Inside Python [OSCON 2012]Tom Lee
 
Way Improved :) GC Tuning Confessions - presented at JavaOne2015
Way Improved :) GC Tuning Confessions - presented at JavaOne2015Way Improved :) GC Tuning Confessions - presented at JavaOne2015
Way Improved :) GC Tuning Confessions - presented at JavaOne2015Monica Beckwith
 
Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...
Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...
Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...Monica Beckwith
 
JVM JIT compilation overview by Vladimir Ivanov
JVM JIT compilation overview by Vladimir IvanovJVM JIT compilation overview by Vladimir Ivanov
JVM JIT compilation overview by Vladimir IvanovZeroTurnaround
 
Java 9: The (G1) GC Awakens!
Java 9: The (G1) GC Awakens!Java 9: The (G1) GC Awakens!
Java 9: The (G1) GC Awakens!Monica Beckwith
 
Garbage First Garbage Collector: Where the Rubber Meets the Road!
Garbage First Garbage Collector: Where the Rubber Meets the Road!Garbage First Garbage Collector: Where the Rubber Meets the Road!
Garbage First Garbage Collector: Where the Rubber Meets the Road!Monica Beckwith
 

Viewers also liked (15)

The Performance Engineer's Guide To (OpenJDK) HotSpot Garbage Collection - Th...
The Performance Engineer's Guide To (OpenJDK) HotSpot Garbage Collection - Th...The Performance Engineer's Guide To (OpenJDK) HotSpot Garbage Collection - Th...
The Performance Engineer's Guide To (OpenJDK) HotSpot Garbage Collection - Th...
 
Game of Performance: A Song of JIT and GC
Game of Performance: A Song of JIT and GCGame of Performance: A Song of JIT and GC
Game of Performance: A Song of JIT and GC
 
GC Tuning Confessions Of A Performance Engineer - Improved :)
GC Tuning Confessions Of A Performance Engineer - Improved :)GC Tuning Confessions Of A Performance Engineer - Improved :)
GC Tuning Confessions Of A Performance Engineer - Improved :)
 
JFokus Java 9 contended locking performance
JFokus Java 9 contended locking performanceJFokus Java 9 contended locking performance
JFokus Java 9 contended locking performance
 
Java Performance Engineer's Survival Guide
Java Performance Engineer's Survival GuideJava Performance Engineer's Survival Guide
Java Performance Engineer's Survival Guide
 
GC Tuning Confessions Of A Performance Engineer
GC Tuning Confessions Of A Performance EngineerGC Tuning Confessions Of A Performance Engineer
GC Tuning Confessions Of A Performance Engineer
 
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
 
Pyjion - a JIT extension system for CPython
Pyjion - a JIT extension system for CPythonPyjion - a JIT extension system for CPython
Pyjion - a JIT extension system for CPython
 
A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]
A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]
A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]
 
Inside Python [OSCON 2012]
Inside Python [OSCON 2012]Inside Python [OSCON 2012]
Inside Python [OSCON 2012]
 
Way Improved :) GC Tuning Confessions - presented at JavaOne2015
Way Improved :) GC Tuning Confessions - presented at JavaOne2015Way Improved :) GC Tuning Confessions - presented at JavaOne2015
Way Improved :) GC Tuning Confessions - presented at JavaOne2015
 
Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...
Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...
Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...
 
JVM JIT compilation overview by Vladimir Ivanov
JVM JIT compilation overview by Vladimir IvanovJVM JIT compilation overview by Vladimir Ivanov
JVM JIT compilation overview by Vladimir Ivanov
 
Java 9: The (G1) GC Awakens!
Java 9: The (G1) GC Awakens!Java 9: The (G1) GC Awakens!
Java 9: The (G1) GC Awakens!
 
Garbage First Garbage Collector: Where the Rubber Meets the Road!
Garbage First Garbage Collector: Where the Rubber Meets the Road!Garbage First Garbage Collector: Where the Rubber Meets the Road!
Garbage First Garbage Collector: Where the Rubber Meets the Road!
 

Similar to The Performance Engineer's Guide To HotSpot Just-in-Time Compilation

"JIT compiler overview" @ JEEConf 2013, Kiev, Ukraine
"JIT compiler overview" @ JEEConf 2013, Kiev, Ukraine"JIT compiler overview" @ JEEConf 2013, Kiev, Ukraine
"JIT compiler overview" @ JEEConf 2013, Kiev, UkraineVladimir Ivanov
 
Java Jit. Compilation and optimization by Andrey Kovalenko
Java Jit. Compilation and optimization by Andrey KovalenkoJava Jit. Compilation and optimization by Andrey Kovalenko
Java Jit. Compilation and optimization by Andrey KovalenkoValeriia Maliarenko
 
The Performance Engineer's Guide to Java (HotSpot) Virtual Machine
The Performance Engineer's Guide to Java (HotSpot) Virtual MachineThe Performance Engineer's Guide to Java (HotSpot) Virtual Machine
The Performance Engineer's Guide to Java (HotSpot) Virtual MachineMonica Beckwith
 
IBM Runtimes Performance Observations with Apache Spark
IBM Runtimes Performance Observations with Apache SparkIBM Runtimes Performance Observations with Apache Spark
IBM Runtimes Performance Observations with Apache SparkAdamRobertsIBM
 
Apache Spark Performance Observations
Apache Spark Performance ObservationsApache Spark Performance Observations
Apache Spark Performance ObservationsAdam Roberts
 
Sista: Improving Cog’s JIT performance
Sista: Improving Cog’s JIT performanceSista: Improving Cog’s JIT performance
Sista: Improving Cog’s JIT performanceESUG
 
How the HotSpot and Graal JVMs execute Java Code
How the HotSpot and Graal JVMs execute Java CodeHow the HotSpot and Graal JVMs execute Java Code
How the HotSpot and Graal JVMs execute Java CodeJim Gough
 
Jvm Performance Tunning
Jvm Performance TunningJvm Performance Tunning
Jvm Performance Tunningguest1f2740
 
Jvm Performance Tunning
Jvm Performance TunningJvm Performance Tunning
Jvm Performance TunningTerry Cho
 
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...chen yuki
 
So You Want To Write Your Own Benchmark
So You Want To Write Your Own BenchmarkSo You Want To Write Your Own Benchmark
So You Want To Write Your Own BenchmarkDror Bereznitsky
 
Auto cad 2006_api_overview
Auto cad 2006_api_overviewAuto cad 2006_api_overview
Auto cad 2006_api_overviewscdhruv5
 
JVM JIT-compiler overview @ JavaOne Moscow 2013
JVM JIT-compiler overview @ JavaOne Moscow 2013JVM JIT-compiler overview @ JavaOne Moscow 2013
JVM JIT-compiler overview @ JavaOne Moscow 2013Vladimir Ivanov
 
Building a SIMD Supported Vectorized Native Engine for Spark SQL
Building a SIMD Supported Vectorized Native Engine for Spark SQLBuilding a SIMD Supported Vectorized Native Engine for Spark SQL
Building a SIMD Supported Vectorized Native Engine for Spark SQLDatabricks
 
7 jvm-arguments-Confoo
7 jvm-arguments-Confoo7 jvm-arguments-Confoo
7 jvm-arguments-ConfooTier1 app
 
Software Profiling: Understanding Java Performance and how to profile in Java
Software Profiling: Understanding Java Performance and how to profile in JavaSoftware Profiling: Understanding Java Performance and how to profile in Java
Software Profiling: Understanding Java Performance and how to profile in JavaIsuru Perera
 
JVM Memory Model - Yoav Abrahami, Wix
JVM Memory Model - Yoav Abrahami, WixJVM Memory Model - Yoav Abrahami, Wix
JVM Memory Model - Yoav Abrahami, WixCodemotion Tel Aviv
 
Five cool ways the JVM can run Apache Spark faster
Five cool ways the JVM can run Apache Spark fasterFive cool ways the JVM can run Apache Spark faster
Five cool ways the JVM can run Apache Spark fasterTim Ellison
 
Software Profiling: Java Performance, Profiling and Flamegraphs
Software Profiling: Java Performance, Profiling and FlamegraphsSoftware Profiling: Java Performance, Profiling and Flamegraphs
Software Profiling: Java Performance, Profiling and FlamegraphsIsuru Perera
 

Similar to The Performance Engineer's Guide To HotSpot Just-in-Time Compilation (20)

"JIT compiler overview" @ JEEConf 2013, Kiev, Ukraine
"JIT compiler overview" @ JEEConf 2013, Kiev, Ukraine"JIT compiler overview" @ JEEConf 2013, Kiev, Ukraine
"JIT compiler overview" @ JEEConf 2013, Kiev, Ukraine
 
Java Jit. Compilation and optimization by Andrey Kovalenko
Java Jit. Compilation and optimization by Andrey KovalenkoJava Jit. Compilation and optimization by Andrey Kovalenko
Java Jit. Compilation and optimization by Andrey Kovalenko
 
The Performance Engineer's Guide to Java (HotSpot) Virtual Machine
The Performance Engineer's Guide to Java (HotSpot) Virtual MachineThe Performance Engineer's Guide to Java (HotSpot) Virtual Machine
The Performance Engineer's Guide to Java (HotSpot) Virtual Machine
 
IBM Runtimes Performance Observations with Apache Spark
IBM Runtimes Performance Observations with Apache SparkIBM Runtimes Performance Observations with Apache Spark
IBM Runtimes Performance Observations with Apache Spark
 
Apache Spark Performance Observations
Apache Spark Performance ObservationsApache Spark Performance Observations
Apache Spark Performance Observations
 
Sista: Improving Cog’s JIT performance
Sista: Improving Cog’s JIT performanceSista: Improving Cog’s JIT performance
Sista: Improving Cog’s JIT performance
 
How the HotSpot and Graal JVMs execute Java Code
How the HotSpot and Graal JVMs execute Java CodeHow the HotSpot and Graal JVMs execute Java Code
How the HotSpot and Graal JVMs execute Java Code
 
Jvm Performance Tunning
Jvm Performance TunningJvm Performance Tunning
Jvm Performance Tunning
 
Jvm Performance Tunning
Jvm Performance TunningJvm Performance Tunning
Jvm Performance Tunning
 
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
 
So You Want To Write Your Own Benchmark
So You Want To Write Your Own BenchmarkSo You Want To Write Your Own Benchmark
So You Want To Write Your Own Benchmark
 
Auto cad 2006_api_overview
Auto cad 2006_api_overviewAuto cad 2006_api_overview
Auto cad 2006_api_overview
 
JVM JIT-compiler overview @ JavaOne Moscow 2013
JVM JIT-compiler overview @ JavaOne Moscow 2013JVM JIT-compiler overview @ JavaOne Moscow 2013
JVM JIT-compiler overview @ JavaOne Moscow 2013
 
Building a SIMD Supported Vectorized Native Engine for Spark SQL
Building a SIMD Supported Vectorized Native Engine for Spark SQLBuilding a SIMD Supported Vectorized Native Engine for Spark SQL
Building a SIMD Supported Vectorized Native Engine for Spark SQL
 
7 jvm-arguments-Confoo
7 jvm-arguments-Confoo7 jvm-arguments-Confoo
7 jvm-arguments-Confoo
 
Software Profiling: Understanding Java Performance and how to profile in Java
Software Profiling: Understanding Java Performance and how to profile in JavaSoftware Profiling: Understanding Java Performance and how to profile in Java
Software Profiling: Understanding Java Performance and how to profile in Java
 
JVM Memory Model - Yoav Abrahami, Wix
JVM Memory Model - Yoav Abrahami, WixJVM Memory Model - Yoav Abrahami, Wix
JVM Memory Model - Yoav Abrahami, Wix
 
Five cool ways the JVM can run Apache Spark faster
Five cool ways the JVM can run Apache Spark fasterFive cool ways the JVM can run Apache Spark faster
Five cool ways the JVM can run Apache Spark faster
 
Java performance tuning
Java performance tuningJava performance tuning
Java performance tuning
 
Software Profiling: Java Performance, Profiling and Flamegraphs
Software Profiling: Java Performance, Profiling and FlamegraphsSoftware Profiling: Java Performance, Profiling and Flamegraphs
Software Profiling: Java Performance, Profiling and Flamegraphs
 

More from Monica Beckwith

The ilities of software engineering.pptx
The ilities of software engineering.pptxThe ilities of software engineering.pptx
The ilities of software engineering.pptxMonica Beckwith
 
Enabling Java: Windows on Arm64 - A Success Story!
Enabling Java: Windows on Arm64 - A Success Story!Enabling Java: Windows on Arm64 - A Success Story!
Enabling Java: Windows on Arm64 - A Success Story!Monica Beckwith
 
Applying Concurrency Cookbook Recipes to SPEC JBB
Applying Concurrency Cookbook Recipes to SPEC JBBApplying Concurrency Cookbook Recipes to SPEC JBB
Applying Concurrency Cookbook Recipes to SPEC JBBMonica Beckwith
 
Intro to Garbage Collection
Intro to Garbage CollectionIntro to Garbage Collection
Intro to Garbage CollectionMonica Beckwith
 
OpenJDK Concurrent Collectors
OpenJDK Concurrent CollectorsOpenJDK Concurrent Collectors
OpenJDK Concurrent CollectorsMonica Beckwith
 
OPENJDK: IN THE NEW AGE OF CONCURRENT GARBAGE COLLECTORS
OPENJDK: IN THE NEW AGE OF CONCURRENT GARBAGE COLLECTORSOPENJDK: IN THE NEW AGE OF CONCURRENT GARBAGE COLLECTORS
OPENJDK: IN THE NEW AGE OF CONCURRENT GARBAGE COLLECTORSMonica Beckwith
 

More from Monica Beckwith (8)

The ilities of software engineering.pptx
The ilities of software engineering.pptxThe ilities of software engineering.pptx
The ilities of software engineering.pptx
 
A G1GC Saga-KCJUG.pptx
A G1GC Saga-KCJUG.pptxA G1GC Saga-KCJUG.pptx
A G1GC Saga-KCJUG.pptx
 
ZGC-SnowOne.pdf
ZGC-SnowOne.pdfZGC-SnowOne.pdf
ZGC-SnowOne.pdf
 
Enabling Java: Windows on Arm64 - A Success Story!
Enabling Java: Windows on Arm64 - A Success Story!Enabling Java: Windows on Arm64 - A Success Story!
Enabling Java: Windows on Arm64 - A Success Story!
 
Applying Concurrency Cookbook Recipes to SPEC JBB
Applying Concurrency Cookbook Recipes to SPEC JBBApplying Concurrency Cookbook Recipes to SPEC JBB
Applying Concurrency Cookbook Recipes to SPEC JBB
 
Intro to Garbage Collection
Intro to Garbage CollectionIntro to Garbage Collection
Intro to Garbage Collection
 
OpenJDK Concurrent Collectors
OpenJDK Concurrent CollectorsOpenJDK Concurrent Collectors
OpenJDK Concurrent Collectors
 
OPENJDK: IN THE NEW AGE OF CONCURRENT GARBAGE COLLECTORS
OPENJDK: IN THE NEW AGE OF CONCURRENT GARBAGE COLLECTORSOPENJDK: IN THE NEW AGE OF CONCURRENT GARBAGE COLLECTORS
OPENJDK: IN THE NEW AGE OF CONCURRENT GARBAGE COLLECTORS
 

Recently uploaded

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

Recently uploaded (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

The Performance Engineer's Guide To HotSpot Just-in-Time Compilation

  • 2. 2 About Me … Java/JVM/GC performance person Current Life: Consultant who solves Managed Runtime performance issues Past Life: Worked with Oracle, Sun, AMD… - Worked with HotSpot VM: JVM heuristics, JIT compiler, GCs: Parallel(Old) GC, G1 GC, CMS GC www.codekaram.com https://www.linkedin.com/in/monicabeckwith Tweet @mon_beck
  • 3. ©2016 CodeKaram Establishing the Characters and The Plot • HotSpot Virtual Machine • Runtime Goal • Common Compilation Techniques • C1, C2 & Tiered Compilations • Adaptive Optimization - The Plot 3
  • 4. ©2016 CodeKaram The Storyline • Dynamic Deoptimization • Inlining • Intrinsics 4
  • 5. ©2016 CodeKaram The StoryLine • Compressed Oops + Compressed Class Pointers • Escape Analysis • Vectorization (Auto and otherwise) 5
  • 7. ©2016 CodeKaram Let’s Peek Under The Hood 7 Java Application Java APIs Execution Engine Java VM OS + Hardware Runtime
  • 8. ©2016 CodeKaram8 Java Application Java API Java VM OS + HardwareJRE Execution Engine Runtime Java Runtime Environment
  • 9. ©2016 CodeKaram The Helpers 9 Java VM Execution Engine Runtime
  • 10. ©2016 CodeKaram HotSpot VM 10 Execution Engine Heap Management - Garbage Collection JIT Compilation - Tiered (C1 + C2)
  • 11. ©2016 CodeKaram HotSpot VM 11 Runtime VM Class loading Interpreter Bytecode Verification, Exception Handling, Synchronization , Thread Management, ….http://openjdk.java.net/groups/hotspot/ docs/RuntimeOverview.html
  • 13. ©2016 CodeKaram HotSpot VM - Template Interpreter 13 Bytecode 1 Bytecode 2 Template Native Code 1 Template Native Code 2 TemplateTable
  • 16. ©2016 CodeKaram • CompileThreshold • Identify root of compilation • Method Compilation or On-stack replacement (Loop)? 16 Identifying Performance Critical Methods
  • 17. 17 JIT Optimization - Client Compiler (C1)
  • 18. ©2016 CodeKaram • Start in interpreter • CompileThreshold = 1500 • Compile with client compiler • Few optimizations 18 Client Compiler
  • 19. 19 JIT Optimization - Server Compiler (C2)
  • 20. ©2016 CodeKaram • Start in interpreter • CompileThreshold = 10000 • Compile with optimized server compiler • High performance optimizations 20 Server Compiler
  • 21. 21 JIT Optimization - Tiered Compilation
  • 22. 22
  • 23. ©2016 CodeKaram • Start in interpreter • Tiered optimization with client compiler • Code profiled information • Enable server compiler 23 Tiered Compilation
  • 24. ©2016 CodeKaram24 Tiered Compilation - Effect on Code Cache Tiered Compilation Code Cache Compiled Native Code
  • 25. ©2016 CodeKaram • C1 compilation threshold for tiered is about a 100 invocations • Tiered Compilation has a lot more profiled information for C1 compiled methods • CodeCache needs to be 5x larger than non-tiered • Default on JDK8 when tiered is enabled (240MB vs 48MB) • Need more? Use -XX:ReservedCodeCacheSize 25 Tiered Compilation - Effect on Code Cache
  • 27. ©2016 CodeKaram27 The Plot Startup (Adaptive) JIT Optimizations Profiling of critical hot- spots Interpreter
  • 28. ©2016 CodeKaram28 The Plot Startup (Adaptive) JIT Optimizations Profiling of critical hot- spots Interpreter
  • 31. ©2016 CodeKaram • Oopsie! • dependencies invalidation • classes unloading and redefinition • uncommon path in compiled code • misguided profiled information 31 Dynamic Deoptimization
  • 33. ©2016 CodeKaram PrintCompilation 33 timestamp compilation-id flags tiered- compilation-level Method <@ osr_bci> code- size <deoptimization>
  • 34. ©2016 CodeKaram PrintCompilation 34 Flags: %: is_osr_method s: is_synchronized !: has_exception_handler b: is_blocking n: is_native
  • 35. ©2016 CodeKaram PrintCompilation 35 567 693 % ! 3 org.h2.command.dml.Insert::insertRows @ 76 (513 bytes) 656 797 n 0 java.lang.Object::clone (native) 779 835 s 4 java.lang.StringBuffer::append (13 bytes)
  • 36. ©2016 CodeKaram36 573 704 2 org.h2.table.Table::fireAfterRow (17 bytes) 7963 2223 4 org.h2.table.Table::fireAfterRow (17 bytes) 7964 704 2 org.h2.table.Table::fireAfterRow (17 bytes) made not entrant 33547 704 2 org.h2.table.Table::fireAfterRow (17 bytes) made zombie Dynamic Deoptimization
  • 37. ©2016 CodeKaram37 573 704 2 org.h2.table.Table::fireAfterRow (17 bytes) 7963 2223 4 org.h2.table.Table::fireAfterRow (17 bytes) 7964 704 2 org.h2.table.Table::fireAfterRow (17 bytes) made not entrant 33547 704 2 org.h2.table.Table::fireAfterRow (17 bytes) made zombie Dynamic Deoptimization
  • 38. ©2016 CodeKaram38 573 704 2 org.h2.table.Table::fireAfterRow (17 bytes) 7963 2223 4 org.h2.table.Table::fireAfterRow (17 bytes) 7964 704 2 org.h2.table.Table::fireAfterRow (17 bytes) made not entrant 33547 704 2 org.h2.table.Table::fireAfterRow (17 bytes) made zombie Dynamic Deoptimization
  • 39. ©2016 CodeKaram39 573 704 2 org.h2.table.Table::fireAfterRow (17 bytes) 7963 2223 4 org.h2.table.Table::fireAfterRow (17 bytes) 7964 704 2 org.h2.table.Table::fireAfterRow (17 bytes) made not entrant 33547 704 2 org.h2.table.Table::fireAfterRow (17 bytes) made zombie Dynamic Deoptimization
  • 40. ©2016 CodeKaram40 573 704 2 org.h2.table.Table::fireAfterRow (17 bytes) 7963 2223 4 org.h2.table.Table::fireAfterRow (17 bytes) 7964 704 2 org.h2.table.Table::fireAfterRow (17 bytes) made not entrant 33547 704 2 org.h2.table.Table::fireAfterRow (17 bytes) made zombie Dynamic Deoptimization
  • 42. ©2016 CodeKaram HotSpot has studied Inlining to it’s max potential! 42 Inlining
  • 43. ©2016 CodeKaram MinInliningThreshold, MaxFreqInlineSize, InlineSmallCode, MaxInlineSize, MaxInlineLevel, DesiredMethodLimit … 43 Inlining
  • 45. ©2016 CodeKaram PrintInling* 45 @ 76 java.util.zip.Inflater::setInput (74 bytes) too big @ 80 java.io.BufferedInputStream::getBufIfOpen (21 bytes) inline (hot) @ 91 java.lang.System::arraycopy (0 bytes) (intrinsic) @ 2 java.lang.ClassLoader::checkName (43 bytes) callee is too large * needs -XX:+UnlockDiagnosticVMOptions
  • 46. ©2016 CodeKaram PrintInling* 46 @ 76 java.util.zip.Inflater::setInput (74 bytes) too big @ 80 java.io.BufferedInputStream::getBufIfOpen (21 bytes) inline (hot) @ 91 java.lang.System::arraycopy (0 bytes) (intrinsic) @ 2 java.lang.ClassLoader::checkName (43 bytes) callee is too large * needs -XX:+UnlockDiagnosticVMOptions
  • 47. 47 JIT Optimization - Intrinsics
  • 48. ©2016 CodeKaram48 Without Intrinsics Java Method JIT Compilation Execute Generated Code
  • 49. ©2016 CodeKaram49 Intrinsics Java Method JIT Compilation Execute Optimized Code Call Hand- Optimized Assembly Code
  • 50. ©2016 CodeKaram PrintInling* 50 @ 76 java.util.zip.Inflater::setInput (74 bytes) too big @ 80 java.io.BufferedInputStream::getBufIfOpen (21 bytes) inline (hot) @ 91 java.lang.System::arraycopy (0 bytes) (intrinsic) @ 2 java.lang.ClassLoader::checkName (43 bytes) callee is too large * needs -XX:+UnlockDiagnosticVMOptions
  • 51. 51 Advanced Optimizations - Compressed Oops + Compressed Class Pointers
  • 54. ©2016 CodeKaram Objects, Fields & Alignment • Objects are 8 byte aligned (default). • Fields: • are aligned by their type. • can fill a gap that maybe required for alignment. • are accessed using offset from the start of the object 54
  • 56. ©2016 CodeKaram56 -Tool to analyze Java object layout :) Java Object Layout (JOL)
  • 57. ©2016 CodeKaram JOL Command Line Options $ java -jar jol-cli.jar Usage: jol-cli.jar <mode> [optional arguments]* Available modes: estimates: Simulate the class layout in different VM modes. externals: Show the object externals: the objects reachable from a given instance. footprint: Estimate the footprint of all objects reachable from a given instance heapdump: Consume the heap dump and estimate the savings in different layout strategies. heapdumpstats: Consume the heap dump and print the most frequent instances. idealpack: Compute the object footprint under different field layout strategies. internals: Show the object internals: field layout and default contents, object header shapes: Dump the object shapes present in JAR files or heap dumps. string-compress: Consume the heap dumps and figures out the savings attainable with compressed strings. 57
  • 58. ©2016 CodeKaram JOL Command Line Options $ java -jar jol-cli.jar Usage: jol-cli.jar <mode> [optional arguments]* Available modes: estimates: Simulate the class layout in different VM modes. externals: Show the object externals: the objects reachable from a given instance. footprint: Estimate the footprint of all objects reachable from a given instance heapdump: Consume the heap dump and estimate the savings in different layout strategies. heapdumpstats: Consume the heap dump and print the most frequent instances. idealpack: Compute the object footprint under different field layout strategies. internals: Show the object internals: field layout and default contents, object header shapes: Dump the object shapes present in JAR files or heap dumps. string-compress: Consume the heap dumps and figures out the savings attainable with compressed strings. 58
  • 59. ©2016 CodeKaram Compressed OOPs and Compressed Class Pointers 59 # Running 64-bit HotSpot VM. # Using compressed oop with 3-bit shift. # Using compressed klass with 3-bit shift.
  • 60. ©2016 CodeKaram Compressed OOPs and Compressed Class Pointers 60 # Running 64-bit HotSpot VM. # Using compressed oop with 3-bit shift. # Using compressed klass with 3-bit shift.
  • 62. ©2016 CodeKaram A Java Object Header 62 Header Klass Mark Word Array Length
  • 63. 63 Java Object Layout Samples - Uncompressed
  • 64. ©2016 CodeKaram JOL: 8 Byte Array [B object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 4 (object header) 01 00 00 00 (00000001 00000000 00000000 00000000) (1) 4 4 (object header) 00 00 00 00 (00000000 00000000 00000000 00000000) (0) 8 4 (object header) a8 07 c0 34 (10101000 00000111 11000000 00110100) (885000104) 12 4 (object header) 02 00 00 00 (00000010 00000000 00000000 00000000) (2) 16 4 (object header) 08 00 00 00 (00001000 00000000 00000000 00000000) (8) 20 4 (alignment/padding gap) N/A 24 8 byte [B.<elements> N/A Instance size: 32 bytes Space losses: 4 bytes internal + 0 bytes external = 4 bytes total 64
  • 65. ©2016 CodeKaram JOL: 8 Byte Array [B object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 4 (object header) 01 00 00 00 (00000001 00000000 00000000 00000000) (1) 4 4 (object header) 00 00 00 00 (00000000 00000000 00000000 00000000) (0) 8 4 (object header) a8 07 c0 34 (10101000 00000111 11000000 00110100) (885000104) 12 4 (object header) 02 00 00 00 (00000010 00000000 00000000 00000000) (2) 16 4 (object header) 08 00 00 00 (00001000 00000000 00000000 00000000) (8) 20 4 (alignment/padding gap) N/A 24 8 byte [B.<elements> N/A Instance size: 32 bytes Space losses: 4 bytes internal + 0 bytes external = 4 bytes total 65 Mark Word
  • 66. ©2016 CodeKaram JOL: 8 Byte Array [B object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 4 (object header) 01 00 00 00 (00000001 00000000 00000000 00000000) (1) 4 4 (object header) 00 00 00 00 (00000000 00000000 00000000 00000000) (0) 8 4 (object header) a8 07 c0 34 (10101000 00000111 11000000 00110100) (885000104) 12 4 (object header) 02 00 00 00 (00000010 00000000 00000000 00000000) (2) 16 4 (object header) 08 00 00 00 (00001000 00000000 00000000 00000000) (8) 20 4 (alignment/padding gap) N/A 24 8 byte [B.<elements> N/A Instance size: 32 bytes Space losses: 4 bytes internal + 0 bytes external = 4 bytes total 66 Klass
  • 67. ©2016 CodeKaram JOL: 8 Byte Array [B object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 4 (object header) 01 00 00 00 (00000001 00000000 00000000 00000000) (1) 4 4 (object header) 00 00 00 00 (00000000 00000000 00000000 00000000) (0) 8 4 (object header) a8 07 c0 34 (10101000 00000111 11000000 00110100) (885000104) 12 4 (object header) 02 00 00 00 (00000010 00000000 00000000 00000000) (2) 16 4 (object header) 08 00 00 00 (00001000 00000000 00000000 00000000) (8) 20 4 (alignment/padding gap) N/A 24 8 byte [B.<elements> N/A Instance size: 32 bytes Space losses: 4 bytes internal + 0 bytes external = 4 bytes total 67
  • 68. ©2016 CodeKaram JOL: 8 Byte Array [B object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 4 (object header) 01 00 00 00 (00000001 00000000 00000000 00000000) (1) 4 4 (object header) 00 00 00 00 (00000000 00000000 00000000 00000000) (0) 8 4 (object header) a8 07 c0 34 (10101000 00000111 11000000 00110100) (885000104) 12 4 (object header) 02 00 00 00 (00000010 00000000 00000000 00000000) (2) 16 4 (object header) 08 00 00 00 (00001000 00000000 00000000 00000000) (8) 20 4 (alignment/padding gap) N/A 24 8 byte [B.<elements> N/A Instance size: 32 bytes Space losses: 4 bytes internal + 0 bytes external = 4 bytes total 68 Array Length
  • 69. ©2016 CodeKaram JOL: 8 Byte Array [B object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 4 (object header) 01 00 00 00 (00000001 00000000 00000000 00000000) (1) 4 4 (object header) 00 00 00 00 (00000000 00000000 00000000 00000000) (0) 8 4 (object header) a8 07 c0 34 (10101000 00000111 11000000 00110100) (885000104) 12 4 (object header) 02 00 00 00 (00000010 00000000 00000000 00000000) (2) 16 4 (object header) 08 00 00 00 (00001000 00000000 00000000 00000000) (8) 20 4 (alignment/padding gap) N/A 24 8 byte [B.<elements> N/A Instance size: 32 bytes Space losses: 4 bytes internal + 0 bytes external = 4 bytes total 69
  • 70. ©2016 CodeKaram JOL: 8 Byte Array [B object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 4 (object header) 01 00 00 00 (00000001 00000000 00000000 00000000) (1) 4 4 (object header) 00 00 00 00 (00000000 00000000 00000000 00000000) (0) 8 4 (object header) a8 07 c0 34 (10101000 00000111 11000000 00110100) (885000104) 12 4 (object header) 02 00 00 00 (00000010 00000000 00000000 00000000) (2) 16 4 (object header) 08 00 00 00 (00001000 00000000 00000000 00000000) (8) 20 4 (alignment/padding gap) N/A 24 8 byte [B.<elements> N/A Instance size: 32 bytes Space losses: 4 bytes internal + 0 bytes external = 4 bytes total 70
  • 71. 71 Java Object Layout Samples - Compressed
  • 72. ©2016 CodeKaram JOL: 8 Byte Array [B object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 4 (object header) 01 00 00 00 (00000001 00000000 00000000 00000000) (1) 4 4 (object header) 00 00 00 00 (00000000 00000000 00000000 00000000) (0) 8 4 (object header) f5 00 00 f8 (11110101 00000000 00000000 11111000) (-134217483) 12 4 (object header) 08 00 00 00 (00001000 00000000 00000000 00000000) (8) 16 8 byte [B.<elements> N/A Instance size: 24 bytes Space losses: 0 bytes internal + 0 bytes external = 0 bytes total 72
  • 73. ©2016 CodeKaram JOL: 8 Byte Array [B object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 4 (object header) 01 00 00 00 (00000001 00000000 00000000 00000000) (1) 4 4 (object header) 00 00 00 00 (00000000 00000000 00000000 00000000) (0) 8 4 (object header) f5 00 00 f8 (11110101 00000000 00000000 11111000) (-134217483) 12 4 (object header) 08 00 00 00 (00001000 00000000 00000000 00000000) (8) 16 8 byte [B.<elements> N/A Instance size: 24 bytes Space losses: 0 bytes internal + 0 bytes external = 0 bytes total 73 Mark Word
  • 74. ©2016 CodeKaram JOL: 8 Byte Array [B object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 4 (object header) 01 00 00 00 (00000001 00000000 00000000 00000000) (1) 4 4 (object header) 00 00 00 00 (00000000 00000000 00000000 00000000) (0) 8 4 (object header) f5 00 00 f8 (11110101 00000000 00000000 11111000) (-134217483) 12 4 (object header) 08 00 00 00 (00001000 00000000 00000000 00000000) (8) 16 8 byte [B.<elements> N/A Instance size: 24 bytes Space losses: 0 bytes internal + 0 bytes external = 0 bytes total 74
  • 75. ©2016 CodeKaram JOL: 8 Byte Array [B object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 4 (object header) 01 00 00 00 (00000001 00000000 00000000 00000000) (1) 4 4 (object header) 00 00 00 00 (00000000 00000000 00000000 00000000) (0) 8 4 (object header) f5 00 00 f8 (11110101 00000000 00000000 11111000) (-134217483) 12 4 (object header) 08 00 00 00 (00001000 00000000 00000000 00000000) (8) 16 8 byte [B.<elements> N/A Instance size: 24 bytes Space losses: 0 bytes internal + 0 bytes external = 0 bytes total 75 Klass
  • 76. ©2016 CodeKaram JOL: 8 Byte Array [B object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 4 (object header) 01 00 00 00 (00000001 00000000 00000000 00000000) (1) 4 4 (object header) 00 00 00 00 (00000000 00000000 00000000 00000000) (0) 8 4 (object header) f5 00 00 f8 (11110101 00000000 00000000 11111000) (-134217483) 12 4 (object header) 08 00 00 00 (00001000 00000000 00000000 00000000) (8) 16 8 byte [B.<elements> N/A Instance size: 24 bytes Space losses: 0 bytes internal + 0 bytes external = 0 bytes total 76
  • 77. ©2016 CodeKaram JOL: 8 Byte Array [B object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 4 (object header) 01 00 00 00 (00000001 00000000 00000000 00000000) (1) 4 4 (object header) 00 00 00 00 (00000000 00000000 00000000 00000000) (0) 8 4 (object header) f5 00 00 f8 (11110101 00000000 00000000 11111000) (-134217483) 12 4 (object header) 08 00 00 00 (00001000 00000000 00000000 00000000) (8) 16 8 byte [B.<elements> N/A Instance size: 24 bytes Space losses: 0 bytes internal + 0 bytes external = 0 bytes total 77 Array Length
  • 78. ©2016 CodeKaram JOL: 8 Byte Array [B object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 4 (object header) 01 00 00 00 (00000001 00000000 00000000 00000000) (1) 4 4 (object header) 00 00 00 00 (00000000 00000000 00000000 00000000) (0) 8 4 (object header) f5 00 00 f8 (11110101 00000000 00000000 11111000) (-134217483) 12 4 (object header) 08 00 00 00 (00001000 00000000 00000000 00000000) (8) 16 8 byte [B.<elements> N/A Instance size: 24 bytes Space losses: 0 bytes internal + 0 bytes external = 0 bytes total 78
  • 79. 79 Java Object Layout Header Comparison
  • 80. ©2016 CodeKaram Compressed vs Uncompressed Compressed: Instance size: 24 bytes Space losses: 0 bytes internal + 0 bytes external = 0 bytes total vs Uncompressed: Instance size: 32 bytes Space losses: 4 bytes internal + 0 bytes external = 4 bytes total 80
  • 81. ©2016 CodeKaram Compressed vs Uncompressed Compressed: Instance size: 24 bytes Space losses: 0 bytes internal + 0 bytes external = 0 bytes total vs Uncompressed: Instance size: 32 bytes Space losses: 4 bytes internal + 0 bytes external = 4 bytes total 81
  • 84. ©2016 CodeKaram Compressed OOPs and Compressed Class Pointers 84 # Running 64-bit HotSpot VM. # Using compressed oop with 3-bit shift. # Using compressed klass with 3-bit shift.
  • 85. 85 Java Object Layout Samples - UnCompressed
  • 86. ©2016 CodeKaram JOL: Class java.lang.Class object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 16 (object header) N/A 16 8 Constructor Class.cachedConstructor N/A 24 8 Class Class.newInstanceCallerCache N/A 32 8 String Class.name N/A 40 8 Module Class.module N/A 48 8 (alignment/padding gap) N/A 56 8 String Class.packageName N/A 64 8 Class Class.componentType N/A 72 8 SoftReference Class.reflectionData N/A 80 8 ClassRepository Class.genericInfo N/A 88 8 Object[] Class.enumConstants N/A 96 8 Map Class.enumConstantDirectory N/A 104 8 AnnotationData Class.annotationData N/A 112 8 AnnotationType Class.annotationType N/A 120 8 ClassValueMap Class.classValueMap N/A 128 32 (alignment/padding gap) N/A 160 4 int Class.classRedefinedCount N/A 164 4 (loss due to the next object alignment) Instance size: 168 bytes Space losses: 40 bytes internal + 4 bytes external = 44 bytes total 86
  • 87. ©2016 CodeKaram java.lang.Class object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 16 (object header) N/A 16 8 Constructor Class.cachedConstructor N/A 24 8 Class Class.newInstanceCallerCache N/A 32 8 String Class.name N/A 40 8 Module Class.module N/A 48 8 (alignment/padding gap) N/A 56 8 String Class.packageName N/A 64 8 Class Class.componentType N/A 72 8 SoftReference Class.reflectionData N/A 80 8 ClassRepository Class.genericInfo N/A 88 8 Object[] Class.enumConstants N/A 96 8 Map Class.enumConstantDirectory N/A 104 8 AnnotationData Class.annotationData N/A 112 8 AnnotationType Class.annotationType N/A 120 8 ClassValueMap Class.classValueMap N/A 128 32 (alignment/padding gap) N/A 160 4 int Class.classRedefinedCount N/A 164 4 (loss due to the next object alignment) Instance size: 168 bytes Space losses: 40 bytes internal + 4 bytes external = 44 bytes total 87 JOL: Class
  • 88. ©2016 CodeKaram java.lang.Class object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 16 (object header) N/A 16 8 Constructor Class.cachedConstructor N/A 24 8 Class Class.newInstanceCallerCache N/A 32 8 String Class.name N/A 40 8 Module Class.module N/A 48 8 (alignment/padding gap) N/A 56 8 String Class.packageName N/A 64 8 Class Class.componentType N/A 72 8 SoftReference Class.reflectionData N/A 80 8 ClassRepository Class.genericInfo N/A 88 8 Object[] Class.enumConstants N/A 96 8 Map Class.enumConstantDirectory N/A 104 8 AnnotationData Class.annotationData N/A 112 8 AnnotationType Class.annotationType N/A 120 8 ClassValueMap Class.classValueMap N/A 128 32 (alignment/padding gap) N/A 160 4 int Class.classRedefinedCount N/A 164 4 (loss due to the next object alignment) Instance size: 168 bytes Space losses: 40 bytes internal + 4 bytes external = 44 bytes total 88 JOL: Class
  • 89. 89 Java Object Layout Samples - Compressed
  • 90. ©2016 CodeKaram java.lang.Class object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 12 (object header) N/A 12 4 Constructor Class.cachedConstructor N/A 16 4 Class Class.newInstanceCallerCache N/A 20 4 String Class.name N/A 24 4 Module Class.module N/A 28 4 (alignment/padding gap) N/A 32 4 String Class.packageName N/A 36 4 Class Class.componentType N/A 40 4 SoftReference Class.reflectionData N/A 44 4 ClassRepository Class.genericInfo N/A 48 4 Object[] Class.enumConstants N/A 52 4 Map Class.enumConstantDirectory N/A 56 4 AnnotationData Class.annotationData N/A 60 4 AnnotationType Class.annotationType N/A 64 4 ClassValueMap Class.classValueMap N/A 68 28 (alignment/padding gap) N/A 96 4 int Class.classRedefinedCount N/A 100 4 (loss due to the next object alignment) 90 JOL: Class
  • 91. ©2016 CodeKaram java.lang.Class object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 12 (object header) N/A 12 4 Constructor Class.cachedConstructor N/A 16 4 Class Class.newInstanceCallerCache N/A 20 4 String Class.name N/A 24 4 Module Class.module N/A 28 4 (alignment/padding gap) N/A 32 4 String Class.packageName N/A 36 4 Class Class.componentType N/A 40 4 SoftReference Class.reflectionData N/A 44 4 ClassRepository Class.genericInfo N/A 48 4 Object[] Class.enumConstants N/A 52 4 Map Class.enumConstantDirectory N/A 56 4 AnnotationData Class.annotationData N/A 60 4 AnnotationType Class.annotationType N/A 64 4 ClassValueMap Class.classValueMap N/A 68 28 (alignment/padding gap) N/A 96 4 int Class.classRedefinedCount N/A 100 4 (loss due to the next object alignment) 91 JOL: Class
  • 92. ©2016 CodeKaram java.lang.Class object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 12 (object header) N/A 12 4 Constructor Class.cachedConstructor N/A 16 4 Class Class.newInstanceCallerCache N/A 20 4 String Class.name N/A 24 4 Module Class.module N/A 28 4 (alignment/padding gap) N/A 32 4 String Class.packageName N/A 36 4 Class Class.componentType N/A 40 4 SoftReference Class.reflectionData N/A 44 4 ClassRepository Class.genericInfo N/A 48 4 Object[] Class.enumConstants N/A 52 4 Map Class.enumConstantDirectory N/A 56 4 AnnotationData Class.annotationData N/A 60 4 AnnotationType Class.annotationType N/A 64 4 ClassValueMap Class.classValueMap N/A 68 28 (alignment/padding gap) N/A 96 4 int Class.classRedefinedCount N/A 100 4 (loss due to the next object alignment) 92 JOL: Class
  • 93. ©2016 CodeKaram Compressed OOPs and Compressed Class Pointers 93 # Running 64-bit HotSpot VM. # Using compressed oop with 3-bit shift. # Using compressed klass with 3-bit shift. P P
  • 94. 94 … but what is the 3-bit shift?
  • 95. ©2016 CodeKaram Compressed OOPs 95 <wide-oop> = <narrow-oop-base> + (<narrow-oop> << 3) + <field-offset>
  • 96. ©2016 CodeKaram Compressed OOPs 96 Heap Size? <4 GB (no encoding/ decoding needed) >4GB; <28GB (zero-based) <wide-oop> = <narrow-oop> <narrow-oop> << 3
  • 97. ©2016 CodeKaram Compressed OOPs 97 Heap Size? >28 GB; <32 GB (regular) >32 GB; <64 GB * (change alignment) <wide-oop> = <narrow-oop-base> + (<narrow-oop> << 3) + <field- offset> <narrow-oop-base> + (<narrow-oop> << 4) + <field- offset>
  • 98. ©2016 CodeKaram Compressed OOPs 98 Heap Size? <4 GB >4GB; <28GB <32GB <64GB Object Alignment? 8 bytes 8 bytes 8 bytes 16 bytes Offset Required? No No Yes Yes Shift by? No shift 3 3 4
  • 100. ©2016 CodeKaram • Fast dynamic type tests for type safety • Range check elimination • Loop unrolling • Escape Analysis • Vectorization! 100 Other Optimizations
  • 101. ©2016 CodeKaram • Fast dynamic type tests for type safety • Range check elimination • Loop unrolling • Escape Analysis • Vectorization! 101 Other Optimizations
  • 103. ©2016 CodeKaram • Entire IR graph • escaping allocations? • not stored to a static field or non-static field of an external object, • not returned from method, • not passed as parameter to another method where it escapes. 103 Escape Analysis
  • 104. ©2016 CodeKaram104 Escape Analysis allocated object doesn’t escape the compiled method allocated object not passed as a parameter + remove allocation and keep field values in registers =
  • 105. ©2016 CodeKaram105 Escape Analysis allocated object is passed as a parameter + remove locks associated with object and use optimized compare instructions = allocated object doesn’t escape the compiled method
  • 106. ©2016 CodeKaram • Fast dynamic type tests for type safety • Range check elimination • Loop unrolling • Escape Analysis • Vectorization! 106 Other JIT Compiler Optimizations
  • 109. ©2016 CodeKaram Vectorization 109 • Utilize SIMD (Single Instruction Multiple Data) instructions offered by the processor. • Generate assembly stubs • Get benefits of operating on cache line size data chunks
  • 112. 112 Look Ma, no stubs!!
  • 113. 113
  • 114. ©2016 CodeKaram SuperWord Level Parallelism 114 http://groups.csail.mit.edu/cag/slp/SLP-PLDI-2000.pdf
  • 115. ©2016 CodeKaram SuperWord Level Parallelism 115 • Loop Unrolling • Alignment Analysis • Pre-Optimization • Identifying Adjacent Memory References • Extending the “PackSet” • Combination and SIMD operation http://groups.csail.mit.edu/cag/slp/SLP-PLDI-2000.pdf
  • 118. ©2016 CodeKaram Compressed Class Pointers 118 • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer space • contains class metadata • is a part of Metaspace
  • 119. ©2016 CodeKaram Compressed Class Pointers 119 PermGen Removal Overview by Coleen Phillimore + Jon Masamitsu @JavaOne 2013
  • 120. ©2016 CodeKaram120 Mark Word - 32 bit vs 64 bit Klass - 32 bit vs 64 bit Array Length - 32 bit on both boolean, byte, char, float, int, short - 32 bit on both double, long - 64 bit on both ILP32 vs. LP64 Field Sizes