Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/jcl/src/java.base/share/classes/java/lang/invoke/InsertHandle.java
12521 views
1
/*[INCLUDE-IF Sidecar17 & !OPENJDK_METHODHANDLES]*/
2
/*******************************************************************************
3
* Copyright (c) 2011, 2020 IBM Corp. and others
4
*
5
* This program and the accompanying materials are made available under
6
* the terms of the Eclipse Public License 2.0 which accompanies this
7
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
8
* or the Apache License, Version 2.0 which accompanies this distribution and
9
* is available at https://www.apache.org/licenses/LICENSE-2.0.
10
*
11
* This Source Code may also be made available under the following
12
* Secondary Licenses when the conditions for such availability set
13
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
14
* General Public License, version 2 with the GNU Classpath
15
* Exception [1] and GNU General Public License, version 2 with the
16
* OpenJDK Assembly Exception [2].
17
*
18
* [1] https://www.gnu.org/software/classpath/license.html
19
* [2] http://openjdk.java.net/legal/assembly-exception.html
20
*
21
* 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-exception
22
*******************************************************************************/
23
package java.lang.invoke;
24
25
/*[IF JAVA_SPEC_VERSION >= 15]*/
26
import java.util.List;
27
/*[ENDIF] JAVA_SPEC_VERSION >= 15 */
28
29
class InsertHandle extends MethodHandle {
30
final MethodHandle next;
31
final int insertionIndex;
32
private final Object[] values;
33
34
/*
35
* next must be an appropriately typed handle to ensure that the bound parameters are typechecked
36
* correctly.
37
*/
38
InsertHandle(MethodType type, MethodHandle next, int insertionIndex, Object values[]) {
39
super(type, KIND_INSERT,infoAffectingThunks(insertionIndex, values.length)); //$NON-NLS-1$
40
this.next = next;
41
this.insertionIndex = insertionIndex;
42
this.values = values;
43
}
44
45
InsertHandle(InsertHandle originalHandle, MethodType newType) {
46
super(originalHandle, newType);
47
this.next = originalHandle.next;
48
this.insertionIndex = originalHandle.insertionIndex;
49
this.values = originalHandle.values;
50
}
51
52
/*[IF JAVA_SPEC_VERSION >= 15]*/
53
@Override
54
boolean addRelatedMHs(List<MethodHandle> relatedMHs) {
55
relatedMHs.add(next);
56
return true;
57
}
58
/*[ENDIF] JAVA_SPEC_VERSION >= 15 */
59
60
// {{{ JIT support
61
62
private static final ThunkTable _thunkTable = new ThunkTable();
63
protected ThunkTable thunkTable(){ return _thunkTable; }
64
65
private static int[] infoAffectingThunks(int insertionIndex, int numberOfValues) {
66
// The location and number of values to insert affects the code generated in the thunks; see ILGen macros below
67
int[] result = { insertionIndex, numberOfValues };
68
return result;
69
}
70
71
protected ThunkTuple computeThunks(Object arg) {
72
int[] info = (int[])arg;
73
return thunkTable().get(new ThunkKeyWithIntArray(ThunkKey.computeThunkableType(type()), info));
74
}
75
76
static native int numPrefixArgs();
77
static native int numSuffixArgs();
78
private static native int numValuesToInsert();
79
80
@FrameIteratorSkip
81
private final int invokeExact_thunkArchetype_X(int argPlaceholder) {
82
if (ILGenMacros.isShareableThunk()) {
83
undoCustomizationLogic(next);
84
}
85
if (!ILGenMacros.isCustomThunk()) {
86
doCustomizationLogic();
87
}
88
return ILGenMacros.invokeExact_X(next, ILGenMacros.placeholder(
89
ILGenMacros.firstN(numPrefixArgs(), argPlaceholder),
90
ILGenMacros.arrayElements(values, 0, numValuesToInsert()),
91
ILGenMacros.lastN(numSuffixArgs(), argPlaceholder)));
92
}
93
94
// }}} JIT support
95
96
@Override
97
MethodHandle cloneWithNewType(MethodType newType) {
98
return new InsertHandle(this, newType);
99
}
100
101
final void compareWith(MethodHandle right, Comparator c) {
102
if (right instanceof InsertHandle) {
103
((InsertHandle)right).compareWithInsert(this, c);
104
} else {
105
c.fail();
106
}
107
}
108
109
final void compareWithInsert(InsertHandle left, Comparator c) {
110
c.compareStructuralParameter(left.insertionIndex, this.insertionIndex);
111
c.compareStructuralParameter(left.values.length, this.values.length);
112
for (int i = 0; (i < left.values.length) && (i < this.values.length); i++) {
113
c.compareUserSuppliedParameter(left.values[i], this.values[i]);
114
}
115
c.compareChildHandle(left.next, this.next);
116
}
117
}
118
119