Path: blob/master/jcl/src/java.base/share/classes/java/lang/invoke/InsertHandle.java
12521 views
/*[INCLUDE-IF Sidecar17 & !OPENJDK_METHODHANDLES]*/1/*******************************************************************************2* Copyright (c) 2011, 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;2324/*[IF JAVA_SPEC_VERSION >= 15]*/25import java.util.List;26/*[ENDIF] JAVA_SPEC_VERSION >= 15 */2728class InsertHandle extends MethodHandle {29final MethodHandle next;30final int insertionIndex;31private final Object[] values;3233/*34* next must be an appropriately typed handle to ensure that the bound parameters are typechecked35* correctly.36*/37InsertHandle(MethodType type, MethodHandle next, int insertionIndex, Object values[]) {38super(type, KIND_INSERT,infoAffectingThunks(insertionIndex, values.length)); //$NON-NLS-1$39this.next = next;40this.insertionIndex = insertionIndex;41this.values = values;42}4344InsertHandle(InsertHandle originalHandle, MethodType newType) {45super(originalHandle, newType);46this.next = originalHandle.next;47this.insertionIndex = originalHandle.insertionIndex;48this.values = originalHandle.values;49}5051/*[IF JAVA_SPEC_VERSION >= 15]*/52@Override53boolean addRelatedMHs(List<MethodHandle> relatedMHs) {54relatedMHs.add(next);55return true;56}57/*[ENDIF] JAVA_SPEC_VERSION >= 15 */5859// {{{ JIT support6061private static final ThunkTable _thunkTable = new ThunkTable();62protected ThunkTable thunkTable(){ return _thunkTable; }6364private static int[] infoAffectingThunks(int insertionIndex, int numberOfValues) {65// The location and number of values to insert affects the code generated in the thunks; see ILGen macros below66int[] result = { insertionIndex, numberOfValues };67return result;68}6970protected ThunkTuple computeThunks(Object arg) {71int[] info = (int[])arg;72return thunkTable().get(new ThunkKeyWithIntArray(ThunkKey.computeThunkableType(type()), info));73}7475static native int numPrefixArgs();76static native int numSuffixArgs();77private static native int numValuesToInsert();7879@FrameIteratorSkip80private final int invokeExact_thunkArchetype_X(int argPlaceholder) {81if (ILGenMacros.isShareableThunk()) {82undoCustomizationLogic(next);83}84if (!ILGenMacros.isCustomThunk()) {85doCustomizationLogic();86}87return ILGenMacros.invokeExact_X(next, ILGenMacros.placeholder(88ILGenMacros.firstN(numPrefixArgs(), argPlaceholder),89ILGenMacros.arrayElements(values, 0, numValuesToInsert()),90ILGenMacros.lastN(numSuffixArgs(), argPlaceholder)));91}9293// }}} JIT support9495@Override96MethodHandle cloneWithNewType(MethodType newType) {97return new InsertHandle(this, newType);98}99100final void compareWith(MethodHandle right, Comparator c) {101if (right instanceof InsertHandle) {102((InsertHandle)right).compareWithInsert(this, c);103} else {104c.fail();105}106}107108final void compareWithInsert(InsertHandle left, Comparator c) {109c.compareStructuralParameter(left.insertionIndex, this.insertionIndex);110c.compareStructuralParameter(left.values.length, this.values.length);111for (int i = 0; (i < left.values.length) && (i < this.values.length); i++) {112c.compareUserSuppliedParameter(left.values[i], this.values[i]);113}114c.compareChildHandle(left.next, this.next);115}116}117118119