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/InvokeGenericHandle.java
12521 views
1
/*[INCLUDE-IF Sidecar17 & !OPENJDK_METHODHANDLES]*/
2
/*******************************************************************************
3
* Copyright (c) 2009, 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
import java.lang.reflect.Modifier;
26
27
/* InvokeGenericHandle is a MethodHandle subclass used to MethodHandle.invokeGeneric
28
* with a specific signature on a MethodHandle.
29
* <p>
30
* The vmSlot will hold 0 as there is no actual method for it.
31
* <p>
32
* Can be thought of as a special case of VirtualHandle.
33
*/
34
final class InvokeGenericHandle extends PrimitiveHandle {
35
/* MethodType that the first argument MethodHandle will be cast to using asType */
36
@VMCONSTANTPOOL_FIELD
37
final MethodType castType;
38
39
40
InvokeGenericHandle(MethodType type) {
41
super(invokeGenericMethodType(type), MethodHandle.class, "invoke", KIND_INVOKEGENERIC, PUBLIC_FINAL_NATIVE, null); //$NON-NLS-1$
42
if (type == null) {
43
throw new IllegalArgumentException();
44
}
45
this.vmSlot = 0;
46
this.defc = MethodHandle.class;
47
this.castType = type;
48
}
49
50
InvokeGenericHandle(InvokeGenericHandle originalHandle, MethodType newType) {
51
super(originalHandle, newType);
52
this.castType = originalHandle.castType;
53
}
54
55
/*
56
* Insert MethodHandle as first argument to existing type.
57
* (LMethodHandle;otherargs)returntype
58
*/
59
private static final MethodType invokeGenericMethodType(MethodType type) {
60
return type.insertParameterTypes(0, MethodHandle.class);
61
}
62
63
@Override
64
boolean canRevealDirect() {
65
/* This is invokevirtual of MethodHandle.invoke() */
66
return true;
67
}
68
69
// {{{ JIT support
70
71
private static final ThunkTable _thunkTable = new ThunkTable();
72
protected final ThunkTable thunkTable(){ return _thunkTable; }
73
74
protected ThunkTuple computeThunks(Object arg) {
75
// The first argument is always a MethodHandle.
76
// We don't upcast that to Object to avoid a downcast in the thunks.
77
//
78
return thunkTable().get(new ThunkKey(ThunkKey.computeThunkableType(type(), 0, 1)));
79
}
80
81
@FrameIteratorSkip
82
private final int invokeExact_thunkArchetype_X(MethodHandle next, int argPlaceholder) throws Throwable {
83
if (ILGenMacros.isShareableThunk()) {
84
undoCustomizationLogic(next);
85
}
86
if (!ILGenMacros.isCustomThunk()) {
87
doCustomizationLogic();
88
}
89
return ILGenMacros.invokeExact_X(next.asType(castType), argPlaceholder);
90
}
91
92
// }}} JIT support
93
94
@Override
95
MethodHandle cloneWithNewType(MethodType newType) {
96
return new InvokeGenericHandle(this, newType);
97
}
98
99
final void compareWith(MethodHandle right, Comparator c) {
100
if (right instanceof InvokeGenericHandle) {
101
((InvokeGenericHandle)right).compareWithInvokeGeneric(this, c);
102
} else {
103
c.fail();
104
}
105
}
106
107
final void compareWithInvokeGeneric(InvokeGenericHandle left, Comparator c) {
108
// Nothing distinguishes InvokeGenericHandles except their type, which Comparator already deals with
109
}
110
}
111
112
113