APIdia Launch Partner
Top Description Inners Constructors Methods
java.lang.invoke

pack-priv Class MethodHandleNatives

extends Object
Class Inheritance
Imports
jdk.internal.misc.VM, jdk.internal.ref.CleanerFactory, sun.invoke.util.Wrapper, java.lang.invoke.MethodHandles.Lookup, java.lang.reflect.Field

The JVM interface for the method handles package is all here. This is an interface internal and private to an implementation of JSR 292. This class is not part of the JSR 292 standard.
Author
jrose

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
MethodHandleNatives.Constants

Compile-time constants go here.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static boolean
pack-priv static boolean
canBeCalledVirtual(MemberName symbolicRef, Class<?> definingClass)

pack-priv static native void
copyOutBootstrapArguments(Class<?> caller, int[] indexInfo, int start, int end, Object[] buf, int pos, boolean resolve, Object ifNotAvailable)

pack-priv static native void
pack-priv static MethodType
findMethodHandleType(Class<?> rtype, Class<?>[] ptypes)

The JVM wants a pointer to a MethodType.

private static MethodType
fixMethodType(Class<?> callerClass, Object type)

private static String
getCallerInfo(Class<?> caller)

Return a human-readable description of the caller.

pack-priv static char
pack-priv static native Object
private static native int
getNamedCon(int which, Object[] name)

pack-priv static String
pack-priv static native void
init(MemberName self, Object ref)

pack-priv static <E extends Error> E
initCauseFrom(E err, Exception ex)

Use best possible cause for err.initCause(), substituting the cause for err itself if the cause has the same (or better) type.

pack-priv static boolean
isCallerSensitive(MemberName mem)

Is this method a caller-sensitive method?

pack-priv static boolean
isPullModeBSM(MethodHandle bsm)

A BSM runs in pull-mode if and only if its sole arguments are (Lookup, BootstrapCallInfo), or can be converted pairwise to those types, and it is not of variable arity.

pack-priv static MemberName
linkCallSite(Object callerObj, Object bootstrapMethodObj, Object nameObj, Object typeObj, Object staticArguments, Object[] appendixResult)

The JVM is linking an invokedynamic instruction.

pack-priv static MemberName
linkCallSiteImpl(Class<?> caller, MethodHandle bootstrapMethod, String name, MethodType type, Object staticArguments, Object[] appendixResult)

pack-priv static MemberName
linkCallSiteTracing(Class<?> caller, MethodHandle bootstrapMethod, String name, MethodType type, Object staticArguments, Object[] appendixResult)

pack-priv static Object
linkDynamicConstant(Object callerObj, Object bootstrapMethodObj, Object nameObj, Object typeObj, Object staticArguments)

pack-priv static Object
linkDynamicConstantImpl(Class<?> caller, MethodHandle bootstrapMethod, String name, Class<?> type, Object staticArguments)

pack-priv static Object
linkDynamicConstantTracing(Class<?> caller, MethodHandle bootstrapMethod, String name, Class<?> type, Object staticArguments)

pack-priv static MemberName
linkMethod(Class<?> callerClass, int refKind, Class<?> defc, String name, Object type, Object[] appendixResult)

The JVM wants to link a call site that requires a dynamic type check.

pack-priv static MethodHandle
linkMethodHandleConstant(Class<?> callerClass, int refKind, Class<?> defc, String name, Object type)

The JVM is resolving a CONSTANT_MethodHandle CP entry.

pack-priv static MemberName
linkMethodImpl(Class<?> callerClass, int refKind, Class<?> defc, String name, Object type, Object[] appendixResult)

pack-priv static MemberName
linkMethodTracing(Class<?> callerClass, int refKind, Class<?> defc, String name, Object type, Object[] appendixResult)

pack-priv static LinkageError
mapLookupExceptionToError(ReflectiveOperationException ex)

Map a reflective exception to a linkage error.

pack-priv static NoSuchMethodError
pack-priv static native long
pack-priv static boolean
refKindDoesDispatch(byte refKind)

pack-priv static boolean
refKindHasReceiver(byte refKind)

pack-priv static boolean
refKindIsConstructor(byte refKind)

pack-priv static boolean
refKindIsField(byte refKind)

pack-priv static boolean
refKindIsGetter(byte refKind)

pack-priv static boolean
refKindIsMethod(byte refKind)

pack-priv static boolean
refKindIsSetter(byte refKind)

pack-priv static boolean
refKindIsStatic(byte refKind)

pack-priv static boolean
refKindIsValid(int refKind)

pack-priv static String
refKindName(byte refKind)

private static native void
pack-priv static native MemberName
resolve(MemberName self, Class<?> caller, int lookupMode, boolean speculativeResolve)

pack-priv static native void
setCallSiteTargetNormal(CallSite site, MethodHandle target)

Tell the JVM that we need to change the target of a CallSite.

pack-priv static native void
private static String
staticArglistForTrace(Object staticArguments)

pack-priv static boolean
staticArgumentsPulled(Object staticArguments)

The JVM is requesting pull-mode bootstrap when it provides a tuple of the form int[]{ argc, vmindex }.

pack-priv static native Object
pack-priv static native long
private static MemberName
varHandleOperationLinkerMethod(String name, MethodType mtype, Object[] appendixResult)

Obtain the method to link to the VarHandle operation.

pack-priv static boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

MethodHandleNativesback to summary
private MethodHandleNatives()

Method Detail

canBeCalledVirtualback to summary
pack-priv static boolean canBeCalledVirtual(MemberName mem)
canBeCalledVirtualback to summary
pack-priv static boolean canBeCalledVirtual(MemberName symbolicRef, Class<?> definingClass)
copyOutBootstrapArgumentsback to summary
pack-priv static native void copyOutBootstrapArguments(Class<?> caller, int[] indexInfo, int start, int end, Object[] buf, int pos, boolean resolve, Object ifNotAvailable)
expandback to summary
pack-priv static native void expand(MemberName self)
findMethodHandleTypeback to summary
pack-priv static MethodType findMethodHandleType(Class<?> rtype, Class<?>[] ptypes)

The JVM wants a pointer to a MethodType. Oblige it by finding or creating one.

fixMethodTypeback to summary
private static MethodType fixMethodType(Class<?> callerClass, Object type)
getCallerInfoback to summary
private static String getCallerInfo(Class<?> caller)

Return a human-readable description of the caller. Something like "java.base/java.security.Security.(Security.java:82)"

getCharTypeback to summary
pack-priv static char getCharType(Class<?> pt)
getMemberVMInfoback to summary
pack-priv static native Object getMemberVMInfo(MemberName self)
getNamedConback to summary
private static native int getNamedCon(int which, Object[] name)
getVarHandleGuardMethodNameback to summary
pack-priv static String getVarHandleGuardMethodName(MethodType guardType)
initback to summary
pack-priv static native void init(MemberName self, Object ref)
initCauseFromback to summary
pack-priv static <E extends Error> E initCauseFrom(E err, Exception ex)

Use best possible cause for err.initCause(), substituting the cause for err itself if the cause has the same (or better) type.

isCallerSensitiveback to summary
pack-priv static boolean isCallerSensitive(MemberName mem)

Is this method a caller-sensitive method? I.e., does it call Reflection.getCallerClass or a similar method to ask about the identity of its caller?

isPullModeBSMback to summary
pack-priv static boolean isPullModeBSM(MethodHandle bsm)

A BSM runs in pull-mode if and only if its sole arguments are (Lookup, BootstrapCallInfo), or can be converted pairwise to those types, and it is not of variable arity. Excluding error cases, we can just test that the arity is a constant 2.

Note

This method currently returns false, since pulling is not currently exposed to a BSM. When pull mode is supported the method block will be replaced with currently commented out code.

linkCallSiteback to summary
pack-priv static MemberName linkCallSite(Object callerObj, Object bootstrapMethodObj, Object nameObj, Object typeObj, Object staticArguments, Object[] appendixResult)

The JVM is linking an invokedynamic instruction. Create a reified call site for it.

linkCallSiteImplback to summary
pack-priv static MemberName linkCallSiteImpl(Class<?> caller, MethodHandle bootstrapMethod, String name, MethodType type, Object staticArguments, Object[] appendixResult)
linkCallSiteTracingback to summary
pack-priv static MemberName linkCallSiteTracing(Class<?> caller, MethodHandle bootstrapMethod, String name, MethodType type, Object staticArguments, Object[] appendixResult)
linkDynamicConstantback to summary
pack-priv static Object linkDynamicConstant(Object callerObj, Object bootstrapMethodObj, Object nameObj, Object typeObj, Object staticArguments)
linkDynamicConstantImplback to summary
pack-priv static Object linkDynamicConstantImpl(Class<?> caller, MethodHandle bootstrapMethod, String name, Class<?> type, Object staticArguments)
linkDynamicConstantTracingback to summary
pack-priv static Object linkDynamicConstantTracing(Class<?> caller, MethodHandle bootstrapMethod, String name, Class<?> type, Object staticArguments)
linkMethodback to summary
pack-priv static MemberName linkMethod(Class<?> callerClass, int refKind, Class<?> defc, String name, Object type, Object[] appendixResult)

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 optional, implicitly added argument (typically the given MethodType)

The nominal method at such a call site is an instance of a signature-polymorphic method (see @PolymorphicSignature). Such method instances are user-visible entities which are "split" from the generic placeholder method in MethodHandle. (Note that the placeholder method is not identical with any of its instances. If invoked reflectively, is guaranteed to throw an UnsupportedOperationException.) If the signature-polymorphic method instance is ever reified, it appears as a "copy" of the original placeholder (a native final member of MethodHandle) except that its type descriptor has shape required by the instance, and the method instance is not varargs. The method instance is also marked synthetic, since the method (by definition) does not appear in Java source code.

The JVM is allowed to reify this method as instance metadata. For example, invokeBasic is always reified. But the JVM may instead call linkMethod. If the result is an * ordered pair of a (method, appendix), the method gets all the arguments (0..N inclusive) plus the appendix (N+1), and uses the appendix to complete the call. In this way, one reusable method (called a "linker method") can perform the function of any number of polymorphic instance methods.

Linker methods are allowed to be weakly typed, with any or all references rewritten to Object and any primitives (except long/float/double) rewritten to int. A linker method is trusted to return a strongly typed result, according to the specific method type descriptor of the signature-polymorphic instance it is emulating. This can involve (as necessary) a dynamic check using data extracted from the appendix argument.

The JVM does not inspect the appendix, other than to pass it verbatim to the linker method at every call. This means that the JDK runtime has wide latitude for choosing the shape of each linker method and its corresponding appendix. Linker methods should be generated from LambdaForms so that they do not become visible on stack traces.

The linkMethod call is free to omit the appendix (returning null) and instead emulate the required function completely in the linker method. As a corner case, if N==255, no appendix is possible. In this case, the method returned must be custom-generated to perform any needed type checking.

If the JVM does not reify a method at a call site, but instead calls linkMethod, the corresponding call represented in the bytecodes may mention a valid method which is not representable with a MemberName. Therefore, use cases for linkMethod tend to correspond to special cases in reflective code such as findVirtual or revealDirect.

linkMethodHandleConstantback to summary
pack-priv static MethodHandle linkMethodHandleConstant(Class<?> callerClass, int refKind, Class<?> defc, String name, Object type)

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.

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.

linkMethodImplback to summary
pack-priv static MemberName linkMethodImpl(Class<?> callerClass, int refKind, Class<?> defc, String name, Object type, Object[] appendixResult)
linkMethodTracingback to summary
pack-priv static MemberName linkMethodTracing(Class<?> callerClass, int refKind, Class<?> defc, String name, Object type, Object[] appendixResult)
mapLookupExceptionToErrorback to summary
pack-priv static LinkageError mapLookupExceptionToError(ReflectiveOperationException ex)

Map a reflective exception to a linkage error.

newNoSuchMethodErrorOnVarHandleback to summary
pack-priv static NoSuchMethodError newNoSuchMethodErrorOnVarHandle(String name, MethodType mtype)
objectFieldOffsetback to summary
pack-priv static native long objectFieldOffset(MemberName self)
refKindDoesDispatchback to summary
pack-priv static boolean refKindDoesDispatch(byte refKind)
refKindHasReceiverback to summary
pack-priv static boolean refKindHasReceiver(byte refKind)
refKindIsConstructorback to summary
pack-priv static boolean refKindIsConstructor(byte refKind)
refKindIsFieldback to summary
pack-priv static boolean refKindIsField(byte refKind)
refKindIsGetterback to summary
pack-priv static boolean refKindIsGetter(byte refKind)
refKindIsMethodback to summary
pack-priv static boolean refKindIsMethod(byte refKind)
refKindIsSetterback to summary
pack-priv static boolean refKindIsSetter(byte refKind)
refKindIsStaticback to summary
pack-priv static boolean refKindIsStatic(byte refKind)
refKindIsValidback to summary
pack-priv static boolean refKindIsValid(int refKind)
refKindNameback to summary
pack-priv static String refKindName(byte refKind)
registerNativesback to summary
private static native void registerNatives()
resolveback to summary
pack-priv static native MemberName resolve(MemberName self, Class<?> caller, int lookupMode, boolean speculativeResolve) throws LinkageError, ClassNotFoundException
setCallSiteTargetNormalback to summary
pack-priv static native void setCallSiteTargetNormal(CallSite site, MethodHandle target)

Tell the JVM that we need to change the target of a CallSite.

setCallSiteTargetVolatileback to summary
pack-priv static native void setCallSiteTargetVolatile(CallSite site, MethodHandle target)
staticArglistForTraceback to summary
private static String staticArglistForTrace(Object staticArguments)
staticArgumentsPulledback to summary
pack-priv static boolean staticArgumentsPulled(Object staticArguments)

The JVM is requesting pull-mode bootstrap when it provides a tuple of the form int[]{ argc, vmindex }. The BSM is expected to call back to the JVM using the caller class and vmindex to resolve the static arguments.

staticFieldBaseback to summary
pack-priv static native Object staticFieldBase(MemberName self)
staticFieldOffsetback to summary
pack-priv static native long staticFieldOffset(MemberName self)
varHandleOperationLinkerMethodback to summary
private static MemberName varHandleOperationLinkerMethod(String name, MethodType mtype, Object[] appendixResult)

Obtain the method to link to the VarHandle operation. This method is located here and not in Invokers to avoid initializing that and other classes early on in VM bootup.

verifyConstantsback to summary
pack-priv static boolean verifyConstants()
java.lang.invoke back to summary

pack-priv Class MethodHandleNatives.Constants

extends Object
Class Inheritance

Compile-time constants go here. This collection exists not only for reference from clients, but also for ensuring the VM and JDK agree on the values of these constants (see verifyConstants()).

Field Summary

Modifier and TypeField and Description
pack-priv static final int
ACCESS_VM_ANNOTATIONS

Flags for Lookup.ClassOptions

pack-priv static final int
HIDDEN_CLASS

Flags for Lookup.ClassOptions

pack-priv static final int
LM_MODULE

Lookup modes

pack-priv static final int
LM_TRUSTED

Lookup modes

pack-priv static final int
LM_UNCONDITIONAL

Lookup modes

pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
NESTMATE_CLASS

Flags for Lookup.ClassOptions

pack-priv static final byte
REF_getField

Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.

pack-priv static final byte
REF_getStatic

Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.

pack-priv static final byte
REF_invokeInterface

Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.

pack-priv static final byte
REF_invokeSpecial

Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.

pack-priv static final byte
REF_invokeStatic

Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.

pack-priv static final byte
REF_invokeVirtual

Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.

pack-priv static final byte
REF_LIMIT

Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.

pack-priv static final byte
REF_newInvokeSpecial

Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.

pack-priv static final byte
REF_NONE

Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.

pack-priv static final byte
REF_putField

Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.

pack-priv static final byte
REF_putStatic

Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.

pack-priv static final int
STRONG_LOADER_LINK

Flags for Lookup.ClassOptions

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ACCESS_VM_ANNOTATIONSback to summary
pack-priv static final int ACCESS_VM_ANNOTATIONS

Flags for Lookup.ClassOptions

HIDDEN_CLASSback to summary
pack-priv static final int HIDDEN_CLASS

Flags for Lookup.ClassOptions

LM_MODULEback to summary
pack-priv static final int LM_MODULE

Lookup modes

LM_TRUSTEDback to summary
pack-priv static final int LM_TRUSTED

Lookup modes

LM_UNCONDITIONALback to summary
pack-priv static final int LM_UNCONDITIONAL

Lookup modes

MN_CALLER_SENSITIVEback to summary
pack-priv static final int MN_CALLER_SENSITIVE
MN_HIDDEN_MEMBERback to summary
pack-priv static final int MN_HIDDEN_MEMBER
MN_IS_CONSTRUCTORback to summary
pack-priv static final int MN_IS_CONSTRUCTOR
MN_IS_FIELDback to summary
pack-priv static final int MN_IS_FIELD
MN_IS_METHODback to summary
pack-priv static final int MN_IS_METHOD
MN_IS_TYPEback to summary
pack-priv static final int MN_IS_TYPE
MN_REFERENCE_KIND_MASKback to summary
pack-priv static final int MN_REFERENCE_KIND_MASK
MN_REFERENCE_KIND_SHIFTback to summary
pack-priv static final int MN_REFERENCE_KIND_SHIFT
MN_TRUSTED_FINALback to summary
pack-priv static final int MN_TRUSTED_FINAL
NESTMATE_CLASSback to summary
pack-priv static final int NESTMATE_CLASS

Flags for Lookup.ClassOptions

REF_getFieldback to summary
pack-priv static final byte REF_getField

Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.

REF_getStaticback to summary
pack-priv static final byte REF_getStatic

Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.

REF_invokeInterfaceback to summary
pack-priv static final byte REF_invokeInterface

Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.

REF_invokeSpecialback to summary
pack-priv static final byte REF_invokeSpecial

Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.

REF_invokeStaticback to summary
pack-priv static final byte REF_invokeStatic

Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.

REF_invokeVirtualback to summary
pack-priv static final byte REF_invokeVirtual

Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.

REF_LIMITback to summary
pack-priv static final byte REF_LIMIT

Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.

REF_newInvokeSpecialback to summary
pack-priv static final byte REF_newInvokeSpecial

Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.

REF_NONEback to summary
pack-priv static final byte REF_NONE

Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.

REF_putFieldback to summary
pack-priv static final byte REF_putField

Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.

REF_putStaticback to summary
pack-priv static final byte REF_putStatic

Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.

Constructor Detail

Constantsback to summary
pack-priv Constants()