APIdia Launch Partner
Top Inners Fields Constructors Methods
jdk.internal.reflect

pack-priv final Class MethodHandleAccessorFactory

extends Object
Class Inheritance
Imports
java.lang.invoke.MethodHandle, .MethodHandles, .MethodType, .VarHandle, java.lang.reflect.Constructor, .Executable, .Field, .Method, .Modifier, jdk.internal.access.JavaLangInvokeAccess, .SharedSecrets, jdk.internal.misc.Unsafe, .VM

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private static final int
private static final ReflectionFactory
pack-priv static final int
private static final Unsafe

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private static boolean
pack-priv static void
ensureClassInitialized(Class<?> defc)

Ensures the given class is initialized.

private static MethodHandle
findCallerSensitiveAdapter(Method method)

Finds the method handle of a caller-sensitive adapter for the given caller-sensitive method.

private static MethodHandle
getDirectMethod(Method method, boolean callerSensitive)

public static boolean

Returns:

true if this method is signature polymorphic
isSignaturePolymorphicMethod
(Method
the method to check
method
)

Signature-polymorphic methods.

private static MethodHandle
pack-priv static MethodHandle

Returns:

transformed dmh to be used as a target in direct method accessors
makeSpecializedTarget
(MethodHandle
DirectMethodHandle
dmh
,
boolean
whether given dmh represents static method or not
isStatic
,
boolean
whether given dmh represents a method with an additional caller Class parameter
hasCallerParameter
)

Transform the given dmh to a specialized target method handle.

pack-priv static MethodHandle
makeTarget(MethodHandle dmh, boolean isStatic, boolean hasCallerParameter)

Transforms the given dmh into a target method handle with the method type (Object, Object[])Object or (Object, Class, Object[])Object

pack-priv static ConstructorAccessorImpl
newConstructorAccessor(Constructor<?> ctor)

Creates a ConstructorAccessor for the given reflected constructor.

pack-priv static FieldAccessorImpl
newFieldAccessor(Field field, boolean isReadOnly)

Creates a FieldAccessor for the given reflected field.

pack-priv static MethodAccessorImpl
newMethodAccessor(Method method, boolean callerSensitive)

Creates a MethodAccessor for the given reflected method.

pack-priv static ConstructorAccessorImpl

Returns:

an accessible constructor
newSerializableConstructorAccessor
(Class<?>
the class to instantiate
decl
,
Constructor<?>
the constructor to call
ctor
)

Creates a ConstructorAccessor that is capable of creating instances of the given class and instantiated by the given constructor.

private static int
pack-priv static MethodType
specializedMethodType(boolean isStatic, boolean hasCallerParameter, int paramCount)

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

Field Detail

MAX_JVM_ARITYback to summary
private static final int MAX_JVM_ARITY
reflectionFactoryback to summary
private static final ReflectionFactory reflectionFactory
SPECIALIZED_PARAM_COUNTback to summary
pack-priv static final int SPECIALIZED_PARAM_COUNT
UNSAFEback to summary
private static final Unsafe UNSAFE

Constructor Detail

MethodHandleAccessorFactoryback to summary
pack-priv MethodHandleAccessorFactory()

Method Detail

constructorInSuperclassback to summary
private static boolean constructorInSuperclass(Class<?> decl, Constructor<?> ctor)
ensureClassInitializedback to summary
pack-priv static void ensureClassInitialized(Class<?> defc)

Ensures the given class is initialized. If this is called from , this method returns but defc's class initialization is not completed.

findCallerSensitiveAdapterback to summary
private static MethodHandle findCallerSensitiveAdapter(Method method) throws IllegalAccessException

Finds the method handle of a caller-sensitive adapter for the given caller-sensitive method. It has the same name as the given method with a trailing caller class parameter.

See Also
CallerSensitiveAdapter
getDirectMethodback to summary
private static MethodHandle getDirectMethod(Method method, boolean callerSensitive) throws IllegalAccessException
isSignaturePolymorphicMethodback to summary
public static boolean isSignaturePolymorphicMethod(Method method)

Signature-polymorphic methods. Lookup has special rules for these methods, but core reflection must observe them as they are declared, and reflective invocation must invoke the native method stubs that throw UOE.

Parameters
method:Method

the method to check

Returns:boolean

true if this method is signature polymorphic

Java Language Specification
15.12.3 Compile-Time Step 3: Is the Chosen Method Appropriate?
Java Virtual Machine Specification
2.9.3 Signature Polymorphic Methods
makeConstructorHandleback to summary
private static MethodHandle makeConstructorHandle(MethodHandle ctor)
makeSpecializedTargetback to summary
pack-priv static MethodHandle makeSpecializedTarget(MethodHandle dmh, boolean isStatic, boolean hasCallerParameter)

Transform the given dmh to a specialized target method handle. If hasCallerParameter parameter is true, transform the method handle of this method type: (Object, Object[], Class)Object for the default case. If hasCallerParameter parameter is false, transform the method handle of this method type: (Object, Object[])Object for the default case. If the number of formal arguments is small, use a method type specialized the number of formal arguments is 0, 1, and 2, for example, the method type of a static method with one argument can be: (Object)Object If it's a static method, there is no leading Object parameter.

API Note

This implementation avoids using MethodHandles::catchException to help cold startup performance since this combination is very costly to setup.

Parameters
dmh:MethodHandle

DirectMethodHandle

isStatic:boolean

whether given dmh represents static method or not

hasCallerParameter:boolean

whether given dmh represents a method with an additional caller Class parameter

Returns:MethodHandle

transformed dmh to be used as a target in direct method accessors

makeTargetback to summary
pack-priv static MethodHandle makeTarget(MethodHandle dmh, boolean isStatic, boolean hasCallerParameter)

Transforms the given dmh into a target method handle with the method type (Object, Object[])Object or (Object, Class, Object[])Object

newConstructorAccessorback to summary
pack-priv static ConstructorAccessorImpl newConstructorAccessor(Constructor<?> ctor)

Creates a ConstructorAccessor for the given reflected constructor. If a given constructor is called before the java.lang.invoke initialization, it will use the native VM reflection support. Otherwise, it will use the direct method handle of the given constructor.

newFieldAccessorback to summary
pack-priv static FieldAccessorImpl newFieldAccessor(Field field, boolean isReadOnly)

Creates a FieldAccessor for the given reflected field. Limitation: Field access via core reflection is only supported after java.lang.invoke completes initialization. java.lang.invoke initialization starts soon after System::initPhase1 and method handles are ready for use when initPhase2 begins. During early VM startup (initPhase1), fields can be accessed directly from the VM or through JNI.

newMethodAccessorback to summary
pack-priv static MethodAccessorImpl newMethodAccessor(Method method, boolean callerSensitive)

Creates a MethodAccessor for the given reflected method. If the given method is called before the java.lang.invoke initialization or the given method is a native method, it will use the native VM reflection support. If the given method is a caller-sensitive method and the corresponding caller-sensitive adapter with the caller class parameter is present, it will use the method handle of the caller-sensitive adapter. Otherwise, it will use the direct method handle of the given method.

See Also
CallerSensitive, CallerSensitiveAdapter
newSerializableConstructorAccessorback to summary
pack-priv static ConstructorAccessorImpl newSerializableConstructorAccessor(Class<?> decl, Constructor<?> ctor)

Creates a ConstructorAccessor that is capable of creating instances of the given class and instantiated by the given constructor.

Parameters
decl:Class<?>

the class to instantiate

ctor:Constructor<?>

the constructor to call

Returns:ConstructorAccessorImpl

an accessible constructor

slotCountback to summary
private static int slotCount(Executable member)
specializedMethodTypeback to summary
pack-priv static MethodType specializedMethodType(boolean isStatic, boolean hasCallerParameter, int paramCount)
specializedMethodTypeForConstructorback to summary
pack-priv static MethodType specializedMethodTypeForConstructor(int paramCount)
useNativeAccessorback to summary
private static boolean useNativeAccessor(Executable member)
jdk.internal.reflect back to summary

pack-priv Class MethodHandleAccessorFactory.LazyStaticHolder

extends Object
Class Inheritance
  • java.lang.Object
  • jdk.internal.reflect.MethodHandleAccessorFactory.LazyStaticHolder

Field Summary

Modifier and TypeField and Description
pack-priv static final JavaLangInvokeAccess

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

JLIAback to summary
pack-priv static final JavaLangInvokeAccess JLIA

Constructor Detail

LazyStaticHolderback to summary
pack-priv LazyStaticHolder()