2009-05-05 22:40:09 -07:00
|
|
|
/*
|
2011-03-18 00:03:24 -07:00
|
|
|
* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
|
2009-05-05 22:40:09 -07:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
2010-05-25 15:58:33 -07:00
|
|
|
* published by the Free Software Foundation. Oracle designates this
|
2009-05-05 22:40:09 -07:00
|
|
|
* particular file as subject to the "Classpath" exception as provided
|
2010-05-25 15:58:33 -07:00
|
|
|
* by Oracle in the LICENSE file that accompanied this code.
|
2009-05-05 22:40:09 -07:00
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-25 15:58:33 -07:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2009-05-05 22:40:09 -07:00
|
|
|
*/
|
|
|
|
|
2011-03-23 23:02:31 -07:00
|
|
|
package java.lang.invoke;
|
2009-05-05 22:40:09 -07:00
|
|
|
|
2011-03-23 23:02:31 -07:00
|
|
|
import java.lang.invoke.MethodHandles.Lookup;
|
2009-05-05 22:40:09 -07:00
|
|
|
import java.lang.reflect.AccessibleObject;
|
|
|
|
import java.lang.reflect.Field;
|
2011-03-23 23:02:31 -07:00
|
|
|
import static java.lang.invoke.MethodHandleNatives.Constants.*;
|
|
|
|
import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
|
2009-05-05 22:40:09 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The JVM interface for the method handles package is all here.
|
2010-04-30 23:48:23 -07:00
|
|
|
* This is an interface internal and private to an implemetantion of JSR 292.
|
|
|
|
* <em>This class is not part of the JSR 292 standard.</em>
|
2009-05-05 22:40:09 -07:00
|
|
|
* @author jrose
|
|
|
|
*/
|
|
|
|
class MethodHandleNatives {
|
|
|
|
|
|
|
|
private MethodHandleNatives() { } // static only
|
|
|
|
|
|
|
|
/// MethodName support
|
|
|
|
|
|
|
|
static native void init(MemberName self, Object ref);
|
|
|
|
static native void expand(MemberName self);
|
|
|
|
static native void resolve(MemberName self, Class<?> caller);
|
|
|
|
static native int getMembers(Class<?> defc, String matchName, String matchSig,
|
|
|
|
int matchFlags, Class<?> caller, int skip, MemberName[] results);
|
|
|
|
|
|
|
|
/// MethodHandle support
|
|
|
|
|
|
|
|
/** Initialize the method handle to adapt the call. */
|
|
|
|
static native void init(AdapterMethodHandle self, MethodHandle target, int argnum);
|
|
|
|
/** Initialize the method handle to call the correct method, directly. */
|
|
|
|
static native void init(BoundMethodHandle self, Object target, int argnum);
|
|
|
|
/** Initialize the method handle to call as if by an invoke* instruction. */
|
|
|
|
static native void init(DirectMethodHandle self, Object ref, boolean doDispatch, Class<?> caller);
|
|
|
|
|
|
|
|
/** Initialize a method type, once per form. */
|
|
|
|
static native void init(MethodType self);
|
|
|
|
|
2010-04-30 23:48:23 -07:00
|
|
|
/** Tell the JVM about a class's bootstrap method. */
|
|
|
|
static native void registerBootstrap(Class<?> caller, MethodHandle bootstrapMethod);
|
|
|
|
|
|
|
|
/** Ask the JVM about a class's bootstrap method. */
|
|
|
|
static native MethodHandle getBootstrap(Class<?> caller);
|
|
|
|
|
2009-05-05 22:40:09 -07:00
|
|
|
/** Tell the JVM that we need to change the target of an invokedynamic. */
|
2010-04-30 23:48:23 -07:00
|
|
|
static native void setCallSiteTarget(CallSite site, MethodHandle target);
|
2009-05-05 22:40:09 -07:00
|
|
|
|
|
|
|
/** Fetch the vmtarget field.
|
|
|
|
* It will be sanitized as necessary to avoid exposing non-Java references.
|
|
|
|
* This routine is for debugging and reflection.
|
|
|
|
*/
|
|
|
|
static native Object getTarget(MethodHandle self, int format);
|
|
|
|
|
|
|
|
/** Fetch the name of the handled method, if available.
|
|
|
|
* This routine is for debugging and reflection.
|
|
|
|
*/
|
|
|
|
static MemberName getMethodName(MethodHandle self) {
|
|
|
|
return (MemberName) getTarget(self, ETF_METHOD_NAME);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Fetch the reflective version of the handled method, if available.
|
|
|
|
*/
|
|
|
|
static AccessibleObject getTargetMethod(MethodHandle self) {
|
|
|
|
return (AccessibleObject) getTarget(self, ETF_REFLECT_METHOD);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Fetch the target of this method handle.
|
2010-01-07 16:16:45 -08:00
|
|
|
* If it directly targets a method, return a MemberName for the method.
|
2009-05-05 22:40:09 -07:00
|
|
|
* If it is chained to another method handle, return that handle.
|
|
|
|
*/
|
|
|
|
static Object getTargetInfo(MethodHandle self) {
|
|
|
|
return getTarget(self, ETF_HANDLE_OR_METHOD_NAME);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Object[] makeTarget(Class<?> defc, String name, String sig, int mods, Class<?> refc) {
|
|
|
|
return new Object[] { defc, name, sig, mods, refc };
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Fetch MH-related JVM parameter.
|
|
|
|
* which=0 retrieves MethodHandlePushLimit
|
|
|
|
* which=1 retrieves stack slot push size (in address units)
|
|
|
|
*/
|
|
|
|
static native int getConstant(int which);
|
|
|
|
|
|
|
|
/** Java copy of MethodHandlePushLimit in range 2..255. */
|
|
|
|
static final int JVM_PUSH_LIMIT;
|
|
|
|
/** JVM stack motion (in words) after one slot is pushed, usually -1.
|
|
|
|
*/
|
|
|
|
static final int JVM_STACK_MOVE_UNIT;
|
|
|
|
|
2010-04-30 23:48:23 -07:00
|
|
|
/** Which conv-ops are implemented by the JVM? */
|
|
|
|
static final int CONV_OP_IMPLEMENTED_MASK;
|
2011-05-12 19:27:49 -07:00
|
|
|
/** Derived mode flag. Only false on some old JVM implementations. */
|
|
|
|
static final boolean HAVE_RICOCHET_FRAMES;
|
2010-04-30 23:48:23 -07:00
|
|
|
|
2011-06-14 22:47:09 -07:00
|
|
|
static final int OP_ROT_ARGS_DOWN_LIMIT_BIAS;
|
|
|
|
|
2009-05-05 22:40:09 -07:00
|
|
|
private static native void registerNatives();
|
|
|
|
static {
|
2011-06-14 22:47:09 -07:00
|
|
|
registerNatives();
|
|
|
|
int k;
|
|
|
|
JVM_PUSH_LIMIT = getConstant(Constants.GC_JVM_PUSH_LIMIT);
|
|
|
|
JVM_STACK_MOVE_UNIT = getConstant(Constants.GC_JVM_STACK_MOVE_UNIT);
|
|
|
|
k = getConstant(Constants.GC_CONV_OP_IMPLEMENTED_MASK);
|
|
|
|
CONV_OP_IMPLEMENTED_MASK = (k != 0) ? k : DEFAULT_CONV_OP_IMPLEMENTED_MASK;
|
|
|
|
k = getConstant(Constants.GC_OP_ROT_ARGS_DOWN_LIMIT_BIAS);
|
|
|
|
OP_ROT_ARGS_DOWN_LIMIT_BIAS = (k != 0) ? (byte)k : -1;
|
|
|
|
HAVE_RICOCHET_FRAMES = (CONV_OP_IMPLEMENTED_MASK & (1<<OP_COLLECT_ARGS)) != 0;
|
|
|
|
//sun.reflect.Reflection.registerMethodsToFilter(MethodHandleImpl.class, "init");
|
2009-05-05 22:40:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// All compile-time constants go here.
|
|
|
|
// There is an opportunity to check them against the JVM's idea of them.
|
|
|
|
static class Constants {
|
|
|
|
Constants() { } // static only
|
|
|
|
// MethodHandleImpl
|
|
|
|
static final int // for getConstant
|
|
|
|
GC_JVM_PUSH_LIMIT = 0,
|
2010-04-30 23:48:23 -07:00
|
|
|
GC_JVM_STACK_MOVE_UNIT = 1,
|
2011-06-14 22:47:09 -07:00
|
|
|
GC_CONV_OP_IMPLEMENTED_MASK = 2,
|
|
|
|
GC_OP_ROT_ARGS_DOWN_LIMIT_BIAS = 3;
|
2009-05-05 22:40:09 -07:00
|
|
|
static final int
|
|
|
|
ETF_HANDLE_OR_METHOD_NAME = 0, // all available data (immediate MH or method)
|
|
|
|
ETF_DIRECT_HANDLE = 1, // ultimate method handle (will be a DMH, may be self)
|
|
|
|
ETF_METHOD_NAME = 2, // ultimate method as MemberName
|
|
|
|
ETF_REFLECT_METHOD = 3; // ultimate method as java.lang.reflect object (sans refClass)
|
|
|
|
|
|
|
|
// MemberName
|
|
|
|
// The JVM uses values of -2 and above for vtable indexes.
|
|
|
|
// Field values are simple positive offsets.
|
|
|
|
// Ref: src/share/vm/oops/methodOop.hpp
|
|
|
|
// This value is negative enough to avoid such numbers,
|
|
|
|
// but not too negative.
|
|
|
|
static final int
|
|
|
|
MN_IS_METHOD = 0x00010000, // method (not constructor)
|
|
|
|
MN_IS_CONSTRUCTOR = 0x00020000, // constructor
|
|
|
|
MN_IS_FIELD = 0x00040000, // field
|
|
|
|
MN_IS_TYPE = 0x00080000, // nested type
|
|
|
|
MN_SEARCH_SUPERCLASSES = 0x00100000, // for MHN.getMembers
|
|
|
|
MN_SEARCH_INTERFACES = 0x00200000, // for MHN.getMembers
|
|
|
|
VM_INDEX_UNINITIALIZED = -99;
|
|
|
|
|
2011-03-23 23:02:31 -07:00
|
|
|
// BoundMethodHandle
|
|
|
|
/** Constants for decoding the vmargslot field, which contains 2 values. */
|
|
|
|
static final int
|
|
|
|
ARG_SLOT_PUSH_SHIFT = 16,
|
|
|
|
ARG_SLOT_MASK = (1<<ARG_SLOT_PUSH_SHIFT)-1;
|
|
|
|
|
2009-05-05 22:40:09 -07:00
|
|
|
// AdapterMethodHandle
|
|
|
|
/** Conversions recognized by the JVM.
|
2011-03-23 23:02:31 -07:00
|
|
|
* They must align with the constants in java.lang.invoke.AdapterMethodHandle,
|
2009-05-05 22:40:09 -07:00
|
|
|
* in the JVM file hotspot/src/share/vm/classfile/javaClasses.hpp.
|
|
|
|
*/
|
|
|
|
static final int
|
|
|
|
OP_RETYPE_ONLY = 0x0, // no argument changes; straight retype
|
2011-05-12 19:27:49 -07:00
|
|
|
OP_RETYPE_RAW = 0x1, // straight retype, trusted (void->int, Object->T)
|
2010-01-07 16:16:45 -08:00
|
|
|
OP_CHECK_CAST = 0x2, // ref-to-ref conversion; requires a Class argument
|
|
|
|
OP_PRIM_TO_PRIM = 0x3, // converts from one primitive to another
|
|
|
|
OP_REF_TO_PRIM = 0x4, // unboxes a wrapper to produce a primitive
|
2011-05-12 19:27:49 -07:00
|
|
|
OP_PRIM_TO_REF = 0x5, // boxes a primitive into a wrapper
|
2010-01-07 16:16:45 -08:00
|
|
|
OP_SWAP_ARGS = 0x6, // swap arguments (vminfo is 2nd arg)
|
|
|
|
OP_ROT_ARGS = 0x7, // rotate arguments (vminfo is displaced arg)
|
|
|
|
OP_DUP_ARGS = 0x8, // duplicates one or more arguments (at TOS)
|
|
|
|
OP_DROP_ARGS = 0x9, // remove one or more argument slots
|
2011-05-12 19:27:49 -07:00
|
|
|
OP_COLLECT_ARGS = 0xA, // combine arguments using an auxiliary function
|
2010-01-07 16:16:45 -08:00
|
|
|
OP_SPREAD_ARGS = 0xB, // expand in place a varargs array (of known size)
|
2011-05-12 19:27:49 -07:00
|
|
|
OP_FOLD_ARGS = 0xC, // combine but do not remove arguments; prepend result
|
|
|
|
//OP_UNUSED_13 = 0xD, // unused code, perhaps for reified argument lists
|
2010-01-07 16:16:45 -08:00
|
|
|
CONV_OP_LIMIT = 0xE; // limit of CONV_OP enumeration
|
2009-05-05 22:40:09 -07:00
|
|
|
/** Shift and mask values for decoding the AMH.conversion field.
|
|
|
|
* These numbers are shared with the JVM for creating AMHs.
|
|
|
|
*/
|
|
|
|
static final int
|
|
|
|
CONV_OP_MASK = 0xF00, // this nybble contains the conversion op field
|
2011-05-12 19:27:49 -07:00
|
|
|
CONV_TYPE_MASK = 0x0F, // fits T_ADDRESS and below
|
2009-05-05 22:40:09 -07:00
|
|
|
CONV_VMINFO_MASK = 0x0FF, // LSB is reserved for JVM use
|
|
|
|
CONV_VMINFO_SHIFT = 0, // position of bits in CONV_VMINFO_MASK
|
|
|
|
CONV_OP_SHIFT = 8, // position of bits in CONV_OP_MASK
|
|
|
|
CONV_DEST_TYPE_SHIFT = 12, // byte 2 has the adapter BasicType (if needed)
|
|
|
|
CONV_SRC_TYPE_SHIFT = 16, // byte 2 has the source BasicType (if needed)
|
|
|
|
CONV_STACK_MOVE_SHIFT = 20, // high 12 bits give signed SP change
|
|
|
|
CONV_STACK_MOVE_MASK = (1 << (32 - CONV_STACK_MOVE_SHIFT)) - 1;
|
|
|
|
|
|
|
|
/** Which conv-ops are implemented by the JVM? */
|
2010-04-30 23:48:23 -07:00
|
|
|
static final int DEFAULT_CONV_OP_IMPLEMENTED_MASK =
|
|
|
|
// Value to use if the corresponding JVM query fails.
|
2009-05-05 22:40:09 -07:00
|
|
|
((1<<OP_RETYPE_ONLY)
|
2010-01-07 16:16:45 -08:00
|
|
|
|(1<<OP_RETYPE_RAW)
|
2009-05-05 22:40:09 -07:00
|
|
|
|(1<<OP_CHECK_CAST)
|
|
|
|
|(1<<OP_PRIM_TO_PRIM)
|
|
|
|
|(1<<OP_REF_TO_PRIM)
|
|
|
|
|(1<<OP_SWAP_ARGS)
|
|
|
|
|(1<<OP_ROT_ARGS)
|
|
|
|
|(1<<OP_DUP_ARGS)
|
|
|
|
|(1<<OP_DROP_ARGS)
|
2010-04-30 23:48:23 -07:00
|
|
|
//|(1<<OP_SPREAD_ARGS)
|
2009-05-05 22:40:09 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Basic types as encoded in the JVM. These code values are not
|
|
|
|
* intended for use outside this class. They are used as part of
|
|
|
|
* a private interface between the JVM and this class.
|
|
|
|
*/
|
|
|
|
static final int
|
|
|
|
T_BOOLEAN = 4,
|
|
|
|
T_CHAR = 5,
|
|
|
|
T_FLOAT = 6,
|
|
|
|
T_DOUBLE = 7,
|
|
|
|
T_BYTE = 8,
|
|
|
|
T_SHORT = 9,
|
|
|
|
T_INT = 10,
|
|
|
|
T_LONG = 11,
|
|
|
|
T_OBJECT = 12,
|
|
|
|
//T_ARRAY = 13
|
2011-05-12 19:27:49 -07:00
|
|
|
T_VOID = 14,
|
2009-05-05 22:40:09 -07:00
|
|
|
//T_ADDRESS = 15
|
2011-05-12 19:27:49 -07:00
|
|
|
T_ILLEGAL = 99;
|
2010-06-08 23:08:56 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.
|
|
|
|
*/
|
|
|
|
static final int
|
|
|
|
REF_getField = 1,
|
|
|
|
REF_getStatic = 2,
|
|
|
|
REF_putField = 3,
|
|
|
|
REF_putStatic = 4,
|
|
|
|
REF_invokeVirtual = 5,
|
|
|
|
REF_invokeStatic = 6,
|
|
|
|
REF_invokeSpecial = 7,
|
|
|
|
REF_newInvokeSpecial = 8,
|
|
|
|
REF_invokeInterface = 9;
|
2009-05-05 22:40:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private static native int getNamedCon(int which, Object[] name);
|
|
|
|
static boolean verifyConstants() {
|
|
|
|
Object[] box = { null };
|
|
|
|
for (int i = 0; ; i++) {
|
|
|
|
box[0] = null;
|
|
|
|
int vmval = getNamedCon(i, box);
|
|
|
|
if (box[0] == null) break;
|
|
|
|
String name = (String) box[0];
|
|
|
|
try {
|
|
|
|
Field con = Constants.class.getDeclaredField(name);
|
|
|
|
int jval = con.getInt(null);
|
2011-05-12 19:27:49 -07:00
|
|
|
if (jval == vmval) continue;
|
|
|
|
String err = (name+": JVM has "+vmval+" while Java has "+jval);
|
|
|
|
if (name.equals("CONV_OP_LIMIT")) {
|
|
|
|
System.err.println("warning: "+err);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
throw new InternalError(err);
|
2009-05-05 22:40:09 -07:00
|
|
|
} catch (Exception ex) {
|
2011-05-12 19:27:49 -07:00
|
|
|
if (ex instanceof NoSuchFieldException) {
|
|
|
|
String err = (name+": JVM has "+vmval+" which Java does not define");
|
|
|
|
// ignore exotic ops the JVM cares about; we just wont issue them
|
|
|
|
if (name.startsWith("OP_") || name.startsWith("GC_")) {
|
|
|
|
System.err.println("warning: "+err);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2009-05-05 22:40:09 -07:00
|
|
|
throw new InternalError(name+": access failed, got "+ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
static {
|
2011-05-12 19:27:49 -07:00
|
|
|
assert(verifyConstants());
|
2009-05-05 22:40:09 -07:00
|
|
|
}
|
2010-04-30 23:48:23 -07:00
|
|
|
|
|
|
|
// Up-calls from the JVM.
|
|
|
|
// These must NOT be public.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The JVM is linking an invokedynamic instruction. Create a reified call site for it.
|
|
|
|
*/
|
|
|
|
static CallSite makeDynamicCallSite(MethodHandle bootstrapMethod,
|
|
|
|
String name, MethodType type,
|
|
|
|
Object info,
|
|
|
|
MemberName callerMethod, int callerBCI) {
|
2011-03-18 00:03:24 -07:00
|
|
|
return CallSite.makeSite(bootstrapMethod, name, type, info, callerMethod, callerBCI);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by the JVM to check the length of a spread array.
|
|
|
|
*/
|
|
|
|
static void checkSpreadArgument(Object av, int n) {
|
|
|
|
MethodHandleStatics.checkSpreadArgument(av, n);
|
2010-04-30 23:48:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The JVM wants a pointer to a MethodType. Oblige it by finding or creating one.
|
|
|
|
*/
|
|
|
|
static MethodType findMethodHandleType(Class<?> rtype, Class<?>[] ptypes) {
|
2011-03-18 00:03:24 -07:00
|
|
|
return MethodType.makeImpl(rtype, ptypes, true);
|
2010-04-30 23:48:23 -07:00
|
|
|
}
|
|
|
|
|
2010-10-30 21:02:30 -07:00
|
|
|
/**
|
2011-05-12 19:27:33 -07:00
|
|
|
* The JVM wants to use a MethodType with inexact invoke. Give the runtime fair warning.
|
2010-10-30 21:02:30 -07:00
|
|
|
*/
|
|
|
|
static void notifyGenericMethodType(MethodType type) {
|
2011-03-18 00:03:24 -07:00
|
|
|
type.form().notifyGenericMethodType();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The JVM wants to raise an exception. Here's the path.
|
|
|
|
*/
|
|
|
|
static void raiseException(int code, Object actual, Object required) {
|
2011-05-12 19:27:49 -07:00
|
|
|
String message = null;
|
|
|
|
switch (code) {
|
|
|
|
case 190: // arraylength
|
|
|
|
try {
|
|
|
|
String reqLength = "";
|
|
|
|
if (required instanceof AdapterMethodHandle) {
|
|
|
|
int conv = ((AdapterMethodHandle)required).getConversion();
|
|
|
|
int spChange = AdapterMethodHandle.extractStackMove(conv);
|
|
|
|
reqLength = " of length "+(spChange+1);
|
|
|
|
}
|
|
|
|
int actualLength = actual == null ? 0 : java.lang.reflect.Array.getLength(actual);
|
|
|
|
message = "required array"+reqLength+", but encountered wrong length "+actualLength;
|
|
|
|
break;
|
|
|
|
} catch (IllegalArgumentException ex) {
|
|
|
|
}
|
|
|
|
required = Object[].class; // should have been an array
|
|
|
|
code = 192; // checkcast
|
|
|
|
break;
|
2011-06-01 23:56:43 -07:00
|
|
|
case 191: // athrow
|
|
|
|
// JVM is asking us to wrap an exception which happened during resolving
|
|
|
|
if (required == BootstrapMethodError.class) {
|
|
|
|
throw new BootstrapMethodError((Throwable) actual);
|
|
|
|
}
|
|
|
|
break;
|
2011-05-12 19:27:49 -07:00
|
|
|
}
|
2011-03-18 00:03:24 -07:00
|
|
|
// disregard the identity of the actual object, if it is not a class:
|
2011-05-12 19:27:49 -07:00
|
|
|
if (message == null) {
|
|
|
|
if (!(actual instanceof Class) && !(actual instanceof MethodType))
|
|
|
|
actual = actual.getClass();
|
|
|
|
if (actual != null)
|
|
|
|
message = "required "+required+" but encountered "+actual;
|
|
|
|
else
|
|
|
|
message = "required "+required;
|
|
|
|
}
|
2011-03-18 00:03:24 -07:00
|
|
|
switch (code) {
|
2011-05-12 19:27:49 -07:00
|
|
|
case 190: // arraylength
|
|
|
|
throw new ArrayIndexOutOfBoundsException(message);
|
|
|
|
case 50: //_aaload
|
|
|
|
throw new ClassCastException(message);
|
2011-03-18 00:03:24 -07:00
|
|
|
case 192: // checkcast
|
|
|
|
throw new ClassCastException(message);
|
|
|
|
default:
|
|
|
|
throw new InternalError("unexpected code "+code+": "+message);
|
2010-10-30 21:02:30 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-08 23:08:56 -07:00
|
|
|
/**
|
|
|
|
* The JVM is resolving a CONSTANT_MethodHandle CP entry. And it wants our help.
|
|
|
|
* It will make an up-call to this method. (Do not change the name or signature.)
|
|
|
|
*/
|
|
|
|
static MethodHandle linkMethodHandleConstant(Class<?> callerClass, int refKind,
|
|
|
|
Class<?> defc, String name, Object type) {
|
2010-09-08 18:40:23 -07:00
|
|
|
try {
|
|
|
|
Lookup lookup = IMPL_LOOKUP.in(callerClass);
|
2011-06-01 23:56:47 -07:00
|
|
|
return lookup.linkMethodHandleConstant(refKind, defc, name, type);
|
2011-02-11 01:26:32 -08:00
|
|
|
} catch (ReflectiveOperationException ex) {
|
2010-09-08 18:40:23 -07:00
|
|
|
Error err = new IncompatibleClassChangeError();
|
|
|
|
err.initCause(ex);
|
|
|
|
throw err;
|
2010-06-08 23:08:56 -07:00
|
|
|
}
|
|
|
|
}
|
2009-05-05 22:40:09 -07:00
|
|
|
}
|