jdk/src/share/classes/java/lang/invoke/MethodType.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot-comp Sdiff jdk/src/share/classes/java/lang/invoke

jdk/src/share/classes/java/lang/invoke/MethodType.java

Print this page
rev 7600 : imported patch stable


  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang.invoke;
  27 
  28 import sun.invoke.util.Wrapper;
  29 import java.lang.ref.WeakReference;
  30 import java.lang.ref.Reference;
  31 import java.lang.ref.ReferenceQueue;
  32 import java.util.Arrays;
  33 import java.util.Collections;
  34 import java.util.List;
  35 import java.util.concurrent.ConcurrentMap;
  36 import java.util.concurrent.ConcurrentHashMap;
  37 import sun.invoke.util.BytecodeDescriptor;
  38 import static java.lang.invoke.MethodHandleStatics.*;

  39 import sun.invoke.util.VerifyType;
  40 
  41 /**
  42  * A method type represents the arguments and return type accepted and
  43  * returned by a method handle, or the arguments and return type passed
  44  * and expected  by a method handle caller.  Method types must be properly
  45  * matched between a method handle and all its callers,
  46  * and the JVM's operations enforce this matching at, specifically
  47  * during calls to {@link MethodHandle#invokeExact MethodHandle.invokeExact}
  48  * and {@link MethodHandle#invoke MethodHandle.invoke}, and during execution
  49  * of {@code invokedynamic} instructions.
  50  * <p>
  51  * The structure is a return type accompanied by any number of parameter types.
  52  * The types (primitive, {@code void}, and reference) are represented by {@link Class} objects.
  53  * (For ease of exposition, we treat {@code void} as if it were a type.
  54  * In fact, it denotes the absence of a return type.)
  55  * <p>
  56  * All instances of {@code MethodType} are immutable.
  57  * Two instances are completely interchangeable if they compare equal.
  58  * Equality depends on pairwise correspondence of the return and parameter types and on nothing else.


  77  * A method type may be loaded by an {@code ldc} instruction which refers
  78  * to a suitable {@code CONSTANT_MethodType} constant pool entry.
  79  * The entry refers to a {@code CONSTANT_Utf8} spelling for the descriptor string.
  80  * For more details, see the <a href="package-summary.html#mtcon">package summary</a>.
  81  * <p>
  82  * When the JVM materializes a {@code MethodType} from a descriptor string,
  83  * all classes named in the descriptor must be accessible, and will be loaded.
  84  * (But the classes need not be initialized, as is the case with a {@code CONSTANT_Class}.)
  85  * This loading may occur at any time before the {@code MethodType} object is first derived.
  86  * @author John Rose, JSR 292 EG
  87  */
  88 public final
  89 class MethodType implements java.io.Serializable {
  90     private static final long serialVersionUID = 292L;  // {rtype, {ptype...}}
  91 
  92     // The rtype and ptypes fields define the structural identity of the method type:
  93     private final Class<?>   rtype;
  94     private final Class<?>[] ptypes;
  95 
  96     // The remaining fields are caches of various sorts:
  97     private MethodTypeForm form; // erased form, plus cached data about primitives
  98     private MethodType wrapAlt;  // alternative wrapped/unwrapped version
  99     private Invokers invokers;   // cache of handy higher-order adapters
 100 
 101     /**
 102      * Check the given parameters for validity and store them into the final fields.
 103      */
 104     private MethodType(Class<?> rtype, Class<?>[] ptypes) {
 105         checkRtype(rtype);
 106         checkPtypes(ptypes);
 107         this.rtype = rtype;
 108         this.ptypes = ptypes;
 109     }
 110 
 111     /*trusted*/ MethodTypeForm form() { return form; }
 112     /*trusted*/ Class<?> rtype() { return rtype; }
 113     /*trusted*/ Class<?>[] ptypes() { return ptypes; }
 114 
 115     void setForm(MethodTypeForm f) { form = f; }
 116 
 117     /** This number, mandated by the JVM spec as 255,
 118      *  is the maximum number of <em>slots</em>
 119      *  that any Java method can receive in its argument list.




  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang.invoke;
  27 
  28 import sun.invoke.util.Wrapper;
  29 import java.lang.ref.WeakReference;
  30 import java.lang.ref.Reference;
  31 import java.lang.ref.ReferenceQueue;
  32 import java.util.Arrays;
  33 import java.util.Collections;
  34 import java.util.List;
  35 import java.util.concurrent.ConcurrentMap;
  36 import java.util.concurrent.ConcurrentHashMap;
  37 import sun.invoke.util.BytecodeDescriptor;
  38 import static java.lang.invoke.MethodHandleStatics.*;
  39 import sun.invoke.Stable;
  40 import sun.invoke.util.VerifyType;
  41 
  42 /**
  43  * A method type represents the arguments and return type accepted and
  44  * returned by a method handle, or the arguments and return type passed
  45  * and expected  by a method handle caller.  Method types must be properly
  46  * matched between a method handle and all its callers,
  47  * and the JVM's operations enforce this matching at, specifically
  48  * during calls to {@link MethodHandle#invokeExact MethodHandle.invokeExact}
  49  * and {@link MethodHandle#invoke MethodHandle.invoke}, and during execution
  50  * of {@code invokedynamic} instructions.
  51  * <p>
  52  * The structure is a return type accompanied by any number of parameter types.
  53  * The types (primitive, {@code void}, and reference) are represented by {@link Class} objects.
  54  * (For ease of exposition, we treat {@code void} as if it were a type.
  55  * In fact, it denotes the absence of a return type.)
  56  * <p>
  57  * All instances of {@code MethodType} are immutable.
  58  * Two instances are completely interchangeable if they compare equal.
  59  * Equality depends on pairwise correspondence of the return and parameter types and on nothing else.


  78  * A method type may be loaded by an {@code ldc} instruction which refers
  79  * to a suitable {@code CONSTANT_MethodType} constant pool entry.
  80  * The entry refers to a {@code CONSTANT_Utf8} spelling for the descriptor string.
  81  * For more details, see the <a href="package-summary.html#mtcon">package summary</a>.
  82  * <p>
  83  * When the JVM materializes a {@code MethodType} from a descriptor string,
  84  * all classes named in the descriptor must be accessible, and will be loaded.
  85  * (But the classes need not be initialized, as is the case with a {@code CONSTANT_Class}.)
  86  * This loading may occur at any time before the {@code MethodType} object is first derived.
  87  * @author John Rose, JSR 292 EG
  88  */
  89 public final
  90 class MethodType implements java.io.Serializable {
  91     private static final long serialVersionUID = 292L;  // {rtype, {ptype...}}
  92 
  93     // The rtype and ptypes fields define the structural identity of the method type:
  94     private final Class<?>   rtype;
  95     private final Class<?>[] ptypes;
  96 
  97     // The remaining fields are caches of various sorts:
  98     private @Stable MethodTypeForm form; // erased form, plus cached data about primitives
  99     private @Stable MethodType wrapAlt;  // alternative wrapped/unwrapped version
 100     private @Stable Invokers invokers;   // cache of handy higher-order adapters
 101 
 102     /**
 103      * Check the given parameters for validity and store them into the final fields.
 104      */
 105     private MethodType(Class<?> rtype, Class<?>[] ptypes) {
 106         checkRtype(rtype);
 107         checkPtypes(ptypes);
 108         this.rtype = rtype;
 109         this.ptypes = ptypes;
 110     }
 111 
 112     /*trusted*/ MethodTypeForm form() { return form; }
 113     /*trusted*/ Class<?> rtype() { return rtype; }
 114     /*trusted*/ Class<?>[] ptypes() { return ptypes; }
 115 
 116     void setForm(MethodTypeForm f) { form = f; }
 117 
 118     /** This number, mandated by the JVM spec as 255,
 119      *  is the maximum number of <em>slots</em>
 120      *  that any Java method can receive in its argument list.


jdk/src/share/classes/java/lang/invoke/MethodType.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File