SlideShare a Scribd company logo
A detailed look at J9’s approach to MethodHandle compilation
Dan Heidinga, J9 Virtual Machine Team Lead
@DanHeidinga
2015-02-02
MethodHandle compilation
pipeline
Important disclaimers
 THE INFORMATION CONTAINED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY.
 WHILST EFFORTS WERE MADE TO VERIFY THE COMPLETENESS AND ACCURACY OF THE INFORMATION
CONTAINED IN THIS PRESENTATION, IT IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED.
 ALL PERFORMANCE DATA INCLUDED IN THIS PRESENTATION HAVE BEEN GATHERED IN A CONTROLLED
ENVIRONMENT. YOUR OWN TEST RESULTS MAY VARY BASED ON HARDWARE, SOFTWARE OR
INFRASTRUCTURE DIFFERENCES.
 ALL DATA INCLUDED IN THIS PRESENTATION ARE MEANT TO BE USED ONLY AS A GUIDE.
 IN ADDITION, THE INFORMATION CONTAINED IN THIS PRESENTATION IS BASED ON IBM’S CURRENT PRODUCT
PLANS AND STRATEGY, WHICH ARE SUBJECT TO CHANGE BY IBM, WITHOUT NOTICE.
 IBM AND ITS AFFILIATED COMPANIES SHALL NOT BE RESPONSIBLE FOR ANY DAMAGES ARISING OUT OF THE
USE OF, OR OTHERWISE RELATED TO, THIS PRESENTATION OR ANY OTHER DOCUMENTATION.
 NOTHING CONTAINED IN THIS PRESENTATION IS INTENDED TO, OR SHALL HAVE THE EFFECT OF:
– CREATING ANY WARRANT OR REPRESENTATION FROM IBM, ITS AFFILIATED COMPANIES OR ITS OR
THEIR SUPPLIERS AND/OR LICENSORS
2
Who am I?
 I've been involved with virtual machine development at IBM since
2007 and am now the J9 Virtual Machine Team Lead. J9 is IBM's
independent implementation of the JVM.
 I've represented IBM on both the JSR 292 ('invokedynamic') and
JSR 335 ('lambda') expert groups and lead J9's implementation of
both JSRs.
 I also maintain the bytecode verifier and deal with various other
parts of the runtime.
3
MethodHandle? What’s that?
4
J9’s MethodHandle hierarchy
 Original prototype had 1 class: MethodHandle
– “kind” field to determine which operation
– “type” field to hold the MethodType
– “vmSlot” field to hold the address, offset, vtable or itable index
 Grab bag of data necessary to support field access and method sends
 2 major problems with this approach
5
MethodHandle
J9’s MethodHandle hierarchy
 Original prototype had 1 class: MethodHandle
– “kind” field to determine which operation
– “type” field to hold the MethodType
– “vmSlot” field to hold the address, offset, vtable or itable index
 Grab bag of data necessary to support field access and method sends
6
MethodHandle
http://commons.wikimedia.org/wiki/File:MudBall03.jpg
Public domain.
J9’s MethodHandle hierarchy
 Hierarchy that separates each MH kind into its own class
 Each MH subclass describes the data needed by the MH
 JITs look at the class rather than the ‘kind’ instance field
– Provides a place to put specialized behaviour
7
MethodHandle
Direct ReceiverBound
Indirect
Virtual
Interface
Constructor
Field
FieldGetter
FieldSetter
StaticFieldGetter
StaticFieldSetter
Collect
DynamicInvoker
FilterArguments
Convert
ArgumentConversion
AsType
ExplicitCast
FilterReturn
GuardWithTestHnadle
Insert
Fold
FoldNonvoid
FoldVoid
InvokeExact
InvokeGeneric
PassThrough
ArgumentMover BruteArgumentMover
Catch
Permute
Spread
VarargsCollector
MethodHandle chains
8
"Broad chain closeup" by Toni Lozano - http://www.flickr.com/photos/quiero-un-pantano/176909201.
Licensed under CC BY 2.0 via Wikimedia Commons -
http://commons.wikimedia.org/wiki/File:Broad_chain_closeup.jpg#mediaviewer/File:Broad_chain_closeup.jp
MethodHandle chains
GuardWithTest
Direct
Target Direct
Direct
9
"Broad chain closeup" by Toni Lozano - http://www.flickr.com/photos/quiero-un-pantano/176909201.
Licensed under CC BY 2.0 via Wikimedia Commons -
http://commons.wikimedia.org/wiki/File:Broad_chain_closeup.jpg#mediaviewer/File:Broad_chain_closeup.jp
MethodHandle chains
GuardWithTest
Direct
Target Direct
Direct
Insert Direct
10
"Broad chain closeup" by Toni Lozano - http://www.flickr.com/photos/quiero-un-pantano/176909201.
Licensed under CC BY 2.0 via Wikimedia Commons -
http://commons.wikimedia.org/wiki/File:Broad_chain_closeup.jpg#mediaviewer/File:Broad_chain_closeup.jp
MethodHandle chains
GuardWithTest
DynamicInvoker ConstantInt
Target GuardWithTest
Direct
Target Direct
Direct
Insert Direct
11
"Broad chain closeup" by Toni Lozano - http://www.flickr.com/photos/quiero-un-pantano/176909201.
Licensed under CC BY 2.0 via Wikimedia Commons -
http://commons.wikimedia.org/wiki/File:Broad_chain_closeup.jpg#mediaviewer/File:Broad_chain_closeup.jp
MethodHandle chains
12
"Broad chain closeup" by Toni Lozano - http://www.flickr.com/photos/quiero-un-pantano/176909201.
Licensed under CC BY 2.0 via Wikimedia Commons -
http://commons.wikimedia.org/wiki/File:Broad_chain_closeup.jpg#mediaviewer/File:Broad_chain_closeup.jp
DynamicInvoker GuardWithTest
DynamicInvoker ConstantInt
Target GuardWithTest
Direct
Target Direct
Direct
Insert Direct
(Mostly) tail recursive MH interpreter
13
1
2
3
4
A
A
B
C
D E F
1
2
3
4
C
1
2
3
D
2
3
1
E
ThunkTuples
 Every MethodHandle has a ThunkTuple.
 ThunkTuples hold onto the compiled code for the MethodHandle
– i2jInvokeExactThunk: interpreter to JIT entrypoint
– invokeExactThunk: JIT to JIT entrypoint
 Each ThunkTuple is generated from a bytecode template for the MethodHandle subclass
14
Compiled CodeMethodHandle
invocationCount
thunks
ThunkTuple
invocationCount
i2jInvokeExactThunk
invokeExactThunk
ThunkArchetypes: MethodHandle templates
15
 Signatures are written in terms of ‘int’ and edited at compile time
 Compile time macros are used to further specialize the code.
– ‘numGuardArgs()’ determines how many arguments are passed to the guard handle
– ILGenMacros.* are used to do signature editing, argument pushing and popping, etc
 This the MH equivalent of compiling a single ‘invokevirtual’ instruction
– Specialized just enough to get out of the interpreter and into compiled code
But that’s a lot of duplicate code!
16
ThunkTuple
invocationCount
invokeExactThunk
MethodHandle
invocationCount
thunks
ThunkTuple
invocationCount
invokeExactThunk
MethodHandle
invocationCount
thunks
ThunkTuple
invocationCount
invokeExactThunk
MethodHandle
invocationCount
thunks
Compiled Code
Compiled Code
Compiled Code
Avoiding duplicate compiles of equivalent MHs
17
MethodHandle
invocationCount
thunks
ThunkTuple
invocationCount
invokeExactThunk
MethodHandle
invocationCount
thunks
MethodHandle
invocationCount
thunks
Compiled Code
ThunkTables allow sharing
 Every MethodHandle subclass has a ThunkTable
 ThunkTables manage the mapping from MethodHandle to ThunkTuple
 Goal: Good compiled code with a high degree of sharing.
– Stay out of the interpreter.
– Don’t waste code cache
18
Compilation states
19
Interpreted
Compilation states
20
Interpreted
SharedThunk
Compilation states
21
Interpreted
SharedThunk
CustomThunk Inlined
Compiled Code
Initial JIT compilation
22
Interpreted
SharedThunk
MethodHandle
invocationCount
thunks
ThunkTuple
invocationCount
invokeExactThunk
SharedThunk delays
 With a compile threshold of 25
 The SharedThunk is run interpreted 72 times
23
MethodHandle
invocationCount
thunks
ThunkTuple
invocationCount
invokeExactThunk
MethodHandle
invocationCount
thunks
MethodHandle
invocationCount
thunks
24
24
24
72
SharedThunk delays
24
MethodHandle
invocationCount
thunks
ThunkTuple
invocationCount
invokeExactThunk
MethodHandle
invocationCount
thunks
MethodHandle
invocationCount
thunks
25
24
24
73
Compiled Code
Request
Compile
SharedThunk delays resolved
25
MethodHandle
invocationCount
thunks
ThunkTuple
invocationCount
invokeExactThunk
MethodHandle
invocationCount
thunks
MethodHandle
invocationCount
thunks
9
8
8
25
Compiled Code
Request
Compile
Addressing the cost of J->I transitions
 On transition, request MethodHandle compile
 Continue in the jitted code rather than completing the transition
26
ThunkTuple
invocationCount
invokeExactThunk
MethodHandle
invocationCount
thunks
Compiled Code
invokehandle
Compilation states
27
Interpreted
SharedThunk
CustomThunk Inlined
28 http://mccom.com/blog/wp-content/uploads/2014/07/Customize-Key-o
Why CustomThunks?
29
MethodHandle
invocationCount
thunks
MethodHandle
invocationCount
thunks
MethodHandle
invocationCount
thunks
Compiled Code Compiled Code Compiled Code
Why CustomThunks?
30
MethodHandle
invocationCount
thunks
MethodHandle
invocationCount
thunks
MethodHandle
invocationCount
thunks
Compiled Code
Invocation counts are not enough
31
A
B
C
D E F
A
Invocation counts are not enough
32
A
B
C
D E F
A C
Invocation counts are not enough
33
A
B
C
D E F
A C D
Invocation counts are not enough
34
A
B
C
D E F
A C D E
Invocation counts are not enough
35
A
B
C
D E F
A C D E F
Wasted compiles
Invocation counts are not enough
36
A
B
C
D E F
A C D E F Delayed compiles
37
"Brisbane Lightening" by Steve Arnold - http://www.flickr.com/photos/stevoarnold/3161660942.
Licensed under Attribution 2.0 Generic CC BY 2.0
Avoiding compile storms
38
A
B
C
D E F
Avoiding compile storms
39
A
B
C
D E F
A
Avoid MethodHandles.invoke()
40
A
B
C
D E F
AsType
AsType
AsType
 MethodHandle
 Counting occurs on the wrong MethodHandle
Avoid MethodHandles.invoke()
41
A
B
C
D E F
AsType
AsType
AsType
 Counting occurs on the AsType handle, not the head of the chain
 AsType from multiple signatures defeats one-element cache solution
42
Static optimizations
http://www.mathpirate.net/log/wp-content/uploads/2009/09/Static.jpg
Super bytecodes!
43
Static optimizations
44
Drop Constant
Insert Permute AsTypeDrop ArgumentMoverHandle
Constant
Permute Permute F Permute F
Future directions
 AOT SharedThunks
 Additional “super handles” like drop+constant
 AsType optimizations
 Faster / smaller MethodHandle compiles
 UNB PhD candidate looking at data mining MH chains from existing applications
45
Winner will be found at IBM’s booth
4th of February at 15.00
Sign up here: ibm.biz/bluemix-jfokus
Meet IBM at Jfokus!
J9's MethodHandle Compilation Pipeline #JFokus2015
IBM Global Entrepreneur offer Startups resources including free software
and technical experts, exposure to 600+ expert mentors, plus access to a
global network of clients.
Also eligible startups can apply for getting between 1 K USD to 10 K USD a
month credits for 12 months on their Softlayer and/or Bluemix account
IBM Global Entrepreneur Program
Sign up here: ibm.com/isv/startup
IBM Global Entrepreneur Program
for Cloud Startups – apply for
credits
Sign up here: ibm.biz/CloudStartup
IBM Analytics Starter Program
Sign-up here:
ibm.biz/analyticsstarter

More Related Content

PDF
invokedynamic: Evolution of a Language Feature
PDF
JavaOne 2016: Life after Modularity
PDF
Clone Clone Make: a better way to build
PDF
J9: Under the hood of the next open source JVM
PPTX
FOSDEM 2017 - Open J9 The Next Free Java VM
PPTX
FOSDEM 2017 - A different Lua JIT using Eclipse OMR
PPTX
PHP Development Tools 2.0 - Success Story
PDF
Java Concurrency, A(nother) Peek Under the Hood [Code One 2019]
invokedynamic: Evolution of a Language Feature
JavaOne 2016: Life after Modularity
Clone Clone Make: a better way to build
J9: Under the hood of the next open source JVM
FOSDEM 2017 - Open J9 The Next Free Java VM
FOSDEM 2017 - A different Lua JIT using Eclipse OMR
PHP Development Tools 2.0 - Success Story
Java Concurrency, A(nother) Peek Under the Hood [Code One 2019]

What's hot (20)

PDF
JDK Mission Control: Where We Are, Where We Are Going [Code One 2019]
PDF
Analysis of software systems using jQAssistant and Neo4j
PDF
CSI (Crash Scene Investigation) HotSpot: Common JVM Crash Causes and Solution...
PDF
llvm-py: Writing Compilers In Python
PDF
Core java interview questions
PPTX
Framework Engineering 2.1
PDF
invokedynamic for Mere Mortals [Code One 2019]
PPTX
Dev labs alliance top 20 basic java interview question for sdet
PDF
Thesis - LLVM toolchain support as a plug-in for Eclipse CDT
PDF
Hangs, Slowdowns, Starvation—Oh My! A Deep Dive into the Life of a Java Threa...
PDF
Best interview questions
PDF
Contract First Development with Microsoft Code Contracts and Microsoft Pex at...
PDF
Extreme Interview Questions
PPT
PDF
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
PPTX
Jfokus 2016 - A JVMs Journey into Polyglot Runtimes
PDF
Oh the compilers you'll build
PDF
Hotspot & AOT
PPTX
chp 3 : Modifiers (scjp/ocjp)
PDF
Semi-Automatic Code Cleanup with Clang-Tidy
JDK Mission Control: Where We Are, Where We Are Going [Code One 2019]
Analysis of software systems using jQAssistant and Neo4j
CSI (Crash Scene Investigation) HotSpot: Common JVM Crash Causes and Solution...
llvm-py: Writing Compilers In Python
Core java interview questions
Framework Engineering 2.1
invokedynamic for Mere Mortals [Code One 2019]
Dev labs alliance top 20 basic java interview question for sdet
Thesis - LLVM toolchain support as a plug-in for Eclipse CDT
Hangs, Slowdowns, Starvation—Oh My! A Deep Dive into the Life of a Java Threa...
Best interview questions
Contract First Development with Microsoft Code Contracts and Microsoft Pex at...
Extreme Interview Questions
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
Jfokus 2016 - A JVMs Journey into Polyglot Runtimes
Oh the compilers you'll build
Hotspot & AOT
chp 3 : Modifiers (scjp/ocjp)
Semi-Automatic Code Cleanup with Clang-Tidy
Ad

Viewers also liked (17)

PPTX
Asset Classes and Constructing a Portfolio
PPTX
Bond Investing Strategy (Part 1)
PDF
Types of Technology
PDF
THE GLORIA
PDF
3100-Food Industry
PDF
Let's have a coffee with Familipreneurship !
PPTX
Alternative Asset Classes
PPTX
Power point zambrano
PDF
lumativ-lookbook-6-17-16
PDF
The norwegian cause of death registry christian l.ellingsen
PDF
Knowledge from health registries, cohorts, and biobanks stein emilvollset
PPTX
Do You Know Your Net Worth?
PPTX
Real Life Finance in Practice
PPTX
Global Investing vs. US-Centric Investing
PPTX
Research on Global Investing vs. US-only Investing
PPTX
Maintaining the Purchasing Power of Portfolios
PDF
Boca Raton, Florida
Asset Classes and Constructing a Portfolio
Bond Investing Strategy (Part 1)
Types of Technology
THE GLORIA
3100-Food Industry
Let's have a coffee with Familipreneurship !
Alternative Asset Classes
Power point zambrano
lumativ-lookbook-6-17-16
The norwegian cause of death registry christian l.ellingsen
Knowledge from health registries, cohorts, and biobanks stein emilvollset
Do You Know Your Net Worth?
Real Life Finance in Practice
Global Investing vs. US-Centric Investing
Research on Global Investing vs. US-only Investing
Maintaining the Purchasing Power of Portfolios
Boca Raton, Florida
Ad

Similar to J9's MethodHandle Compilation Pipeline #JFokus2015 (20)

PPTX
#Interactive Session by Kirti Ranjan Satapathy and Nandini K, "Elements of Qu...
PDF
Data Con LA 2022-Pre-recorded - Hamilton, General Purpose framework for Scala...
PPT
Data flow
PPT
How to Data Flow Diagram
PPT
208 dataflowdgm
 
PPT
Ab initio training Ab-initio Architecture
PDF
PDF
Userland Hooking in Windows
PDF
MITRE-Module 3 Slides.pdf
PDF
Flink Forward 2016
PDF
Experiences in Mainframe-to-Splunk Big Data Access
PDF
Implementing Hypermedia Clients: It's Not Rocket Science – Mike Amundsen, Pri...
PPT
208-dataflowdgm_5.ppt
PPT
data flow diagram power point presentation
PPT
208-dataflowdgm.ppt
PDF
Fuzzing malware for fun & profit. Applying Coverage-Guided Fuzzing to Find Bu...
PDF
The unconventional devices for the video streaming in Android
PDF
Ana M Martinez - AMIDST Toolbox- Scalable probabilistic machine learning with...
PPTX
Using hypervisor and container technology to increase datacenter security pos...
PPTX
Using hypervisor and container technology to increase datacenter security pos...
#Interactive Session by Kirti Ranjan Satapathy and Nandini K, "Elements of Qu...
Data Con LA 2022-Pre-recorded - Hamilton, General Purpose framework for Scala...
Data flow
How to Data Flow Diagram
208 dataflowdgm
 
Ab initio training Ab-initio Architecture
Userland Hooking in Windows
MITRE-Module 3 Slides.pdf
Flink Forward 2016
Experiences in Mainframe-to-Splunk Big Data Access
Implementing Hypermedia Clients: It's Not Rocket Science – Mike Amundsen, Pri...
208-dataflowdgm_5.ppt
data flow diagram power point presentation
208-dataflowdgm.ppt
Fuzzing malware for fun & profit. Applying Coverage-Guided Fuzzing to Find Bu...
The unconventional devices for the video streaming in Android
Ana M Martinez - AMIDST Toolbox- Scalable probabilistic machine learning with...
Using hypervisor and container technology to increase datacenter security pos...
Using hypervisor and container technology to increase datacenter security pos...

Recently uploaded (20)

PDF
top salesforce developer skills in 2025.pdf
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
medical staffing services at VALiNTRY
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
System and Network Administration Chapter 2
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
AI in Product Development-omnex systems
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Digital Strategies for Manufacturing Companies
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
ai tools demonstartion for schools and inter college
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
top salesforce developer skills in 2025.pdf
wealthsignaloriginal-com-DS-text-... (1).pdf
Softaken Excel to vCard Converter Software.pdf
Odoo POS Development Services by CandidRoot Solutions
medical staffing services at VALiNTRY
Design an Analysis of Algorithms I-SECS-1021-03
System and Network Administration Chapter 2
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
How Creative Agencies Leverage Project Management Software.pdf
AI in Product Development-omnex systems
Design an Analysis of Algorithms II-SECS-1021-03
Upgrade and Innovation Strategies for SAP ERP Customers
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Understanding Forklifts - TECH EHS Solution
Reimagine Home Health with the Power of Agentic AI​
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Digital Strategies for Manufacturing Companies
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
ai tools demonstartion for schools and inter college
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises

J9's MethodHandle Compilation Pipeline #JFokus2015