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

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

InvokeDynamic - You Ain't Seen Nothin Yet

4,223
views

Published on

Keynote from JAX 2012

Keynote from JAX 2012

Published in: Technology

0 Comments
15 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
4,223
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
104
Comments
0
Likes
15
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • \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
  • Transcript

    • 1. invokedynamic You Ain’t Seen Nothin’ Yet
    • 2. Me
    • 3. @headius
    • 4. JRuby Guy
    • 5. JVM Guy
    • 6. I KNOW π
    • 7. What isinvokedynamic?
    • 8. Invoke?
    • 9. Invoke?That’s one use, but there are many others
    • 10. Dynamic?
    • 11. Dynamic?Dynamic typing is a common reason, but there are many others
    • 12. User-defined Data Endpoint
    • 13. User-defined Data Endpoint Hä ?!
    • 14. JVM 101
    • 15. JVM 101200 opcodes
    • 16. JVM 101 200 opcodesTen (or 16) “data endpoints”
    • 17. JVM 101 200 opcodes Ten (or 16) “data endpoints” Invocation invokevirtualinvokeinterface invokestatic invokespecial
    • 18. JVM 101 200 opcodes Ten (or 16) “data endpoints” Invocation Field Access invokevirtual getfieldinvokeinterface setfield invokestatic getstatic invokespecial setstatic
    • 19. 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
    • 20. 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
    • 21. JVMOpcodes
    • 22. JVM Opcodes Invocation Field Access Array Access invokevirtual getfield *aloadinvokeinterface setfield *astore invokestatic getstatic b,s,c,i,l,d,f,a invokespecial setstatic
    • 23. 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
    • 24. 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
    • 25. 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
    • 26. Invocation
    • 27. Invocation
    • 28. InvocationCall Site VM Operations
    • 29. Invocation Call Site VM OperationsMethod Name SignatureTarget + Args
    • 30. Invocation Call Site VM OperationsMethod Name Method Lookup Signature Type CheckingTarget + Args Branch Method Cache
    • 31. Invocation Target Object instanceofobj.foo() JVM Object’s Class void foo() static void bar()
    • 32. InvocationVM Operations Target Object instanceof obj.foo() JVM Object’s Class Call Site void foo() static void bar()
    • 33. InvocationVM Operations Target Object instanceof obj.foo() JVM Object’s Class Call Site void foo() static void bar()
    • 34. InvocationVM Operations Method Lookup Target Object instanceof obj.foo() JVM Object’s Class Call Site void foo() void foo() static void bar()
    • 35. InvocationVM Operations Method Lookup Type Checking Target Object instanceof obj.foo() JVM Object’s Class Call Site void foo() void foo() static void bar()
    • 36. 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()
    • 37. 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()
    • 38. Invocation
    • 39. Invocation Virtual InterfaceMethod Lookup Method LookupType Checking Type Checking Branch BranchMethod Cache Method Cache
    • 40. Invocation Virtual InterfaceMethod Lookup Method LookupType Checking Type Checking Branch BranchMethod Cache Method Cache StaticMethod Lookup BranchMethod Cache
    • 41. 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
    • 42. Field Access
    • 43. Field Access Call Site Field Name SignatureTarget [+ Value]
    • 44. Field Access Call Site VM Operations Field Name Get Field Offset Signature Type CheckTarget [+ Value] Access Field
    • 45. Array Access
    • 46. Array Access Call SiteTarget + Offset [+ Value]
    • 47. Array Access Call Site VM OperationsTarget + Offset [+ Value] Type Check Access Element
    • 48. Deja Vu?• Similar call site• Similar VM operations• Why can’t we compose our own?
    • 49. invokedynamic
    • 50. Call Siteinvokedynamic
    • 51. Call Site VM Operationsinvokedynamic
    • 52. bytecode + Site Call bootstrap Method Handles VM Operationsinvokedynamic
    • 53. bytecode
    • 54. bytecode• invokedynamic • like invokevirtual, invokestatic, etc• Name and signature, like the others• Additional bootstrap method • JVM defers to you
    • 55. Method Handles• Function/field/array pointers• Argument manipulation• Flow control• Optimizable by the JVM • This is very important
    • 56. invokedynamic bytecode
    • 57. invokedynamic bytecodebo ot stra p m et ho d
    • 58. invokedynamic bytecodebo ot stra p m et ho d method handles
    • 59. invokedynamic bytecode target methodbo ot stra p m et ho d method handles
    • 60. invokedynamic bytecode target methodbo ot stra p m et ho d method handles
    • 61. invokedynamic bytecode target methodbo ot stra p m et ho d method handles
    • 62. You DecideHow to reach some data endpoint
    • 63. You DecideWhat transformations to perform on arguments
    • 64. You DecideWhen and why the endpoint should change
    • 65. You DecideHow to make the JVM work for you!
    • 66. Use Cases
    • 67. Dynamic Invocation• The obvious one• Method lookup based on runtime types • Potentially mutable types• Type check specific to language
    • 68. Dynamic Invocation Target Object associated withobj.foo() JVM Method Table def foo ... def bar ...
    • 69. Dynamic InvocationVM Operations Target Object associated with obj.foo() JVM Method Table Call Site def foo ... def bar ...
    • 70. Dynamic InvocationVM Operations Target Object associated with obj.foo() JVM Method Table Call Site def foo ... def bar ...
    • 71. Dynamic InvocationVM Operations Method Lookup Target Object associated with obj.foo() JVM Method Table Call Site def foo ... def foo ... def bar ...
    • 72. Dynamic InvocationVM Operations Method Lookup Target Branch Object associated with obj.foo() JVM Method Table Call Site def foo ... def foo ... def bar ...
    • 73. 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 ...
    • 74. Lazy Constants• Call site just produces a value• Value calculated once• Subsequent access is direct, optimizable
    • 75. Lazy Constant JVM LazyLAZY_CONST Computation Call Site
    • 76. Lazy ConstantVM Operations JVM LazyLAZY_CONST Computation Call Site
    • 77. Lazy ConstantVM Operations JVM LazyLAZY_CONST Computation Call Site
    • 78. Lazy ConstantVM Operations Calculate Value JVM LazyLAZY_CONST Computation value Call Site
    • 79. Lazy ConstantVM Operations Calculate Value Bind Permanently JVM LazyLAZY_CONST value Computation Call Site
    • 80. Delegates• Arbitrary function pointers • No anon inner classes • No bridge methods• Java 8 “Lambda” will do this
    • 81. Lambda Expression SurroundingString s -> JVM ClasstoString() lambda body Call Site
    • 82. Lambda ExpressionVM Operations Surrounding String s -> JVM Class toString() lambda body Call Site
    • 83. Lambda ExpressionVM Operations Surrounding String s -> JVM Class toString() lambda body Call Site
    • 84. Lambda ExpressionVM OperationsRetrieve Lambda Obj Surrounding String s -> lambda JVM Class body toString() Call Site
    • 85. Lambda ExpressionVM OperationsRetrieve Lambda Obj Bind and Invoke Surrounding String s -> lambda JVM Class body toString() Call Site
    • 86. 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
    • 87. How Do You Benefit?
    • 88. Future• New language impls • JavaScript: Dyn.js and Nashorn • Redline Smalltalk• Improved language performance • JRuby, Groovy, Jython, Clojure, Scala • Java features too!
    • 89. JRuby/Java 6 JRuby/Java 7
    • 90. JRuby/Java 6 JRuby/Java 7 Times Faster than Ruby 1.9.3 53.75 2.51.25 0 base64 richards neural redblack
    • 91. 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
    • 92. 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
    • 93. invokedynamicis the future of Java!
    • 94. 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!