Path: blob/master/jcl/src/java.base/share/classes/java/lang/invoke/InvokeGenericHandle.java
12521 views
/*[INCLUDE-IF Sidecar17 & !OPENJDK_METHODHANDLES]*/1/*******************************************************************************2* Copyright (c) 2009, 2020 IBM Corp. and others3*4* This program and the accompanying materials are made available under5* the terms of the Eclipse Public License 2.0 which accompanies this6* distribution and is available at https://www.eclipse.org/legal/epl-2.0/7* or the Apache License, Version 2.0 which accompanies this distribution and8* is available at https://www.apache.org/licenses/LICENSE-2.0.9*10* This Source Code may also be made available under the following11* Secondary Licenses when the conditions for such availability set12* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU13* General Public License, version 2 with the GNU Classpath14* Exception [1] and GNU General Public License, version 2 with the15* OpenJDK Assembly Exception [2].16*17* [1] https://www.gnu.org/software/classpath/license.html18* [2] http://openjdk.java.net/legal/assembly-exception.html19*20* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception21*******************************************************************************/22package java.lang.invoke;2324import java.lang.reflect.Modifier;2526/* InvokeGenericHandle is a MethodHandle subclass used to MethodHandle.invokeGeneric27* with a specific signature on a MethodHandle.28* <p>29* The vmSlot will hold 0 as there is no actual method for it.30* <p>31* Can be thought of as a special case of VirtualHandle.32*/33final class InvokeGenericHandle extends PrimitiveHandle {34/* MethodType that the first argument MethodHandle will be cast to using asType */35@VMCONSTANTPOOL_FIELD36final MethodType castType;373839InvokeGenericHandle(MethodType type) {40super(invokeGenericMethodType(type), MethodHandle.class, "invoke", KIND_INVOKEGENERIC, PUBLIC_FINAL_NATIVE, null); //$NON-NLS-1$41if (type == null) {42throw new IllegalArgumentException();43}44this.vmSlot = 0;45this.defc = MethodHandle.class;46this.castType = type;47}4849InvokeGenericHandle(InvokeGenericHandle originalHandle, MethodType newType) {50super(originalHandle, newType);51this.castType = originalHandle.castType;52}5354/*55* Insert MethodHandle as first argument to existing type.56* (LMethodHandle;otherargs)returntype57*/58private static final MethodType invokeGenericMethodType(MethodType type) {59return type.insertParameterTypes(0, MethodHandle.class);60}6162@Override63boolean canRevealDirect() {64/* This is invokevirtual of MethodHandle.invoke() */65return true;66}6768// {{{ JIT support6970private static final ThunkTable _thunkTable = new ThunkTable();71protected final ThunkTable thunkTable(){ return _thunkTable; }7273protected ThunkTuple computeThunks(Object arg) {74// The first argument is always a MethodHandle.75// We don't upcast that to Object to avoid a downcast in the thunks.76//77return thunkTable().get(new ThunkKey(ThunkKey.computeThunkableType(type(), 0, 1)));78}7980@FrameIteratorSkip81private final int invokeExact_thunkArchetype_X(MethodHandle next, int argPlaceholder) throws Throwable {82if (ILGenMacros.isShareableThunk()) {83undoCustomizationLogic(next);84}85if (!ILGenMacros.isCustomThunk()) {86doCustomizationLogic();87}88return ILGenMacros.invokeExact_X(next.asType(castType), argPlaceholder);89}9091// }}} JIT support9293@Override94MethodHandle cloneWithNewType(MethodType newType) {95return new InvokeGenericHandle(this, newType);96}9798final void compareWith(MethodHandle right, Comparator c) {99if (right instanceof InvokeGenericHandle) {100((InvokeGenericHandle)right).compareWithInvokeGeneric(this, c);101} else {102c.fail();103}104}105106final void compareWithInvokeGeneric(InvokeGenericHandle left, Comparator c) {107// Nothing distinguishes InvokeGenericHandles except their type, which Comparator already deals with108}109}110111112113