0
votes

I manipulate some bytecode by Soot, and produce some strange bytecode. Here is an example. After I just insert a str = null; inside am empty synchronized block, the bytecode is:

 0 new #15 <java/lang/String>
 3 dup
 4 invokespecial #16 <java/lang/String.<init> : ()V>
 7 monitorenter
 8 aconst_null
 9 astore_0
10 aload_0
11 monitorexit
12 goto 20 (+8)
15 astore_1
16 aload_0
17 monitorexit
18 aload_1
19 athrow
20 return

I run this bytecode on HotSpot 11, but find it can't finish execution. Why?

I wouldn't expect this code to run without termination, but rather, to throw a NullPointerException at instruction 11. The monitorexit instruction will act on a null which you pushed to the stack at instruction 10.boneill
@boneil Yes, you're right. I miss the exception table which has an item <15, 17, 15, Throwable>, causing the infinite jump to 15.cbcwestwolf