--- a/indy.patch Fri Jun 19 03:03:53 2009 -0700
+++ b/indy.patch Fri Jun 19 03:39:09 2009 -0700
@@ -449,7 +449,7 @@ 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
-@@ -97,6 +111,43 @@
+@@ -97,6 +111,59 @@
* 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.
@@ -489,11 +489,27 @@ diff --git a/src/share/classes/java/dyn/
+ * 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}.)
++ * (This type parameter may be a primitive, and it defaults to {@code Object}.)
++ * <p>
++ * <em>A note on generic typing:</em> Method handles do not represent
++ * their function types in terms of Java parameterized (generic) types,
++ * because there are three mismatches between function types and parameterized
++ * Java types.
++ * <ol>
++ * <li>Method types range over all possible arities,
++ * from no arguments to an arbitrary number of arguments.
++ * Generics are not variadic, and so cannot represent this.</li>
++ * <li>Method types can specify arguments of primitive types,
++ * which Java generic types cannot range over.</li>
++ * <li>Higher order functions over method handles (combinators) are
++ * often generic across a wide range of function types, including
++ * those of multiple arities. It is impossible to represent such
++ * genericity with a Java type parameter.</li>
++ * </ol>
*
* @see MethodType
* @see MethodHandles
-@@ -107,10 +158,12 @@
+@@ -107,10 +174,12 @@
// with a JVM change which moves the required hidden state onto this class.
extends MethodHandleImpl
{
@@ -509,7 +525,7 @@ diff --git a/src/share/classes/java/dyn/
/**
* Report the type of this method handle.
-@@ -130,6 +183,33 @@
+@@ -130,6 +199,33 @@
*/
protected MethodHandle(Access token, MethodType type) {
super(token);
@@ -546,15 +562,32 @@ diff --git a/src/share/classes/java/dyn/
diff --git a/src/share/classes/java/dyn/MethodHandles.java b/src/share/classes/java/dyn/MethodHandles.java
--- a/src/share/classes/java/dyn/MethodHandles.java
+++ b/src/share/classes/java/dyn/MethodHandles.java
-@@ -53,7 +53,6 @@
- * Generics are not variadic, and so cannot represent this.</li>
- * <li>Method types can specify arguments of primitive types,
- * which Java generic types cannot range over.</li>
+@@ -44,17 +44,14 @@
+
+ /**
+ * Fundamental operations and utilities for MethodHandle.
++ * They fall into several categories:
++ * <ul>
++ * <li>Reifying methods and fields. This is subject to access checks.
++ * <li>Invoking method handles on dynamically typed arguments and/or varargs arrays.
++ * <li>Combining or transforming pre-existing method handles into new ones.
++ * <li>Miscellaneous emulation of common JVM operations or control flow patterns.
++ * </ul>
+ * <p>
+- * <em>API Note:</em> The matching of method types in this API cannot
+- * be completely checked by Java's generic type system for three reasons:
+- * <ol>
+- * <li>Method types range over all possible arities,
+- * from no arguments to an arbitrary number of arguments.
+- * Generics are not variadic, and so cannot represent this.</li>
+- * <li>Method types can specify arguments of primitive types,
+- * which Java generic types cannot range over.</li>
- * <li>Method types can optionally specify varargs (ellipsis).</li>
- * </ol>
+- * </ol>
* @author John Rose, JSR 292 EG
*/
-@@ -68,12 +67,22 @@
+ public class MethodHandles {
+@@ -68,12 +65,22 @@
//// Method handle creation from ordinary methods.
@@ -578,7 +611,7 @@ diff --git a/src/share/classes/java/dyn/
* A factory object for creating method handles, when the creation
* requires access checking. Method handles do not perform
* access checks when they are called; this is a major difference
-@@ -121,7 +130,8 @@
+@@ -121,7 +128,8 @@
/** Which class is performing the lookup? It is this class against
* which checks are performed for visibility and access permissions.
* <p>
@@ -588,7 +621,7 @@ diff --git a/src/share/classes/java/dyn/
*/
public Class<?> lookupClass() {
return lookupClass;
-@@ -135,23 +145,46 @@
+@@ -135,23 +143,46 @@
* an access$N method.
*/
Lookup() {
@@ -640,7 +673,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 +211,16 @@
+@@ -178,12 +209,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.
@@ -657,7 +690,7 @@ diff --git a/src/share/classes/java/dyn/
* 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 +233,11 @@
+@@ -196,10 +231,11 @@
*/
public
MethodHandle findStatic(Class<?> defc, String name, MethodType type) throws NoAccessException {
@@ -672,7 +705,7 @@ diff --git a/src/share/classes/java/dyn/
}
/**
-@@ -228,9 +266,10 @@
+@@ -228,9 +264,10 @@
* @exception NoAccessException if the method does not exist or access checking fails
*/
public MethodHandle findVirtual(Class<?> defc, String name, MethodType type) throws NoAccessException {
@@ -686,7 +719,7 @@ diff --git a/src/share/classes/java/dyn/
}
/**
-@@ -259,15 +298,17 @@
+@@ -259,15 +296,17 @@
*/
public MethodHandle findSpecial(Class<?> defc, String name, MethodType type,
Class<?> specialCaller) throws NoAccessException {
@@ -709,7 +742,7 @@ diff --git a/src/share/classes/java/dyn/
}
/**
-@@ -275,13 +316,19 @@
+@@ -275,13 +314,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.
@@ -733,7 +766,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 +339,18 @@
+@@ -292,16 +337,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);
@@ -756,7 +789,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 +365,11 @@
+@@ -316,10 +363,11 @@
* @exception NoAccessException if access checking fails
*/
public MethodHandle unreflect(Method m) throws NoAccessException {
@@ -769,7 +802,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 +383,41 @@
+@@ -333,37 +381,41 @@
* @exception NoAccessException if access checking fails
*/
public MethodHandle unreflectSpecial(Method m, Class<?> specialCaller) throws NoAccessException {
@@ -820,7 +853,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 +425,17 @@
+@@ -371,16 +423,17 @@
* @exception NoAccessException if access checking fails
*/
public MethodHandle unreflectGetter(Field f) throws NoAccessException {
@@ -842,7 +875,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 +443,63 @@
+@@ -388,59 +441,63 @@
* @exception NoAccessException if access checking fails
*/
public MethodHandle unreflectSetter(Field f) throws NoAccessException {
@@ -925,7 +958,7 @@ diff --git a/src/share/classes/java/dyn/
}
/**
-@@ -472,7 +531,6 @@
+@@ -472,7 +529,6 @@
return MethodHandleImpl.accessArrayElement(IMPL_TOKEN, arrayClass, true);
}
@@ -933,7 +966,7 @@ diff --git a/src/share/classes/java/dyn/
/// method handle invocation (reflective style)
/**
-@@ -500,110 +558,203 @@
+@@ -500,110 +556,203 @@
* or forced to null if the return type is void.
* <p>
* This call is a convenience method for the following code:
@@ -1180,7 +1213,7 @@ diff --git a/src/share/classes/java/dyn/
* @param type the desired target type
* @return a method handle suitable for invoking any method handle of the given type
*/
-@@ -612,6 +763,29 @@
+@@ -612,6 +761,29 @@
return invokers(type).exactInvoker();
}
@@ -1210,7 +1243,7 @@ diff --git a/src/share/classes/java/dyn/
static private Invokers invokers(MethodType type) {
return MethodTypeImpl.invokers(IMPL_TOKEN, type);
}
-@@ -690,12 +864,10 @@
+@@ -690,12 +862,10 @@
/**
* <em>PROVISIONAL API, WORK IN PROGRESS:</em>
* Produce a method handle which adapts the type of the
@@ -1226,7 +1259,7 @@ diff --git a/src/share/classes/java/dyn/
* <p>
* If the original type and new type are equal, returns target.
* <p>
-@@ -703,26 +875,15 @@
+@@ -703,26 +873,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.
@@ -1259,7 +1292,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 +906,9 @@
+@@ -745,9 +904,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.
@@ -1272,7 +1305,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 +1033,14 @@
+@@ -872,20 +1031,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
@@ -1295,7 +1328,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,50 +1055,66 @@
+@@ -900,50 +1053,66 @@
int numCollect = (inargs - collectPos);
if (collectPos < 0 || numCollect < 0)
throw newIllegalArgumentException("wrong number of arguments");
@@ -1387,7 +1420,7 @@ diff --git a/src/share/classes/java/dyn/
}
/**
-@@ -953,10 +1124,25 @@
+@@ -953,10 +1122,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>
@@ -1414,7 +1447,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)
-@@ -980,6 +1166,131 @@
+@@ -980,6 +1164,131 @@
/**
* <em>PROVISIONAL API, WORK IN PROGRESS:</em>
@@ -1546,7 +1579,7 @@ diff --git a/src/share/classes/java/dyn/
* Make a method handle which adapts a target method handle,
* by guarding it with a test, a boolean-valued method handle.
* If the guard fails, a fallback handle is called instead.
-@@ -1040,65 +1351,100 @@
+@@ -1040,65 +1349,100 @@
/**
* <em>PROVISIONAL API, WORK IN PROGRESS:</em>