On 10/23/2014 12:42 AM, Mandy Chung wrote:
Talking about exceptions and fillInStackTrace, it's known to be
significant cost. It'd be interesting to have the VM flag that can
measure the time it spends in filling in the backtrace of each
exception type (and perhaps the mean and max stack depth) that will
give a better idea of the performance distribution. In addition,
doPrivileged wraps checked exception with PrivilegedActionException
that essentially has the same stack trace and it doubles the cost even
in the absence of security manager. I have exchanged some mail with
the security team to see if this is a low-hanging fruit to improve the
performance.
Mandy
For such cases, where the purpose is to just change the type of
exception, a Throwable constructor (+ Exception, RuntimeException and
Error constructors chained to it) like the following would be helpful:
protected Throwable(Throwable cause, boolean poseAsCause) {
if (poseAsCause && cause != null) {
backtrace = cause.backtrace;
stackTrace = cause.stackTrace;
suppressedExceptions = cause.suppressedExceptions;
detailMessage = "Posing as: " + cause;
} else {
fillInStackTrace();
detailMessage = (cause==null ? null : cause.toString());
}
this.cause = cause;
}
Such exceptions would inherit the stack-trace from their cause,
eliminating the need to construct their own stack-trace that would be
basically a suffix of the stack-trace of the cause.
Regards, Peter