Exception handler question
Neal Gafter
neal at gafter.com
Mon Dec 8 17:53:11 PST 2008
This is necessary to guarantee that the block is not exited until the
monitor has been exited, even in the presence of asynchronous
exceptions.
On Mon, Nov 17, 2008 at 1:48 PM, Roman Kennke <roman.kennke at aicas.com> wrote:
> 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