Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
None
Description
Consider the following:
def test() { try { print 'hello' } finally { print ' world' } }
For any non-void method where the try/finally is part of the return value, a long sequence of nop bytecode instructions is produced. The sample code from GROOVY-4721 produces 18 nop in a row.
// Method descriptor #42 ()Ljava/lang/Object; // Stack: 2, Locals: 3 public java.lang.Object test(); 0 aload_0 [this] 1 ldc <String "hello"> [47] 3 invokedynamic 1 invoke(Scratch, java.lang.String) : java.lang.Object [53] 8 astore_1 9 nop 10 aload_0 [this] 11 ldc <String " world"> [55] 13 invokedynamic 1 invoke(Scratch, java.lang.String) : java.lang.Object [53] 18 pop 19 nop 20 aload_1 21 areturn 22 nop 23 nop 24 athrow 25 nop 26 nop 27 nop 28 nop 29 nop 30 nop 31 nop 32 nop 33 athrow 34 nop 35 nop 36 athrow 37 astore_2 38 aload_0 [this] 39 ldc <String " world"> [55] 41 invokedynamic 1 invoke(Scratch, java.lang.String) : java.lang.Object [53] 46 pop 47 aload_2 48 athrow 49 nop 50 athrow Exception Table: [pc: 0, pc: 10] -> 37 when : any [pc: 20, pc: 22] -> 37 when : any Line numbers: [pc: 0, line: 3] [pc: 10, line: 5] [pc: 49, line: 7] Local variable table: [pc: 0, pc: 49] local: this index: 0 type: Scratch