java如何移除字节码_java – 如何正确退出字节码中的监视器?

我正在阅读JVM规范,试图找出如何正确处理监视器.他们在

the relevant section中给出的示例如下所示:

0 aload_1 // Push f

1 dup // Duplicate it on the stack

2 astore_2 // Store duplicate in local variable 2

3 monitorenter // Enter the monitor associated with f

4 aload_0 // Holding the monitor, pass this and...

5 invokevirtual #5 // ...call Example.doSomething()V

8 aload_2 // Push local variable 2 (f)

9 monitorexit // Exit the monitor associated with f

10 goto 18 // Complete the method normally

13 astore_3 // In case of any throw, end up here

14 aload_2 // Push local variable 2 (f)

15 monitorexit // Be sure to exit the monitor!

16 aload_3 // Push thrown value...

17 athrow // ...and rethrow value to the invoker

18 return // Return in the normal case

Exception table:

From To Target Type

4 10 13 any

13 16 13 any

我无法弄清楚为什么需要第二个异常表条目.如果monitorexit抛出异常,我真的想再次尝试退出监视器吗?

据我所知,抛出的可能异常是NullPointerException和IllegalMonitorStateException.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值