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/InterfaceHandle.java
12521 views
1
/*[INCLUDE-IF Sidecar17 & !OPENJDK_METHODHANDLES]*/
2
/*******************************************************************************
3
* Copyright (c) 2009, 2021 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.Method;
26
27
import static java.lang.invoke.MethodHandleResolver.getJ9ClassFromClass;
28
29
/*
30
* InterfaceHandle is a MethodHandle that does interface dispatch
31
* on the receiver.
32
* <p>
33
* The vmSlot holds the itable index for the correct method.
34
* The type is the same as the method's except with the interface class prepended
35
*/
36
final class InterfaceHandle extends IndirectHandle {
37
38
/*[IF ]*/
39
// Support natives defined in the JIT dll
40
/*[ENDIF]*/
41
static native void registerNatives();
42
static {
43
registerNatives();
44
}
45
46
InterfaceHandle(Class<?> referenceClass, String methodName, MethodType type) throws NoSuchMethodException, IllegalAccessException {
47
super(indirectMethodType(type, referenceClass), referenceClass, methodName, KIND_INTERFACE);
48
assert referenceClass.isInterface();
49
this.defc = finishMethodInitialization(null, type);
50
}
51
52
53
InterfaceHandle(Method method) throws IllegalAccessException {
54
super(indirectMethodType(method), method.getDeclaringClass(), method.getName(), KIND_INTERFACE, method.getModifiers());
55
56
if (!referenceClass.isInterface()) {
57
throw new IllegalArgumentException();
58
}
59
60
boolean succeed = setVMSlotAndRawModifiersFromMethod(this, referenceClass, method, this.kind, specialCaller);
61
if (!succeed) {
62
throw new IllegalAccessException();
63
}
64
}
65
66
public InterfaceHandle(InterfaceHandle originalHandle, MethodType newType) {
67
super(originalHandle, newType);
68
}
69
70
/// {{{ JIT support
71
protected final long vtableOffset(Object receiver) {
72
/*[IF]*/
73
/* Must be 'referenceClass' rather than 'type().parameterType(0)' or
74
* 'defc' so that the itable index matches the defining interface at
75
* handle creation time, otherwise handles on interfaces methods defined
76
* in parent interfaces will crash
77
*/
78
/*[ENDIF]*/
79
Class<?> interfaceClass = referenceClass;
80
if (interfaceClass.isInstance(receiver)) {
81
long interfaceJ9Class = getJ9ClassFromClass(interfaceClass);
82
long receiverJ9Class = getJ9ClassFromClass(receiver.getClass());
83
int result = convertITableIndexToVTableIndex(interfaceJ9Class, (int)vmSlot, receiverJ9Class) << VTABLE_ENTRY_SHIFT;
84
if (result < 0) {
85
throw new IllegalAccessError();
86
}
87
return result;
88
} else {
89
throw new IncompatibleClassChangeError();
90
}
91
}
92
93
protected static native int convertITableIndexToVTableIndex(long interfaceClass, int itableIndex, long receiverClass);
94
95
// Thunks
96
97
private static final ThunkTable _thunkTable = new ThunkTable();
98
protected final ThunkTable thunkTable(){ return _thunkTable; }
99
100
@FrameIteratorSkip
101
private final void invokeExact_thunkArchetype_V(Object receiver, int argPlaceholder) {
102
ComputedCalls.dispatchVirtual_V(jittedMethodAddress(receiver), vtableIndexArgument(receiver), receiver, argPlaceholder);
103
}
104
105
@FrameIteratorSkip
106
private final int invokeExact_thunkArchetype_I(Object receiver, int argPlaceholder) {
107
return ComputedCalls.dispatchVirtual_I(jittedMethodAddress(receiver), vtableIndexArgument(receiver), receiver, argPlaceholder);
108
}
109
110
@FrameIteratorSkip
111
private final long invokeExact_thunkArchetype_J(Object receiver, int argPlaceholder) {
112
return ComputedCalls.dispatchVirtual_J(jittedMethodAddress(receiver), vtableIndexArgument(receiver), receiver, argPlaceholder);
113
}
114
115
@FrameIteratorSkip
116
private final float invokeExact_thunkArchetype_F(Object receiver, int argPlaceholder) {
117
return ComputedCalls.dispatchVirtual_F(jittedMethodAddress(receiver), vtableIndexArgument(receiver), receiver, argPlaceholder);
118
}
119
120
@FrameIteratorSkip
121
private final double invokeExact_thunkArchetype_D(Object receiver, int argPlaceholder) {
122
return ComputedCalls.dispatchVirtual_D(jittedMethodAddress(receiver), vtableIndexArgument(receiver), receiver, argPlaceholder);
123
}
124
125
@FrameIteratorSkip
126
private final Object invokeExact_thunkArchetype_L(Object receiver, int argPlaceholder) {
127
return ComputedCalls.dispatchVirtual_L(jittedMethodAddress(receiver), vtableIndexArgument(receiver), receiver, argPlaceholder);
128
}
129
130
/// }}} JIT support
131
132
@Override
133
MethodHandle cloneWithNewType(MethodType newType) {
134
return new InterfaceHandle(this, newType);
135
}
136
137
final void compareWith(MethodHandle right, Comparator c) {
138
if (right instanceof InterfaceHandle) {
139
((InterfaceHandle)right).compareWithInterface(this, c);
140
} else {
141
c.fail();
142
}
143
}
144
145
final void compareWithInterface(InterfaceHandle left, Comparator c) {
146
super.compareWithIndirect(left, c);
147
}
148
}
149
150
151