Using Soot as a Program Optimizer

Patrick Lam (

March 23, 2000


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.


The user should have a working installation of Soot; successful completion of the introduction is one way to exercise one's installation of Soot.

Classfile Optimization

Soot is able to optimize individual classfiles. Some of the transformations which can be carried out on individual classfiles include: common subexpression elimination, partial redundency 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, soot.Scene. This indicates that the Scene class belongs to the soot package. It will be in a soot/ subdirectory. In order to Sootify this file, you must be in the parent directory (not soot/), and you must specify java soot.Main -O soot.Scene.

Unfortunately, our current optimizations with -O tend to have little effect on the program execution time.

Program Optimization

Soot provides the -app switch to make it work on all the class files in an applicaion. When this switch is present, the user specifies the main classfile, and Soot will load all needed classes.

Soot has a whole-program mode 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; use

> java soot.Main --app -p wjop.smb on -p off -W -O

This type of optimization has produced significant speedups on some benchmarks.


This lesson has described how Soot can be used to optimize classfiles and whole applications.


About this document ...

Using Soot as a Program Optimizer

This document was generated using the LaTeX2HTML translator Version 2008 (1.71)

Copyright © 1993, 1994, 1995, 1996, Nikos Drakos, Computer Based Learning Unit, University of Leeds.
Copyright © 1997, 1998, 1999, Ross Moore, Mathematics Department, Macquarie University, Sydney.

The command line arguments were:
latex2html optimizer -split 0 -nonavigation -dir ./

The translation was initiated by Eric Bodden on 2012-01-22

Eric Bodden 2012-01-22