4 ms·
I don't know if the JVM does this right now, but you CAN detect useless stack building and simply not do it. In other words, the CPU cycle penalty of java's (an
by rzwitserloot 18y ago
I don't know if the JVM does this right now, but you CAN detect useless stack building and simply not do it. In other words, the CPU cycle penalty of java's (and most other language's) exception mechanism can be virtually eliminated. The other benefits (resuming, for example) are a different issue.
The issue that I think the lisper of the OP is talking about is something like this:
try {
something();
} catch ( SomeException e ) {
//don't ever even look at e's stack, and do something else.
}
Assuming the exception occurs, then to be safe the VM has to build the entire stack, which involves unwinding a lot of JIT work if you're unlucky, even though at the end it wasn't actually needed. However, assuming it matters that this is slow, which pretty much means that this is in a tight loop someplace, then a JIT compiler can detect that this situation always occurs, and simply avoid creating the stack.
There are still very interesting applications, such as logging and resuming, for not unwinding down the stack before giving the handlers in the chain an opportunity, but the CPU argument seems void to me.