Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Using Soot as a Program Optimizer
This tutorial describes the use of Soot as an optimization tool. After completing this tutorial, the user will be able to use Soot to optimize classfiles and whole applications.
Prerequisites The user should have a working installation of Soot. How to setup Soot can be found in the first section of the Running Soot tutorial.
Soot is able to optimize individual classfiles. Some of the transformations which can be carried out on individual classfiles include: common subexpression elimination, partial redundancy elimination, copy propagation, constant propagation and folding, conditional branch folding, dead assignment elimination, unreachable code elimination, unconditional branch folding, and unused local elimination.
In order to optimize the Hello example from the previous tutorial, we issue the command:
java soot.Main -O Hello Transforming Hello...
Soot will then leave a new, improved Hello.class file in the sootOutput directory. For this class, the improvement after Sootification is not so obvious. Soot does, however, eliminate unused locals. Try adding an unused local to Hello and giving this command:
java soot.Main -O -f jimple Hello Transforming Hello...
You should see that the unused local is no longer present.
Any number of classfiles can be specified to Soot in this mode, as long as they are in the
Note that your classfile may belong to some package; it may be called, for instance,
your.package.Foo This indicates that the Foo class belongs to the package
your.package.. It will be in a
your/package/ subdirectory. In order to Sootify this file, you must be in the parent directory of
your/package/, and you must specify
java soot.Main -O your.package.Foo
Soot provides the
--app option switch to make it work on all the class files in an application. When this switch is present, the user specifies the main classfile, and Soot will load all needed classes.
Soot has a whole-program mode (activated with the
-W option) in which allows it to carry out whole-program transformations; for instance, method inlining requires the whole program to correctly resolve virtual method calls.
To specify that Soot should do whole-program optimizations (-W), as well as single-class optimizations, use the command:
java soot.Main --app -W Hello Transforming Hello...
Soot will write out all classes except those in the java., javax. and sun.* packages.
The default behaviour of
-W is to statically inline methods.
Soot is also capable of static method binding to do so use
java soot.Main --app -p wjop.smb on -p wjop.si off -W -O Hello
This type of optimization has produced significant speedups on some benchmarks.