Top Description Inners Fields Constructors Methods
java.lang.invoke

pack-priv abstract Class MethodHandleImpl

extends Object
Class Inheritance
Imports
jdk.internal.access.JavaLangInvokeAccess, .SharedSecrets, jdk.internal.foreign.abi.NativeEntryPoint, jdk.internal.org.objectweb.asm.ClassWriter, jdk.internal.reflect.CallerSensitive, .Reflection, jdk.internal.vm.annotation.ForceInline, .Hidden, .Stable, sun.invoke.empty.Empty, sun.invoke.util.ValueConversions, .VerifyType, .Wrapper, java.lang.invoke.MethodHandles.Lookup, java.lang.reflect.Array, .Constructor, .Field, java.nio.ByteOrder, java.util.Arrays, .Collections, .HashMap, .Iterator, .List, .Map, .Objects, .Set, java.util.concurrent.ConcurrentHashMap, java.util.function.Function, java.util.stream.Stream

Trusted implementation code for MethodHandle.
Author
jrose

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static enum
pack-priv static class
pack-priv static class
private static class
pack-priv static class
pack-priv static class
MethodHandleImpl.CountingWrapper

Counting method handle.

pack-priv static enum
pack-priv static class
MethodHandleImpl.IntrinsicMethodHandle

Mark arbitrary method handle as intrinsic.

pack-priv static class
private static class
private static class
pack-priv static class
MethodHandleImpl.WrappedMember

This subclass allows a wrapped method handle to be re-associated with an arbitrary member name.

Field Summary

Modifier and TypeField and Description
private static final MethodHandle[]
pack-priv static MethodHandle[]
private static final MethodHandle[]
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
pack-priv static final int
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
private static final LambdaForm.NamedFunction[]

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private static boolean
pack-priv static void
pack-priv static MethodHandle
bindCaller(MethodHandle mh, Class<?> hostClass)

Create an alias for the method handle which, when called, appears to be called from the same class loader and protection domain as hostClass.

pack-priv static void
pack-priv static Object[]
computeValueConversions(MethodType srcType, MethodType dstType, boolean strict, boolean monobox)

pack-priv static boolean

Returns:

whether the counter has reached the limit.
countedLoopPredicate
(int
the upper bound of the parameter, statically bound at loop creation time.
limit
,
int
the counter parameter, passed in during loop execution.
counter
)

This method is bound as the predicate in counting loops.

pack-priv static int

Returns:

the loop counter incremented by 1.
countedLoopStep
(int
the upper bound of the loop counter (ignored).
limit
,
int
the loop counter.
counter
)

This method is bound as the step function in counting loops to increment the counter.

private static int
private static LambdaForm.NamedFunction
createFunction(byte func)

pack-priv static MethodHandle
pack-priv static MethodHandle
pack-priv static MethodHandle
pack-priv static LambdaForm.NamedFunction
getFunction(byte func)

pack-priv static Object
guardWithCatch(MethodHandle target, Class<? extends Throwable> exType, MethodHandle catcher, Object... av)

Intrinsified during LambdaForm compilation (see emitGuardWithCatch).

pack-priv static Iterator<?>

Returns:

an Iterator over the argument's elements.
initIterator
(Iterable<?>
the Iterable over which the loop iterates.
it
)

This is bound to initialize the loop-local iterator in iterating loops.

pack-priv static boolean
pack-priv static Object

Returns:

the next element from the iterator.
iterateNext
(Iterator<?>
the iterator.
it
)

This method is bound as the step for retrieving the current value from the iterator in iterating loops.

pack-priv static boolean

Returns:

true iff there are more elements to iterate over.
iteratePredicate
(Iterator<?>
the iterator to be checked.
it
)

This method is bound as the predicate in iterating loops.

pack-priv static Object
loop(LambdaForm.BasicType[] localTypes, MethodHandleImpl.LoopClauses clauseData, Object... av)

Intrinsified during LambdaForm compilation (see InvokerBytecodeGenerator#emitLoop(int)).

pack-priv static MethodHandle
pack-priv static MethodHandle
makeBlockInliningWrapper(MethodHandle target)

Block inlining during JIT-compilation of a target method handle if it hasn't been invoked enough times.

private static MethodHandle
makeCollector(Class<?> arrayType, int parameterCount)

private static LambdaForm
makeCollectorForm(MethodType basicType, Class<?> arrayType)

private static MethodHandle
pack-priv static MethodHandle
makeGuardWithCatch(MethodHandle target, Class<? extends Throwable> exType, MethodHandle catcher)

private static LambdaForm
makeGuardWithCatchForm(MethodType basicType)

The LambdaForm shape for catchException combinator is the following:

guardWithCatch=Lambda(a0:L,a1:L,a2:L)=>{
   t3:L=BoundMethodHandle$Species_LLLLL.argL0(a0:L);
   t4:L=BoundMethodHandle$Species_LLLLL.argL1(a0:L);
   t5:L=BoundMethodHandle$Species_LLLLL.argL2(a0:L);
   t6:L=BoundMethodHandle$Species_LLLLL.argL3(a0:L);
   t7:L=BoundMethodHandle$Species_LLLLL.argL4(a0:L);
   t8:L=MethodHandle.invokeBasic(t6:L,a1:L,a2:L);
   t9:L=MethodHandleImpl.guardWithCatch(t3:L,t4:L,t5:L,t8:L);
  t10:I=MethodHandle.invokeBasic(t7:L,t9:L);t10:I}
pack-priv static MethodHandle
pack-priv static LambdaForm
pack-priv static MethodHandle
pack-priv static MethodHandle
makeIntrinsic(MethodHandle target, MethodHandleImpl.Intrinsic intrinsicName, Object intrinsicData)

pack-priv static MethodHandle
pack-priv static MethodHandle

Returns:

a handle that, when invoked, will execute the loop.
makeLoop
(Class<?>
the return type of the loop.
tloop
,
List<Class<?>>
types of the arguments to be passed to the loop.
targs
,
List<MethodHandle>
sanitized array of initializers for loop-local variables.
init
,
List<MethodHandle>
sanitized array of loop bodies.
step
,
List<MethodHandle>
sanitized array of predicates.
pred
,
List<MethodHandle>
sanitized array of loop finalizers.
fini
)

Assembles a loop method handle from the given handles and type information.

private static LambdaForm
makeLoopForm(MethodType basicType, LambdaForm.BasicType[] localVarTypes)

Loops introduce some complexity as they can have additional local state.

pack-priv static MethodHandle

Returns:

an adapter to the original handle with the desired new type, or the original target if the types are already identical or null if the adaptation cannot be made
makePairwiseConvert
(MethodHandle
original method handle
target
,
MethodType
required call type
srcType
,
boolean
if true, only asType conversions are allowed; if false, explicitCastArguments conversions allowed
strict
,
boolean
if true, unboxing conversions are assumed to be exactly typed (Integer to int only, not long or double)
monobox
)

Create a JVM-level adapter method handle to conform the given method handle to the similar newType, using only pairwise argument conversions.

pack-priv static MethodHandle
makePairwiseConvert(MethodHandle target, MethodType srcType, boolean strict)

pack-priv static MethodHandle
makePairwiseConvertByEditor(MethodHandle target, MethodType srcType, boolean strict, boolean monobox)

pack-priv static MethodHandle
makeTableSwitch(MethodType type, MethodHandle defaultCase, MethodHandle[] caseActions)

private static LambdaForm
pack-priv static MethodHandle

Returns:

a handle on the constructed try-finally block.
makeTryFinally
(MethodHandle
the target to execute in a try-finally block.
target
,
MethodHandle
the cleanup to execute in the finally block.
cleanup
,
Class<?>
the result type of the entire construct.
rtype
,
Class<?>[]
the types of the arguments.
argTypes
)

Makes a try-finally handle that conforms to the type constraints.

private static LambdaForm
makeTryFinallyForm(MethodType basicType)

The LambdaForm shape for the tryFinally combinator is as follows (assuming one reference parameter passed in a1, and a reference return type, with the return value represented by t8):

tryFinally=Lambda(a0:L,a1:L)=>{
   t2:L=BoundMethodHandle$Species_LLLL.argL0(a0:L);  // target method handle
   t3:L=BoundMethodHandle$Species_LLLL.argL1(a0:L);  // cleanup method handle
   t4:L=BoundMethodHandle$Species_LLLL.argL2(a0:L);  // helper handle to box the arguments into an Object[]
   t5:L=BoundMethodHandle$Species_LLLL.argL3(a0:L);  // helper handle to unbox the result
   t6:L=MethodHandle.invokeBasic(t4:L,a1:L);         // box the arguments into an Object[]
   t7:L=MethodHandleImpl.tryFinally(t2:L,t3:L,t6:L); // call the tryFinally executor
   t8:L=MethodHandle.invokeBasic(t5:L,t7:L);t8:L}    // unbox the result; return the result
pack-priv static MethodHandle
makeVarargsCollector(MethodHandle target, Class<?> arrayType)

pack-priv static MethodHandle
makeWrappedMember(MethodHandle target, MemberName member, boolean isInvokeSpecial)

private static Object[]
prepend(Object[] array, Object... elems)

Prepend elements to an array.

pack-priv static MethodHandle
pack-priv static boolean
profileBoolean(boolean result, int[] counters)

pack-priv static MethodHandle
selectAlternative(boolean testResult, MethodHandle target, MethodHandle fallback)

private static synchronized MethodHandle
setCachedHandle(int idx, final MethodHandle method)

pack-priv static Object
tableSwitch(int input, MethodHandle defaultCase, MethodHandleImpl.CasesHolder holder, Object[] args)

pack-priv static MethodHandle
pack-priv static <T extends Throwable> Empty
private static MethodHandle[]
pack-priv static Object
tryFinally(MethodHandle target, MethodHandle cleanup, Object... av)

Intrinsified during LambdaForm compilation (see emitTryFinally).

private static MethodHandle
unboxResultHandle(Class<?> returnType)

Result unboxing: ValueConversions.unbox() OR ValueConversions.identity() OR ValueConversions.ignore().

pack-priv static InternalError
pack-priv static Object
valueConversion(Class<?> src, Class<?> dst, boolean strict, boolean monobox)

Find a conversion function from the given source to the given destination.

pack-priv static MethodHandle
varargsArray(int nargs)

Return a method handle that takes the indicated number of Object arguments and returns an Object array of them, as if for varargs.

pack-priv static MethodHandle
varargsArray(Class<?> arrayType, int nargs)

Return a method handle that takes the indicated number of typed arguments and returns an array of them.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait