8236285: [JVMCI] improve TranslatedException traces

Reviewed-by: never, kvn
This commit is contained in:
Doug Simon 2020-03-18 13:11:09 -07:00
parent bf54c47471
commit 34b9ac2287
2 changed files with 24 additions and 11 deletions
src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot
test/hotspot/jtreg/compiler/jvmci/jdk.vm.ci.hotspot.test/src/jdk/vm/ci/hotspot/test

@ -36,8 +36,14 @@ import java.util.Objects;
@SuppressWarnings("serial")
final class TranslatedException extends Exception {
private TranslatedException(String message, Throwable translationFailure) {
super("[" + translationFailure + "]" + Objects.toString(message, ""));
/**
* Class name of exception that could not be instantiated.
*/
private String originalExceptionClassName;
private TranslatedException(String message, String originalExceptionClassName) {
super(message);
this.originalExceptionClassName = originalExceptionClassName;
}
/**
@ -49,6 +55,18 @@ final class TranslatedException extends Exception {
return this;
}
@Override
public String toString() {
String s;
if (originalExceptionClassName.equals(TranslatedException.class.getName())) {
s = getClass().getName();
} else {
s = getClass().getName() + "[" + originalExceptionClassName + "]";
}
String message = getMessage();
return (message != null) ? (s + ": " + message) : s;
}
/**
* Prints a stack trace for {@code throwable} and returns {@code true}. Used to print stack
* traces only when assertions are enabled.
@ -86,14 +104,9 @@ final class TranslatedException extends Exception {
if (message == null) {
return initCause((Throwable) cls.getConstructor().newInstance(), cause);
}
cls.getDeclaredConstructor(String.class);
return initCause((Throwable) cls.getConstructor(String.class).newInstance(message), cause);
return initCause((Throwable) cls.getDeclaredConstructor(String.class).newInstance(message), cause);
} catch (Throwable translationFailure) {
if (className.equals(TranslatedException.class.getName())) {
// Chop the class name when boxing another TranslatedException
return initCause(new TranslatedException(message, translationFailure), cause);
}
return initCause(new TranslatedException(null, translationFailure), cause);
return initCause(new TranslatedException(message, className), cause);
}
}
@ -236,7 +249,7 @@ final class TranslatedException extends Exception {
return throwable;
} catch (Throwable translationFailure) {
assert printStackTrace(translationFailure);
return new TranslatedException("Error decoding exception: " + encodedThrowable, translationFailure);
return new TranslatedException("Error decoding exception: " + encodedThrowable, translationFailure.getClass().getName());
}
}
}

@ -75,7 +75,7 @@ public class TestTranslatedException {
while (original != null) {
if (Untranslatable.class.equals(original.getClass())) {
Assert.assertEquals("jdk.vm.ci.hotspot.TranslatedException", decoded.getClass().getName());
Assert.assertEquals("[java.lang.ClassNotFoundException: jdk/vm/ci/hotspot/test/TestTranslatedException$Untranslatable]", decoded.getMessage());
Assert.assertEquals("jdk.vm.ci.hotspot.TranslatedException[jdk.vm.ci.hotspot.test.TestTranslatedException$Untranslatable]: test exception", decoded.toString());
Assert.assertEquals("test exception", original.getMessage());
} else {
Assert.assertEquals(original.getClass().getName(), decoded.getClass().getName());