author | stsmirno |
Mon, 17 Oct 2016 18:54:12 -0400 | |
changeset 41705 | 332239c052cc |
parent 40631 | ed82623d7831 |
child 42607 | acd91f1875d4 |
permissions | -rw-r--r-- |
33160 | 1 |
/* |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
40059
diff
changeset
|
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
33160 | 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 |
|
39291
a4efe145313d
8157831: JVMCI tests should not be executed on linux-arm32
lmesnik
parents:
38152
diff
changeset
|
27 |
* @requires (vm.simpleArch == "x64" | vm.simpleArch == "sparcv9" | vm.simpleArch == "aarch64") |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
40059
diff
changeset
|
28 |
* @library /test/lib / |
36508 | 29 |
* @library ../common/patches |
38152
80e5da81fb2c
8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents:
36508
diff
changeset
|
30 |
* @modules java.base/jdk.internal.misc |
36508 | 31 |
* @modules java.base/jdk.internal.org.objectweb.asm |
32 |
* java.base/jdk.internal.org.objectweb.asm.tree |
|
33 |
* jdk.vm.ci/jdk.vm.ci.hotspot |
|
34 |
* jdk.vm.ci/jdk.vm.ci.code |
|
35 |
* @build jdk.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper |
|
33160 | 36 |
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI |
36508 | 37 |
* compiler.jvmci.compilerToVM.GetExceptionTableTest |
33160 | 38 |
*/ |
39 |
||
40 |
package compiler.jvmci.compilerToVM; |
|
41 |
||
42 |
import compiler.jvmci.common.CTVMUtilities; |
|
40059 | 43 |
import jdk.test.lib.Asserts; |
44 |
import jdk.vm.ci.hotspot.CompilerToVMHelper; |
|
45 |
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod; |
|
46 |
||
33160 | 47 |
import java.io.IOException; |
48 |
import java.lang.reflect.Executable; |
|
49 |
import java.net.Socket; |
|
50 |
import java.util.HashMap; |
|
51 |
import java.util.Map; |
|
52 |
||
53 |
public class GetExceptionTableTest { |
|
54 |
||
55 |
public static final int TRY_CATCH_COUNT = 3; |
|
56 |
public static final int TRY_CATCH_FINALLY_COUNT = 8; |
|
57 |
public static final int TRY_WITH_RESOURCES_COUNT = 6; |
|
58 |
public static final int EMPTY_COUNT = 0; |
|
59 |
||
60 |
public static void main(String[] args) { |
|
61 |
Map<Executable, Integer> testCases = createTestCases(); |
|
62 |
testCases.forEach(GetExceptionTableTest::runSanityTest); |
|
63 |
} |
|
64 |
||
65 |
private static Map<Executable, Integer> createTestCases() { |
|
66 |
HashMap<Executable, Integer> methods = new HashMap<>(); |
|
67 |
try { |
|
68 |
Class<?> aClass = GetExceptionTableTest.DummyClass.class; |
|
69 |
methods.put(aClass.getMethod("tryCatchDummy"), TRY_CATCH_COUNT); |
|
70 |
methods.put(aClass.getMethod("tryCatchFinallyDummy"), |
|
71 |
TRY_CATCH_FINALLY_COUNT); |
|
72 |
methods.put(aClass.getMethod("tryWithResourcesDummy"), |
|
73 |
TRY_WITH_RESOURCES_COUNT); |
|
74 |
methods.put(aClass.getMethod("emptyFunction"), EMPTY_COUNT); |
|
75 |
} catch (NoSuchMethodException e) { |
|
76 |
throw new Error("TEST BUG", e); |
|
77 |
} |
|
78 |
return methods; |
|
79 |
} |
|
80 |
||
81 |
private static void runSanityTest(Executable aMethod, |
|
82 |
Integer expectedTableLength) { |
|
33632 | 83 |
HotSpotResolvedJavaMethod method = CTVMUtilities |
33160 | 84 |
.getResolvedMethod(aMethod); |
85 |
int tableLength = CompilerToVMHelper.getExceptionTableLength(method); |
|
86 |
Asserts.assertEQ(tableLength, expectedTableLength, aMethod |
|
87 |
+ " incorrect exception table length."); |
|
88 |
||
89 |
long tableStart = CompilerToVMHelper.getExceptionTableStart(method); |
|
90 |
if (tableLength > 0) { |
|
91 |
Asserts.assertNE(tableStart, 0L, aMethod + " exception table starts " |
|
92 |
+ "at 0."); |
|
93 |
} |
|
94 |
} |
|
95 |
||
96 |
private static class DummyClass { |
|
97 |
public static void emptyFunction() {} |
|
98 |
public static void tryCatchDummy() throws Throwable { |
|
99 |
try { |
|
100 |
throw new Exception("Dummy exception"); |
|
101 |
} catch (ArithmeticException ex) { |
|
102 |
throw new IOException(ex.getMessage()); |
|
103 |
} catch (IOException ex) { |
|
104 |
throw new Exception(ex); |
|
105 |
} catch (Exception ex) { |
|
106 |
throw new Exception(ex); |
|
107 |
} |
|
108 |
} |
|
109 |
||
110 |
public int tryCatchFinallyDummy() { |
|
111 |
// 4 times catch/finally = 8 catch-blocks and finally-blocks |
|
112 |
try { |
|
113 |
throw new Exception("Dummy exception"); |
|
114 |
} catch (IndexOutOfBoundsException ex) { |
|
115 |
return 1; |
|
116 |
} catch (ArithmeticException ex) { |
|
117 |
return 2; |
|
118 |
} catch (IOException ex) { |
|
119 |
return 3; |
|
120 |
} catch (Exception ex) { |
|
121 |
return 4; |
|
122 |
} finally { |
|
123 |
return 0; |
|
124 |
} |
|
125 |
} |
|
126 |
||
127 |
public static int tryWithResourcesDummy() throws Throwable { |
|
128 |
try (Socket socket = new Socket()) { |
|
129 |
throw new Exception("Dummy exception"); |
|
130 |
} catch (ArithmeticException ex) { |
|
131 |
return 1; |
|
132 |
} catch (IOException ex) { |
|
133 |
return 2; |
|
134 |
} catch (Exception ex) { |
|
135 |
return 3; |
|
136 |
} |
|
137 |
} |
|
138 |
} |
|
139 |
} |
|
140 |