Upgrade to Pro — share decks privately, control downloads, hide ads and more …

InvokeDynamic - You Ain't Seen Nothing Yet

headius
April 20, 2012

InvokeDynamic - You Ain't Seen Nothing Yet

Keynote from JAX 2012

headius

April 20, 2012
Tweet

More Decks by headius

Other Decks in Technology

Transcript

  1. Dynamic? Dynamic typing is a common reason, but there are

    many others Saturday, April 21, 2012
  2. JVM 101 200 opcodes Invocation invokevirtual invokeinterface invokestatic invokespecial Field

    Access getfield setfield getstatic setstatic Ten (or 16) “data endpoints” Saturday, April 21, 2012
  3. JVM 101 200 opcodes Invocation invokevirtual invokeinterface invokestatic invokespecial Field

    Access getfield setfield getstatic setstatic Array Access *aload *astore b,s,c,i,l,d,f,a Ten (or 16) “data endpoints” Saturday, April 21, 2012
  4. JVM 101 200 opcodes Invocation invokevirtual invokeinterface invokestatic invokespecial Field

    Access getfield setfield getstatic setstatic Array Access *aload *astore b,s,c,i,l,d,f,a Ten (or 16) “data endpoints” All Java code revolves around these endpoints Remaining ops are stack, local vars, flow control allocation, and math/boolean/bit operations Saturday, April 21, 2012
  5. JVM Opcodes Invocation invokevirtual invokeinterface invokestatic invokespecial Field Access getfield

    setfield getstatic setstatic Array Access *aload *astore b,s,c,i,l,d,f,a Saturday, April 21, 2012
  6. JVM Opcodes Invocation invokevirtual invokeinterface invokestatic invokespecial Field Access getfield

    setfield getstatic setstatic Array Access *aload *astore b,s,c,i,l,d,f,a Stack Local Vars Flow Control Allocation Boolean and Numeric Saturday, April 21, 2012
  7. JVM Opcodes Invocation invokevirtual invokeinterface invokestatic invokespecial Field Access getfield

    setfield getstatic setstatic Array Access *aload *astore b,s,c,i,l,d,f,a Stack Local Vars Flow Control Allocation Boolean and Numeric Saturday, April 21, 2012
  8. JVM Opcodes Invocation invokevirtual invokeinterface invokestatic invokespecial Field Access getfield

    setfield getstatic setstatic Array Access *aload *astore b,s,c,i,l,d,f,a Stack Local Vars Flow Control Allocation Boolean and Numeric Saturday, April 21, 2012
  9. VM Operations Method Lookup Type Checking Branch Method Cache Invocation

    Call Site Method Name Signature Target + Args Saturday, April 21, 2012
  10. Invocation Target Object Object’s Class void foo() static void bar()

    instanceof obj.foo() JVM Saturday, April 21, 2012
  11. VM Operations Invocation Target Object Object’s Class void foo() static

    void bar() instanceof obj.foo() JVM Call Site Saturday, April 21, 2012
  12. VM Operations Invocation Target Object Object’s Class void foo() static

    void bar() instanceof obj.foo() JVM Call Site Saturday, April 21, 2012
  13. VM Operations Method Lookup Invocation Target Object Object’s Class void

    foo() static void bar() instanceof obj.foo() JVM void foo() Call Site Saturday, April 21, 2012
  14. VM Operations Method Lookup Type Checking Invocation Target Object Object’s

    Class void foo() static void bar() instanceof obj.foo() JVM void foo() Call Site Saturday, April 21, 2012
  15. VM Operations Method Lookup Type Checking Branch Invocation Target Object

    Object’s Class void foo() static void bar() instanceof obj.foo() JVM void foo() Call Site Saturday, April 21, 2012
  16. VM Operations Method Lookup Type Checking Branch Method Cache Invocation

    Target Object Object’s Class void foo() static void bar() instanceof obj.foo() JVM void foo() Call Site Saturday, April 21, 2012
  17. Virtual Method Lookup Type Checking Branch Method Cache Invocation Interface

    Method Lookup Type Checking Branch Method Cache Saturday, April 21, 2012
  18. Virtual Method Lookup Type Checking Branch Method Cache Invocation Interface

    Method Lookup Type Checking Branch Method Cache Static Method Lookup Branch Method Cache Saturday, April 21, 2012
  19. Virtual Method Lookup Type Checking Branch Method Cache Invocation Interface

    Method Lookup Type Checking Branch Method Cache Static Method Lookup Branch Method Cache Special Method Lookup Access Checking Branch Method Cache Saturday, April 21, 2012
  20. Field Access VM Operations Get Field Offset Type Check Access

    Field Call Site Field Name Signature Target [+ Value] Saturday, April 21, 2012
  21. Array Access VM Operations Type Check Access Element Call Site

    Target + Offset [+ Value] Saturday, April 21, 2012
  22. Deja Vu? • Similar call site • Similar VM operations

    • Why can’t we compose our own? Saturday, April 21, 2012
  23. bytecode • invokedynamic • like invokevirtual, invokestatic, etc • Name

    and signature, like the others • Additional bootstrap method • JVM defers to you Saturday, April 21, 2012
  24. Method Handles • Function/field/array pointers • Argument manipulation • Flow

    control • Optimizable by the JVM • This is very important Saturday, April 21, 2012
  25. Dynamic Invocation • The obvious one • Method lookup based

    on runtime types • Potentially mutable types • Type check specific to language Saturday, April 21, 2012
  26. Dynamic Invocation Target Object Method Table def foo ... def

    bar ... associated with obj.foo() JVM Saturday, April 21, 2012
  27. VM Operations Dynamic Invocation Target Object Method Table def foo

    ... def bar ... associated with obj.foo() JVM Call Site Saturday, April 21, 2012
  28. VM Operations Dynamic Invocation Target Object Method Table def foo

    ... def bar ... associated with obj.foo() JVM Call Site Saturday, April 21, 2012
  29. VM Operations Method Lookup Dynamic Invocation Target Object Method Table

    def foo ... def bar ... associated with obj.foo() JVM def foo ... Call Site Saturday, April 21, 2012
  30. VM Operations Method Lookup Branch Dynamic Invocation Target Object Method

    Table def foo ... def bar ... associated with obj.foo() JVM def foo ... Call Site Saturday, April 21, 2012
  31. VM Operations Method Lookup Branch Method Cache Dynamic Invocation Target

    Object Method Table def foo ... def bar ... associated with obj.foo() JVM def foo ... Call Site Saturday, April 21, 2012
  32. Lazy Constants • Call site just produces a value •

    Value calculated once • Subsequent access is direct, optimizable Saturday, April 21, 2012
  33. VM Operations Calculate Value Bind Permanently Lazy Constant Lazy Computation

    LAZY_CONST JVM Call Site value Saturday, April 21, 2012
  34. Delegates • Arbitrary function pointers • No anon inner classes

    • No bridge methods • Java 8 “Lambda” will do this Saturday, April 21, 2012
  35. VM Operations Lambda Expression Surrounding Class String s -> toString()

    JVM Call Site lambda body Saturday, April 21, 2012
  36. VM Operations Lambda Expression Surrounding Class String s -> toString()

    JVM Call Site lambda body Saturday, April 21, 2012
  37. VM Operations Retrieve Lambda Obj Lambda Expression Surrounding Class String

    s -> toString() JVM Call Site lambda body Saturday, April 21, 2012
  38. VM Operations Retrieve Lambda Obj Bind and Invoke Lambda Expression

    Surrounding Class String s -> toString() JVM Call Site lambda body Saturday, April 21, 2012
  39. 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 Saturday, April 21, 2012
  40. Future • New language impls • JavaScript: Dyn.js and Nashorn

    • Redline Smalltalk • Improved language performance • JRuby, Groovy, Jython, Clojure, Scala • Java features too! Saturday, April 21, 2012
  41. base64 richards neural redblack 0 1.25 2.5 3.75 5 Times

    Faster than Ruby 1.9.3 JRuby/Java 6 JRuby/Java 7 Saturday, April 21, 2012
  42. base64 richards neural redblack 0 1.25 2.5 3.75 5 1.346

    1.538 1.914 1.565 Times Faster than Ruby 1.9.3 JRuby/Java 6 JRuby/Java 7 Saturday, April 21, 2012
  43. base64 richards neural redblack 0 1.25 2.5 3.75 5 1.346

    1.538 1.914 1.565 2.658 3.44 3.66 4.32 Times Faster than Ruby 1.9.3 JRuby/Java 6 JRuby/Java 7 Saturday, April 21, 2012
  44. Thank You! • @headius • blog.headius.com • invokedynamic post coming

    soon • [email protected] • Come to my deep dive at 16:00 • Have fun with invokedynamic! Saturday, April 21, 2012