bart.jacobs at cs.kuleuven.be
Thu May 22 09:33:15 PDT 2008
The Java Virtual Machine Specification (JVMS) states that the JVM can
throw UnknownError and InternalError exceptions anywhere. (I.e., any
bytecode instruction can throw these exceptions.) However, I presume
that when running a program on a given build of the actual OpenJDK JVM,
there are certain instructions that never actually throw such an
exception. So, my question is: How bad is it really? Where can the
current build of the OpenJDK JVM actually throw these exceptions? Can a
programmer make stronger assumptions if he knows he's running on the
OpenJDK? And how stable would those assumptions be under evolution of
the JVM implementation?
My hypothesis is that you can't really make any assumptions as to the
program points where these exceptions can occur, especially because of
JIT optimizations that move instructions around. Would this be a fair
assessment? Or would this be overly cautious?
The reason I'm asking is because I'm doing research into how to
facilitate writing Java programs that preserve their safety properties
even in the presence of these internal exceptions. In Java as it is
today, this is not trivial, especially if the program catches Throwable
or uses try-finally statements or synchronized statements. If it were
the case that internal exceptions could be ruled out at certain classes
of program points, then this would seem to make it more feasible to deal
with them on a case-by-case basis, rather than trying to provide a
blanket solution for internal exceptions occurring in a computation,
regardless of the specific program point where they occur.
This is especially relevant for small pieces of code in a finally block.
Are there categories of such code that are guaranteed to execute to
completion successfully? In certain other execution engines, a
programmer needs to specially "prepare" such a block of code (by marking
it specially in a way recognized by the runtime) to ensure that no
internal exception can happen within that block due to the JITter
running out of memory, or because of a lack of stack space. Would
something similar be necessary for the OpenJDK JVM, or does this source
of internal exceptions not exist there?
(My current thinking on a new language construct for facilitating
writing programs with provably safe exception handling is at
Many thanks in advance for any feedback!
Postdoc at Dept. Computer Science, Katholieke Universiteit Leuven, Belgium
More information about the hotspot-dev