Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/jvmci/compilerToVM/GetExceptionTableTest.java
41153 views
1
/*
2
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/**
25
* @test
26
* @bug 8136421
27
* @requires vm.jvmci
28
* @library /test/lib /
29
* @library ../common/patches
30
* @modules java.base/jdk.internal.misc
31
* @modules java.base/jdk.internal.org.objectweb.asm
32
* java.base/jdk.internal.org.objectweb.asm.tree
33
* jdk.internal.vm.ci/jdk.vm.ci.hotspot
34
* jdk.internal.vm.ci/jdk.vm.ci.code
35
* jdk.internal.vm.ci/jdk.vm.ci.meta
36
* jdk.internal.vm.ci/jdk.vm.ci.runtime
37
*
38
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper
39
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
40
* -XX:-UseJVMCICompiler
41
* compiler.jvmci.compilerToVM.GetExceptionTableTest
42
*/
43
44
package compiler.jvmci.compilerToVM;
45
46
import compiler.jvmci.common.CTVMUtilities;
47
import jdk.test.lib.Asserts;
48
import jdk.vm.ci.hotspot.CompilerToVMHelper;
49
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
50
51
import java.io.IOException;
52
import java.lang.reflect.Executable;
53
import java.net.Socket;
54
import java.util.HashMap;
55
import java.util.Map;
56
57
public class GetExceptionTableTest {
58
59
public static final int TRY_CATCH_COUNT = 3;
60
public static final int TRY_CATCH_FINALLY_COUNT = 8;
61
public static final int TRY_WITH_RESOURCES_COUNT = 5;
62
public static final int EMPTY_COUNT = 0;
63
64
public static void main(String[] args) {
65
Map<Executable, Integer> testCases = createTestCases();
66
testCases.forEach(GetExceptionTableTest::runSanityTest);
67
}
68
69
private static Map<Executable, Integer> createTestCases() {
70
HashMap<Executable, Integer> methods = new HashMap<>();
71
try {
72
Class<?> aClass = GetExceptionTableTest.DummyClass.class;
73
methods.put(aClass.getMethod("tryCatchDummy"), TRY_CATCH_COUNT);
74
methods.put(aClass.getMethod("tryCatchFinallyDummy"),
75
TRY_CATCH_FINALLY_COUNT);
76
methods.put(aClass.getMethod("tryWithResourcesDummy"),
77
TRY_WITH_RESOURCES_COUNT);
78
methods.put(aClass.getMethod("emptyFunction"), EMPTY_COUNT);
79
} catch (NoSuchMethodException e) {
80
throw new Error("TEST BUG", e);
81
}
82
return methods;
83
}
84
85
private static void runSanityTest(Executable aMethod,
86
Integer expectedTableLength) {
87
HotSpotResolvedJavaMethod method = CTVMUtilities
88
.getResolvedMethod(aMethod);
89
int tableLength = CompilerToVMHelper.getExceptionTableLength(method);
90
Asserts.assertEQ(tableLength, expectedTableLength, aMethod
91
+ " incorrect exception table length.");
92
93
long tableStart = CompilerToVMHelper.getExceptionTableStart(method);
94
if (tableLength > 0) {
95
Asserts.assertNE(tableStart, 0L, aMethod + " exception table starts "
96
+ "at 0.");
97
}
98
}
99
100
private static class DummyClass {
101
public static void emptyFunction() {}
102
public static void tryCatchDummy() throws Throwable {
103
try {
104
throw new Exception("Dummy exception");
105
} catch (ArithmeticException ex) {
106
throw new IOException(ex.getMessage());
107
} catch (IOException ex) {
108
throw new Exception(ex);
109
} catch (Exception ex) {
110
throw new Exception(ex);
111
}
112
}
113
114
public int tryCatchFinallyDummy() {
115
// 4 times catch/finally = 8 catch-blocks and finally-blocks
116
try {
117
throw new Exception("Dummy exception");
118
} catch (IndexOutOfBoundsException ex) {
119
return 1;
120
} catch (ArithmeticException ex) {
121
return 2;
122
} catch (IOException ex) {
123
return 3;
124
} catch (Exception ex) {
125
return 4;
126
} finally {
127
return 0;
128
}
129
}
130
131
public static int tryWithResourcesDummy() throws Throwable {
132
try (Socket socket = new Socket()) {
133
throw new Exception("Dummy exception");
134
} catch (ArithmeticException ex) {
135
return 1;
136
} catch (IOException ex) {
137
return 2;
138
} catch (Exception ex) {
139
return 3;
140
}
141
}
142
}
143
}
144
145