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/InvokeExactHandle.java
12520 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
/* InvokeExactHandle is a MethodHandle subclass used to MethodHandle.invokeExact
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 InvokeExactHandle extends PrimitiveHandle {
35
/* MethodType that the first argument MethodHandle must match */
36
final MethodType nextType;
37
38
InvokeExactHandle(MethodType type) {
39
super(invokeExactMethodType(type), MethodHandle.class, "invokeExact", KIND_INVOKEEXACT, PUBLIC_FINAL_NATIVE, null); //$NON-NLS-1$
40
nextType = type;
41
this.vmSlot = 0;
42
this.defc = MethodHandle.class;
43
}
44
45
InvokeExactHandle(InvokeExactHandle originalHandle, MethodType newType) {
46
super(originalHandle, newType);
47
this.nextType = originalHandle.nextType;
48
}
49
50
/*
51
* Insert MethodHandle as first argument to existing type.
52
* (LMethodHandle;otherargs)returntype
53
*/
54
private static final MethodType invokeExactMethodType(MethodType type){
55
if (type == null) {
56
throw new IllegalArgumentException();
57
}
58
return type.insertParameterTypes(0, MethodHandle.class);
59
}
60
61
@Override
62
boolean canRevealDirect() {
63
/* This is invokevirtual of MethodHandle.invokeExact() */
64
return true;
65
}
66
67
// {{{ JIT support
68
69
private static final ThunkTable _thunkTable = new ThunkTable();
70
protected final ThunkTable thunkTable(){ return _thunkTable; }
71
72
protected ThunkTuple computeThunks(Object arg) {
73
// The first argument is always a MethodHandle.
74
// We don't upcast that to Object to avoid a downcast in the thunks.
75
//
76
return thunkTable().get(new ThunkKey(ThunkKey.computeThunkableType(type(), 0, 1)));
77
}
78
79
@FrameIteratorSkip
80
private final int invokeExact_thunkArchetype_X(MethodHandle next, int argPlaceholder) throws Throwable {
81
if (ILGenMacros.isShareableThunk()) {
82
undoCustomizationLogic(next);
83
}
84
if (!ILGenMacros.isCustomThunk()) {
85
doCustomizationLogic();
86
}
87
ILGenMacros.typeCheck(next, nextType);
88
return ILGenMacros.invokeExact_X(next, argPlaceholder);
89
}
90
91
// }}} JIT support
92
93
@Override
94
MethodHandle cloneWithNewType(MethodType newType) {
95
return new InvokeExactHandle(this, newType);
96
}
97
98
final void compareWith(MethodHandle right, Comparator c) {
99
if (right instanceof InvokeExactHandle) {
100
((InvokeExactHandle)right).compareWithInvokeExact(this, c);
101
} else {
102
c.fail();
103
}
104
}
105
106
final void compareWithInvokeExact(InvokeExactHandle left, Comparator c) {
107
// Nothing distinguishes InvokeExactHandles except their type, which Comparator already deals with
108
}
109
}
110
111
112