34 import sun.dyn.MethodTypeImpl; |
34 import sun.dyn.MethodTypeImpl; |
35 import sun.dyn.util.BytecodeDescriptor; |
35 import sun.dyn.util.BytecodeDescriptor; |
36 import static sun.dyn.MemberName.newIllegalArgumentException; |
36 import static sun.dyn.MemberName.newIllegalArgumentException; |
37 |
37 |
38 /** |
38 /** |
39 * Run-time token used to match call sites with method handles. |
39 * A method type represents the arguments and return type accepted and |
|
40 * returned by a method handle, or the arguments and return type passed |
|
41 * and expected by a method handle caller. Method types must be properly |
|
42 * matched between a method handle and all its callers, |
|
43 * and the JVM's operations enforce this matching at all times. |
|
44 * <p> |
40 * The structure is a return type accompanied by any number of parameter types. |
45 * The structure is a return type accompanied by any number of parameter types. |
41 * The types (primitive, void, and reference) are represented by Class objects. |
46 * The types (primitive, void, and reference) are represented by Class objects. |
|
47 * <p> |
42 * All instances of <code>MethodType</code> are immutable. |
48 * All instances of <code>MethodType</code> are immutable. |
43 * Two instances are completely interchangeable if they compare equal. |
49 * Two instances are completely interchangeable if they compare equal. |
44 * Equality depends exactly on the return and parameter types. |
50 * Equality depends on pairwise correspondence of the return and parameter types and on nothing else. |
45 * <p> |
51 * <p> |
46 * This type can be created only by factory methods, which manage interning. |
52 * This type can be created only by factory methods. |
47 * |
53 * All factory methods may cache values, though caching is not guaranteed. |
|
54 * <p> |
|
55 * Note: Like classes and strings, method types can be represented directly |
|
56 * as constants to be loaded by {@code ldc} bytecodes. |
48 * @author John Rose, JSR 292 EG |
57 * @author John Rose, JSR 292 EG |
49 */ |
58 */ |
50 public final |
59 public final |
51 class MethodType { |
60 class MethodType { |
52 private final Class<?> rtype; |
61 private final Class<?> rtype; |
107 static final Class<?>[] NO_PTYPES = {}; |
116 static final Class<?>[] NO_PTYPES = {}; |
108 |
117 |
109 /** Find or create an instance of the given method type. |
118 /** Find or create an instance of the given method type. |
110 * @param rtype the return type |
119 * @param rtype the return type |
111 * @param ptypes the parameter types |
120 * @param ptypes the parameter types |
112 * @return the interned method type with the given parts |
121 * @return a method type with the given parts |
113 * @throws NullPointerException if rtype or any ptype is null |
122 * @throws NullPointerException if rtype or any ptype is null |
114 * @throws IllegalArgumentException if any of the ptypes is void |
123 * @throws IllegalArgumentException if any of the ptypes is void |
115 */ |
124 */ |
116 public static |
125 public static |
117 MethodType methodType(Class<?> rtype, Class<?>[] ptypes) { |
126 MethodType methodType(Class<?> rtype, Class<?>[] ptypes) { |
624 public int returnSlotCount() { |
633 public int returnSlotCount() { |
625 return form.returnSlotCount(); |
634 return form.returnSlotCount(); |
626 } |
635 } |
627 |
636 |
628 /** Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[])}. |
637 /** Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[])}. |
629 * Find or create an instance (interned) of the given method type. |
638 * Find or create an instance of the given method type. |
630 * Any class or interface name embedded in the signature string |
639 * Any class or interface name embedded in the signature string |
631 * will be resolved by calling {@link ClassLoader#loadClass(java.lang.String)} |
640 * will be resolved by calling {@link ClassLoader#loadClass(java.lang.String)} |
632 * on the given loader (or if it is null, on the system class loader). |
641 * on the given loader (or if it is null, on the system class loader). |
633 * <p> |
642 * <p> |
634 * Note that it is possible to build method types which cannot be |
643 * Note that it is possible to build method types which cannot be |