/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*
* 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.
*/
/**
* The JVM interface for the method handles package is all here.
* 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>
* @author jrose
*/
class MethodHandleNatives {
/// MemberName support
/// Field layout queries parallel to sun.misc.Unsafe:
/// MethodHandle support
/** Fetch MH-related JVM parameter.
* which=0 retrieves MethodHandlePushLimit
* which=1 retrieves stack slot push size (in address units)
*/
static final boolean COUNT_GWT;
/// CallSite support
/** Tell the JVM that we need to change the target of a CallSite. */
private static native void registerNatives();
static {
// The JVM calls MethodHandleNatives.<clinit>. Cascade the <clinit> calls as needed:
}
// All compile-time constants go here.
// There is an opportunity to check them against the JVM's idea of them.
static class Constants {
// MethodHandleImpl
static final int // for getConstant
// 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
// The SEARCH_* bits are not for MN.flags but for the matchFlags argument of MHN.getMembers:
/**
* 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_ARRAY = 13
//T_ADDRESS = 15
/**
* Constant pool entry types.
*/
static final byte
/**
* Access modifier flags.
*/
static final char
// aliases:
/**
* Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.
*/
static final byte
}
}
assert(refKindIsValid(refKind));
return (refKind <= REF_putStatic);
}
assert(refKindIsValid(refKind));
return (refKind <= REF_getStatic);
}
}
}
assert(refKindIsValid(refKind));
}
}
assert(refKindIsValid(refKind));
return (refKind == REF_invokeVirtual ||
}
static {
(1 << REF_putField) |
(1 << REF_invokeVirtual) |
(1 << REF_invokeSpecial) |
(1 << REF_invokeInterface)
);
}
}
assert(refKindIsValid(refKind));
return REFERENCE_KIND_NAME[refKind];
}
null,
"getField",
"getStatic",
"putField",
"putStatic",
"invokeVirtual",
"invokeStatic",
"invokeSpecial",
"newInvokeSpecial",
"invokeInterface"
};
static boolean verifyConstants() {
for (int i = 0; ; i++) {
try {
continue;
}
throw new InternalError(err);
// ignore exotic ops the JVM cares about; we just wont issue them
//System.err.println("warning: "+err);
continue;
}
}
return true;
}
static {
assert(verifyConstants());
}
// Up-calls from the JVM.
// These must NOT be public.
/**
* The JVM is linking an invokedynamic instruction. Create a reified call site for it.
*/
Object[] appendixResult) {
name,
type,
caller);
}
/**
* The JVM wants a pointer to a MethodType. Oblige it by finding or creating one.
*/
}
/**
* The JVM wants to link a call site that requires a dynamic type check.
* Name is a type-checking invoker, invokeExact or invoke.
* Return a JVM method (MemberName) to handle the invoking.
* The method assumes the following arguments on the stack:
* 0: the method handle being invoked
* 1-N: the arguments to the method handle invocation
* N+1: an implicitly added type argument (the given MethodType)
*/
Object[] appendixResult) {
if (!TRACE_METHOD_LINKAGE)
}
Object[] appendixResult) {
try {
switch (name) {
case "invoke":
case "invokeExact":
}
}
if (ex instanceof LinkageError)
throw (LinkageError) ex;
else
}
}
if (type instanceof MethodType)
return (MethodType) type;
else
}
// Tracing logic:
Object[] appendixResult) {
try {
return res;
throw ex;
}
}
/**
* 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.)
* The type argument is a Class for field requests and a MethodType for non-fields.
* <p>
* Recent versions of the JVM may also pass a resolved MemberName for the type.
* In that case, the name is ignored and may be null.
*/
try {
assert(refKindIsValid(refKind));
} catch (ReflectiveOperationException ex) {
throw err;
}
}
/**
* Is this method a caller-sensitive method?
* I.e., does it call Reflection.getCallerClass or a similer method
* to ask about the identity of its caller?
*/
// when the VM support is available, call mem.isCallerSensitive() instead
}
// this method is also called by test/sun/reflect/CallerSensitiveFinder
// to validate the hand-maintained list
switch (method) {
case "doPrivileged":
case "doPrivilegedWithCombiner":
case "checkMemberAccess":
case "getUnsafe":
case "lookup":
case "invoke":
case "get":
case "getBoolean":
case "getByte":
case "getChar":
case "getShort":
case "getInt":
case "getLong":
case "getFloat":
case "getDouble":
case "set":
case "setBoolean":
case "setByte":
case "setChar":
case "setShort":
case "setInt":
case "setLong":
case "setFloat":
case "setDouble":
case "newInstance":
break;
case "getFields":
case "forName":
case "getClassLoader":
case "getClasses":
case "getMethods":
case "getConstructors":
case "getDeclaredClasses":
case "getDeclaredFields":
case "getDeclaredMethods":
case "getDeclaredConstructors":
case "getField":
case "getMethod":
case "getConstructor":
case "getDeclaredField":
case "getDeclaredMethod":
case "getDeclaredConstructor":
case "getEnclosingClass":
case "getEnclosingMethod":
case "getEnclosingConstructor":
case "getConnection":
case "getDriver":
case "getDrivers":
case "deregisterDriver":
case "newUpdater":
break;
case "getContextClassLoader":
case "getPackage":
case "getPackages":
case "getParent":
case "getSystemClassLoader":
case "load":
case "loadLibrary":
break;
case "getCallerClass":
break;
case "getCallerClassLoader":
case "registerAsParallelCapable":
case "getProxyClass":
case "newProxyInstance":
case "asInterfaceInstance":
case "getBundle":
case "clearCache":
case "getType":
case "forClass":
case "getLogger":
case "getAnonymousLogger":
}
return false;
}
assert(mem.isInvocable());
case "checkMemberAccess":
case "getContextClassLoader":
}
return false;
}
if (symbolicRefClass == definingClass) return true;
}
}