-
-
Notifications
You must be signed in to change notification settings - Fork 712
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 CLASSPATH
.
Hidden Trap
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.
Also check out Soot's webpage.
NOTE: If you find any bugs in those tutorials (or other parts of Soot) please help us out by reporting them in our issue tracker.
- Home
- Getting Help
- Tutorials
- Reference Material
- General Notions
- Getting Started
- A Few Uses of Soot
- Using Soot as a Command-Line Tool
- Using the Soot Eclipse Plugin
- Using Soot as a Compiler Framework
- Building Soot
- Coding Conventions
- Contributing to Soot
- Updating the Soot Web Page
- Reporting Bugs
- Preparing a New Soot Release