SlideShare a Scribd company logo
The following is intended to outline our general product direction. It is intended for information purposes
only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code,
or functionality, and should not be relied upon in making purchasing decisions. The development,
release, timing, and pricing of any features or functionality described for Oracle’s products may change
and remains at the sole discretion of Oracle Corporation.
Statements in this presentation relating to Oracle’s future plans, expectations, beliefs, intentions and
prospects are “forward-looking statements” and are subject to material risks and uncertainties. A detailed
discussion of these factors and other risks that affect our business is contained in Oracle’s Securities and
Exchange Commission (SEC) filings, including our most recent reports on Form 10-K and Form 10-Q
under the heading “Risk Factors.” These filings are available on the SEC’s website or on Oracle’s website
at http://www.oracle.com/investor. All information in this presentation is current as of September 2019
and Oracle undertakes no duty to update any statement in light of new information or future events.
Safe Harbor
Copyright © 2019 Oracle and/or its affiliates.
Invokedynamic for Mere Mortals
[DEV4253]
Principal Member of Technical Staff
Java Platform Group
September 17, 2019
David Buck
Copyright © 2019 Oracle and/or its affiliates.
JVM Sustaining Engineer
OpenJDK Update Project
Maintainer
JavaOne Rock Star
Co-author of Oracle WebLogic
Server 11g 構築・運用ガイド
@DavidBuckJP
https://blogs.oracle.com/buck/
Who am I? David Buck (left)
Program Agenda
Introduction
java.lang.invoke
invokedynamic instruction
Other stuff
1
2
3
4
4
Introduction
5
Target Audience
Not compiler writers
Curious
6
Motivation
Understand javap output better
Understand the value JVM has as a multi-language JVM
7
Da Vinci Machine Project
The JVM is a great platform for running all sorts of languages
Great performance
Portability
Security (sandbox)
Pre-existing libraries and frameworks
8
JVM-specific
Scala
Clojure
Groovy
Ceylon
Fortress
Gosu
Kotlin
Ported to JVM
JRuby
Jython
Smalltalk
Ada
Scheme
REXX
Prolog
Pascal
Common LISP
(a small subset of) JVM languages
9
Java Code
Language Runtime
10
JVM
OS
Java
Class Library
JRuby Runtime
JVM
OS
Java
Class Library
Ruby Code
non-Java language wish list
Continuations
Dynamic invocation
Tail recursion
Interface injection
Other stuff
11
non-Java language wish list
Continuations
Dynamic invocation
Tail recursion
Interface injection
Other stuff
12
What is dynamic typing?
13
What is dynamic typing?
def addtwo(a, b)
a + b;
end
14
What is dynamic typing?
We do not know what the types are until runtime
15
statically-typed vs. dynamically-typed
When do we type check / link?
Compilation time (javac)
Runtime
16
Compile-time checking / linking
Catch errors early
Limits the type of code we can write (false positives)
17
Run time checking / linking
Allow more freedom of programming (less false positives)
Less guarantees about runtime behavior
18
dynamic typing != type inference
object InferenceTest1 extends App {
val x = 1 + 2 * 3 // the type of x is Int
val y = x.toString() // the type of y is String
def succ(x: Int) = x + 1 // succ returns Int values
}
(Shamelessly copied from http://docs.scala-
lang.org/tutorials/tour/local-type-inference.html)
19
dynamic typing != week typing
a = "40"
b = a + 2
20
Dynamically-typed languages
Allow more programs, but have to do more runtime checking.
No perfect type information at compile time
21
Polymorphism != Dynamic typing (?!)
public String bar(Object o) {
return "You passed me " + o.toString();
}
22
The original invocation lineup
invokestatic
Class method
invokevirtual
Instance method
invokeinterface
Interface method
Invokespecial
Everything else (private, super class, constructors)
23
The original invocation lineup
invokestatic
Class method
invokevirtual
Instance method
invokeinterface
Interface method
Invokespecial
Everything else (private, super class, constructors)
24
invokestatic
public class InvokeStaticExample {
public static void main(String[] args) {
InvokeStaticExample.foo();
}
public static void foo() {
System.out.println("I am foo!");
}
}
25
The original invocation lineup
invokestatic
Class method
invokevirtual
Instance method
invokeinterface
Interface method
Invokespecial
Everything else (private, super class, constructors)
26
invokevirtual
public class InvokeVirtualExample {
public static void main(String[] args) {
InvokeVirtualExample ive = new InvokeVirtualExample();
ive.foo();
}
public void foo() {
System.out.println("I am foo!");
}
}
27
The original invocation lineup
invokestatic
Class method
invokevirtual
Instance method
invokeinterface
Interface method
Invokespecial
Everything else (private, super class, constructors)
28
public class InvokeInterfaceExample
implements MyInterface {
public static void main(String[] args)
{
MyInterface iie = new
InvokeInterfaceExample();
iie.foo();
}
public void foo() {
System.out.println("I am foo!");
}
}
interface MyInterface {
public void foo();
}
29
invokeinterface
The original invocation lineup
invokestatic
Class method
invokevirtual
Instance method
invokeinterface
Interface method
Invokespecial
Everything else (private, super class, constructors)
30
invokespecial
public class InvokeSpecialExample {
public static void main(String[] args) {
InvokeSpecialExample ise = new InvokeSpecialExample();
ise.foo();
}
private void foo() {
System.out.println("I am foo!");
}
}
31
Poor dynamic languages on JVM?
invocation logic is not baked into the JVM like it is for Java
we need to fall back on reflection
32
Reflection is slow
security check on each invocation
all arguments are Objects (boxing)
33
What the JVM doesn’t know can hurt it
34
Caller
Reflection
Magic! Callee
Reflection prevents inlining!
35
Caller
Reflection
Magic! Callee
No one writes code like this
if (false) {
// do some important stuff...
System.out.println("I'm important!");
}
36
Or this…
boolean cond = true;
if (cond) {
// do some important stuff...
System.out.println("I'm important!");
}
37
public void methodB() {
// ...
methodA(false);
// ...
}
public void methodA(boolean
optionalStuff) {
// ...
if (optionalStuff) {
// do some optional, but
important stuff...
System.out.println("I'm important
sometimes!");
}
// ...
}
38
But we do write stuff like
JSR-292
java.lang.invoke API
A “better reflection”
invokedynamic bytecode
Allows us to dispatch to linkage logic defined by invoke API
39
invokedynamic
We call it “indy”
No clear way to express in Java language
Important milestone for JVM
First new instruction in decades
First new JVM feature to only (mainly) target non-java languages
40
java.lang.invoke API
MethodHandle
CallSite
Bootstrap Method (BSM)
41
MethodHandle
42
int foo()Method Handle
MethodHandle
Points to a method
Is a “function pointer” (am I allowed to say this?)
Polymorphic signature
43
MethodHandle Performance
44
MethodHandle Performance
Early performance was not ideal
45
MethodHandle Performance
Early performance was not ideal
Performance improved tremendously with lambda forms
46
MethodHandle Performance
Early performance was not ideal
Performance improved tremendously with lambda forms
Is now often significantly faster than reflection
47
MethodHandle Performance
Early performance was not ideal
Performance improved tremendously with lambda forms
Is now often significantly faster than reflection
Can be used independently of invokedynamic
48
CallSite
49
private void doStuff();
descriptor: ()V
flags: ACC_PRIVATE
Code:
stack=2, locals=2, args_size=1
0: new #7
3: dup
4: invokespecial #8
7: astore_1
8: aload_1
9: aload_0
10: invokedynamic #9, 0
15: invokevirtual #10
18: return
CS Method Handle int foo()
CallSite
50
private void doStuff();
descriptor: ()V
flags: ACC_PRIVATE
Code:
stack=2, locals=2, args_size=1
0: new #7
3: dup
4: invokespecial #8
7: astore_1
8: aload_1
9: aload_0
10: invokedynamic #9, 0
15: invokevirtual #10
18: return
CS
int bar()
int foo()
CallSite
Reifies Indy invocation side
Has a MethodHandle
51
Bootstrapping Step 1
52
private void doStuff();
descriptor: ()V
flags: ACC_PRIVATE
Code:
stack=2, locals=2, args_size=1
0: new #7
3: dup
4: invokespecial #8
7: astore_1
8: aload_1
9: aload_0
10: invokedynamic #9, 0
15: invokevirtual #10
18: return
Bootstrapping Step 2
53
private void doStuff();
descriptor: ()V
flags: ACC_PRIVATE
Code:
stack=2, locals=2, args_size=1
0: new #7
3: dup
4: invokespecial #8
7: astore_1
8: aload_1
9: aload_0
10: invokedynamic #9, 0
15: invokevirtual #10
18: return BootStrap Method
Bootstrapping Step 3
54
private void doStuff();
descriptor: ()V
flags: ACC_PRIVATE
Code:
stack=2, locals=2, args_size=1
0: new #7
3: dup
4: invokespecial #8
7: astore_1
8: aload_1
9: aload_0
10: invokedynamic #9, 0
15: invokevirtual #10
18: return BootStrap Method
int foo()
Bootstrapping Step 4
55
private void doStuff();
descriptor: ()V
flags: ACC_PRIVATE
Code:
stack=2, locals=2, args_size=1
0: new #7
3: dup
4: invokespecial #8
7: astore_1
8: aload_1
9: aload_0
10: invokedynamic #9, 0
15: invokevirtual #10
18: return BootStrap Method
int foo()
CS
Bootstrapping Step 5
56
private void doStuff();
descriptor: ()V
flags: ACC_PRIVATE
Code:
stack=2, locals=2, args_size=1
0: new #7
3: dup
4: invokespecial #8
7: astore_1
8: aload_1
9: aload_0
10: invokedynamic #9, 0
15: invokevirtual #10
18: return
int foo()
CS
Bootstrap Method
Only called on the first invocation of each indy bytecode
Returns a CallSite
57
"Dr Martens, black, old" by Tarquin
is licensed under CC BY-SA 3.0
Indy lifecycle
Initial Invocation
1. A specific indy invocation is executed for the first time
2. Bootstrap method is called and if finds (generates?!) a method to
run
3. Bootstrap method returns a permanent CallSite object for this
indy invocation
4. We jump to the method pointed to by the CallSite
58
Indy Lifecycle
All subsequent calls
We jump to the method pointed to by the CallSite
59
Picture from
National Archives and Records Administration
This performance tragedy becomes
60
Caller
Reflection
Magic! Callee
61
Caller Callee
MethodHandle
Linkage != Invocation
62
Linkage != Invocation
Linkage (i.e. bootstrap)
Usually only needs to be done once
Is expensive
63
Linkage != Invocation
Linkage (i.e. bootstrap)
Usually only needs to be done once
Is expensive
Invocation
Done a lot
Only needs a jmp/call (and possibly a guard)
64
Linkage != Invocation
Avoid the cost of linkage on almost every call
65
• Mismatch between language and bytecode
• JDK <= 8 javac uses StringBuilder.append()
• StringBuilder has performance issues
• JDK >= 9 uses invoke dynamic
Copyright © 2019 Oracle and/or its affiliates.
String Concatenation
Takeaways
67
Takeaways
Invokedynamic lets us programmatically alter linkage
68
Takeaways
Invokedynamic lets us programmatically alter linkage
Then it gets out of the way! (linkage != invocation)
69
Takeaways
Invokedynamic lets us programmatically alter linkage
Then it gets out of the way! (linkage != invocation)
The Invoke API can often be used without indy
70
Takeaways
Invokedynamic lets us programmatically alter linkage
Then it gets out of the way! (linkage != invocation)
The Invoke API can often be used without indy
JVM is a great platform for just about any language!
71
Resources
JVM Language Summit
http://openjdk.java.net/projects/mlvm/jvmlangsummit/
Linkers & Loaders book
http://linker.iecc.com/
John Rose’s Blog
https://blogs.oracle.com/jrose/
72
Thank You!
73
The preceding is intended to outline our general product direction. It is intended for information purposes
only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code,
or functionality, and should not be relied upon in making purchasing decisions. The development,
release, timing, and pricing of any features or functionality described for Oracle’s products may change
and remains at the sole discretion of Oracle Corporation.
Statements in this presentation relating to Oracle’s future plans, expectations, beliefs, intentions and
prospects are “forward-looking statements” and are subject to material risks and uncertainties. A detailed
discussion of these factors and other risks that affect our business is contained in Oracle’s Securities and
Exchange Commission (SEC) filings, including our most recent reports on Form 10-K and Form 10-Q
under the heading “Risk Factors.” These filings are available on the SEC’s website or on Oracle’s website
at http://www.oracle.com/investor. All information in this presentation is current as of September 2019
and Oracle undertakes no duty to update any statement in light of new information or future events.
Safe Harbor
Copyright © 2019 Oracle and/or its affiliates.

More Related Content

PDF
CSI (Crash Scene Investigation) HotSpot: Common JVM Crash Causes and Solution...
PDF
JDK Mission Control: Where We Are, Where We Are Going [Code One 2019]
PDF
Java Concurrency, A(nother) Peek Under the Hood [Code One 2019]
PDF
Hangs, Slowdowns, Starvation—Oh My! A Deep Dive into the Life of a Java Threa...
PDF
Java Bytecode Crash Course [Code One 2019]
PDF
Hotspot & AOT
PPTX
Future of Java EE with Java SE 8
PPTX
JavaOne 2015 CON5211 Digital Java EE 7 with JSF Conversations, Flows, and CDI...
CSI (Crash Scene Investigation) HotSpot: Common JVM Crash Causes and Solution...
JDK Mission Control: Where We Are, Where We Are Going [Code One 2019]
Java Concurrency, A(nother) Peek Under the Hood [Code One 2019]
Hangs, Slowdowns, Starvation—Oh My! A Deep Dive into the Life of a Java Threa...
Java Bytecode Crash Course [Code One 2019]
Hotspot & AOT
Future of Java EE with Java SE 8
JavaOne 2015 CON5211 Digital Java EE 7 with JSF Conversations, Flows, and CDI...

What's hot (20)

PDF
JavaEE & GlassFish UG - Digital JavaEE 7 New & Noteworthy by P.Pilgrim
PPTX
Java EE 7 for Real Enterprise Systems
PPTX
Hacking Oracle From Web Apps 1 9
PDF
Compile ahead of time. It's fine?
PDF
Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013
PDF
CompletableFuture уже здесь
PPTX
XML-Free Programming
PDF
Visage Android Hands-on Lab (OSCON)
PDF
英文【Xu hao chen xiaobo】find your_own_ios_kernel_bug
PDF
JavaOne 2016: Life after Modularity
ODP
Javaee6 Overview
PDF
Java EE 7: Boosting Productivity and Embracing HTML5
PDF
Flavors of Concurrency in Java
PDF
JavaOne San Francisco 2013 - Servlet 3.1 (JSR 340)
PDF
Clone Clone Make: a better way to build
PDF
Concierge - Bringing OSGi (back) to Embedded Devices
PDF
RESTful API Design & Implementation with CodeIgniter PHP Framework
PDF
How to reverse engineer Android applications
PDF
Defcon_Oracle_The_Making_of_the_2nd_sql_injection_worm
PDF
Building a web application with ontinuation monads
JavaEE & GlassFish UG - Digital JavaEE 7 New & Noteworthy by P.Pilgrim
Java EE 7 for Real Enterprise Systems
Hacking Oracle From Web Apps 1 9
Compile ahead of time. It's fine?
Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013
CompletableFuture уже здесь
XML-Free Programming
Visage Android Hands-on Lab (OSCON)
英文【Xu hao chen xiaobo】find your_own_ios_kernel_bug
JavaOne 2016: Life after Modularity
Javaee6 Overview
Java EE 7: Boosting Productivity and Embracing HTML5
Flavors of Concurrency in Java
JavaOne San Francisco 2013 - Servlet 3.1 (JSR 340)
Clone Clone Make: a better way to build
Concierge - Bringing OSGi (back) to Embedded Devices
RESTful API Design & Implementation with CodeIgniter PHP Framework
How to reverse engineer Android applications
Defcon_Oracle_The_Making_of_the_2nd_sql_injection_worm
Building a web application with ontinuation monads
Ad

Similar to invokedynamic for Mere Mortals [Code One 2019] (20)

PDF
InvokeDynamic for Mere Mortals [JavaOne 2015 CON7682]
PDF
invokedynamic: Evolution of a Language Feature
PDF
Optimizing JavaScript and Dynamic Languages on the JVM
PPTX
GOTO Night with Charles Nutter Slides
PDF
JRuby and Invokedynamic - Japan JUG 2015
PDF
Java Full Throttle
PDF
Invoke dynamic your api to hotspot
PDF
The State of Managed Runtimes 2013, by Attila Szegedi
PDF
Projects Panama, Valhalla, and Babylon: Java is the New Python v0.9
PDF
JVM JIT compilation overview by Vladimir Ivanov
KEY
Java 7: Fork/Join, Invokedynamic and the future
PPTX
Software Uni Conf October 2014
PDF
Владимир Иванов. JIT для Java разработчиков
PPTX
JIT vs. AOT: Unity And Conflict of Dynamic and Static Compilers
PDF
Jax keynote
PDF
"JIT compiler overview" @ JEEConf 2013, Kiev, Ukraine
PDF
Java jdk-update-nov10-sde-v3m
PDF
JSR 335 / java 8 - update reference
PDF
Ola Bini Evolving The Java Platform
PDF
NDK Primer (AnDevCon Boston 2014)
InvokeDynamic for Mere Mortals [JavaOne 2015 CON7682]
invokedynamic: Evolution of a Language Feature
Optimizing JavaScript and Dynamic Languages on the JVM
GOTO Night with Charles Nutter Slides
JRuby and Invokedynamic - Japan JUG 2015
Java Full Throttle
Invoke dynamic your api to hotspot
The State of Managed Runtimes 2013, by Attila Szegedi
Projects Panama, Valhalla, and Babylon: Java is the New Python v0.9
JVM JIT compilation overview by Vladimir Ivanov
Java 7: Fork/Join, Invokedynamic and the future
Software Uni Conf October 2014
Владимир Иванов. JIT для Java разработчиков
JIT vs. AOT: Unity And Conflict of Dynamic and Static Compilers
Jax keynote
"JIT compiler overview" @ JEEConf 2013, Kiev, Ukraine
Java jdk-update-nov10-sde-v3m
JSR 335 / java 8 - update reference
Ola Bini Evolving The Java Platform
NDK Primer (AnDevCon Boston 2014)
Ad

More from David Buck (20)

PDF
JDK 13 New Features [MeetUp with Java Experts! @Gaienmae/Dojima 2019]
PDF
JDK Mission Control: Where We Are, Where We Are Going [Groundbreakers APAC 20...
PDF
Z Garbage Collector
PDF
Valhalla Update JJUG CCC Spring 2019
PDF
Var handles jjug_ccc_spring_2018
PDF
JDK 10 へようこそ
PDF
Java SE 8におけるHotSpotの進化 [Java Day Tokyo 2014 C-2]
PDF
HotSpot のロック: A Peek Under the Hood [JJUG ナイトセミナ JVM 特集 2015年8月]
PDF
Java Concurrency, A(nother) Peek Under the Hood [JavaOne 2016 CON1497]
PDF
Bytecode Verification, the Hero That Java Needs [JavaOne 2016 CON1500]
PDF
Java Debuggers: A Peek Under the Hood [JavaOne 2016 CON1503]
PDF
Lambda: A Peek Under The Hood [Java Day Tokyo 2015 6-3]
PDF
Java Concurrency, A(nother) Peek Under the Hood [Java Day Tokyo 2016 3-C]
PDF
Ahead-of-Time Compilation with JDK 9 [Java Day Tokyo 2017 D1-A1]
PDF
HotSpot Synchronization, A Peek Under the Hood [JavaOne 2015 CON7570]
PDF
Let’s Write Our Own Chip-8 Interpreter! [JavaOne 2017 CON3584]
PDF
Everything You Wanted to Know About JIT Compilation but Were Afraid to Ask [J...
PDF
Full Speed Ahead! (Ahead-of-Time Compilation for Java SE) [JavaOne 2017 CON3738]
PPTX
OpenJDK: How to Join In on All the Fun [JavaOne 2017 CON3667]
PPTX
OpenJDK 参加入門 [JJUG CCC 2017 Fall E2]
JDK 13 New Features [MeetUp with Java Experts! @Gaienmae/Dojima 2019]
JDK Mission Control: Where We Are, Where We Are Going [Groundbreakers APAC 20...
Z Garbage Collector
Valhalla Update JJUG CCC Spring 2019
Var handles jjug_ccc_spring_2018
JDK 10 へようこそ
Java SE 8におけるHotSpotの進化 [Java Day Tokyo 2014 C-2]
HotSpot のロック: A Peek Under the Hood [JJUG ナイトセミナ JVM 特集 2015年8月]
Java Concurrency, A(nother) Peek Under the Hood [JavaOne 2016 CON1497]
Bytecode Verification, the Hero That Java Needs [JavaOne 2016 CON1500]
Java Debuggers: A Peek Under the Hood [JavaOne 2016 CON1503]
Lambda: A Peek Under The Hood [Java Day Tokyo 2015 6-3]
Java Concurrency, A(nother) Peek Under the Hood [Java Day Tokyo 2016 3-C]
Ahead-of-Time Compilation with JDK 9 [Java Day Tokyo 2017 D1-A1]
HotSpot Synchronization, A Peek Under the Hood [JavaOne 2015 CON7570]
Let’s Write Our Own Chip-8 Interpreter! [JavaOne 2017 CON3584]
Everything You Wanted to Know About JIT Compilation but Were Afraid to Ask [J...
Full Speed Ahead! (Ahead-of-Time Compilation for Java SE) [JavaOne 2017 CON3738]
OpenJDK: How to Join In on All the Fun [JavaOne 2017 CON3667]
OpenJDK 参加入門 [JJUG CCC 2017 Fall E2]

Recently uploaded (20)

PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
AutoCAD Professional Crack 2025 With License Key
PDF
Complete Guide to Website Development in Malaysia for SMEs
PPTX
Advanced SystemCare Ultimate Crack + Portable (2025)
PPTX
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
PDF
Digital Systems & Binary Numbers (comprehensive )
PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Download FL Studio Crack Latest version 2025 ?
PDF
Salesforce Agentforce AI Implementation.pdf
PDF
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
PDF
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Autodesk AutoCAD Crack Free Download 2025
PDF
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
PDF
CapCut Video Editor 6.8.1 Crack for PC Latest Download (Fully Activated) 2025
PDF
Cost to Outsource Software Development in 2025
Design an Analysis of Algorithms I-SECS-1021-03
Odoo Companies in India – Driving Business Transformation.pdf
AutoCAD Professional Crack 2025 With License Key
Complete Guide to Website Development in Malaysia for SMEs
Advanced SystemCare Ultimate Crack + Portable (2025)
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
Digital Systems & Binary Numbers (comprehensive )
Computer Software and OS of computer science of grade 11.pptx
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
Operating system designcfffgfgggggggvggggggggg
Wondershare Filmora 15 Crack With Activation Key [2025
Download FL Studio Crack Latest version 2025 ?
Salesforce Agentforce AI Implementation.pdf
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development
Autodesk AutoCAD Crack Free Download 2025
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
CapCut Video Editor 6.8.1 Crack for PC Latest Download (Fully Activated) 2025
Cost to Outsource Software Development in 2025

invokedynamic for Mere Mortals [Code One 2019]

  • 1. The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, timing, and pricing of any features or functionality described for Oracle’s products may change and remains at the sole discretion of Oracle Corporation. Statements in this presentation relating to Oracle’s future plans, expectations, beliefs, intentions and prospects are “forward-looking statements” and are subject to material risks and uncertainties. A detailed discussion of these factors and other risks that affect our business is contained in Oracle’s Securities and Exchange Commission (SEC) filings, including our most recent reports on Form 10-K and Form 10-Q under the heading “Risk Factors.” These filings are available on the SEC’s website or on Oracle’s website at http://www.oracle.com/investor. All information in this presentation is current as of September 2019 and Oracle undertakes no duty to update any statement in light of new information or future events. Safe Harbor Copyright © 2019 Oracle and/or its affiliates.
  • 2. Invokedynamic for Mere Mortals [DEV4253] Principal Member of Technical Staff Java Platform Group September 17, 2019 David Buck Copyright © 2019 Oracle and/or its affiliates.
  • 3. JVM Sustaining Engineer OpenJDK Update Project Maintainer JavaOne Rock Star Co-author of Oracle WebLogic Server 11g 構築・運用ガイド @DavidBuckJP https://blogs.oracle.com/buck/ Who am I? David Buck (left)
  • 6. Target Audience Not compiler writers Curious 6
  • 7. Motivation Understand javap output better Understand the value JVM has as a multi-language JVM 7
  • 8. Da Vinci Machine Project The JVM is a great platform for running all sorts of languages Great performance Portability Security (sandbox) Pre-existing libraries and frameworks 8
  • 10. Java Code Language Runtime 10 JVM OS Java Class Library JRuby Runtime JVM OS Java Class Library Ruby Code
  • 11. non-Java language wish list Continuations Dynamic invocation Tail recursion Interface injection Other stuff 11
  • 12. non-Java language wish list Continuations Dynamic invocation Tail recursion Interface injection Other stuff 12
  • 13. What is dynamic typing? 13
  • 14. What is dynamic typing? def addtwo(a, b) a + b; end 14
  • 15. What is dynamic typing? We do not know what the types are until runtime 15
  • 16. statically-typed vs. dynamically-typed When do we type check / link? Compilation time (javac) Runtime 16
  • 17. Compile-time checking / linking Catch errors early Limits the type of code we can write (false positives) 17
  • 18. Run time checking / linking Allow more freedom of programming (less false positives) Less guarantees about runtime behavior 18
  • 19. dynamic typing != type inference object InferenceTest1 extends App { val x = 1 + 2 * 3 // the type of x is Int val y = x.toString() // the type of y is String def succ(x: Int) = x + 1 // succ returns Int values } (Shamelessly copied from http://docs.scala- lang.org/tutorials/tour/local-type-inference.html) 19
  • 20. dynamic typing != week typing a = "40" b = a + 2 20
  • 21. Dynamically-typed languages Allow more programs, but have to do more runtime checking. No perfect type information at compile time 21
  • 22. Polymorphism != Dynamic typing (?!) public String bar(Object o) { return "You passed me " + o.toString(); } 22
  • 23. The original invocation lineup invokestatic Class method invokevirtual Instance method invokeinterface Interface method Invokespecial Everything else (private, super class, constructors) 23
  • 24. The original invocation lineup invokestatic Class method invokevirtual Instance method invokeinterface Interface method Invokespecial Everything else (private, super class, constructors) 24
  • 25. invokestatic public class InvokeStaticExample { public static void main(String[] args) { InvokeStaticExample.foo(); } public static void foo() { System.out.println("I am foo!"); } } 25
  • 26. The original invocation lineup invokestatic Class method invokevirtual Instance method invokeinterface Interface method Invokespecial Everything else (private, super class, constructors) 26
  • 27. invokevirtual public class InvokeVirtualExample { public static void main(String[] args) { InvokeVirtualExample ive = new InvokeVirtualExample(); ive.foo(); } public void foo() { System.out.println("I am foo!"); } } 27
  • 28. The original invocation lineup invokestatic Class method invokevirtual Instance method invokeinterface Interface method Invokespecial Everything else (private, super class, constructors) 28
  • 29. public class InvokeInterfaceExample implements MyInterface { public static void main(String[] args) { MyInterface iie = new InvokeInterfaceExample(); iie.foo(); } public void foo() { System.out.println("I am foo!"); } } interface MyInterface { public void foo(); } 29 invokeinterface
  • 30. The original invocation lineup invokestatic Class method invokevirtual Instance method invokeinterface Interface method Invokespecial Everything else (private, super class, constructors) 30
  • 31. invokespecial public class InvokeSpecialExample { public static void main(String[] args) { InvokeSpecialExample ise = new InvokeSpecialExample(); ise.foo(); } private void foo() { System.out.println("I am foo!"); } } 31
  • 32. Poor dynamic languages on JVM? invocation logic is not baked into the JVM like it is for Java we need to fall back on reflection 32
  • 33. Reflection is slow security check on each invocation all arguments are Objects (boxing) 33
  • 34. What the JVM doesn’t know can hurt it 34 Caller Reflection Magic! Callee
  • 36. No one writes code like this if (false) { // do some important stuff... System.out.println("I'm important!"); } 36
  • 37. Or this… boolean cond = true; if (cond) { // do some important stuff... System.out.println("I'm important!"); } 37
  • 38. public void methodB() { // ... methodA(false); // ... } public void methodA(boolean optionalStuff) { // ... if (optionalStuff) { // do some optional, but important stuff... System.out.println("I'm important sometimes!"); } // ... } 38 But we do write stuff like
  • 39. JSR-292 java.lang.invoke API A “better reflection” invokedynamic bytecode Allows us to dispatch to linkage logic defined by invoke API 39
  • 40. invokedynamic We call it “indy” No clear way to express in Java language Important milestone for JVM First new instruction in decades First new JVM feature to only (mainly) target non-java languages 40
  • 43. MethodHandle Points to a method Is a “function pointer” (am I allowed to say this?) Polymorphic signature 43
  • 46. MethodHandle Performance Early performance was not ideal Performance improved tremendously with lambda forms 46
  • 47. MethodHandle Performance Early performance was not ideal Performance improved tremendously with lambda forms Is now often significantly faster than reflection 47
  • 48. MethodHandle Performance Early performance was not ideal Performance improved tremendously with lambda forms Is now often significantly faster than reflection Can be used independently of invokedynamic 48
  • 49. CallSite 49 private void doStuff(); descriptor: ()V flags: ACC_PRIVATE Code: stack=2, locals=2, args_size=1 0: new #7 3: dup 4: invokespecial #8 7: astore_1 8: aload_1 9: aload_0 10: invokedynamic #9, 0 15: invokevirtual #10 18: return CS Method Handle int foo()
  • 50. CallSite 50 private void doStuff(); descriptor: ()V flags: ACC_PRIVATE Code: stack=2, locals=2, args_size=1 0: new #7 3: dup 4: invokespecial #8 7: astore_1 8: aload_1 9: aload_0 10: invokedynamic #9, 0 15: invokevirtual #10 18: return CS int bar() int foo()
  • 51. CallSite Reifies Indy invocation side Has a MethodHandle 51
  • 52. Bootstrapping Step 1 52 private void doStuff(); descriptor: ()V flags: ACC_PRIVATE Code: stack=2, locals=2, args_size=1 0: new #7 3: dup 4: invokespecial #8 7: astore_1 8: aload_1 9: aload_0 10: invokedynamic #9, 0 15: invokevirtual #10 18: return
  • 53. Bootstrapping Step 2 53 private void doStuff(); descriptor: ()V flags: ACC_PRIVATE Code: stack=2, locals=2, args_size=1 0: new #7 3: dup 4: invokespecial #8 7: astore_1 8: aload_1 9: aload_0 10: invokedynamic #9, 0 15: invokevirtual #10 18: return BootStrap Method
  • 54. Bootstrapping Step 3 54 private void doStuff(); descriptor: ()V flags: ACC_PRIVATE Code: stack=2, locals=2, args_size=1 0: new #7 3: dup 4: invokespecial #8 7: astore_1 8: aload_1 9: aload_0 10: invokedynamic #9, 0 15: invokevirtual #10 18: return BootStrap Method int foo()
  • 55. Bootstrapping Step 4 55 private void doStuff(); descriptor: ()V flags: ACC_PRIVATE Code: stack=2, locals=2, args_size=1 0: new #7 3: dup 4: invokespecial #8 7: astore_1 8: aload_1 9: aload_0 10: invokedynamic #9, 0 15: invokevirtual #10 18: return BootStrap Method int foo() CS
  • 56. Bootstrapping Step 5 56 private void doStuff(); descriptor: ()V flags: ACC_PRIVATE Code: stack=2, locals=2, args_size=1 0: new #7 3: dup 4: invokespecial #8 7: astore_1 8: aload_1 9: aload_0 10: invokedynamic #9, 0 15: invokevirtual #10 18: return int foo() CS
  • 57. Bootstrap Method Only called on the first invocation of each indy bytecode Returns a CallSite 57 "Dr Martens, black, old" by Tarquin is licensed under CC BY-SA 3.0
  • 58. Indy lifecycle Initial Invocation 1. A specific indy invocation is executed for the first time 2. Bootstrap method is called and if finds (generates?!) a method to run 3. Bootstrap method returns a permanent CallSite object for this indy invocation 4. We jump to the method pointed to by the CallSite 58
  • 59. Indy Lifecycle All subsequent calls We jump to the method pointed to by the CallSite 59 Picture from National Archives and Records Administration
  • 60. This performance tragedy becomes 60 Caller Reflection Magic! Callee
  • 63. Linkage != Invocation Linkage (i.e. bootstrap) Usually only needs to be done once Is expensive 63
  • 64. Linkage != Invocation Linkage (i.e. bootstrap) Usually only needs to be done once Is expensive Invocation Done a lot Only needs a jmp/call (and possibly a guard) 64
  • 65. Linkage != Invocation Avoid the cost of linkage on almost every call 65
  • 66. • Mismatch between language and bytecode • JDK <= 8 javac uses StringBuilder.append() • StringBuilder has performance issues • JDK >= 9 uses invoke dynamic Copyright © 2019 Oracle and/or its affiliates. String Concatenation
  • 68. Takeaways Invokedynamic lets us programmatically alter linkage 68
  • 69. Takeaways Invokedynamic lets us programmatically alter linkage Then it gets out of the way! (linkage != invocation) 69
  • 70. Takeaways Invokedynamic lets us programmatically alter linkage Then it gets out of the way! (linkage != invocation) The Invoke API can often be used without indy 70
  • 71. Takeaways Invokedynamic lets us programmatically alter linkage Then it gets out of the way! (linkage != invocation) The Invoke API can often be used without indy JVM is a great platform for just about any language! 71
  • 72. Resources JVM Language Summit http://openjdk.java.net/projects/mlvm/jvmlangsummit/ Linkers & Loaders book http://linker.iecc.com/ John Rose’s Blog https://blogs.oracle.com/jrose/ 72
  • 74. The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, timing, and pricing of any features or functionality described for Oracle’s products may change and remains at the sole discretion of Oracle Corporation. Statements in this presentation relating to Oracle’s future plans, expectations, beliefs, intentions and prospects are “forward-looking statements” and are subject to material risks and uncertainties. A detailed discussion of these factors and other risks that affect our business is contained in Oracle’s Securities and Exchange Commission (SEC) filings, including our most recent reports on Form 10-K and Form 10-Q under the heading “Risk Factors.” These filings are available on the SEC’s website or on Oracle’s website at http://www.oracle.com/investor. All information in this presentation is current as of September 2019 and Oracle undertakes no duty to update any statement in light of new information or future events. Safe Harbor Copyright © 2019 Oracle and/or its affiliates.