[Soot-list] Exception in JasminClass after adding static method invocation

Jae-Woo Lee lee575 at purdue.edu
Mon Apr 6 19:28:49 EDT 2009


Hi.

I am working on adding a profiling code after analysis.
When I add a static method invocation and when it is written with JasminClass,
it generates ClassCastException.
I just added a static method invocation in the source code of "Creating a Class
File from Scratch" document.

Do you have any idea what is wrong in my code ?

========= code snippet for adding static method invocation ==========

// insert DynamicRefCounter.incrementEscapingObjectCnt()
{
    Scene.v().loadClassAndSupport("myanalysis.DynamicRefCounter");
    SootMethod myCall = Scene.v().getMethod("<myanalysis.DynamicRefCounter: void
incrementEscapingObjectCnt()>");
    System.out.println(Jimple.v().newStaticInvokeExpr(myCall.makeRef()).toString());
                units.add(Jimple.v().newStaticInvokeExpr(myCall.makeRef()));
}

==============================
Iterator it = units.iterator();
while(it.hasNext()) {
   System.out.println(it.next().toString());
}
==================================
shows the following Jimple code: 

l0 := @parameter0: java.lang.String[]
tmpRef = <java.lang.System: java.io.PrintStream out>
virtualinvoke tmpRef.<java.io.PrintStream: void
println(java.lang.String)>("Hello world!")
staticinvoke <myanalysis.DynamicRefCounter: void incrementEscapingObjectCnt()>()
return

========================

I have the following exception from the execution.

Exception in thread "main" java.lang.ClassCastException:
soot.jimple.internal.JStaticInvokeExpr cannot be cast to soot.Unit
        at soot.Body.getUseBoxes(Body.java:528)
        at soot.Body.validateLocals(Body.java:263)
        at soot.Body.validate(Body.java:229)
        at soot.jimple.JimpleBody.validate(JimpleBody.java:66)
        at soot.jimple.JasminClass.emitMethodBody(JasminClass.java:92)
        at soot.AbstractJasminClass.emitMethod(AbstractJasminClass.java:689)
        at soot.AbstractJasminClass.<init>(AbstractJasminClass.java:568)
        at soot.jimple.JasminClass.<init>(JasminClass.java:62)
        at myanalysis.ProfileCodeCreator.main(ProfileCodeCreator.java:108)

============ code snippet which generate the exception

String fileName = SourceLocator.v().getFileNameFor(sClass,  
Options.output_format_class);
OutputStream streamOut = new JasminOutputStream(
          new FileOutputStream(fileName));
PrintWriter writerOut = new PrintWriter(
                new OutputStreamWriter(streamOut));
JasminClass jasminClass = new soot.jimple.JasminClass(sClass); <== This generate
exception.

I am using soot 2.3.0 and jasmin 2.3.0. 

Thank you.

Sincerely,
Jaewoo


More information about the Soot-list mailing list