--- a/indy.patch Wed Jun 17 13:16:23 2009 -0700
+++ b/indy.patch Wed Jun 17 15:56:53 2009 -0700
@@ -67,7 +67,23 @@ diff --git a/src/share/classes/java/dyn/
}
/**
-@@ -118,7 +135,7 @@
+@@ -102,10 +119,11 @@
+
+ /**
+ * Report the current linkage state of the call site. (This is mutable.)
+- * The value maybe null only if the call site is currently unlinked.
+- * When a linked call site is invoked, the target method is used directly.
+- * When an unlinked call site is invoked, its bootstrap method receives
+- * the call, as if via {@link Linkage#bootstrapInvokeDynamic}.
++ * The value may not be null after the {@code CallSite} object is returned
++ * from the bootstrap method of the {@code invokedynamic} instruction.
++ * When an {@code invokedynamic} instruction is executed, the target method
++ * of its associated {@code call site} object is invoked directly,
++ * as if via {@link MethodHandle}{@code .invoke}.
+ * <p>
+ * The interactions of {@code getTarget} with memory are the same
+ * as of a read from an ordinary variable, such as an array element or a
+@@ -118,7 +136,7 @@
* @see #setTarget
*/
public MethodHandle getTarget() {
@@ -76,7 +92,7 @@ diff --git a/src/share/classes/java/dyn/
}
/**
-@@ -140,7 +157,7 @@
+@@ -140,7 +158,7 @@
*/
public void setTarget(MethodHandle target) {
checkTarget(target);
@@ -85,7 +101,7 @@ diff --git a/src/share/classes/java/dyn/
}
protected void checkTarget(MethodHandle target) {
-@@ -219,6 +236,6 @@
+@@ -219,6 +237,6 @@
@Override
public String toString() {
@@ -93,6 +109,33 @@ diff --git a/src/share/classes/java/dyn/
+ return "CallSite#"+hashCode()+"["+name+type+" => "+getTarget()+"]";
}
}
+diff --git a/src/share/classes/java/dyn/InvokeDynamic.java b/src/share/classes/java/dyn/InvokeDynamic.java
+--- a/src/share/classes/java/dyn/InvokeDynamic.java
++++ b/src/share/classes/java/dyn/InvokeDynamic.java
+@@ -45,6 +45,23 @@
+ * class or interface supertype, or an object type; it can never be instantiated.
+ * Logically, it denotes a source of all dynamically typed methods.
+ * It may be viewed as a pure syntactic marker (an importable one) of static calls.
++ * <p>
++ * Example of use:
++ * <blockquote><pre>
++ * Object x, y; String s; int i;
++ * x = InvokeDynamic.greet("world"); // greet(Ljava/lang/String;)Ljava/lang/Object;
++ * y = "world";
++ * s = InvokeDynamic.<String>hail(x); // hail(Ljava/lang/Object;)Ljava/lang/String;
++ * InvokeDynamic.<void>cogito(); // cogito()V
++ * i = InvokeDynamic.<int>#"op:+"(2, 3); // +(II)I
++ * </pre></blockquote>
++ * Each of the above calls generates a single invokedynamic instruction
++ * with the name-and-type descriptors indicated in the comments.
++ * The argument types are taken directly from the actual arguments,
++ * while the return type is taken from the type parameter.
++ * (This type parameter may be a primtive, and it defaults to {@code Object}.)
++ * The final example uses a special syntax for uttering non-Java names.
++ * Any name legal to the JVM may be given between the double quotes.
+ * @author John Rose, JSR 292 EG
+ */
+ public final class InvokeDynamic {
diff --git a/src/share/classes/java/dyn/InvokeDynamicBootstrapError.java b/src/share/classes/java/dyn/InvokeDynamicBootstrapError.java
--- a/src/share/classes/java/dyn/InvokeDynamicBootstrapError.java
+++ b/src/share/classes/java/dyn/InvokeDynamicBootstrapError.java
@@ -259,7 +302,51 @@ diff --git a/src/share/classes/java/dyn/
* Bytecode in an extended JVM can directly obtain a method handle
* for any accessible method from a <code>ldc</code> instruction
* which refers to a <code>CONSTANT_Methodref</code> or
-@@ -107,8 +121,8 @@
+@@ -97,6 +111,43 @@
+ * can also be created. These do not perform virtual lookup based on
+ * receiver type. Such a method handle simulates the effect of
+ * an <code>invokespecial</code> instruction to the same method.
++ * <p>
++ * Example of use:
++ * <blockquote><pre>
++ * Object x, y; String s; int i;
++ * MethodType mt; MethodHandle mh;
++ * MethodHandles.Lookup lookup = MethodHandles.lookup();
++ * // mt is {(char,char) => String}
++ * mt = MethodType.make(String.class, char.class, char.class);
++ * mh = lookup.findVirtual(String.class, "replace", mt);
++ * // (Ljava/lang/String;CC)Ljava/lang/String;
++ * s = mh.<String>invoke("would",'u','r');
++ * assert(s.equals("world"));
++ * // weakly typed invocation (using MHs.invoke)
++ * s = (String) MethodHandles.invoke(mh, "sappy", 'p', 'v');
++ * assert(s.equals("savvy"));
++ * // mt is {Object[] => List}
++ * mt = MethodType.make(List.class, Object[].class);
++ * mh = lookup.findStatic(java.util.Arrays.class, "asList", mt);
++ * // mt is {(Object,Object,Object) => Object}
++ * mt = MethodType.makeGeneric(3);
++ * mh = MethodHandles.collectArguments(mh, mt);
++ * // mt is {(Object,Object,Object) => Object}
++ * // (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
++ * x = mh.invoke((Object)1, (Object)2, (Object)3);
++ * assert(x.equals(java.util.Arrays.asList(1,2,3)));
++ * // mt is { => int}
++ * mt = MethodType.make(int.class);
++ * mh = lookup.findVirtual(List.class, "size", mt);
++ * // (Ljava/util/List;)I
++ * i = mh.<int>invoke(java.util.Arrays.asList(1,2,3));
++ * assert(i == 3);
++ * </pre></blockquote>
++ * Each of the above calls generates a single invokevirtual instruction
++ * with the name {@code invoke} and the type descriptors indicated in the comments.
++ * The argument types are taken directly from the actual arguments,
++ * while the return type is taken from the type parameter.
++ * (This type parameter may be a primtive, and it defaults to {@code Object}.)
+ *
+ * @see MethodType
+ * @see MethodHandles
+@@ -107,8 +158,8 @@
// with a JVM change which moves the required hidden state onto this class.
extends MethodHandleImpl
{
@@ -290,7 +377,7 @@ diff --git a/src/share/classes/java/dyn/
* </ol>
* @author John Rose, JSR 292 EG
*/
-@@ -68,10 +69,21 @@
+@@ -68,12 +69,22 @@
//// Method handle creation from ordinary methods.
@@ -310,9 +397,11 @@ diff --git a/src/share/classes/java/dyn/
+ }
+
/**
- * <em>PROVISIONAL API, WORK IN PROGRESS:</em>
+- * <em>PROVISIONAL API, WORK IN PROGRESS:</em>
* A factory object for creating method handles, when the creation
-@@ -121,7 +133,8 @@
+ * requires access checking. Method handles do not perform
+ * access checks when they are called; this is a major difference
+@@ -121,7 +132,8 @@
/** Which class is performing the lookup? It is this class against
* which checks are performed for visibility and access permissions.
* <p>
@@ -322,7 +411,7 @@ diff --git a/src/share/classes/java/dyn/
*/
public Class<?> lookupClass() {
return lookupClass;
-@@ -135,23 +148,46 @@
+@@ -135,23 +147,46 @@
* an access$N method.
*/
Lookup() {
@@ -374,7 +463,7 @@ diff --git a/src/share/classes/java/dyn/
/** Package-private version of lookup which is trusted. */
static final Lookup IMPL_LOOKUP = new Lookup(null);
-@@ -178,12 +214,16 @@
+@@ -178,12 +213,16 @@
// 0: Reflection.getCC, 1: getCallerClassAtEntryPoint,
// 2: Lookup.<init>, 3: MethodHandles.*, 4: caller
// Note: This should be the only use of getCallerClass in this file.
@@ -387,11 +476,11 @@ diff --git a/src/share/classes/java/dyn/
* The type of the method handle will be that of the method.
+ * (Since static methods do not take receivers, there is no
+ * additional receiver argument inserted into the method handle type,
-+ * as there would be with {@linkplain findVirtual} or {@linkplain findSpecial}.)
++ * as there would be with {@linkplain #findVirtual} or {@linkplain #findSpecial}.)
* The method and all its argument types must be accessible to the lookup class.
* If the method's class has not yet been initialized, that is done
* immediately, before the method handle is returned.
-@@ -196,10 +236,11 @@
+@@ -196,10 +235,11 @@
*/
public
MethodHandle findStatic(Class<?> defc, String name, MethodType type) throws NoAccessException {
@@ -406,7 +495,7 @@ diff --git a/src/share/classes/java/dyn/
}
/**
-@@ -228,9 +269,10 @@
+@@ -228,9 +268,10 @@
* @exception NoAccessException if the method does not exist or access checking fails
*/
public MethodHandle findVirtual(Class<?> defc, String name, MethodType type) throws NoAccessException {
@@ -420,7 +509,7 @@ diff --git a/src/share/classes/java/dyn/
}
/**
-@@ -259,15 +301,17 @@
+@@ -259,15 +300,17 @@
*/
public MethodHandle findSpecial(Class<?> defc, String name, MethodType type,
Class<?> specialCaller) throws NoAccessException {
@@ -443,7 +532,7 @@ diff --git a/src/share/classes/java/dyn/
}
/**
-@@ -275,13 +319,19 @@
+@@ -275,13 +318,19 @@
* The receiver must have a supertype {@code defc} in which a method
* of the given name and type is accessible to the lookup class.
* The method and all its argument types must be accessible to the lookup class.
@@ -458,7 +547,8 @@ diff --git a/src/share/classes/java/dyn/
- * Equivalent to the following expression:
+ * This is equivalent to the following expression:
* <code>
- * {@link #insertArgument}({@link #findVirtual}(defc, name, type), receiver)
+- * {@link #insertArgument}({@link #findVirtual}(defc, name, type), receiver)
++ * {@link #insertArguments}({@link #findVirtual}(defc, name, type), receiver)
* </code>
+ * where {@code defc} is either {@code receiver.getClass()} or a super
+ * type of that class, in which the requested method is accessible
@@ -466,7 +556,7 @@ diff --git a/src/share/classes/java/dyn/
* @param receiver the object from which the method is accessed
* @param name the name of the method
* @param type the type of the method, with the receiver argument omitted
-@@ -292,16 +342,18 @@
+@@ -292,16 +341,18 @@
public MethodHandle bind(Object receiver, String name, MethodType type) throws NoAccessException {
Class<? extends Object> rcvc = receiver.getClass(); // may get NPE
MemberName reference = new MemberName(rcvc, name, type);
@@ -489,7 +579,7 @@ diff --git a/src/share/classes/java/dyn/
* Make a direct method handle to <i>m</i>, if the lookup class has permission.
* If <i>m</i> is non-static, the receiver argument is treated as an initial argument.
* If <i>m</i> is virtual, overriding is respected on every call.
-@@ -316,10 +368,11 @@
+@@ -316,10 +367,11 @@
* @exception NoAccessException if access checking fails
*/
public MethodHandle unreflect(Method m) throws NoAccessException {
@@ -502,7 +592,7 @@ diff --git a/src/share/classes/java/dyn/
* Produce a method handle for a reflected method.
* It will bypass checks for overriding methods on the receiver,
* as if by the {@code invokespecial} instruction.
-@@ -333,37 +386,41 @@
+@@ -333,37 +385,41 @@
* @exception NoAccessException if access checking fails
*/
public MethodHandle unreflectSpecial(Method m, Class<?> specialCaller) throws NoAccessException {
@@ -553,7 +643,7 @@ diff --git a/src/share/classes/java/dyn/
* If the method's {@code accessible} flag is not set,
* access checking is performed immediately on behalf of the lookup class.
* @param f the reflected field
-@@ -371,16 +428,17 @@
+@@ -371,16 +427,17 @@
* @exception NoAccessException if access checking fails
*/
public MethodHandle unreflectGetter(Field f) throws NoAccessException {
@@ -575,7 +665,7 @@ diff --git a/src/share/classes/java/dyn/
* If the method's {@code accessible} flag is not set,
* access checking is performed immediately on behalf of the lookup class.
* @param f the reflected field
-@@ -388,59 +446,63 @@
+@@ -388,59 +445,63 @@
* @exception NoAccessException if access checking fails
*/
public MethodHandle unreflectSetter(Field f) throws NoAccessException {
@@ -658,7 +748,7 @@ diff --git a/src/share/classes/java/dyn/
}
/**
-@@ -509,51 +571,113 @@
+@@ -509,51 +570,113 @@
* @return the result returned by the target
*/
public static
@@ -790,7 +880,7 @@ diff --git a/src/share/classes/java/dyn/
}
/**
-@@ -703,26 +827,15 @@
+@@ -703,26 +826,15 @@
* arguments and return types. Let T0 and T1 be the differing
* new and old parameter types (or old and new return types)
* for corresponding values passed by the new and old method types.
@@ -823,7 +913,7 @@ diff --git a/src/share/classes/java/dyn/
* <li>If T0 and T1 are primitives, then a Java casting
* conversion (JLS 5.5) is applied, if one exists.
* <li>If T0 and T1 are primitives and one is boolean,
-@@ -745,9 +858,9 @@
+@@ -745,9 +857,9 @@
* if necessary to T1 by one of the preceding conversions.
* Otherwise, T0 is converted directly to the wrapper type for T1,
* which is then unboxed.
@@ -836,7 +926,7 @@ diff --git a/src/share/classes/java/dyn/
* </ul>
* @param target the method handle to invoke after arguments are retyped
* @param newType the expected type of the new method handle
-@@ -872,20 +985,14 @@
+@@ -872,20 +984,14 @@
* <em>PROVISIONAL API, WORK IN PROGRESS:</em>
* Produce a method handle which adapts the type of the
* given method handle to a new type, by collecting a series of
@@ -859,7 +949,7 @@ diff --git a/src/share/classes/java/dyn/
* @param target the method handle to invoke after the argument is prepended
* @param newType the expected type of the new method handle
* @return a new method handle which collects some trailings argument
-@@ -900,24 +1007,27 @@
+@@ -900,50 +1006,62 @@
int numCollect = (inargs - collectPos);
if (collectPos < 0 || numCollect < 0)
throw newIllegalArgumentException("wrong number of arguments");
@@ -897,8 +987,9 @@ diff --git a/src/share/classes/java/dyn/
+ * (after bound parameter types are dropped).
* @param target the method handle to invoke after the argument is inserted
* @param pos where to insert the argument (zero for the first)
- * @param value the argument to insert
-@@ -925,25 +1035,34 @@
+- * @param value the argument to insert
++ * @param values the series of arguments to insert
+ * @return a new method handle which inserts an additional argument,
* before calling the original method handle
*/
public static
@@ -946,7 +1037,7 @@ diff --git a/src/share/classes/java/dyn/
}
/**
-@@ -953,10 +1072,25 @@
+@@ -953,10 +1071,25 @@
* The type of the new method handle will insert the given argument
* type(s), at that position, into the original handle's type.
* <p>
@@ -973,7 +1064,7 @@ diff --git a/src/share/classes/java/dyn/
* @param target the method handle to invoke after the argument is dropped
* @param valueTypes the type(s) of the argument to drop
* @param pos which argument to drop (zero for the first)
-@@ -1040,65 +1174,123 @@
+@@ -1040,65 +1173,121 @@
/**
* <em>PROVISIONAL API, WORK IN PROGRESS:</em>
@@ -1095,8 +1186,8 @@ diff --git a/src/share/classes/java/dyn/
* }
* </pre></blockquote>
* @param target the method handle to invoke after arguments are combined
- * @param pos where the return value of {@code combiner} is to
- * be inserted as an argument to {@code target}
+- * @param pos where the return value of {@code combiner} is to
+- * be inserted as an argument to {@code target}
* @param combiner method handle to call initially on the incoming arguments
- * @return method handle which incorporates the specified dispatch logic
- * @throws IllegalArgumentException if {@code combiner} does not itself
@@ -1321,6 +1412,17 @@ diff --git a/src/share/classes/java/dyn/
+ return fromMethodDescriptorString(descriptor, loader);
}
}
+diff --git a/src/share/classes/java/dyn/package-info.java b/src/share/classes/java/dyn/package-info.java
+--- a/src/share/classes/java/dyn/package-info.java
++++ b/src/share/classes/java/dyn/package-info.java
+@@ -24,6 +24,7 @@
+ */
+
+ /**
++ * <em>PROVISIONAL API, WORK IN PROGRESS:</em>
+ * This package contains dynamic language support provided directly by
+ * the Java core class libraries and virtual machine.
+ * @author John Rose, JSR 292 EG
diff --git a/src/share/classes/sun/dyn/AdapterMethodHandle.java b/src/share/classes/sun/dyn/AdapterMethodHandle.java
--- a/src/share/classes/sun/dyn/AdapterMethodHandle.java
+++ b/src/share/classes/sun/dyn/AdapterMethodHandle.java