[Soot-list] Proper way to handle new statement in jimple
Shams Imam
smi1 at rice.edu
Mon Mar 5 22:54:52 EST 2012
Below is a simplified version of a class we are trying to compile with
Habanero-Java:
public class Foo {
public static void process(Foo f) {}
public static void main(String[] args) {
try {
Foo f = new Foo();
process(f);
} catch (Throwable th) {
} finally {
}
}
}
We are using Jimple to generate the AST which is then written to class
files using Jasmin.
While the generated class file runs correctly, we run into errors
while trying to verify the class file using BCEL 5.2.
The error message we get is:
Pass 3b, method number 3 ['public static void main(String[] arg0)']:
VERIFIED_REJECTED
Constraint violated in method 'public static void main(String[] arg0)':
Backwards branch with an uninitialized object in the local variables
detected.Execution flow:
18: astore_2 [InstructionContext]
The issue, however, is with the generated bytecode for new Foo()
statement:
0: new #9; //class Foo
3: astore_1
4: aload_1
5: invokespecial #2; //Method "<init>":()V
This because of the AST we generated with Jimple in our compiler. It
includes two statements, one for the new statement, and then an
invocation to <init>:
$r1 = new Foo [JAssignStmt]
specialinvoke $r1.<Foo: void <init>()>() [JInvokeStmt]
Instead, if we create a single grimp node
(soot.grimp.internal.GNewInvokeExpr) for the new statement:
$r1 = new Foo() [JAssignStmt, but rhs
expr is grimp...]
the bytecode generated by Jasmin matches what is normally generated by
javac and passes verification by BCEL:
0: new #2; //class Foo2
3: dup
4: invokespecial #3; //Method "<init>":()V
7: astore_1
Can someone help verify whether the way we are handling new
expressions in Jimple is correct or what the alternate way is to
generate the proper class file from Jasmin in Soot?
Ideally we would like to use Jasmin AST that generates bytecode which
passes verification by BCEL.
Thanks,
Shams.
More information about the Soot-list
mailing list