the performance - qcon · java/jvm/gc performance consultant - worked with jit compiler, ... •...

79
1 THE PERFORMANCE ENGINEER’S GUIDE TO HOTSPOT JIT COMPILATION Monica Beckwith CODE KARAM LLC QCon NY Jun 14th 2016

Upload: others

Post on 10-Sep-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

1

THE

PERFORMANCEENGINEER’SGUIDETOHOTSPOT

JITCOMPILATION

MonicaBeckwith

CODEKARAMLLC

QConNY

Jun14th2016

Page 2: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

2

About Me …Java/JVM/GC Performance Consultant

- Worked with JIT compiler, JVM heuristics, Heap Management, Various Garbage Collectors (GCs) - Worked with AMD, Oracle and Sun - Was the Performance Lead for G1 GC

www.codekaram.com https://www.linkedin.com/in/monicabeckwith Tweet @mon_beck

Page 3: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

Topics We May Cover Today

• HotSpot Virtual Machine

• Runtime Goal

• Common Techniques

• Adaptive Optimization - The Plot

• C1, C2 & Tiered Compilations

3

Page 4: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

Topics We May Cover Today• Adaptive Optimization - The Plot

• Dynamic Deoptimization

• Inlining

• Intrinsics

• Vectorization (Auto and otherwise)

• Escape Analysis4

Page 5: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

Topics We May Cover Today

• Time Check!

• Adaptive Optimization - The Plot

• Compressed Oops

• Compressed Class Pointers

• Q & A

5

Page 6: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

6

HotSpot Virtual Machine

Page 7: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

Let’s Peek Under The Hood

7

Java Application

Java APIs Execution Engine

Java VM

OS + Hardware

Runtime

Page 8: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram8

Java Application

Java API

Java VM

OS + HardwareJRE

Execution EngineRuntime

Java Runtime Environment

Page 9: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

The Helpers

9

Java VM

Execution EngineRuntime

Page 10: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

HotSpot VM

10

Execution Engine

Heap Management - Garbage Collection

JIT Compilation - Tiered (C1 + C2)

Page 11: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©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

Page 12: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

Runtime Goal

12

Bytecode

Native code

Page 13: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

HotSpot VM - Template Interpreter

13

Bytecode 1 Bytecode 2

Template Native Code 1 Template Native Code 2

TemplateTable

Page 14: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

Common Compilation Techniques

14

Compilation

Adaptive Optimization

Ahead Of

Time

Profile-guided

Static

Page 15: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

HotSpot VM

15

Compilation

Adaptive Optimization

Ahead Of

Time

Profile-guided

Static

Page 16: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

16

Advanced JIT & Runtime Optimizations - Adaptive

Optimization

Page 17: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram17

The PlotStartup

Adaptive Optimization

Profiling of critical hot-

spots

Interpreter

Page 18: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

• CompileThreshold

• Identify root of compilation

• Method Compilation or On-stack replacement (Loop)?

18

Identifying Performance Critical Methods

Page 19: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

19

Adaptive Optimization - Client Compiler (C1)

Page 20: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

• Start in interpreter

• CompileThreshold = 1500

• Compile with client compiler

• Few optimizations

20

Client Compiler

Page 21: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

21

Adaptive Optimization - Server Compiler (C2)

Page 22: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

• Start in interpreter

• CompileThreshold = 10000

• Compile with optimized server compiler

• High performance optimizations

22

Server Compiler

Page 23: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

23

Adaptive Optimization - Tiered Compilation

Page 24: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

24

Page 25: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

• Start in interpreter

• Tiered optimization with client compiler

• Code profiled information

• Enable server compiler

25

Tiered Compilation

Page 26: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram26

Tiered Compilation - Effect on Code Cache

Tiered Compilation

Code Cache

Compiled Native Code

Page 27: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©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

27

Tiered Compilation - Effect on Code Cache

Page 28: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram28

The PlotStartup

Adaptive Optimization

Profiling of critical hot-

spots

Interpreter

Page 29: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram29

The PlotStartup

Adaptive Optimization

Profiling of critical hot-

spots

Interpreter

Page 30: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

30

Adaptive Optimization - Dynamic Deoptimization

Page 31: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram31

Dynamic Deoptimization

Page 32: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

• Oopsie!

• dependencies invalidation

• classes unloading and redefinition

• uncommon path in compiled code

• misguided profiled information

32

Dynamic Deoptimization

Page 33: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

33

Understanding Adaptive Optimization -

PrintCompilation

Page 34: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

PrintCompilation

34

timestamp compilation-id flags tiered-compilation-level Method <@ osr_bci> code-size <deoptimization>

Page 35: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

PrintCompilation

35

Flags:%: is_osr_methods: is_synchronized!: has_exception_handlerb: is_blockingn: is_native

Page 36: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

PrintCompilation

36

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)

Page 37: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©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

Page 38: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©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

Page 39: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©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

Page 40: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©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

Page 41: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram41

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

Page 42: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

42

Adaptive Optimization - Inlining

Page 43: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

HotSpot has studied Inlining to it’s max potential!

43

Inlining

Page 44: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

MinInliningThreshold, MaxFreqInlineSize, InlineSmallCode, MaxInlineSize, MaxInlineLevel, DesiredMethodLimit …

44

Inlining

Page 45: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

45

Understanding Adaptive Optimization - PrintInlining

Page 46: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©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

Page 47: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

PrintInling*

47

@ 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

Page 48: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

48

Adaptive Optimization - Intrinsics

Page 49: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram49

Without IntrinsicsJava Method

JIT Compilation

Execute Generated Code

Page 50: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram50

IntrinsicsJava Method

JIT Compilation

Execute Optimized Code

Call Hand-Optimized

Assembly Code

Page 51: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

PrintInling*

51

@ 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

Page 52: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

52

Adaptive Optimization - Vectorization

Page 53: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

53

Vectorization in HotSpot VM??

Page 54: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

Vectorization

54

• Utilize SIMD (Single Instruction Multiple Data) instructions offered by the processor.

• Generate assembly stubs

• Get benefits of operating on cache line size data chunks

Page 55: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

55

Adaptive Optimization - Auto-Vectorization

Page 56: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

56

Auto-Vectorization in HotSpot VM??

Page 57: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

57

Look Ma, no stubs!!

Page 58: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

58

Page 59: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

SuperWord Level Parallelism

59

http://groups.csail.mit.edu/cag/slp/SLP-PLDI-2000.pdf

Page 60: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

SuperWord Level Parallelism

60

• Loop Unrolling

• Alignment Analysis

• Pre-Optimization

• Identifying Adjacent Memory References

• Extending the “PackSet”

• Combination and SIMD operationhttp://groups.csail.mit.edu/cag/slp/SLP-PLDI-2000.pdf

Page 61: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

61

Other Adaptive Optimization

Page 62: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

• Fast dynamic type tests for type safety

• Range check elimination

• Loop unrolling

• Escape Analysis

62

Other JIT Compiler Optimizations

Page 63: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

• Fast dynamic type tests for type safety

• Range check elimination

• Loop unrolling

• Escape Analysis

63

Other JIT Compiler Optimizations

Page 64: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

64

Adaptive Optimization - Escape Analysis

Page 65: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©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.

65

Escape Analysis

Page 66: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram66

Escape Analysisallocated object doesn’t

escape the compiled method

allocated object not passed as a parameter

+

remove allocation and keep field values in registers

=

Page 67: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram67

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

Page 68: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

Time Check!

68

Page 69: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

69

Advanced JIT & Runtime Optimizations - Compressed

Oops

Page 70: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

A Java Object

70

Header Body

KlassMark Word

Array Length

Page 71: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©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

71

Page 72: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram72

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

Page 73: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

Compressed OOPs

73

<wide-oop> = <narrow-oop-base> + (<narrow-oop> << 3) + <field-offset>

Page 74: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

Compressed OOPs

74

Heap Size?<4 GB

(no encoding/decoding needed)

>4GB; <28GB (zero-based)

<wide-oop> = <narrow-oop> <narrow-oop> << 3

Page 75: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

Compressed OOPs

75

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>

Page 76: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

Compressed OOPs

76

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

Page 77: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

Compressed Class Pointers

77

• JDK 8 —> Perm Gen Removal —> Class Data outside of heap

• Compressed class pointer space

• contains class metadata

• is a part of Metaspace

Page 78: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

Compressed Class Pointers

78

PermGen Removal Overview by Coleen Phillimore + Jon Masamitsu @JavaOne 2013

Page 79: THE PERFORMANCE - QCon · Java/JVM/GC Performance Consultant - Worked with JIT compiler, ... • JDK 8 —> Perm Gen Removal —> Class Data outside of heap • Compressed class pointer

©2016 CodeKaram

Q & A

79