In the generated LocalVariableTable wide variables should allocate 2 stack slots . It is easy to reproduce - just declare several fan Int variables and watch their values in the debugger.
The minimal patch fixing it is follows.
diff -r e94fdf58964c src/sys/java/fanx/emit/FCodeEmit.java
--- a/src/sys/java/fanx/emit/FCodeEmit.java Sun Oct 18 10:19:31 2009 -0400
+++ b/src/sys/java/fanx/emit/FCodeEmit.java Mon Oct 19 10:50:48 2009 +0700
@@ -263,8 +263,8 @@
Box info = attr.info;
FMethodVar[] vars = fmethod.vars;
int num = vars.length; // num of vars including implicit this
- int offset = 0; // offset if including implicit this
- if (!fmethod.isStatic()) { ++offset; ++num; }
+ int offset = 0;
+ if (!fmethod.isStatic()) { ++num; }
// Fan variables never reuse stack registers, so
// we can declare their scope across entire method
@@ -280,16 +280,19 @@
info.u2(end);
info.u2(code.emit.utf("this"));
info.u2(code.emit.utf(pod.typeRef(parent.type.self).jsig()));
- info.u2(0);
+ info.u2(offset);
+ ++offset;
}
for (int i=0; i<vars.length; ++i)
{
FMethodVar var = vars[i];
+ FTypeRef typeref = pod.typeRef(var.type);
info.u2(start);
info.u2(end);
info.u2(code.emit.utf(var.name));
- info.u2(code.emit.utf(pod.typeRef(var.type).jsig()));
- info.u2(i+offset);
+ info.u2(code.emit.utf(typeref.jsig()));
+ info.u2(offset);
+ offset += typeref.isWide() ? 2 : 1;
}
}
Thank you, Alex
brianTue 20 Oct 2009
Alex, Thanks for digging into that and submitting a nice clean patch! Surprised that hasn't bitten anyone before.
I actually decided to rework that code to use the Reg data structures I am already calculating which takes wide variables into account.
alex_panchenko Mon 19 Oct 2009
Hello all,
In the generated LocalVariableTable wide variables should allocate 2 stack slots . It is easy to reproduce - just declare several fan Int variables and watch their values in the debugger.
The minimal patch fixing it is follows.
diff -r e94fdf58964c src/sys/java/fanx/emit/FCodeEmit.java --- a/src/sys/java/fanx/emit/FCodeEmit.java Sun Oct 18 10:19:31 2009 -0400 +++ b/src/sys/java/fanx/emit/FCodeEmit.java Mon Oct 19 10:50:48 2009 +0700 @@ -263,8 +263,8 @@ Box info = attr.info; FMethodVar[] vars = fmethod.vars; int num = vars.length; // num of vars including implicit this - int offset = 0; // offset if including implicit this - if (!fmethod.isStatic()) { ++offset; ++num; } + int offset = 0; + if (!fmethod.isStatic()) { ++num; } // Fan variables never reuse stack registers, so // we can declare their scope across entire method @@ -280,16 +280,19 @@ info.u2(end); info.u2(code.emit.utf("this")); info.u2(code.emit.utf(pod.typeRef(parent.type.self).jsig())); - info.u2(0); + info.u2(offset); + ++offset; } for (int i=0; i<vars.length; ++i) { FMethodVar var = vars[i]; + FTypeRef typeref = pod.typeRef(var.type); info.u2(start); info.u2(end); info.u2(code.emit.utf(var.name)); - info.u2(code.emit.utf(pod.typeRef(var.type).jsig())); - info.u2(i+offset); + info.u2(code.emit.utf(typeref.jsig())); + info.u2(offset); + offset += typeref.isWide() ? 2 : 1; } }Thank you, Alex
brian Tue 20 Oct 2009
Alex, Thanks for digging into that and submitting a nice clean patch! Surprised that hasn't bitten anyone before.
I actually decided to rework that code to use the Reg data structures I am already calculating which takes wide variables into account.
changeset