tuesday, july 19, 2011wiki.jvmlangsummit.com/images/8/88/rose-2011-futuredirections.pdf|2011 oracle...

219
| © 2011 Oracle Corporation – Proprietary and Confidential Tuesday, July 19, 2011

Upload: others

Post on 29-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation – Proprietary and Confidential

Tuesday, July 19, 2011

Page 2: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation – Proprietary and Confidential

John R. Rose, Da Vinci Machine Project, JSR 292 Lead

Tuesday, July 19, 2011

Page 3: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation – Proprietary and Confidential

Method Handles and Beyond...Some basis vectorsJohn R. Rose, Da Vinci Machine Project, JSR 292 Lead

Tuesday, July 19, 2011

Page 4: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Victory in JDK 7!

Tuesday, July 19, 2011

Page 5: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Victory in JDK 7! JSR 292 is finished.

Tuesday, July 19, 2011

Page 6: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Victory in JDK 7! JSR 292 is finished.

(Or is it?)

Tuesday, July 19, 2011

Page 7: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Victory in JDK 7! JSR 292 is finished.

(Or is it?)

Tuesday, July 19, 2011

Page 8: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

Back to the future!...a perspective from the original JVM Specification

| © 2011 Oracle Corporation

Tuesday, July 19, 2011

Page 9: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

Back to the future!...a perspective from the original JVM Specification

| © 2011 Oracle Corporation

The Java Virtual Machine knows nothing about the Java programming language, only of a particular binary format, the class file format.A class file contains Java Virtual Machine instructions (or bytecodes) and a symbol table, as well as other ancillary information.Any language with functionality that can be expressed in terms of a valid class file can be hosted by the Java virtual machine.Attracted by a generally available, machine-independent platform, implementors of other languages are turning to the Java Virtual Machine as a delivery vehicle for their languages.In the future, we will consider bounded extensions to the Java Virtual Machine to provide better support for other languages.

Tuesday, July 19, 2011

Page 10: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Overview...

• What we did in JDK 7• How it works in Hotspot• Advice to users• Next steps in JSR 292• Building the future

Tuesday, July 19, 2011

Page 11: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Overview...

• What we did in JDK 7• How it works in Hotspot• Advice to users• Next steps in JSR 292• Building the future

Tuesday, July 19, 2011

Page 12: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

In summary, invokedynamic...• is a natural general purpose primitive• Not tied to semantics of a specific programming language• Flexible building block for a variety of method invocation

semantics• enables relatively simple and efficient method dispatch

Tuesday, July 19, 2011

Page 13: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

In summary, invokedynamic...• is a natural general purpose primitive• Not tied to semantics of a specific programming language• Flexible building block for a variety of method invocation

semantics• enables relatively simple and efficient method dispatch

Gilad BrachaSun Microsystems, JAOO 2005http://blogs.sun.com/roller/resources/gbracha/JAOO2005.pdf

Tuesday, July 19, 2011

Page 14: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

In summary, invokedynamic...• is a natural general purpose primitive• Not tied to semantics of a specific programming language• Flexible building block for a variety of method invocation

semantics• enables relatively simple and efficient method dispatch

Gilad BrachaSun Microsystems, JAOO 2005http://blogs.sun.com/roller/resources/gbracha/JAOO2005.pdf

Tuesday, July 19, 2011

Page 15: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

JSR 292 Timeline

Tuesday, July 19, 2011

Page 16: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

JSR 292 Timeline

• 2005: Initial design sketch

Tuesday, July 19, 2011

Page 17: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

JSR 292 Timeline

• 2005: Initial design sketch• 2006: JSR 292 Expert Group formed

Tuesday, July 19, 2011

Page 18: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

JSR 292 Timeline

• 2005: Initial design sketch• 2006: JSR 292 Expert Group formed• 2007: EG reboot

Tuesday, July 19, 2011

Page 19: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

JSR 292 Timeline

• 2005: Initial design sketch• 2006: JSR 292 Expert Group formed• 2007: EG reboot• 2008: API with Method Handles (Early Draft Review)

Tuesday, July 19, 2011

Page 20: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

JSR 292 Timeline

• 2005: Initial design sketch• 2006: JSR 292 Expert Group formed• 2007: EG reboot• 2008: API with Method Handles (Early Draft Review)• 2009: API refinement (e.g., CONSTANT_MethodHandle)

Tuesday, July 19, 2011

Page 21: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

JSR 292 Timeline

• 2005: Initial design sketch• 2006: JSR 292 Expert Group formed• 2007: EG reboot• 2008: API with Method Handles (Early Draft Review)• 2009: API refinement (e.g., CONSTANT_MethodHandle)• 2010: API refinement (e.g., BootstrapMethods)

Tuesday, July 19, 2011

Page 22: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

JSR 292 Timeline

• 2005: Initial design sketch• 2006: JSR 292 Expert Group formed• 2007: EG reboot• 2008: API with Method Handles (Early Draft Review)• 2009: API refinement (e.g., CONSTANT_MethodHandle)• 2010: API refinement (e.g., BootstrapMethods)• 2011: Final balloting.

Tuesday, July 19, 2011

Page 23: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Key Features

Tuesday, July 19, 2011

Page 24: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Key Features

• New bytecode instruction: invokedynamic.

Tuesday, July 19, 2011

Page 25: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Key Features

• New bytecode instruction: invokedynamic.– Linked reflectively, under user control.

Tuesday, July 19, 2011

Page 26: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Key Features

• New bytecode instruction: invokedynamic.– Linked reflectively, under user control.– User-visible object: java.lang.invoke.CallSite

Tuesday, July 19, 2011

Page 27: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Key Features

• New bytecode instruction: invokedynamic.– Linked reflectively, under user control.– User-visible object: java.lang.invoke.CallSite– Dynamic call sites can be linked and relinked, dynamically.

Tuesday, July 19, 2011

Page 28: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Key Features

• New bytecode instruction: invokedynamic.– Linked reflectively, under user control.– User-visible object: java.lang.invoke.CallSite– Dynamic call sites can be linked and relinked, dynamically.

• New unit of behavior: method handle

Tuesday, July 19, 2011

Page 29: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Key Features

• New bytecode instruction: invokedynamic.– Linked reflectively, under user control.– User-visible object: java.lang.invoke.CallSite– Dynamic call sites can be linked and relinked, dynamically.

• New unit of behavior: method handle – The content of a dynamic call site is a method handle.

Tuesday, July 19, 2011

Page 30: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Key Features

• New bytecode instruction: invokedynamic.– Linked reflectively, under user control.– User-visible object: java.lang.invoke.CallSite– Dynamic call sites can be linked and relinked, dynamically.

• New unit of behavior: method handle – The content of a dynamic call site is a method handle.– Method handles are function pointers for the JVM.

Tuesday, July 19, 2011

Page 31: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Key Features

• New bytecode instruction: invokedynamic.– Linked reflectively, under user control.– User-visible object: java.lang.invoke.CallSite– Dynamic call sites can be linked and relinked, dynamically.

• New unit of behavior: method handle – The content of a dynamic call site is a method handle.– Method handles are function pointers for the JVM.

– (Or if you like, each MH implements a single-method interface.)

Tuesday, July 19, 2011

Page 32: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Dynamic program composition

Tuesday, July 19, 2011

Page 33: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Dynamic program composition

• Bytecodes are created by Java compilers or dynamic runtimes. Bytecodes

Tuesday, July 19, 2011

Page 34: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Dynamic program composition

• Bytecodes are created by Java compilers or dynamic runtimes. Bytecodes

• A dynamic call site is created for each invokedynamic bytecode. Dynamic call

sites

Tuesday, July 19, 2011

Page 35: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

• Each call site is bound to one or more method handles, which point back to bytecoded methods.

Method handles

Dynamic program composition

• Bytecodes are created by Java compilers or dynamic runtimes. Bytecodes

• A dynamic call site is created for each invokedynamic bytecode. Dynamic call

sites

Tuesday, July 19, 2011

Page 36: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

• Each call site is bound to one or more method handles, which point back to bytecoded methods.

Method handles

Dynamic program composition

• Bytecodes are created by Java compilers or dynamic runtimes. Bytecodes

• A dynamic call site is created for each invokedynamic bytecode. Dynamic call

sites

JVMJIT• The JVM seamlessly

integrates execution, optimizing to native code as necessary.

Tuesday, July 19, 2011

Page 37: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

What’s in a method call? (before invokedynamic)Source code

Bytecode Linking Executing

Naming

Selecting

Adapting

Calling

Identifiers Utf8 constants

JVM “dictionary”

Scopes Class names

Loaded classes

V-table lookup

Argument conversion

C2I / I2C adapters

Receiver narrowing

Jump with arguments

Tuesday, July 19, 2011

Page 38: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

What’s in a method call? (using invokedynamic)Source code

Bytecode Linking Executing

Naming

Selecting

Adapting

Calling

∞ ∞ ∞ ∞

∞ Bootstrap methods

Bootstrap method call ∞

∞ Method handles ∞

Jump with arguments

Tuesday, July 19, 2011

Page 39: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Coding directly with method handles

Tuesday, July 19, 2011

Page 40: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Coding directly with method handles

import static java.lang.invoke.MethodHandles.*;

Tuesday, July 19, 2011

Page 41: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Coding directly with method handles

import static java.lang.invoke.MethodHandles.*;import static java.lang.invoke.MethodType.*;

Tuesday, July 19, 2011

Page 42: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Coding directly with method handles

import static java.lang.invoke.MethodHandles.*;import static java.lang.invoke.MethodType.*;...

Tuesday, July 19, 2011

Page 43: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Coding directly with method handles

import static java.lang.invoke.MethodHandles.*;import static java.lang.invoke.MethodType.*;...MethodHandles.Lookup LOOKUP = lookup();

Tuesday, July 19, 2011

Page 44: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Coding directly with method handles

import static java.lang.invoke.MethodHandles.*;import static java.lang.invoke.MethodType.*;...MethodHandles.Lookup LOOKUP = lookup();

MethodHandle HASHCODE = LOOKUP

Tuesday, July 19, 2011

Page 45: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Coding directly with method handles

import static java.lang.invoke.MethodHandles.*;import static java.lang.invoke.MethodType.*;...MethodHandles.Lookup LOOKUP = lookup();

MethodHandle HASHCODE = LOOKUP .findStatic(System.class,

Tuesday, July 19, 2011

Page 46: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Coding directly with method handles

import static java.lang.invoke.MethodHandles.*;import static java.lang.invoke.MethodType.*;...MethodHandles.Lookup LOOKUP = lookup();

MethodHandle HASHCODE = LOOKUP .findStatic(System.class, "identityHashCode", methodType(int.class, Object.class));

Tuesday, July 19, 2011

Page 47: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Coding directly with method handles

import static java.lang.invoke.MethodHandles.*;import static java.lang.invoke.MethodType.*;...MethodHandles.Lookup LOOKUP = lookup();

MethodHandle HASHCODE = LOOKUP .findStatic(System.class, "identityHashCode", methodType(int.class, Object.class));{assertEquals(System.identityHashCode("xy"),

Tuesday, July 19, 2011

Page 48: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Coding directly with method handles

import static java.lang.invoke.MethodHandles.*;import static java.lang.invoke.MethodType.*;...MethodHandles.Lookup LOOKUP = lookup();

MethodHandle HASHCODE = LOOKUP .findStatic(System.class, "identityHashCode", methodType(int.class, Object.class));{assertEquals(System.identityHashCode("xy"), (int) HASHCODE.invoke("xy"));}

Tuesday, July 19, 2011

Page 49: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Coding directly with method handles

import static java.lang.invoke.MethodHandles.*;import static java.lang.invoke.MethodType.*;...MethodHandles.Lookup LOOKUP = lookup();

MethodHandle HASHCODE = LOOKUP .findStatic(System.class, "identityHashCode", methodType(int.class, Object.class));{assertEquals(System.identityHashCode("xy"), (int) HASHCODE.invoke("xy"));}

MethodHandle CONCAT = LOOKUP

Tuesday, July 19, 2011

Page 50: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Coding directly with method handles

import static java.lang.invoke.MethodHandles.*;import static java.lang.invoke.MethodType.*;...MethodHandles.Lookup LOOKUP = lookup();

MethodHandle HASHCODE = LOOKUP .findStatic(System.class, "identityHashCode", methodType(int.class, Object.class));{assertEquals(System.identityHashCode("xy"), (int) HASHCODE.invoke("xy"));}

MethodHandle CONCAT = LOOKUP .findVirtual(String.class,

Tuesday, July 19, 2011

Page 51: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Coding directly with method handles

import static java.lang.invoke.MethodHandles.*;import static java.lang.invoke.MethodType.*;...MethodHandles.Lookup LOOKUP = lookup();

MethodHandle HASHCODE = LOOKUP .findStatic(System.class, "identityHashCode", methodType(int.class, Object.class));{assertEquals(System.identityHashCode("xy"), (int) HASHCODE.invoke("xy"));}

MethodHandle CONCAT = LOOKUP .findVirtual(String.class, "concat", methodType(String.class, String.class));

Tuesday, July 19, 2011

Page 52: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Coding directly with method handles

import static java.lang.invoke.MethodHandles.*;import static java.lang.invoke.MethodType.*;...MethodHandles.Lookup LOOKUP = lookup();

MethodHandle HASHCODE = LOOKUP .findStatic(System.class, "identityHashCode", methodType(int.class, Object.class));{assertEquals(System.identityHashCode("xy"), (int) HASHCODE.invoke("xy"));}

MethodHandle CONCAT = LOOKUP .findVirtual(String.class, "concat", methodType(String.class, String.class));{assertEquals("xy", (String) CONCAT.invokeExact("x", "y"));}

Tuesday, July 19, 2011

Page 53: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Coding directly with method handles

import static java.lang.invoke.MethodHandles.*;import static java.lang.invoke.MethodType.*;...MethodHandles.Lookup LOOKUP = lookup();

MethodHandle HASHCODE = LOOKUP .findStatic(System.class, "identityHashCode", methodType(int.class, Object.class));{assertEquals(System.identityHashCode("xy"), (int) HASHCODE.invoke("xy"));}

MethodHandle CONCAT = LOOKUP .findVirtual(String.class, "concat", methodType(String.class, String.class));{assertEquals("xy", (String) CONCAT.invokeExact("x", "y"));}

MethodHandle CONCAT_FU = CONCAT.bindTo("fu");

Tuesday, July 19, 2011

Page 54: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Coding directly with method handles

import static java.lang.invoke.MethodHandles.*;import static java.lang.invoke.MethodType.*;...MethodHandles.Lookup LOOKUP = lookup();

MethodHandle HASHCODE = LOOKUP .findStatic(System.class, "identityHashCode", methodType(int.class, Object.class));{assertEquals(System.identityHashCode("xy"), (int) HASHCODE.invoke("xy"));}

MethodHandle CONCAT = LOOKUP .findVirtual(String.class, "concat", methodType(String.class, String.class));{assertEquals("xy", (String) CONCAT.invokeExact("x", "y"));}

MethodHandle CONCAT_FU = CONCAT.bindTo("fu");{assertEquals("futbol", CONCAT_FU.invoke("tbol"));}

Tuesday, July 19, 2011

Page 57: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Pseudo-coding with invokedynamic http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/ tip/test/java/lang/invoke/InvokeDynamicPrintArgs.java

invokedynamic baz(Ljava/lang/String;ID)V [#bsm2, 1234.5]

static CallSite bsm2( Lookup caller, String name, MethodType type, Object... arg) {

Tuesday, July 19, 2011

Page 58: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Pseudo-coding with invokedynamic http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/ tip/test/java/lang/invoke/InvokeDynamicPrintArgs.java

invokedynamic baz(Ljava/lang/String;ID)V [#bsm2, 1234.5]

static CallSite bsm2( Lookup caller, String name, MethodType type, Object... arg) { // ignore caller and name, but match the type: return new PrintingCallSite(caller, name, type, arg);}

Tuesday, July 19, 2011

Page 59: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Pseudo-coding with invokedynamic http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/ tip/test/java/lang/invoke/InvokeDynamicPrintArgs.java

invokedynamic baz(Ljava/lang/String;ID)V [#bsm2, 1234.5]

static CallSite bsm2( Lookup caller, String name, MethodType type, Object... arg) { // ignore caller and name, but match the type: return new PrintingCallSite(caller, name, type, arg);}

INDY_baz.CALL_SITE.invokeExact("baz arg", 2, 3.14);

Tuesday, July 19, 2011

Page 60: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Pseudo-coding with invokedynamic http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/ tip/test/java/lang/invoke/InvokeDynamicPrintArgs.java

invokedynamic baz(Ljava/lang/String;ID)V [#bsm2, 1234.5]

static CallSite bsm2( Lookup caller, String name, MethodType type, Object... arg) { // ignore caller and name, but match the type: return new PrintingCallSite(caller, name, type, arg);}

INDY_baz.CALL_SITE.invokeExact("baz arg", 2, 3.14);static private class INDY_baz { static final MethodHandle CALL_SITE; static {

Tuesday, July 19, 2011

Page 61: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Pseudo-coding with invokedynamic http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/ tip/test/java/lang/invoke/InvokeDynamicPrintArgs.java

invokedynamic baz(Ljava/lang/String;ID)V [#bsm2, 1234.5]

static CallSite bsm2( Lookup caller, String name, MethodType type, Object... arg) { // ignore caller and name, but match the type: return new PrintingCallSite(caller, name, type, arg);}

INDY_baz.CALL_SITE.invokeExact("baz arg", 2, 3.14);static private class INDY_baz { static final MethodHandle CALL_SITE; static { MethodType mt = methodType(void.class, String.class, int.class, double.class);

Tuesday, July 19, 2011

Page 62: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Pseudo-coding with invokedynamic http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/ tip/test/java/lang/invoke/InvokeDynamicPrintArgs.java

invokedynamic baz(Ljava/lang/String;ID)V [#bsm2, 1234.5]

static CallSite bsm2( Lookup caller, String name, MethodType type, Object... arg) { // ignore caller and name, but match the type: return new PrintingCallSite(caller, name, type, arg);}

INDY_baz.CALL_SITE.invokeExact("baz arg", 2, 3.14);static private class INDY_baz { static final MethodHandle CALL_SITE; static { MethodType mt = methodType(void.class, String.class, int.class, double.class); CallSite cs = (CallSite) MH_bsm2().invoke( lookup(), "baz", mt // standard BSM arguments

Tuesday, July 19, 2011

Page 63: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Pseudo-coding with invokedynamic http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/ tip/test/java/lang/invoke/InvokeDynamicPrintArgs.java

invokedynamic baz(Ljava/lang/String;ID)V [#bsm2, 1234.5]

static CallSite bsm2( Lookup caller, String name, MethodType type, Object... arg) { // ignore caller and name, but match the type: return new PrintingCallSite(caller, name, type, arg);}

INDY_baz.CALL_SITE.invokeExact("baz arg", 2, 3.14);static private class INDY_baz { static final MethodHandle CALL_SITE; static { MethodType mt = methodType(void.class, String.class, int.class, double.class); CallSite cs = (CallSite) MH_bsm2().invoke( lookup(), "baz", mt // standard BSM arguments , 1234.5); // optional static argument

Tuesday, July 19, 2011

Page 64: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Pseudo-coding with invokedynamic http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/ tip/test/java/lang/invoke/InvokeDynamicPrintArgs.java

invokedynamic baz(Ljava/lang/String;ID)V [#bsm2, 1234.5]

static CallSite bsm2( Lookup caller, String name, MethodType type, Object... arg) { // ignore caller and name, but match the type: return new PrintingCallSite(caller, name, type, arg);}

INDY_baz.CALL_SITE.invokeExact("baz arg", 2, 3.14);static private class INDY_baz { static final MethodHandle CALL_SITE; static { MethodType mt = methodType(void.class, String.class, int.class, double.class); CallSite cs = (CallSite) MH_bsm2().invoke( lookup(), "baz", mt // standard BSM arguments , 1234.5); // optional static argument CALL_SITE = cs.dynamicInvoker();} }

Tuesday, July 19, 2011

Page 66: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Bonus book plug!

Interesting account of human language change.

Tuesday, July 19, 2011

Page 67: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Bonus book plug!

Interesting account of human language change.

Tuesday, July 19, 2011

Page 68: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Bonus book plug!

Interesting account of human language change.

Makes computer language change look easy.

Tuesday, July 19, 2011

Page 69: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Overview...

• What we did in JDK 7• How it works in Hotspot• Advice to users• Next steps in JSR 292• Building the future

Tuesday, July 19, 2011

Page 70: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Invokedynamic “plumbing”, take 1

Tuesday, July 19, 2011

Page 71: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Invokedynamic pseudo-code

Tuesday, July 19, 2011

Page 72: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Invokedynamic pseudo-code

Object a1 = ..., a2 = ...;

Tuesday, July 19, 2011

Page 73: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Invokedynamic pseudo-code

Object a1 = ..., a2 = ...;

CallSite cs = INDY_lessThan.CALL_SITE; // linked as a constant

Tuesday, July 19, 2011

Page 74: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Invokedynamic pseudo-code

Object a1 = ..., a2 = ...;

CallSite cs = INDY_lessThan.CALL_SITE; // linked as a constant

MethodHandle mh = cs.getTarget(); // can be variable

Tuesday, July 19, 2011

Page 75: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Invokedynamic pseudo-code

Object a1 = ..., a2 = ...;

CallSite cs = INDY_lessThan.CALL_SITE; // linked as a constant

MethodHandle mh = cs.getTarget(); // can be variable

boolean z = (boolean) mh.invokeExact(a1, a2);

Tuesday, July 19, 2011

Page 76: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Invokedynamic pseudo-code

Object a1 = ..., a2 = ...;

CallSite cs = INDY_lessThan.CALL_SITE; // linked as a constant

MethodHandle mh = cs.getTarget(); // can be variable

boolean z = (boolean) mh.invokeExact(a1, a2);

if (z) { ... }

Tuesday, July 19, 2011

Page 77: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code

Tuesday, July 19, 2011

Page 78: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code

MethodHandle mh = ...;// (boolean) mh.invokeExact(a1, a2);

Tuesday, July 19, 2011

Page 79: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code

MethodHandle mh = ...;// (boolean) mh.invokeExact(a1, a2);

MethodType mt = methodType(boolean.class, Object.class, Object.class); // internal constantif (mh.type() != mt) throw new WrongMethodTypeException();

Tuesday, July 19, 2011

Page 80: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code

MethodHandle mh = ...;// (boolean) mh.invokeExact(a1, a2);

MethodType mt = methodType(boolean.class, Object.class, Object.class); // internal constantif (mh.type() != mt) throw new WrongMethodTypeException();

goto (*mh.vmentry) // jump indirect to invokestatic_mh

Tuesday, July 19, 2011

Page 81: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code

MethodHandle mh = ...;// (boolean) mh.invokeExact(a1, a2);

MethodType mt = methodType(boolean.class, Object.class, Object.class); // internal constantif (mh.type() != mt) throw new WrongMethodTypeException();

goto (*mh.vmentry) // jump indirect to invokestatic_mh

invokestatic_mh: // vmentry for direct MH to a static method

Tuesday, July 19, 2011

Page 82: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code

MethodHandle mh = ...;// (boolean) mh.invokeExact(a1, a2);

MethodType mt = methodType(boolean.class, Object.class, Object.class); // internal constantif (mh.type() != mt) throw new WrongMethodTypeException();

goto (*mh.vmentry) // jump indirect to invokestatic_mh

invokestatic_mh: // vmentry for direct MH to a static methodaddr = mh.vmtarget // Runtime#lessThan

Tuesday, July 19, 2011

Page 83: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code

MethodHandle mh = ...;// (boolean) mh.invokeExact(a1, a2);

MethodType mt = methodType(boolean.class, Object.class, Object.class); // internal constantif (mh.type() != mt) throw new WrongMethodTypeException();

goto (*mh.vmentry) // jump indirect to invokestatic_mh

invokestatic_mh: // vmentry for direct MH to a static methodaddr = mh.vmtarget // Runtime#lessThan

goto (*addr.from_interpreted_entry) // entry point of #lessThan

Tuesday, July 19, 2011

Page 84: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code

MethodHandle mh = ...;// (boolean) mh.invokeExact(a1, a2);

MethodType mt = methodType(boolean.class, Object.class, Object.class); // internal constantif (mh.type() != mt) throw new WrongMethodTypeException();

goto (*mh.vmentry) // jump indirect to invokestatic_mh

invokestatic_mh: // vmentry for direct MH to a static methodaddr = mh.vmtarget // Runtime#lessThan

goto (*addr.from_interpreted_entry) // entry point of #lessThan

static boolean lessThan(Object x, Object y) { ... }

Tuesday, July 19, 2011

Page 85: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

More details about method handles

Tuesday, July 19, 2011

Page 86: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

More details about method handles

• A direct method handle points to a Java method.– A DMH can emulate any of the pre-existing invoke instructions.

Tuesday, July 19, 2011

Page 87: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

More details about method handles

• A direct method handle points to a Java method.– A DMH can emulate any of the pre-existing invoke instructions.

• A bound method handle includes an saved argument.– The bound argument is specified on creation, and is used on call.– The bound argument is inserted into the argument list.– Any MH can be be bound, and the binding is invisible to callers.

Tuesday, July 19, 2011

Page 88: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

More details about method handles

• A direct method handle points to a Java method.– A DMH can emulate any of the pre-existing invoke instructions.

• A bound method handle includes an saved argument.– The bound argument is specified on creation, and is used on call.– The bound argument is inserted into the argument list.– Any MH can be be bound, and the binding is invisible to callers.

• An adapter method handle adjusts values on the fly.– Both argument and return values can be adjusted.– Adaptations include cast, box/unbox, collect/spread, filter, etc.– Any MH can be adapted. Adaptation is invisible to callers.

Tuesday, July 19, 2011

Page 89: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Invokedynamic “plumbing”, take 2

Tuesday, July 19, 2011

Page 90: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code (take 2)

Tuesday, July 19, 2011

Page 91: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code (take 2)

MethodHandle mh1 = cs.getTarget(); // an adapter method handle

Tuesday, July 19, 2011

Page 92: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code (take 2)

MethodHandle mh1 = cs.getTarget(); // an adapter method handlegoto (*mh1.vmentry) // jump indirect to adapter_collect_argsadapter_collect_args:

Tuesday, July 19, 2011

Page 93: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code (take 2)

MethodHandle mh1 = cs.getTarget(); // an adapter method handlegoto (*mh1.vmentry) // jump indirect to adapter_collect_argsadapter_collect_args:push_frame // for eventual call to #booleanValue

Tuesday, July 19, 2011

Page 94: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code (take 2)

MethodHandle mh1 = cs.getTarget(); // an adapter method handlegoto (*mh1.vmentry) // jump indirect to adapter_collect_argsadapter_collect_args:push_frame // for eventual call to #booleanValuemh2 = mh1.vmtarget // a bound method handle

Tuesday, July 19, 2011

Page 95: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code (take 2)

MethodHandle mh1 = cs.getTarget(); // an adapter method handlegoto (*mh1.vmentry) // jump indirect to adapter_collect_argsadapter_collect_args:push_frame // for eventual call to #booleanValuemh2 = mh1.vmtarget // a bound method handlegoto (*mh2.vmentry) // jump indirect to bound_ref_mhbound_ref_mh:

Tuesday, July 19, 2011

Page 96: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code (take 2)

MethodHandle mh1 = cs.getTarget(); // an adapter method handlegoto (*mh1.vmentry) // jump indirect to adapter_collect_argsadapter_collect_args:push_frame // for eventual call to #booleanValuemh2 = mh1.vmtarget // a bound method handlegoto (*mh2.vmentry) // jump indirect to bound_ref_mhbound_ref_mh:push mh2.vmargument // insert extra argument &"lessThan"

Tuesday, July 19, 2011

Page 97: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code (take 2)

MethodHandle mh1 = cs.getTarget(); // an adapter method handlegoto (*mh1.vmentry) // jump indirect to adapter_collect_argsadapter_collect_args:push_frame // for eventual call to #booleanValuemh2 = mh1.vmtarget // a bound method handlegoto (*mh2.vmentry) // jump indirect to bound_ref_mhbound_ref_mh:push mh2.vmargument // insert extra argument &"lessThan"mh3 = mh2.vmtarget // a direct method handle

Tuesday, July 19, 2011

Page 98: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code (take 2)

MethodHandle mh1 = cs.getTarget(); // an adapter method handlegoto (*mh1.vmentry) // jump indirect to adapter_collect_argsadapter_collect_args:push_frame // for eventual call to #booleanValuemh2 = mh1.vmtarget // a bound method handlegoto (*mh2.vmentry) // jump indirect to bound_ref_mhbound_ref_mh:push mh2.vmargument // insert extra argument &"lessThan"mh3 = mh2.vmtarget // a direct method handlegoto (*mh3.vmentry) // jump indirect to invokestatic_mhinvokestatic_mh: // vmentry for direct MH to static method

Tuesday, July 19, 2011

Page 99: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code (take 2)

MethodHandle mh1 = cs.getTarget(); // an adapter method handlegoto (*mh1.vmentry) // jump indirect to adapter_collect_argsadapter_collect_args:push_frame // for eventual call to #booleanValuemh2 = mh1.vmtarget // a bound method handlegoto (*mh2.vmentry) // jump indirect to bound_ref_mhbound_ref_mh:push mh2.vmargument // insert extra argument &"lessThan"mh3 = mh2.vmtarget // a direct method handlegoto (*mh3.vmentry) // jump indirect to invokestatic_mhinvokestatic_mh: // vmentry for direct MH to static methodaddr = mh3.vmtarget // Runtime#invoke_2

Tuesday, July 19, 2011

Page 100: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code (take 2)

MethodHandle mh1 = cs.getTarget(); // an adapter method handlegoto (*mh1.vmentry) // jump indirect to adapter_collect_argsadapter_collect_args:push_frame // for eventual call to #booleanValuemh2 = mh1.vmtarget // a bound method handlegoto (*mh2.vmentry) // jump indirect to bound_ref_mhbound_ref_mh:push mh2.vmargument // insert extra argument &"lessThan"mh3 = mh2.vmtarget // a direct method handlegoto (*mh3.vmentry) // jump indirect to invokestatic_mhinvokestatic_mh: // vmentry for direct MH to static methodaddr = mh3.vmtarget // Runtime#invoke_2goto (*addr.from_interpreted_entry) // entry point of #invoke_2

Tuesday, July 19, 2011

Page 101: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code (take 2)

MethodHandle mh1 = cs.getTarget(); // an adapter method handlegoto (*mh1.vmentry) // jump indirect to adapter_collect_argsadapter_collect_args:push_frame // for eventual call to #booleanValuemh2 = mh1.vmtarget // a bound method handlegoto (*mh2.vmentry) // jump indirect to bound_ref_mhbound_ref_mh:push mh2.vmargument // insert extra argument &"lessThan"mh3 = mh2.vmtarget // a direct method handlegoto (*mh3.vmentry) // jump indirect to invokestatic_mhinvokestatic_mh: // vmentry for direct MH to static methodaddr = mh3.vmtarget // Runtime#invoke_2goto (*addr.from_interpreted_entry) // entry point of #invoke_2

static Object invoke_2(String m, Object x, Object y) { ... }

Tuesday, July 19, 2011

Page 102: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code (take 2)

Tuesday, July 19, 2011

Page 103: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code (take 2)

MethodHandle mh1 = cs.getTarget(); // an adapter method handlegoto (*mh1.vmentry) // jump indirect to adapter_collect_argsadapter_collect_args:push_frame // for eventual call to #booleanValue...static Object invoke_2(String m, Object x, Object y) {

Tuesday, July 19, 2011

Page 104: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code (take 2)

MethodHandle mh1 = cs.getTarget(); // an adapter method handlegoto (*mh1.vmentry) // jump indirect to adapter_collect_argsadapter_collect_args:push_frame // for eventual call to #booleanValue...static Object invoke_2(String m, Object x, Object y) { return (Object) true;}

Tuesday, July 19, 2011

Page 105: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code (take 2)

MethodHandle mh1 = cs.getTarget(); // an adapter method handlegoto (*mh1.vmentry) // jump indirect to adapter_collect_argsadapter_collect_args:push_frame // for eventual call to #booleanValue...static Object invoke_2(String m, Object x, Object y) { return (Object) true;}pop_frame // return to call to mh1

Tuesday, July 19, 2011

Page 106: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code (take 2)

MethodHandle mh1 = cs.getTarget(); // an adapter method handlegoto (*mh1.vmentry) // jump indirect to adapter_collect_argsadapter_collect_args:push_frame // for eventual call to #booleanValue...static Object invoke_2(String m, Object x, Object y) { return (Object) true;}pop_frame // return to call to mh1mh4 = mh1.argument // adapter method handle auxiliary

Tuesday, July 19, 2011

Page 107: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code (take 2)

MethodHandle mh1 = cs.getTarget(); // an adapter method handlegoto (*mh1.vmentry) // jump indirect to adapter_collect_argsadapter_collect_args:push_frame // for eventual call to #booleanValue...static Object invoke_2(String m, Object x, Object y) { return (Object) true;}pop_frame // return to call to mh1mh4 = mh1.argument // adapter method handle auxiliarypush rax // push object return value as argument

Tuesday, July 19, 2011

Page 108: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code (take 2)

MethodHandle mh1 = cs.getTarget(); // an adapter method handlegoto (*mh1.vmentry) // jump indirect to adapter_collect_argsadapter_collect_args:push_frame // for eventual call to #booleanValue...static Object invoke_2(String m, Object x, Object y) { return (Object) true;}pop_frame // return to call to mh1mh4 = mh1.argument // adapter method handle auxiliarypush rax // push object return value as argumentgoto (*mh4.vmentry) // jump indirect to conversion method

Tuesday, July 19, 2011

Page 109: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code (take 2)

MethodHandle mh1 = cs.getTarget(); // an adapter method handlegoto (*mh1.vmentry) // jump indirect to adapter_collect_argsadapter_collect_args:push_frame // for eventual call to #booleanValue...static Object invoke_2(String m, Object x, Object y) { return (Object) true;}pop_frame // return to call to mh1mh4 = mh1.argument // adapter method handle auxiliarypush rax // push object return value as argumentgoto (*mh4.vmentry) // jump indirect to conversion method...

Tuesday, July 19, 2011

Page 110: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle invocation pseudo-code (take 2)

MethodHandle mh1 = cs.getTarget(); // an adapter method handlegoto (*mh1.vmentry) // jump indirect to adapter_collect_argsadapter_collect_args:push_frame // for eventual call to #booleanValue...static Object invoke_2(String m, Object x, Object y) { return (Object) true;}pop_frame // return to call to mh1mh4 = mh1.argument // adapter method handle auxiliarypush rax // push object return value as argumentgoto (*mh4.vmentry) // jump indirect to conversion method...

static boolean convL2Z(Object x) { return (boolean)x; }

Tuesday, July 19, 2011

Page 111: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Overview...

• What we did in JDK 7• How it works in Hotspot• Advice to users• Next steps in JSR 292• Building the future

Tuesday, July 19, 2011

Page 112: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle life cycle

Tuesday, July 19, 2011

Page 113: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle life cycle

• Creation (direct MHs)– reflective factory API: MethodHandles.Lookup– ldc of CONSTANT_MethodHandle– special factories: identity, invoker

Tuesday, July 19, 2011

Page 114: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle life cycle

• Creation (direct MHs)– reflective factory API: MethodHandles.Lookup– ldc of CONSTANT_MethodHandle– special factories: identity, invoker

• Transformation (bound or adapter MHs)– bindTo, insertArguments, guardWithTest, etc.– asType, filterArguments, etc.

Tuesday, July 19, 2011

Page 115: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle life cycle

• Creation (direct MHs)– reflective factory API: MethodHandles.Lookup– ldc of CONSTANT_MethodHandle– special factories: identity, invoker

• Transformation (bound or adapter MHs)– bindTo, insertArguments, guardWithTest, etc.– asType, filterArguments, etc.

• Invocation (exact or inexact)

Tuesday, July 19, 2011

Page 116: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle life cycle

• Creation (direct MHs)– reflective factory API: MethodHandles.Lookup– ldc of CONSTANT_MethodHandle– special factories: identity, invoker

• Transformation (bound or adapter MHs)– bindTo, insertArguments, guardWithTest, etc.– asType, filterArguments, etc.

• Invocation (exact or inexact)• Linking (invokedynamic call site or other constant)

Tuesday, July 19, 2011

Page 117: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle life cycle: Creation

Tuesday, July 19, 2011

Page 118: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle life cycle: Creation

• Method handle creation performs method linkage

Tuesday, July 19, 2011

Page 119: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle life cycle: Creation

• Method handle creation performs method linkage• Can be slow; do it just once if possible

Tuesday, July 19, 2011

Page 120: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle life cycle: Creation

• Method handle creation performs method linkage• Can be slow; do it just once if possible• If generating bytecode, use CONSTANT_MethodHandle

Tuesday, July 19, 2011

Page 121: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle life cycle: Transformation

Tuesday, July 19, 2011

Page 122: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle life cycle: Transformation

• Bound or adapter method handles are additional nodes.– This adds internal pointers seen by GC and MH.invoke

Tuesday, July 19, 2011

Page 123: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle life cycle: Transformation

• Bound or adapter method handles are additional nodes.– This adds internal pointers seen by GC and MH.invoke

• In OpenJDK7, creation requires a JNI call– This means even a simple transform can be surprisingly slow.

Tuesday, July 19, 2011

Page 124: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle life cycle: Transformation

• Bound or adapter method handles are additional nodes.– This adds internal pointers seen by GC and MH.invoke

• In OpenJDK7, creation requires a JNI call– This means even a simple transform can be surprisingly slow.

• We hope to fix this soon.

Tuesday, July 19, 2011

Page 125: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle life cycle: Invocation

Tuesday, July 19, 2011

Page 126: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle life cycle: Invocation

• Exact invocation (MH.invokeExact) is simple.– In OpenJDK7, a pointer check and jump.– Only slightly more expensive than a regular method call.

Tuesday, July 19, 2011

Page 127: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle life cycle: Invocation

• Exact invocation (MH.invokeExact) is simple.– In OpenJDK7, a pointer check and jump.– Only slightly more expensive than a regular method call.

• Inexact invocation (MH.invoke) can be complex.– If the types match exactly, same as MH.invokeExact.– If the types do not match, can perform asType transform.

Tuesday, July 19, 2011

Page 128: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle life cycle: Invocation

• Exact invocation (MH.invokeExact) is simple.– In OpenJDK7, a pointer check and jump.– Only slightly more expensive than a regular method call.

• Inexact invocation (MH.invoke) can be complex.– If the types match exactly, same as MH.invokeExact.– If the types do not match, can perform asType transform.

• Invocation via an invokedynamic instruction is fast– Always exact (since call sites are strongly typed)– No runtime check of the type (VM enforces the invariant)– The MH code is typically inlined.

Tuesday, July 19, 2011

Page 129: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle life cycle: Linking

Tuesday, July 19, 2011

Page 130: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle life cycle: Linking

• An invokedynamic instruction is a constant CallSite...

Tuesday, July 19, 2011

Page 131: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle life cycle: Linking

• An invokedynamic instruction is a constant CallSite...• ...with an optimistically predicted target method handle.

– Predicted handle is treated as a constant.

Tuesday, July 19, 2011

Page 132: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle life cycle: Linking

• An invokedynamic instruction is a constant CallSite...• ...with an optimistically predicted target method handle.

– Predicted handle is treated as a constant.• “static final” MH variables are also constant.

Tuesday, July 19, 2011

Page 133: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Method handle life cycle: Linking

• An invokedynamic instruction is a constant CallSite...• ...with an optimistically predicted target method handle.

– Predicted handle is treated as a constant.• “static final” MH variables are also constant.• Constant method handles (of any source) can be inlined

– Inlining can boil away adapters and bound arguments.– Inlining can continue all the way through a direct method handle.

Tuesday, July 19, 2011

Page 134: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Bottom lines (specific to OpenJDK7!)

Tuesday, July 19, 2011

Page 135: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Bottom lines (specific to OpenJDK7!)

• Don’t make new method handles in inner loops (yet).

Tuesday, July 19, 2011

Page 136: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Bottom lines (specific to OpenJDK7!)

• Don’t make new method handles in inner loops (yet).• Bind method handles to invokedynamic or constants.

Tuesday, July 19, 2011

Page 137: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Bottom lines (specific to OpenJDK7!)

• Don’t make new method handles in inner loops (yet).• Bind method handles to invokedynamic or constants.• Prefer invokeExact.

Tuesday, July 19, 2011

Page 138: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Bottom lines (specific to OpenJDK7!)

• Don’t make new method handles in inner loops (yet).• Bind method handles to invokedynamic or constants.• Prefer invokeExact.• Work with us to prioritize benchmark/optimization work.

Tuesday, July 19, 2011

Page 139: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Overview...

• What we did in JDK 7• How it works in Hotspot• Advice to users• Next steps in JSR 292• Building the future

Tuesday, July 19, 2011

Page 140: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation – Proprietary and Confidential | © 2011 Oracle Corporation

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, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.

Tuesday, July 19, 2011

Page 141: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Loose ends in the Java 7 API

Tuesday, July 19, 2011

Page 142: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Loose ends in the Java 7 API

• Method handle introspection (reflection)

Tuesday, July 19, 2011

Page 143: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Loose ends in the Java 7 API

• Method handle introspection (reflection)• Generalized proxies (more than single-method intfs)

Tuesday, July 19, 2011

Page 144: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Loose ends in the Java 7 API

• Method handle introspection (reflection)• Generalized proxies (more than single-method intfs)• Class hierarchy analysis (override notification)

Tuesday, July 19, 2011

Page 145: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Loose ends in the Java 7 API

• Method handle introspection (reflection)• Generalized proxies (more than single-method intfs)• Class hierarchy analysis (override notification)• Smaller issues:

– usability (MethodHandle.toString, polymorphic bindTo)– sharp corners (MethodHandle.invokeWithArguments)– repertoire (tryFinally, more fold/spread/collect options)

Tuesday, July 19, 2011

Page 146: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Loose ends in the Java 7 API

• Method handle introspection (reflection)• Generalized proxies (more than single-method intfs)• Class hierarchy analysis (override notification)• Smaller issues:

– usability (MethodHandle.toString, polymorphic bindTo)– sharp corners (MethodHandle.invokeWithArguments)– repertoire (tryFinally, more fold/spread/collect options)

• Integration with other APIs (java.lang.reflect)

Tuesday, July 19, 2011

Page 147: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Support for Lambda in OpenJDK8

Tuesday, July 19, 2011

Page 148: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Support for Lambda in OpenJDK8

• More transforms for SAM types (as needed).

Tuesday, July 19, 2011

Page 149: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Support for Lambda in OpenJDK8

• More transforms for SAM types (as needed).• Faster bindTo operation to create bound MHs

– No JNI calls.– Maybe multiple-value bindTo.

Tuesday, July 19, 2011

Page 150: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Support for Lambda in OpenJDK8

• More transforms for SAM types (as needed).• Faster bindTo operation to create bound MHs

– No JNI calls.– Maybe multiple-value bindTo.

• Faster inexact invoke (as needed).

Tuesday, July 19, 2011

Page 151: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Issue tracking

Tuesday, July 19, 2011

Page 152: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Issue tracking

• http://java.net/jira/browse/MLVM

Tuesday, July 19, 2011

Page 153: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Issue tracking

• http://java.net/jira/browse/MLVM• This is an experiment. Can we make it work?

Tuesday, July 19, 2011

Page 154: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Issue tracking

• http://java.net/jira/browse/MLVM• This is an experiment. Can we make it work?• Public readable, writable after java.net login.

Tuesday, July 19, 2011

Page 155: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Issue tracking

Tuesday, July 19, 2011

Page 156: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Issue tracking

• http://java.net/jira/browse/MLVM

Tuesday, July 19, 2011

Page 157: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Issue tracking

• http://java.net/jira/browse/MLVM• This is an experiment. Can we make it work?

Tuesday, July 19, 2011

Page 158: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Issue tracking

• http://java.net/jira/browse/MLVM• This is an experiment. Can we make it work?• (Is there a JIRA expert in the house?)

Tuesday, July 19, 2011

Page 159: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Overview...

• What we did in JDK 7• How it works in Hotspot• Advice to users• Next steps in JSR 292• Building the future

Tuesday, July 19, 2011

Page 160: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s build up libraries and client languages

Tuesday, July 19, 2011

Page 161: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s build up libraries and client languages

• Asm

Tuesday, July 19, 2011

Page 162: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s build up libraries and client languages

• Asm• Mirah

Tuesday, July 19, 2011

Page 163: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s build up libraries and client languages

• Asm• Mirah• Dynalang

Tuesday, July 19, 2011

Page 164: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s build up libraries and client languages

• Asm• Mirah• Dynalang• Indify

Tuesday, July 19, 2011

Page 165: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s build up libraries and client languages

• Asm• Mirah• Dynalang• Indify• JSR 292 backport

Tuesday, July 19, 2011

Page 166: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s build up libraries and client languages

• Asm• Mirah• Dynalang• Indify• JSR 292 backport• MethodHandle transforms/adapters

Tuesday, July 19, 2011

Page 167: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s build up libraries and client languages

• Asm• Mirah• Dynalang• Indify• JSR 292 backport• MethodHandle transforms/adapters

• Ruby/Smalltalk/Groovy/Scala/...

Tuesday, July 19, 2011

Page 168: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s build up libraries and client languages

• Asm• Mirah• Dynalang• Indify• JSR 292 backport• MethodHandle transforms/adapters

• Ruby/Smalltalk/Groovy/Scala/...• (your favorite language here)

Tuesday, July 19, 2011

Page 169: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s nurture Project Lambda

Tuesday, July 19, 2011

Page 170: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s nurture Project Lambda

• More than aid to Lisp refugees...

Tuesday, July 19, 2011

Page 171: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s nurture Project Lambda

• More than aid to Lisp refugees...• More than a renaissance of languages...

Tuesday, July 19, 2011

Page 172: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s nurture Project Lambda

• More than aid to Lisp refugees...• More than a renaissance of languages...• Part of our attack on multi-cores

Tuesday, July 19, 2011

Page 173: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s nurture Project Lambda

• More than aid to Lisp refugees...• More than a renaissance of languages...• Part of our attack on multi-cores

• Optimization problems:

Tuesday, July 19, 2011

Page 174: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s nurture Project Lambda

• More than aid to Lisp refugees...• More than a renaissance of languages...• Part of our attack on multi-cores

• Optimization problems:– Support for closures via invokedynamic.

Tuesday, July 19, 2011

Page 175: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s nurture Project Lambda

• More than aid to Lisp refugees...• More than a renaissance of languages...• Part of our attack on multi-cores

• Optimization problems:– Support for closures via invokedynamic.– SAM / MH conversion (boxing/unboxing).

Tuesday, July 19, 2011

Page 176: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s nurture Project Lambda

• More than aid to Lisp refugees...• More than a renaissance of languages...• Part of our attack on multi-cores

• Optimization problems:– Support for closures via invokedynamic.– SAM / MH conversion (boxing/unboxing).– Loop versioning in the presence of closures.

Tuesday, July 19, 2011

Page 177: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s nurture Project Lambda

• More than aid to Lisp refugees...• More than a renaissance of languages...• Part of our attack on multi-cores

• Optimization problems:– Support for closures via invokedynamic.– SAM / MH conversion (boxing/unboxing).– Loop versioning in the presence of closures.– Online optimistic (re-)compilation.

Tuesday, July 19, 2011

Page 178: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s continue building our “future VM”http://hg.openjdk.java.net/mlvm/mlvm/hotspot/

Tuesday, July 19, 2011

Page 179: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s continue building our “future VM”

• Da Vinci Machine Project: an open source incubator for JVM futures

http://hg.openjdk.java.net/mlvm/mlvm/hotspot/

Tuesday, July 19, 2011

Page 180: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s continue building our “future VM”

• Da Vinci Machine Project: an open source incubator for JVM futures

• Contains code fragments (patches).

http://hg.openjdk.java.net/mlvm/mlvm/hotspot/

Tuesday, July 19, 2011

Page 181: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s continue building our “future VM”

• Da Vinci Machine Project: an open source incubator for JVM futures

• Contains code fragments (patches).• Movement to OpenJDK requires:

http://hg.openjdk.java.net/mlvm/mlvm/hotspot/

Tuesday, July 19, 2011

Page 182: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s continue building our “future VM”

• Da Vinci Machine Project: an open source incubator for JVM futures

• Contains code fragments (patches).• Movement to OpenJDK requires:

– a standard (e.g., JSR 292)

http://hg.openjdk.java.net/mlvm/mlvm/hotspot/

Tuesday, July 19, 2011

Page 183: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s continue building our “future VM”

• Da Vinci Machine Project: an open source incubator for JVM futures

• Contains code fragments (patches).• Movement to OpenJDK requires:

– a standard (e.g., JSR 292)– a feature release plan (7 vs. 8 vs. ...)

http://hg.openjdk.java.net/mlvm/mlvm/hotspot/

Tuesday, July 19, 2011

Page 184: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s continue building our “future VM”

• Da Vinci Machine Project: an open source incubator for JVM futures

• Contains code fragments (patches).• Movement to OpenJDK requires:

– a standard (e.g., JSR 292)– a feature release plan (7 vs. 8 vs. ...)

• bsd-port for developer friendliness.

http://hg.openjdk.java.net/mlvm/mlvm/hotspot/

Tuesday, July 19, 2011

Page 185: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s continue building our “future VM”

• Da Vinci Machine Project: an open source incubator for JVM futures

• Contains code fragments (patches).• Movement to OpenJDK requires:

– a standard (e.g., JSR 292)– a feature release plan (7 vs. 8 vs. ...)

• bsd-port for developer friendliness.• [email protected]

http://hg.openjdk.java.net/mlvm/mlvm/hotspot/

Tuesday, July 19, 2011

Page 186: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

MLVM  patches

meth method  handles  implementa.on

indy invokedynamic

coro lightweight  corou.nes

in. interface  injec.on  (Tobias  Ivarsson)

tailc hard  tail  call  op.miza.on  (Arnold  Schwaighofer)

tuple integra.ng  tuple  types  (new  from  Michael  Barker!)

hotswap online  general  class  schema  updates  (Thomas  Wuerthinger)

anonk anonymous  classes;  light  weight  bytecode  loading

| © 2011 Oracle Corporation

Current Da Vinci Machine patches

Tuesday, July 19, 2011

Page 187: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Caveat: Change is hard and slow(especially the “last 20%”)

Tuesday, July 19, 2011

Page 188: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Caveat: Change is hard and slow

• Hacking code is relatively simple.

(especially the “last 20%”)

Tuesday, July 19, 2011

Page 189: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Caveat: Change is hard and slow

• Hacking code is relatively simple.• Removing bugs is harder.

(especially the “last 20%”)

Tuesday, July 19, 2011

Page 190: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Caveat: Change is hard and slow

• Hacking code is relatively simple.• Removing bugs is harder.• Verifying is difficult (millions of users).

(especially the “last 20%”)

Tuesday, July 19, 2011

Page 191: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Caveat: Change is hard and slow

• Hacking code is relatively simple.• Removing bugs is harder.• Verifying is difficult (millions of users).• Integrating to a giant system very hard.

(especially the “last 20%”)

Tuesday, July 19, 2011

Page 192: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Caveat: Change is hard and slow

• Hacking code is relatively simple.• Removing bugs is harder.• Verifying is difficult (millions of users).• Integrating to a giant system very hard.

– interpreter, multiple compilers

(especially the “last 20%”)

Tuesday, July 19, 2011

Page 193: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Caveat: Change is hard and slow

• Hacking code is relatively simple.• Removing bugs is harder.• Verifying is difficult (millions of users).• Integrating to a giant system very hard.

– interpreter, multiple compilers– managed heap (multiple GC algos.)

(especially the “last 20%”)

Tuesday, July 19, 2011

Page 194: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Caveat: Change is hard and slow

• Hacking code is relatively simple.• Removing bugs is harder.• Verifying is difficult (millions of users).• Integrating to a giant system very hard.

– interpreter, multiple compilers– managed heap (multiple GC algos.)– debugging, monitoring, profiling machinery

(especially the “last 20%”)

Tuesday, July 19, 2011

Page 195: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Caveat: Change is hard and slow

• Hacking code is relatively simple.• Removing bugs is harder.• Verifying is difficult (millions of users).• Integrating to a giant system very hard.

– interpreter, multiple compilers– managed heap (multiple GC algos.)– debugging, monitoring, profiling machinery– security interactions

(especially the “last 20%”)

Tuesday, July 19, 2011

Page 196: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Caveat: Change is hard and slow

• Hacking code is relatively simple.• Removing bugs is harder.• Verifying is difficult (millions of users).• Integrating to a giant system very hard.

– interpreter, multiple compilers– managed heap (multiple GC algos.)– debugging, monitoring, profiling machinery– security interactions

• Specifying is hard (the last 20%...).

(especially the “last 20%”)

Tuesday, July 19, 2011

Page 197: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Caveat: Change is hard and slow

• Hacking code is relatively simple.• Removing bugs is harder.• Verifying is difficult (millions of users).• Integrating to a giant system very hard.

– interpreter, multiple compilers– managed heap (multiple GC algos.)– debugging, monitoring, profiling machinery– security interactions

• Specifying is hard (the last 20%...).• Running process is time-consuming.

(especially the “last 20%”)

Tuesday, July 19, 2011

Page 198: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s continue designing our “future VM”http://java.net/jira/browse/MLVM

Tuesday, July 19, 2011

Page 199: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s continue designing our “future VM”

• JIRA issue tracker for API conversations

http://java.net/jira/browse/MLVM

Tuesday, July 19, 2011

Page 200: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s continue designing our “future VM”

• JIRA issue tracker for API conversations• Contains specification fragments.

http://java.net/jira/browse/MLVM

Tuesday, July 19, 2011

Page 201: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s continue designing our “future VM”

• JIRA issue tracker for API conversations• Contains specification fragments.• Requires login to java.net!

http://java.net/jira/browse/MLVM

Tuesday, July 19, 2011

Page 202: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Let’s continue designing our “future VM”

• JIRA issue tracker for API conversations• Contains specification fragments.• Requires login to java.net!

• No code; for all JVMs (not just OpenJDK).

http://java.net/jira/browse/MLVM

Tuesday, July 19, 2011

Page 203: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Category Descrip3on

bytecode  loading Mechanisms  for  bytecode  loading,  such  as  anonymous  classes,  single-­‐method  loads,  and  whole-­‐module  loads.

corou.nes Corou.nes,  fibers,  con.nua.ons,  and  other  extensions  to  threading.

immutability Immutable  variables  and  objects.  (I.e.,  beyond  blank  finals  ini.alized  in  constructors.)

interface  injec.on JVM  features  related  to  online  updates  to  interface  APIs.

invokedynamic The  invokedynamic  instruc.on,  with  related  APIs  such  as  java.lang.invoke.CallSite.

memory  localityMechanisms  for  giving  applica.ons  control  (at  the  bytecode  level)  over  memory  locality,  such  as  na.ve  layout,  heterogeneous  arrays,  object  fusing,  object  federa.on,  and  object  replica.on.

method  handlesjava.lang.invoke.MethodHandle  and  related  APIs.  For  bootstrap  methods  and  CallSite,  use  the  "invokedynamic"  component.

reifica.on Mechanisms  for  reifying  erased  informa.on,  such  as  generic  type  instance  parameters.

tailcalls Bytecode  support  for  hard  (user-­‐specified)  tail  call  elimina.on.

tuplesSignature-­‐polymorphic  structural  record  types.  Proposals  may  affect  arguments,  return  values,  fields,  or  array  elements,  and  interoperability  (via  box/unbox)  with  reference  types.

typestate Mechanisms  for  upda.ng  the  run.me  type  descrip.on  of  an  object.

JVM design issue tracking by category

Tuesday, July 19, 2011

Page 204: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Discussions at previous Summitshttp://cr.openjdk.java.net/~jrose/pres/201007-JVMFutureTalk.pdf

Tuesday, July 19, 2011

Page 205: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Discussions at previous Summits

• E.g., see my talk from last year

http://cr.openjdk.java.net/~jrose/pres/201007-JVMFutureTalk.pdf

Tuesday, July 19, 2011

Page 206: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Discussions at previous Summits

• E.g., see my talk from last year– starting slide 25, “JVM features to investigate”

http://cr.openjdk.java.net/~jrose/pres/201007-JVMFutureTalk.pdf

Tuesday, July 19, 2011

Page 207: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Discussions at previous Summits

• E.g., see my talk from last year– starting slide 25, “JVM features to investigate”

• Value versus Identity

http://cr.openjdk.java.net/~jrose/pres/201007-JVMFutureTalk.pdf

Tuesday, July 19, 2011

Page 208: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Discussions at previous Summits

• E.g., see my talk from last year– starting slide 25, “JVM features to investigate”

• Value versus Identity• Tail calls

http://cr.openjdk.java.net/~jrose/pres/201007-JVMFutureTalk.pdf

Tuesday, July 19, 2011

Page 209: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Discussions at previous Summits

• E.g., see my talk from last year– starting slide 25, “JVM features to investigate”

• Value versus Identity• Tail calls• Better data structures

http://cr.openjdk.java.net/~jrose/pres/201007-JVMFutureTalk.pdf

Tuesday, July 19, 2011

Page 210: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Discussions at previous Summits

• E.g., see my talk from last year– starting slide 25, “JVM features to investigate”

• Value versus Identity• Tail calls• Better data structures

• Object species (typestate)http://blogs.oracle.com/jrose/entry/larval_objects_in_the_vm

http://cr.openjdk.java.net/~jrose/pres/201007-JVMFutureTalk.pdf

Tuesday, July 19, 2011

Page 211: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

An integrating goal: Get multi.

Tuesday, July 19, 2011

Page 212: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

An integrating goal: Get multi.

• Thread/task/loop decomposition.

Tuesday, July 19, 2011

Page 213: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

An integrating goal: Get multi.

• Thread/task/loop decomposition.• Immutability & replication.

Tuesday, July 19, 2011

Page 214: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

An integrating goal: Get multi.

• Thread/task/loop decomposition.• Immutability & replication.• Transactional APIs.

Tuesday, July 19, 2011

Page 215: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

An integrating goal: Get multi.

• Thread/task/loop decomposition.• Immutability & replication.• Transactional APIs.• Memory locality.

Tuesday, July 19, 2011

Page 216: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

An integrating goal: Get multi.

• Thread/task/loop decomposition.• Immutability & replication.• Transactional APIs.• Memory locality.• More fluid code.

Tuesday, July 19, 2011

Page 217: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

An integrating goal: Get multi.

• Thread/task/loop decomposition.• Immutability & replication.• Transactional APIs.• Memory locality.• More fluid code.• More fluid data (traits, species).

Tuesday, July 19, 2011

Page 218: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation

Q&A

(continuing in today’s workshop)

Tuesday, July 19, 2011

Page 219: Tuesday, July 19, 2011wiki.jvmlangsummit.com/images/8/88/Rose-2011-FutureDirections.pdf|2011 Oracle Corporation – Proprietary and Confidential Method Handles and Beyond... Some basis

| © 2011 Oracle Corporation – Proprietary and Confidential

Tuesday, July 19, 2011