InvokeDynamic - You Ain't Seen Nothin Yet
Upcoming SlideShare
Loading in...5
×
 

InvokeDynamic - You Ain't Seen Nothin Yet

on

  • 4,751 views

Keynote from JAX 2012

Keynote from JAX 2012

Statistics

Views

Total Views
4,751
Views on SlideShare
4,736
Embed Views
15

Actions

Likes
14
Downloads
92
Comments
0

4 Embeds 15

https://twimg0-a.akamaihd.net 7
https://si0.twimg.com 6
http://us-w1.rockmelt.com 1
http://tweetedtimes.com 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Perhaps even more transcendental...\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Also loading constants, which are read-only; not as interesting\n
  • Also loading constants, which are read-only; not as interesting\n
  • Also loading constants, which are read-only; not as interesting\n
  • Also loading constants, which are read-only; not as interesting\n
  • Also loading constants, which are read-only; not as interesting\n
  • Also loading constants, which are read-only; not as interesting\n
  • Also loading constants, which are read-only; not as interesting\n
  • Also loading constants, which are read-only; not as interesting\n
  • Also loading constants, which are read-only; not as interesting\n
  • Also loading constants, which are read-only; not as interesting\n
  • Also loading constants, which are read-only; not as interesting\n
  • Also loading constants, which are read-only; not as interesting\n
  • Also loading constants, which are read-only; not as interesting\n
  • Also loading constants, which are read-only; not as interesting\n
  • Also loading constants, which are read-only; not as interesting\n
  • Also loading constants, which are read-only; not as interesting\n
  • Also loading constants, which are read-only; not as interesting\n
  • Also loading constants, which are read-only; not as interesting\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Type check for instances; statics are known\nField offset remains static\n
  • Type check for instances; statics are known\nField offset remains static\n
  • Type check for instances; statics are known\nField offset remains static\n
  • Type check for instances; statics are known\nField offset remains static\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

InvokeDynamic - You Ain't Seen Nothin Yet InvokeDynamic - You Ain't Seen Nothin Yet Presentation Transcript

  • invokedynamic You Ain’t Seen Nothin’ Yet
  • Me
  • @headius
  • JRuby Guy
  • JVM Guy
  • I KNOW π
  • What isinvokedynamic?
  • Invoke?
  • Invoke?That’s one use, but there are many others
  • Dynamic?
  • Dynamic?Dynamic typing is a common reason, but there are many others
  • User-defined Data Endpoint
  • User-defined Data Endpoint Hä ?!
  • JVM 101
  • JVM 101200 opcodes
  • JVM 101 200 opcodesTen (or 16) “data endpoints”
  • JVM 101 200 opcodes Ten (or 16) “data endpoints” Invocation invokevirtualinvokeinterface invokestatic invokespecial
  • JVM 101 200 opcodes Ten (or 16) “data endpoints” Invocation Field Access invokevirtual getfieldinvokeinterface setfield invokestatic getstatic invokespecial setstatic
  • JVM 101 200 opcodes Ten (or 16) “data endpoints” Invocation Field Access Array Access invokevirtual getfield *aloadinvokeinterface setfield *astore invokestatic getstatic b,s,c,i,l,d,f,a invokespecial setstatic
  • JVM 101 200 opcodes Ten (or 16) “data endpoints” Invocation Field Access Array Access invokevirtual getfield *aloadinvokeinterface setfield *astore invokestatic getstatic b,s,c,i,l,d,f,a invokespecial setstatic All Java code revolves around these endpoints Remaining ops are stack, local vars, flow control allocation, and math/boolean/bit operations
  • JVMOpcodes
  • JVM Opcodes Invocation Field Access Array Access invokevirtual getfield *aloadinvokeinterface setfield *astore invokestatic getstatic b,s,c,i,l,d,f,a invokespecial setstatic
  • JVM Opcodes Invocation Field Access Array Access invokevirtual getfield *aloadinvokeinterface setfield *astore invokestatic getstatic b,s,c,i,l,d,f,a invokespecial setstatic Stack Local Vars Flow Control Allocation Boolean and Numeric
  • JVM Opcodes Invocation Field Access Array Access invokevirtual getfield *aloadinvokeinterface setfield *astore invokestatic getstatic b,s,c,i,l,d,f,a invokespecial setstatic Stack Local Vars Flow Control Allocation Boolean and Numeric
  • JVM Opcodes Invocation Field Access Array Access invokevirtual getfield *aloadinvokeinterface setfield *astore invokestatic getstatic b,s,c,i,l,d,f,a invokespecial setstatic Stack Local Vars Flow Control Allocation Boolean and Numeric
  • Invocation
  • Invocation
  • InvocationCall Site VM Operations
  • Invocation Call Site VM OperationsMethod Name SignatureTarget + Args
  • Invocation Call Site VM OperationsMethod Name Method Lookup Signature Type CheckingTarget + Args Branch Method Cache
  • Invocation Target Object instanceofobj.foo() JVM Object’s Class void foo() static void bar()
  • InvocationVM Operations Target Object instanceof obj.foo() JVM Object’s Class Call Site void foo() static void bar()
  • InvocationVM Operations Target Object instanceof obj.foo() JVM Object’s Class Call Site void foo() static void bar()
  • InvocationVM Operations Method Lookup Target Object instanceof obj.foo() JVM Object’s Class Call Site void foo() void foo() static void bar()
  • InvocationVM Operations Method Lookup Type Checking Target Object instanceof obj.foo() JVM Object’s Class Call Site void foo() void foo() static void bar()
  • InvocationVM Operations Method Lookup Type Checking Target Branch Object instanceof obj.foo() JVM Object’s Class Call Site void foo() void foo() static void bar()
  • InvocationVM Operations Method Lookup Type Checking Target Branch Object Method Cache instanceof obj.foo() JVM Object’s Class void foo() Call Site void foo() static void bar()
  • Invocation
  • Invocation Virtual InterfaceMethod Lookup Method LookupType Checking Type Checking Branch BranchMethod Cache Method Cache
  • Invocation Virtual InterfaceMethod Lookup Method LookupType Checking Type Checking Branch BranchMethod Cache Method Cache StaticMethod Lookup BranchMethod Cache
  • Invocation Virtual InterfaceMethod Lookup Method LookupType Checking Type Checking Branch BranchMethod Cache Method Cache Static Special Method LookupMethod Lookup Access Checking Branch BranchMethod Cache Method Cache
  • Field Access
  • Field Access Call Site Field Name SignatureTarget [+ Value]
  • Field Access Call Site VM Operations Field Name Get Field Offset Signature Type CheckTarget [+ Value] Access Field
  • Array Access
  • Array Access Call SiteTarget + Offset [+ Value]
  • Array Access Call Site VM OperationsTarget + Offset [+ Value] Type Check Access Element
  • Deja Vu?• Similar call site• Similar VM operations• Why can’t we compose our own?
  • invokedynamic
  • Call Siteinvokedynamic
  • Call Site VM Operationsinvokedynamic
  • bytecode + Site Call bootstrap Method Handles VM Operationsinvokedynamic
  • bytecode
  • bytecode• invokedynamic • like invokevirtual, invokestatic, etc• Name and signature, like the others• Additional bootstrap method • JVM defers to you
  • Method Handles• Function/field/array pointers• Argument manipulation• Flow control• Optimizable by the JVM • This is very important
  • invokedynamic bytecode
  • invokedynamic bytecodebo ot stra p m et ho d
  • invokedynamic bytecodebo ot stra p m et ho d method handles
  • invokedynamic bytecode target methodbo ot stra p m et ho d method handles
  • invokedynamic bytecode target methodbo ot stra p m et ho d method handles
  • invokedynamic bytecode target methodbo ot stra p m et ho d method handles
  • You DecideHow to reach some data endpoint
  • You DecideWhat transformations to perform on arguments
  • You DecideWhen and why the endpoint should change
  • You DecideHow to make the JVM work for you!
  • Use Cases
  • Dynamic Invocation• The obvious one• Method lookup based on runtime types • Potentially mutable types• Type check specific to language
  • Dynamic Invocation Target Object associated withobj.foo() JVM Method Table def foo ... def bar ...
  • Dynamic InvocationVM Operations Target Object associated with obj.foo() JVM Method Table Call Site def foo ... def bar ...
  • Dynamic InvocationVM Operations Target Object associated with obj.foo() JVM Method Table Call Site def foo ... def bar ...
  • Dynamic InvocationVM Operations Method Lookup Target Object associated with obj.foo() JVM Method Table Call Site def foo ... def foo ... def bar ...
  • Dynamic InvocationVM Operations Method Lookup Target Branch Object associated with obj.foo() JVM Method Table Call Site def foo ... def foo ... def bar ...
  • Dynamic InvocationVM Operations Method Lookup Target Branch Method Cache Object associated with obj.foo() JVM def foo ... Method Table Call Site def foo ... def bar ...
  • Lazy Constants• Call site just produces a value• Value calculated once• Subsequent access is direct, optimizable
  • Lazy Constant JVM LazyLAZY_CONST Computation Call Site
  • Lazy ConstantVM Operations JVM LazyLAZY_CONST Computation Call Site
  • Lazy ConstantVM Operations JVM LazyLAZY_CONST Computation Call Site
  • Lazy ConstantVM Operations Calculate Value JVM LazyLAZY_CONST Computation value Call Site
  • Lazy ConstantVM Operations Calculate Value Bind Permanently JVM LazyLAZY_CONST value Computation Call Site
  • Delegates• Arbitrary function pointers • No anon inner classes • No bridge methods• Java 8 “Lambda” will do this
  • Lambda Expression SurroundingString s -> JVM ClasstoString() lambda body Call Site
  • Lambda ExpressionVM Operations Surrounding String s -> JVM Class toString() lambda body Call Site
  • Lambda ExpressionVM Operations Surrounding String s -> JVM Class toString() lambda body Call Site
  • Lambda ExpressionVM OperationsRetrieve Lambda Obj Surrounding String s -> lambda JVM Class body toString() Call Site
  • Lambda ExpressionVM OperationsRetrieve Lambda Obj Bind and Invoke Surrounding String s -> lambda JVM Class body toString() Call Site
  • Multi-dispatch• Dispatch based on runtime types • Java is single-dispatch• Call site looks like normal invoke• VM side examines target, args• Multiple targets cached with branches
  • How Do You Benefit?
  • Future• New language impls • JavaScript: Dyn.js and Nashorn • Redline Smalltalk• Improved language performance • JRuby, Groovy, Jython, Clojure, Scala • Java features too!
  • JRuby/Java 6 JRuby/Java 7
  • JRuby/Java 6 JRuby/Java 7 Times Faster than Ruby 1.9.3 53.75 2.51.25 0 base64 richards neural redblack
  • JRuby/Java 6 JRuby/Java 7 Times Faster than Ruby 1.9.3 53.75 2.5 1.914 1.538 1.5651.25 1.346 0 base64 richards neural redblack
  • JRuby/Java 6 JRuby/Java 7 Times Faster than Ruby 1.9.3 5 4.323.75 3.66 3.44 2.5 2.658 1.914 1.538 1.5651.25 1.346 0 base64 richards neural redblack
  • invokedynamicis the future of Java!
  • Thank You!• @headius• blog.headius.com • invokedynamic post coming soon• headius@headius.com• Come to my deep dive at 16:00• Have fun with invokedynamic!