Search code examples
javasoot

Running the Soot Jimple Optimizer on a class


Is it possible to run the JOP optimizer on a SootClass? I'd like to optimize a class that I've generated manually with Jimple statements through the Java API. As far as I understand, the optimizer is only run at resolve-time, so not every time after Jimple bodies have been manipulated. Is it possible to rerun this optimalization manually, from within Java?


Solution

  • I found the right function calls, after some searching!

    PhaseOptions.v().setPhaseOption("jop", "enabled:true")
    PackManager.v().getPack("jop").apply(jimpleBody)
    

    Run this on every method body of the class you want to optimize (with jimpleBody being replaced by that method body), and it will run the JOP optimizer on the Jimple code.