This content has been marked as final. Show 2 replies
Such optimization are done by JIT compiler (not by javac).
C++ have just the same problems, exceptions make CFG analisis more difficult but not impossible.
PS You can read JLS about volatile variables there some additional restrictions on them.
zhmur is right, this makes optimization harder not impossible.
There are sicentific papers aimed at making more analysis/optimization in the presence of many try/catch blocks. For instance, JIT can reorder statements, and then put compensation code into the catch body, recovering program state back if an exception was thrown.
General principle is simple: exceptions are rare. So JIT optimizes the "normal" control flow by the cost of more complex catch body.
You may also look/post to the comp.compilers newsgroup regarding compilers and optimization techniques
High-Performance JVM for J2SE