EDA045F Program Analysis: Homework 1

Please try to track the time that you need for the homework assignment and report it, so that we can calibrate the effort for future classes.

Dataflow Analysis 1

This is a group project and intended to be worked on in a team of two. If you have no partner, you can also submit alone.

Background

In this excerise, you will work with the Soot framework to develop a small number of program analyses, including two dataflow analyses.

Soot already provides its own framework for dataflow analysis, but in this exercise we will only use Soot for access to its intermediate representation.

To validate your analyses, you will use a test suite that we provide. I recommend that you also test on some custom tests, too, as that may make it easier for you to trigger specific behaviour in the analysis.

For the analyses below, you may disregard the semantics of parameter-passing, method calls, exception handling, and field accesses. You must consider accesses to local variables.

Compatibility note: We are using Soot 3.1.0. This version of Soot supports Java 8, but no later versions of Java (the Soot team has an unreleased in-development version with support for Java 9 that we will not be using for this class). Make sure that you are compiling and running your Java code with Java 8, not with a later version.

Resources

Using Soot

Since you are most likely new to Soot, I recommend that you use the stub program listed above to start implementing your analysis. If you rename it to MyMainClass and compile it (linking against Soot), you should be able to run your analysis on all classes in bin.jar as follows:

java MyMainClass -cp <soot-classpath> -process-dir ./bin.jar
where <soot-classpath> is the classpath of all classes that Soot needs to know about; this typically includes your Java's standard library: rt.jar. For example, I use:
java MyMainClass -cp ./bin.jar:/opt/jdk1.8.0_144/jre/lib/rt.jar:junit.jar:/opt/jdk1.8.0_144/jre/lib/jce.jar -process-dir ./bin.jar
(check the reosurces for a copy of junit.jar if you don't already have it on your system.)
Note that the Soot classpath is fundamentally different from the CLASSPATH environment variable (the Java classpath) that you can use to tell Java which libraries to use: To run on a single class that is in your Soot classpath, run:
java MyMainClass -cp <soot-classpath> MyClass
For debugging, you can ask Soot to output Jimple intermediate code by running:
java MyMainClass -f j -cp <soot-classpath> MyClass
This will generate the file sootOutput/MyClass.jimple, containing intermediate Jimple code. Try running Soot with -h for a more complete list of options.

Submission

1. Finding Main Entry Points (0.5 points)

Execution of a Java program starts by executing a main method. For instance, when you write

  java -cp foo.jar MainClass a b c
Java will attempt to invoke the method MainClass.main(String[]) with the parameters ["a", "b", "c"]. If this is possible, then we refer to the method MainClass.main(String[]) as a main entry point of the program that it is part of.

However, not all methods called main are permitted as main entry points Java Language Specification. Conversely, many programs have several main entry points.

2. Finding Deprecated Calls (0.5 points)

Java permits methods to be marked deprecated. The intent is to signal that these methods may be removed in the future, or that their use is discouraged for other reasons. Since libraries and application code often evolve separately, it can happen that an application relies on a library method that becomes deprecated, without the original application developer being aware of this evolution.

3. Simplified Array Bounds Checking (1.5 points)

Array-out-of-bounds checking tries to determine whether the index i in a[i] is invalid. In this exercise, you will implement a simplified version that detects whether i is guaranteed to be negative. To detect this property, you may want to build on one of the abstract domains that we discussed in class, but refine the domain model first (e.g., consider what happens when merging A0 and A+).

Consider using one of Soot's built in CFG generators, such as the class ExceptionalBlockGraph.

When designing your code for this task, make sure to also consider part 5 of this homework, which asks you to make your code reusable.

4. Finding Useless Assignments with Live Variables Analysis (1.5 points)

Live Variables Analysis is a backward analysis (and one of our examples from the second lecture) that can detect whether a variable is assigned to even though it is not needed later in the program. In this exercise you will implement this analysis (or, thanks to Mattias, you can alternatively implement an equivalent forward analysis).

Try to reuse your code from part 3 (if you have already completed part 3). See also part 5.

5. Reusing Your Code (1 point)