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/FinallyHandle.java
12520 views
1
/*[INCLUDE-IF Sidecar19-SE & !OPENJDK_METHODHANDLES]*/
2
/*******************************************************************************
3
* Copyright (c) 2016, 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
final class FinallyHandle extends PassThroughHandle {
26
private final MethodHandle tryTarget;
27
private final MethodHandle finallyTarget;
28
29
protected FinallyHandle(MethodHandle tryTarget, MethodHandle finallyTarget, MethodHandle equivalent) {
30
super(equivalent, infoAffectingThunks(finallyTarget.type().parameterCount())); //$NON-NLS-1$
31
this.tryTarget = tryTarget;
32
this.finallyTarget = finallyTarget;
33
}
34
35
FinallyHandle(FinallyHandle finallyHandle, MethodType newType) {
36
super(finallyHandle, newType);
37
this.tryTarget = finallyHandle.tryTarget;
38
this.finallyTarget = finallyHandle.finallyTarget;
39
}
40
41
public static FinallyHandle get(MethodHandle tryTarget, MethodHandle finallyTarget, MethodHandle equivalent) {
42
return new FinallyHandle(tryTarget, finallyTarget, equivalent);
43
}
44
45
// {{{ JIT support
46
private static final ThunkTable _thunkTable = new ThunkTable();
47
protected final ThunkTable thunkTable(){ return _thunkTable; }
48
49
private static native int numFinallyTargetArgsToPassThrough();
50
51
private static Object infoAffectingThunks(int numFinallyTargetArgs) {
52
// The number of arguments passed to the finally target affects the code generated in the thunks
53
return numFinallyTargetArgs;
54
}
55
56
protected final ThunkTuple computeThunks(Object arg) {
57
int numFinallyTargetArgs = (Integer)arg;
58
return thunkTable().get(new ThunkKeyWithInt(ThunkKey.computeThunkableType(type()), numFinallyTargetArgs));
59
}
60
// }}} JIT support
61
62
final void compareWith(MethodHandle right, Comparator c) {
63
if (right instanceof FinallyHandle) {
64
((FinallyHandle)right).compareWithFinally(this, c);
65
} else {
66
c.fail();
67
}
68
}
69
70
final void compareWithFinally(FinallyHandle left, Comparator c) {
71
c.compareChildHandle(left.tryTarget, this.tryTarget);
72
c.compareChildHandle(left.finallyTarget, this.finallyTarget);
73
}
74
75
MethodHandle cloneWithNewType(MethodType newType) {
76
return new FinallyHandle(this, newType);
77
}
78
79
@FrameIteratorSkip
80
private final void invokeExact_thunkArchetype_V(int argPlaceholder) throws Throwable {
81
if (ILGenMacros.isShareableThunk()) {
82
undoCustomizationLogic(tryTarget, finallyTarget);
83
}
84
if (!ILGenMacros.isCustomThunk()) {
85
doCustomizationLogic();
86
}
87
88
Throwable finallyThrowable = null;
89
try {
90
ILGenMacros.invokeExact_V(tryTarget, argPlaceholder);
91
} catch (Throwable tryThrowable) {
92
finallyThrowable = tryThrowable;
93
throw tryThrowable;
94
} finally {
95
ILGenMacros.invokeExact_V(finallyTarget,
96
ILGenMacros.placeholder(finallyThrowable,
97
ILGenMacros.firstN(numFinallyTargetArgsToPassThrough(),
98
argPlaceholder)));
99
}
100
}
101
102
@FrameIteratorSkip
103
@SuppressWarnings("finally")
104
private final boolean invokeExact_thunkArchetype_Z(int argPlaceholder) throws Throwable {
105
if (ILGenMacros.isShareableThunk()) {
106
undoCustomizationLogic(tryTarget, finallyTarget);
107
}
108
if (!ILGenMacros.isCustomThunk()) {
109
doCustomizationLogic();
110
}
111
112
Throwable finallyThrowable = null;
113
boolean result = false;
114
try {
115
result = ILGenMacros.invokeExact_Z(tryTarget, argPlaceholder);
116
} catch (Throwable tryThrowable) {
117
finallyThrowable = tryThrowable;
118
throw tryThrowable;
119
} finally {
120
return ILGenMacros.invokeExact_Z(finallyTarget,
121
ILGenMacros.placeholder(finallyThrowable, result,
122
ILGenMacros.firstN(numFinallyTargetArgsToPassThrough(),
123
argPlaceholder)));
124
}
125
}
126
127
@FrameIteratorSkip
128
@SuppressWarnings("finally")
129
private final byte invokeExact_thunkArchetype_B(int argPlaceholder) throws Throwable {
130
if (ILGenMacros.isShareableThunk()) {
131
undoCustomizationLogic(tryTarget, finallyTarget);
132
}
133
if (!ILGenMacros.isCustomThunk()) {
134
doCustomizationLogic();
135
}
136
137
Throwable finallyThrowable = null;
138
byte result = 0x0;
139
try {
140
result = ILGenMacros.invokeExact_B(tryTarget, argPlaceholder);
141
} catch (Throwable tryThrowable) {
142
finallyThrowable = tryThrowable;
143
throw tryThrowable;
144
} finally {
145
return ILGenMacros.invokeExact_B(finallyTarget,
146
ILGenMacros.placeholder(finallyThrowable, result,
147
ILGenMacros.firstN(numFinallyTargetArgsToPassThrough(),
148
argPlaceholder)));
149
}
150
}
151
152
@FrameIteratorSkip
153
@SuppressWarnings("finally")
154
private final short invokeExact_thunkArchetype_S(int argPlaceholder) throws Throwable {
155
if (ILGenMacros.isShareableThunk()) {
156
undoCustomizationLogic(tryTarget, finallyTarget);
157
}
158
if (!ILGenMacros.isCustomThunk()) {
159
doCustomizationLogic();
160
}
161
162
Throwable finallyThrowable = null;
163
short result = 0;
164
try {
165
result = ILGenMacros.invokeExact_S(tryTarget, argPlaceholder);
166
} catch (Throwable tryThrowable) {
167
finallyThrowable = tryThrowable;
168
throw tryThrowable;
169
} finally {
170
return ILGenMacros.invokeExact_S(finallyTarget,
171
ILGenMacros.placeholder(finallyThrowable, result,
172
ILGenMacros.firstN(numFinallyTargetArgsToPassThrough(),
173
argPlaceholder)));
174
}
175
}
176
177
@FrameIteratorSkip
178
@SuppressWarnings("finally")
179
private final int invokeExact_thunkArchetype_X(int argPlaceholder) throws Throwable {
180
if (ILGenMacros.isShareableThunk()) {
181
undoCustomizationLogic(tryTarget, finallyTarget);
182
}
183
if (!ILGenMacros.isCustomThunk()) {
184
doCustomizationLogic();
185
}
186
187
Throwable finallyThrowable = null;
188
int result = 0;
189
try {
190
result = ILGenMacros.invokeExact_X(tryTarget, argPlaceholder);
191
} catch (Throwable tryThrowable) {
192
finallyThrowable = tryThrowable;
193
throw tryThrowable;
194
} finally {
195
return ILGenMacros.invokeExact_X(finallyTarget,
196
ILGenMacros.placeholder(finallyThrowable, result,
197
ILGenMacros.firstN(numFinallyTargetArgsToPassThrough(),
198
argPlaceholder)));
199
}
200
}
201
202
@FrameIteratorSkip
203
@SuppressWarnings("finally")
204
private final long invokeExact_thunkArchetype_J(int argPlaceholder) throws Throwable {
205
if (ILGenMacros.isShareableThunk()) {
206
undoCustomizationLogic(tryTarget, finallyTarget);
207
}
208
if (!ILGenMacros.isCustomThunk()) {
209
doCustomizationLogic();
210
}
211
212
Throwable finallyThrowable = null;
213
long result = 0L;
214
try {
215
result = ILGenMacros.invokeExact_J(tryTarget, argPlaceholder);
216
} catch (Throwable tryThrowable) {
217
finallyThrowable = tryThrowable;
218
throw tryThrowable;
219
} finally {
220
return ILGenMacros.invokeExact_J(finallyTarget,
221
ILGenMacros.placeholder(finallyThrowable, result,
222
ILGenMacros.firstN(numFinallyTargetArgsToPassThrough(),
223
argPlaceholder)));
224
}
225
}
226
227
@FrameIteratorSkip
228
@SuppressWarnings("finally")
229
private final float invokeExact_thunkArchetype_F(int argPlaceholder) throws Throwable {
230
if (ILGenMacros.isShareableThunk()) {
231
undoCustomizationLogic(tryTarget, finallyTarget);
232
}
233
if (!ILGenMacros.isCustomThunk()) {
234
doCustomizationLogic();
235
}
236
237
Throwable finallyThrowable = null;
238
float result = 0.0F;
239
try {
240
result = ILGenMacros.invokeExact_F(tryTarget, argPlaceholder);
241
} catch (Throwable tryThrowable) {
242
finallyThrowable = tryThrowable;
243
throw tryThrowable;
244
} finally {
245
return ILGenMacros.invokeExact_F(finallyTarget,
246
ILGenMacros.placeholder(finallyThrowable, result,
247
ILGenMacros.firstN(numFinallyTargetArgsToPassThrough(),
248
argPlaceholder)));
249
}
250
}
251
252
@FrameIteratorSkip
253
@SuppressWarnings("finally")
254
private final double invokeExact_thunkArchetype_D(int argPlaceholder) throws Throwable {
255
if (ILGenMacros.isShareableThunk()) {
256
undoCustomizationLogic(tryTarget, finallyTarget);
257
}
258
if (!ILGenMacros.isCustomThunk()) {
259
doCustomizationLogic();
260
}
261
262
Throwable finallyThrowable = null;
263
double result = 0.0D;
264
try {
265
result = ILGenMacros.invokeExact_D(tryTarget, argPlaceholder);
266
} catch (Throwable tryThrowable) {
267
finallyThrowable = tryThrowable;
268
throw tryThrowable;
269
} finally {
270
return ILGenMacros.invokeExact_D(finallyTarget,
271
ILGenMacros.placeholder(finallyThrowable, result,
272
ILGenMacros.firstN(numFinallyTargetArgsToPassThrough(),
273
argPlaceholder)));
274
}
275
}
276
277
@FrameIteratorSkip
278
@SuppressWarnings("finally")
279
private final Object invokeExact_thunkArchetype_L(int argPlaceholder) throws Throwable {
280
if (ILGenMacros.isShareableThunk()) {
281
undoCustomizationLogic(tryTarget, finallyTarget);
282
}
283
if (!ILGenMacros.isCustomThunk()) {
284
doCustomizationLogic();
285
}
286
287
Throwable finallyThrowable = null;
288
Object result = null;
289
try {
290
result = ILGenMacros.invokeExact_L(tryTarget, argPlaceholder);
291
} catch (Throwable tryThrowable) {
292
finallyThrowable = tryThrowable;
293
throw tryThrowable;
294
} finally {
295
return ILGenMacros.invokeExact_L(finallyTarget,
296
ILGenMacros.placeholder(finallyThrowable, result,
297
ILGenMacros.firstN(numFinallyTargetArgsToPassThrough(),
298
argPlaceholder)));
299
}
300
}
301
}
302
303