SlideShare a Scribd company logo
InvokeDynamic
Java 7 dynamically typed language support




                              arkadi.shishlov@gmail.com
Invoke Dynamic
Statically typed languages
 Java
 Scala
 C#
 C
 C++
 F#
 Haskel
Dynamic languages
Groovy
Clojure
JavaScript
Perl
Python
Ruby
PHP
Dynamic language

object runtime alteration (open program code)
metaobject protocol
eval
functional programming, closures, macros
Dynamically typed language

type checking performed at runtime
variable does not have a type
value is associated with a type
duck typing
The program must be compiled
to bytecode to achieve Java
level performance
Use case
groovy:000> f = { it + it }
===> groovysh_evaluate$_run_closure1@dc737be
groovy:000> f(1)
===> 2
groovy:000> f("qw")
===> qwqw
groovy:000> [2, "qwe"].collect(f)
===> [4, qweqwe]
groovy:000>
collect (list, func) {
  foreach (list)
      push (result, func (it))
}
The problem
invokevirtual
  some/class/Name.func(Ljava/lang/String)Z,
  objectref,
  arg1, arg2, ...


invokespecial
invokestatic        has similar calling convention
invokeinterface
The solution


 Reflection is (relatively) slow
 There are others possibilities
Java 7 approach - JSR292
invokedynamic (indy)
  boostrapFuncRef,
  NameLiteral(Lorg/jruby/runtime/builtin/IRubyObject)
    Lorg/jruby/runtime/builtin/IRubyObject,
  arg1, arg2, ...
java.lang.invoke.*
 MethodHandle
 CallSite
   ConstantCallSite
   MutableCallSite
   VolatileCallSite
 MethodType
public static CallSite bootstrap (
  MethodHandles.Lookup lookup,
  String                    dynMethodName,
  MethodType                dynMethodType) throws Throwable {

    MethodHandle handle = lookup.findStatic(
           SomeClosure.class,
           "func",
           MethodType.methodType(
              Integer.class, Object.class, Object.class));
    if (!dynMethodType.equals(handle.type()))
         handle = handle.asType(dynMethodType);

    return new ConstantCallSite(handle);
}
MutableCallSite.setTarget(MethodHandle newTarget)
Advantages

fast
JIT-ted
inlined
signature polymorphism, arguments adaptation
Invoke Dynamic
Invoke Dynamic
Work in Progress
JRuby - works, sort of; Mirah
Rhino (JavaScript) - J.Rose experiment, V8 for
performance freaks
Groovy - proposed for 1.9, no impl
Jython (Python) - different priorities: PyPy, Cython,
language features upgrade
Clojure - many features not applicable to Indy
PHP.reboot
Learn more

http://download.java.net/jdk7/docs/technotes/guides/vm/multiple-language-support.html

JDK 7 JSR-292 java.lang.invoke.* API

JRuby source: src/org/jruby/compiler/impl/*.java

http://code.google.com/p/jsr292-cookbook/

http://mail.openjdk.java.net/pipermail/mlvm-dev/

http://www.oracle.com/technetwork/issue-archive/2010/10-may/o30java-099612.html

http://blog.headius.com/2008/09/first-taste-of-invokedynamic.html

More Related Content

PDF
PHPUnit your bug exterminator
PDF
Basic c++ 11/14 for python programmers
ZIP
Lisp Macros in 20 Minutes (Featuring Clojure)
PDF
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...
ODP
Groovy AST Transformations
PDF
JavaScript LevelUp by Lee Brandt
PDF
Grant Rogerson SDEC2015
PDF
Justjava 2007 Arquitetura Java EE Paulo Silveira, Phillip Calçado
PHPUnit your bug exterminator
Basic c++ 11/14 for python programmers
Lisp Macros in 20 Minutes (Featuring Clojure)
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...
Groovy AST Transformations
JavaScript LevelUp by Lee Brandt
Grant Rogerson SDEC2015
Justjava 2007 Arquitetura Java EE Paulo Silveira, Phillip Calçado

What's hot (20)

PDF
Про асинхронность / Максим Щепелин / Web Developer Wargaming
PDF
ConFess Vienna 2015 - Metaprogramming with Groovy
PDF
Kotlin workshop 2018-06-11
ODP
Ast transformation
ODP
AST Transformations at JFokus
PDF
Introduction to Groovy runtime metaprogramming and AST transforms
ODP
Groovy and Grails intro
PDF
Ruxmon.2013-08.-.CodeBro!
PDF
AST Transformations: Groovy’s best kept secret by Andres Almiray
PDF
Go 1.10 Release Party - PDX Go
PDF
Java objects on steroids
PPTX
LISP: назад в будущее, Микола Мозговий
PDF
Android and cpp
ODP
Groovy Ast Transformations (greach)
PDF
cdac@parag.gajbhiye@groovy metaprogrammning
PDF
ooc - OSDC 2010 - Amos Wenger
PPTX
Go. Why it goes
PPTX
Metaprogramming Techniques In Groovy And Grails
PPT
Java 7
PDF
ClojureScript interfaces to React
Про асинхронность / Максим Щепелин / Web Developer Wargaming
ConFess Vienna 2015 - Metaprogramming with Groovy
Kotlin workshop 2018-06-11
Ast transformation
AST Transformations at JFokus
Introduction to Groovy runtime metaprogramming and AST transforms
Groovy and Grails intro
Ruxmon.2013-08.-.CodeBro!
AST Transformations: Groovy’s best kept secret by Andres Almiray
Go 1.10 Release Party - PDX Go
Java objects on steroids
LISP: назад в будущее, Микола Мозговий
Android and cpp
Groovy Ast Transformations (greach)
cdac@parag.gajbhiye@groovy metaprogrammning
ooc - OSDC 2010 - Amos Wenger
Go. Why it goes
Metaprogramming Techniques In Groovy And Grails
Java 7
ClojureScript interfaces to React
Ad

Viewers also liked (8)

PDF
PDF
National Technical Honor Society Summer Conference 2011
PDF
Oklahoma 4H Roundup 2011
PPTX
PDF
Surface finishing
PPTX
Can You See Me Now?
PPTX
Building an Active Online Member Community
PPTX
A Practical Approach to Content Marketing for your Association
National Technical Honor Society Summer Conference 2011
Oklahoma 4H Roundup 2011
Surface finishing
Can You See Me Now?
Building an Active Online Member Community
A Practical Approach to Content Marketing for your Association
Ad

Similar to Invoke Dynamic (20)

PDF
Invokedynamic / JSR-292
PDF
JRuby and Invokedynamic - Japan JUG 2015
PDF
Optimizing JavaScript and Dynamic Languages on the JVM
PDF
invokedynamic: Evolution of a Language Feature
KEY
Java 7: Fork/Join, Invokedynamic and the future
PDF
Invoke dynamic your api to hotspot
PDF
invokedynamic for Mere Mortals [Code One 2019]
PDF
InvokeDynamic for Mere Mortals [JavaOne 2015 CON7682]
PDF
J9's MethodHandle Compilation Pipeline #JFokus2015
PPTX
GOTO Night with Charles Nutter Slides
PDF
Pimp My Java LavaJUG
PPT
Invoke dynamics
PDF
Invokedynamic in 45 Minutes
PPTX
Java 10, Java 11 and beyond
PDF
Invokedynamic: Tales from the Trenches
PPTX
Making Java more dynamic: runtime code generation for the JVM
PPT
Slides
KEY
High Performance Ruby - Golden Gate RubyConf 2012
PDF
Ola Bini Evolving The Java Platform
PDF
wtf is in Java/JDK/wtf7?
Invokedynamic / JSR-292
JRuby and Invokedynamic - Japan JUG 2015
Optimizing JavaScript and Dynamic Languages on the JVM
invokedynamic: Evolution of a Language Feature
Java 7: Fork/Join, Invokedynamic and the future
Invoke dynamic your api to hotspot
invokedynamic for Mere Mortals [Code One 2019]
InvokeDynamic for Mere Mortals [JavaOne 2015 CON7682]
J9's MethodHandle Compilation Pipeline #JFokus2015
GOTO Night with Charles Nutter Slides
Pimp My Java LavaJUG
Invoke dynamics
Invokedynamic in 45 Minutes
Java 10, Java 11 and beyond
Invokedynamic: Tales from the Trenches
Making Java more dynamic: runtime code generation for the JVM
Slides
High Performance Ruby - Golden Gate RubyConf 2012
Ola Bini Evolving The Java Platform
wtf is in Java/JDK/wtf7?

More from Dmitry Buzdin (20)

PDF
How Payment Cards Really Work?
PDF
Как построить свой фреймворк для автотестов?
PDF
How to grow your own Microservice?
PDF
How to Build Your Own Test Automation Framework?
PDF
Delivery Pipeline for Windows Machines
PPTX
Big Data Processing Using Hadoop Infrastructure
PDF
JOOQ and Flyway
PDF
Developing Useful APIs
PPTX
Whats New in Java 8
PPTX
Архитектура Ленты на Одноклассниках
PDF
Dart Workshop
PDF
Riding Redis @ask.fm
PDF
Rubylight JUG Contest Results Part II
PDF
Rubylight Pattern-Matching Solutions
PDF
Refactoring to Macros with Clojure
PPTX
Poor Man's Functional Programming
PDF
Rubylight programming contest
PPTX
Continuous Delivery
PPTX
Introduction to DevOps
PDF
Thread Dump Analysis
How Payment Cards Really Work?
Как построить свой фреймворк для автотестов?
How to grow your own Microservice?
How to Build Your Own Test Automation Framework?
Delivery Pipeline for Windows Machines
Big Data Processing Using Hadoop Infrastructure
JOOQ and Flyway
Developing Useful APIs
Whats New in Java 8
Архитектура Ленты на Одноклассниках
Dart Workshop
Riding Redis @ask.fm
Rubylight JUG Contest Results Part II
Rubylight Pattern-Matching Solutions
Refactoring to Macros with Clojure
Poor Man's Functional Programming
Rubylight programming contest
Continuous Delivery
Introduction to DevOps
Thread Dump Analysis

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Cloud computing and distributed systems.
PDF
cuic standard and advanced reporting.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
KodekX | Application Modernization Development
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Spectroscopy.pptx food analysis technology
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Dropbox Q2 2025 Financial Results & Investor Presentation
Building Integrated photovoltaic BIPV_UPV.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
MYSQL Presentation for SQL database connectivity
Advanced methodologies resolving dimensionality complications for autism neur...
Big Data Technologies - Introduction.pptx
Cloud computing and distributed systems.
cuic standard and advanced reporting.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
KodekX | Application Modernization Development
Unlocking AI with Model Context Protocol (MCP)
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Spectroscopy.pptx food analysis technology
Agricultural_Statistics_at_a_Glance_2022_0.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Machine learning based COVID-19 study performance prediction
How UI/UX Design Impacts User Retention in Mobile Apps.pdf

Invoke Dynamic