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/CatchHandle.java
12520 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
final class CatchHandle extends PassThroughHandle {
26
private final MethodHandle tryTarget;
27
private final Class<? extends Throwable> exceptionClass;
28
private final MethodHandle catchTarget;
29
30
protected CatchHandle(MethodHandle tryTarget, Class<? extends Throwable> exceptionClass, MethodHandle catchTarget, MethodHandle equivalent) {
31
super(equivalent, infoAffectingThunks(catchTarget.type().parameterCount())); //$NON-NLS-1$
32
this.tryTarget = tryTarget;
33
this.exceptionClass = exceptionClass;
34
this.catchTarget = catchTarget;
35
}
36
37
CatchHandle(CatchHandle catchHandle, MethodType newType) {
38
super(catchHandle, newType);
39
this.tryTarget = catchHandle.tryTarget;
40
this.exceptionClass = catchHandle.exceptionClass;
41
this.catchTarget = catchHandle.catchTarget;
42
}
43
44
MethodHandle cloneWithNewType(MethodType newType) {
45
return new CatchHandle(this, newType);
46
}
47
48
public static CatchHandle get(MethodHandle tryTarget, Class<? extends Throwable> exceptionClass, MethodHandle catchTarget, MethodHandle equivalent) {
49
return new CatchHandle(tryTarget, exceptionClass, catchTarget, equivalent);
50
}
51
52
// {{{ JIT support
53
private static final ThunkTable _thunkTable = new ThunkTable();
54
protected final ThunkTable thunkTable(){ return _thunkTable; }
55
56
private static native int numCatchTargetArgsToPassThrough();
57
58
private static Object infoAffectingThunks(int numCatchTargetArgs) {
59
// The number of arguments passed to the catch target affects the code generated in the thunks
60
return numCatchTargetArgs;
61
}
62
63
protected final ThunkTuple computeThunks(Object arg) {
64
int numCatchTargetArgs = (Integer)arg;
65
return thunkTable().get(new ThunkKeyWithInt(ThunkKey.computeThunkableType(type()), numCatchTargetArgs));
66
}
67
68
@FrameIteratorSkip
69
private final int invokeExact_thunkArchetype_X(int argPlaceholder) {
70
if (ILGenMacros.isShareableThunk()) {
71
undoCustomizationLogic(tryTarget, catchTarget);
72
}
73
if (!ILGenMacros.isCustomThunk()) {
74
doCustomizationLogic();
75
}
76
try {
77
return ILGenMacros.invokeExact_X(tryTarget, argPlaceholder);
78
} catch (Throwable t) {
79
if (exceptionClass.isInstance(t)) {
80
return ILGenMacros.invokeExact_X(catchTarget, ILGenMacros.placeholder(t, ILGenMacros.firstN(numCatchTargetArgsToPassThrough(), argPlaceholder)));
81
} else {
82
throw t;
83
}
84
}
85
}
86
87
// }}} JIT support
88
89
final void compareWith(MethodHandle right, Comparator c) {
90
if (right instanceof CatchHandle) {
91
((CatchHandle)right).compareWithCatch(this, c);
92
} else {
93
c.fail();
94
}
95
}
96
97
final void compareWithCatch(CatchHandle left, Comparator c) {
98
c.compareStructuralParameter(left.exceptionClass, this.exceptionClass);
99
c.compareChildHandle(left.tryTarget, this.tryTarget);
100
c.compareChildHandle(left.catchTarget, this.catchTarget);
101
}
102
}
103
104
105