Exception handler question
Roman Kennke
roman.kennke at aicas.com
Mon Nov 17 13:48:48 PST 2008
Hi,
I have a question regarding exception handlers. If I have code like
this:
synchronized (o)
{
x();
}
produces bytecode like this:
0: aload_1
1: dup
2: astore_2
3: monitorenter
# 4: aload_0
# 5: invokevirtual #2; //Method x:()V
# 8: aload_2
# 9: monitorexit
10: goto 18
* 13: astore_3
* 14: aload_2
* 15: monitorexit
16: aload_3
17: athrow
18: return
Exception table:
from to target type
# 4 10 13 any
* 13 16 13 any
The code marked with # has an exception handler, which is marked with *.
This is clearly ok, it is made so that the monitors are correctly exited
when an exception is thrown in the sync block.
My question is, why does the exception handler * point to itself?
Wouldn't that catapult the VM into a loop, if monitorexit fails? A
scenario that comes to mind is when x() is a JNI function that does a
monitorexit. I'd like to understand why this code is generated like
this.
/Roman
--
Dipl.-Inform. (FH) Roman Kennke, Software Engineer, http://kennke.org
aicas Allerton Interworks Computer Automated Systems GmbH
Haid-und-Neu-Straße 18 * D-76131 Karlsruhe * Germany
http://www.aicas.com * Tel: +49-721-663 968-48
USt-Id: DE216375633, Handelsregister HRB 109481, AG Karlsruhe
Geschäftsführer: Dr. James J. Hunt
More information about the compiler-dev
mailing list