Dave Cowden
2014-11-30 18:56:55 UTC
Sorry to cross-post: I posted this on users but the realized that the dev
list is probably the right place to post...
Consider this simple class:
@groovy.transform.CompileStatic
class ScriptTestClass{
void test_method(String x,String y,String z){
x = "foo";
}
}
When compiled to bytecode, i get the below bytecode ( results of javap -c
-v ScriptTestClass.class, edited for the subject method only ):
Results of javap -c -v ScriptTestClass.class ( just the subject method
though ):
public void test_method(java.lang.String, java.lang.String,
java.lang.String);
flags: ACC_PUBLIC
Code:
stack=1, locals=5, args_size=4
0: ldc #32 // String foo
2: astore 4
4: aload 4
6: astore_1
7: aload 4
9: pop
10: return
LocalVariableTable:
Start Length Slot Name Signature
0 10 0 this LScriptTestClass;
0 10 1 x Ljava/lang/String;
0 10 2 y Ljava/lang/String;
0 10 3 z Ljava/lang/String;
LineNumberTable:
line 4: 0
Clearly, **ASTORE / ALOAD 4** are not appropriate here. Slot 4 is not even
defined in the local variable table. In fact, they appear extraneous. The
bytecode is correct if these are removed.
âI cannot really say this bytecode is _Wrong_ because it technically
works. But its certainly not what I'd expect. â
The correct bytecode ( which I get when i write this same code in a Java
class is:
public void test_method(java.lang.String, java.lang.String,
java.lang.String);
flags: ACC_PUBLIC
Code:
stack=1, locals=4, args_size=4
0: ldc #7 // String foo
2: astore_1
3: return
LineNumberTable:
line 26: 0
line 27: 3
LocalVariableTable:
Start Length Slot Name Signature
0 4 0 this Ltesting/ScriptTestClass;
0 4 1 x Ljava/lang/String;
0 4 2 y Ljava/lang/String;
0 4 3 z Ljava/lang/String;
I suspect this may be some leftovers from what the code looks like when
@CompileStatic is removed-- i think in that case there are other variables
involved.
Ideas/Thoughts?
list is probably the right place to post...
Consider this simple class:
@groovy.transform.CompileStatic
class ScriptTestClass{
void test_method(String x,String y,String z){
x = "foo";
}
}
When compiled to bytecode, i get the below bytecode ( results of javap -c
-v ScriptTestClass.class, edited for the subject method only ):
Results of javap -c -v ScriptTestClass.class ( just the subject method
though ):
public void test_method(java.lang.String, java.lang.String,
java.lang.String);
flags: ACC_PUBLIC
Code:
stack=1, locals=5, args_size=4
0: ldc #32 // String foo
2: astore 4
4: aload 4
6: astore_1
7: aload 4
9: pop
10: return
LocalVariableTable:
Start Length Slot Name Signature
0 10 0 this LScriptTestClass;
0 10 1 x Ljava/lang/String;
0 10 2 y Ljava/lang/String;
0 10 3 z Ljava/lang/String;
LineNumberTable:
line 4: 0
Clearly, **ASTORE / ALOAD 4** are not appropriate here. Slot 4 is not even
defined in the local variable table. In fact, they appear extraneous. The
bytecode is correct if these are removed.
âI cannot really say this bytecode is _Wrong_ because it technically
works. But its certainly not what I'd expect. â
The correct bytecode ( which I get when i write this same code in a Java
class is:
public void test_method(java.lang.String, java.lang.String,
java.lang.String);
flags: ACC_PUBLIC
Code:
stack=1, locals=4, args_size=4
0: ldc #7 // String foo
2: astore_1
3: return
LineNumberTable:
line 26: 0
line 27: 3
LocalVariableTable:
Start Length Slot Name Signature
0 4 0 this Ltesting/ScriptTestClass;
0 4 1 x Ljava/lang/String;
0 4 2 y Ljava/lang/String;
0 4 3 z Ljava/lang/String;
I suspect this may be some leftovers from what the code looks like when
@CompileStatic is removed-- i think in that case there are other variables
involved.
Ideas/Thoughts?