Path: blob/master/jcl/src/java.base/share/classes/java/lang/invoke/InvokeExactHandle.java
12520 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/* InvokeExactHandle is a MethodHandle subclass used to MethodHandle.invokeExact27* 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 InvokeExactHandle extends PrimitiveHandle {34/* MethodType that the first argument MethodHandle must match */35final MethodType nextType;3637InvokeExactHandle(MethodType type) {38super(invokeExactMethodType(type), MethodHandle.class, "invokeExact", KIND_INVOKEEXACT, PUBLIC_FINAL_NATIVE, null); //$NON-NLS-1$39nextType = type;40this.vmSlot = 0;41this.defc = MethodHandle.class;42}4344InvokeExactHandle(InvokeExactHandle originalHandle, MethodType newType) {45super(originalHandle, newType);46this.nextType = originalHandle.nextType;47}4849/*50* Insert MethodHandle as first argument to existing type.51* (LMethodHandle;otherargs)returntype52*/53private static final MethodType invokeExactMethodType(MethodType type){54if (type == null) {55throw new IllegalArgumentException();56}57return type.insertParameterTypes(0, MethodHandle.class);58}5960@Override61boolean canRevealDirect() {62/* This is invokevirtual of MethodHandle.invokeExact() */63return true;64}6566// {{{ JIT support6768private static final ThunkTable _thunkTable = new ThunkTable();69protected final ThunkTable thunkTable(){ return _thunkTable; }7071protected ThunkTuple computeThunks(Object arg) {72// The first argument is always a MethodHandle.73// We don't upcast that to Object to avoid a downcast in the thunks.74//75return thunkTable().get(new ThunkKey(ThunkKey.computeThunkableType(type(), 0, 1)));76}7778@FrameIteratorSkip79private final int invokeExact_thunkArchetype_X(MethodHandle next, int argPlaceholder) throws Throwable {80if (ILGenMacros.isShareableThunk()) {81undoCustomizationLogic(next);82}83if (!ILGenMacros.isCustomThunk()) {84doCustomizationLogic();85}86ILGenMacros.typeCheck(next, nextType);87return ILGenMacros.invokeExact_X(next, argPlaceholder);88}8990// }}} JIT support9192@Override93MethodHandle cloneWithNewType(MethodType newType) {94return new InvokeExactHandle(this, newType);95}9697final void compareWith(MethodHandle right, Comparator c) {98if (right instanceof InvokeExactHandle) {99((InvokeExactHandle)right).compareWithInvokeExact(this, c);100} else {101c.fail();102}103}104105final void compareWithInvokeExact(InvokeExactHandle left, Comparator c) {106// Nothing distinguishes InvokeExactHandles except their type, which Comparator already deals with107}108}109110111112