author | iignatyev |
Sat, 09 Nov 2019 10:27:53 -0800 | |
changeset 59001 | d595f1faace2 |
parent 58974 | 2b0f2fe82735 |
permissions | -rw-r--r-- |
55206 | 1 |
/* |
2 |
* Copyright (c) 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 |
*/ |
|
58974
2b0f2fe82735
8230364: [JVMCI] a number of JVMCI tests are not jtreg enabled
iignatyev
parents:
55206
diff
changeset
|
23 |
|
2b0f2fe82735
8230364: [JVMCI] a number of JVMCI tests are not jtreg enabled
iignatyev
parents:
55206
diff
changeset
|
24 |
/* |
2b0f2fe82735
8230364: [JVMCI] a number of JVMCI tests are not jtreg enabled
iignatyev
parents:
55206
diff
changeset
|
25 |
* @test |
2b0f2fe82735
8230364: [JVMCI] a number of JVMCI tests are not jtreg enabled
iignatyev
parents:
55206
diff
changeset
|
26 |
* @requires vm.jvmci |
2b0f2fe82735
8230364: [JVMCI] a number of JVMCI tests are not jtreg enabled
iignatyev
parents:
55206
diff
changeset
|
27 |
* @modules jdk.internal.vm.ci/jdk.vm.ci.hotspot:open |
2b0f2fe82735
8230364: [JVMCI] a number of JVMCI tests are not jtreg enabled
iignatyev
parents:
55206
diff
changeset
|
28 |
* @library /compiler/jvmci/jdk.vm.ci.hotspot.test/src |
2b0f2fe82735
8230364: [JVMCI] a number of JVMCI tests are not jtreg enabled
iignatyev
parents:
55206
diff
changeset
|
29 |
* @run testng/othervm |
2b0f2fe82735
8230364: [JVMCI] a number of JVMCI tests are not jtreg enabled
iignatyev
parents:
55206
diff
changeset
|
30 |
* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:-UseJVMCICompiler |
2b0f2fe82735
8230364: [JVMCI] a number of JVMCI tests are not jtreg enabled
iignatyev
parents:
55206
diff
changeset
|
31 |
* jdk.vm.ci.hotspot.test.TestTranslatedException |
2b0f2fe82735
8230364: [JVMCI] a number of JVMCI tests are not jtreg enabled
iignatyev
parents:
55206
diff
changeset
|
32 |
*/ |
2b0f2fe82735
8230364: [JVMCI] a number of JVMCI tests are not jtreg enabled
iignatyev
parents:
55206
diff
changeset
|
33 |
|
55206 | 34 |
package jdk.vm.ci.hotspot.test; |
35 |
||
36 |
import java.io.ByteArrayOutputStream; |
|
37 |
import java.io.PrintStream; |
|
38 |
import java.lang.reflect.InvocationTargetException; |
|
39 |
import java.lang.reflect.Method; |
|
40 |
||
58974
2b0f2fe82735
8230364: [JVMCI] a number of JVMCI tests are not jtreg enabled
iignatyev
parents:
55206
diff
changeset
|
41 |
import org.testng.Assert; |
2b0f2fe82735
8230364: [JVMCI] a number of JVMCI tests are not jtreg enabled
iignatyev
parents:
55206
diff
changeset
|
42 |
import org.testng.annotations.Test; |
55206 | 43 |
|
44 |
public class TestTranslatedException { |
|
45 |
@SuppressWarnings("serial") |
|
46 |
public static class Untranslatable extends RuntimeException { |
|
47 |
public Untranslatable(String message, Throwable cause) { |
|
48 |
super(message, cause); |
|
49 |
} |
|
50 |
} |
|
51 |
||
52 |
@SuppressWarnings("unchecked") |
|
53 |
@Test |
|
54 |
public void encodeDecodeTest() throws Exception { |
|
55 |
||
56 |
Class<?> translatedExceptionClass = Class.forName("jdk.vm.ci.hotspot.TranslatedException"); |
|
57 |
||
58 |
Method encode = translatedExceptionClass.getDeclaredMethod("encodeThrowable", Throwable.class); |
|
59 |
Method decode = translatedExceptionClass.getDeclaredMethod("decodeThrowable", String.class); |
|
60 |
encode.setAccessible(true); |
|
61 |
decode.setAccessible(true); |
|
62 |
||
63 |
Throwable throwable = new ExceptionInInitializerError(new InvocationTargetException(new Untranslatable("test exception", new NullPointerException()), "invoke")); |
|
64 |
for (int i = 0; i < 10; i++) { |
|
65 |
throwable = new ExceptionInInitializerError(new InvocationTargetException(new RuntimeException(String.valueOf(i), throwable), "invoke")); |
|
66 |
} |
|
67 |
String encoding = (String) encode.invoke(null, throwable); |
|
68 |
Throwable decoded = (Throwable) decode.invoke(null, encoding); |
|
59001
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
69 |
assertThrowableEquals(throwable, decoded); |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
70 |
} |
55206 | 71 |
|
59001
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
72 |
private static void assertThrowableEquals(Throwable original, Throwable decoded) { |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
73 |
try { |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
74 |
Assert.assertEquals(original == null, decoded == null); |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
75 |
while (original != null) { |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
76 |
if (Untranslatable.class.equals(original.getClass())) { |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
77 |
Assert.assertEquals("jdk.vm.ci.hotspot.TranslatedException", decoded.getClass().getName()); |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
78 |
Assert.assertEquals("[java.lang.ClassNotFoundException: jdk/vm/ci/hotspot/test/TestTranslatedException$Untranslatable]", decoded.getMessage()); |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
79 |
Assert.assertEquals("test exception", original.getMessage()); |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
80 |
} else { |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
81 |
Assert.assertEquals(original.getClass().getName(), decoded.getClass().getName()); |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
82 |
Assert.assertEquals(original.getMessage(), decoded.getMessage()); |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
83 |
} |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
84 |
StackTraceElement[] originalStack = original.getStackTrace(); |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
85 |
StackTraceElement[] decodedStack = decoded.getStackTrace(); |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
86 |
Assert.assertEquals(originalStack.length, decodedStack.length); |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
87 |
for (int i = 0, n = originalStack.length; i < n; ++i) { |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
88 |
StackTraceElement originalStackElement = originalStack[i]; |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
89 |
StackTraceElement decodedStackElement = decodedStack[i]; |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
90 |
Assert.assertEquals(originalStackElement.getClassLoaderName(), decodedStackElement.getClassLoaderName()); |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
91 |
Assert.assertEquals(originalStackElement.getModuleName(), decodedStackElement.getModuleName()); |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
92 |
Assert.assertEquals(originalStackElement.getClassName(), decodedStackElement.getClassName()); |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
93 |
Assert.assertEquals(originalStackElement.getMethodName(), decodedStackElement.getMethodName()); |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
94 |
Assert.assertEquals(originalStackElement.getFileName(), decodedStackElement.getFileName()); |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
95 |
Assert.assertEquals(originalStackElement.getLineNumber(), decodedStackElement.getLineNumber()); |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
96 |
} |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
97 |
original = original.getCause(); |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
98 |
decoded = decoded.getCause(); |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
99 |
} |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
100 |
} catch (AssertionError e) { |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
101 |
System.err.println("original:["); |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
102 |
original.printStackTrace(System.err); |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
103 |
System.err.println("]"); |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
104 |
System.err.println("decoded:["); |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
105 |
original.printStackTrace(System.err); |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
106 |
System.err.println("]"); |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
107 |
throw e; |
d595f1faace2
8233745: [JVMCI] TranslatedException should serialize classloader and module info
iignatyev
parents:
58974
diff
changeset
|
108 |
} |
55206 | 109 |
} |
110 |
} |