CS243: Program Analysis and Optimization Winter 2012
Assignment 2: Dataflow in JoeQ
Your assignment this week is to implement a basic dataflow framework for the joeq system. We will provide the interfaces that your framework must support. You will write the iterative algorithm for any analysis matching these interfaces, and also phrase Reaching Definitions in terms that any implementation of the solver can understand.
We have setup an environment for the programming assignments found here. Download and unpack this archive on your own machine, or in your home directory on a Stanford machine like myth (you can use elaine, but don't test on it: its gcj produces different bytecode for the test cases).
Framework Contents
The top level directory structure of the parun environment is:
parun/ |
Root parun environment for our JoeQ distribution |
parun/bin/ |
Contains the parun scripts to set up the environment and launch analyses |
parun/lib/ |
Contains the Joeq JAR. Unzip the JAR to see the JoeQ source. |
parun/src/ |
Contains examples, as well as stubs for your code |
parun/Makefile |
Compiles all the src .java files into a jar, ready to be run using the parun script |
The src directory contains the source files that you'll be using and creating for this programming assignment. This includes the following subdirectories/packages:
parun/src/examples/ |
Contains example analyses, such as PrintQuads, discussed in the JoeQ tutorial. |
parun/src/flow/ |
Contains the dataflow analysis framework and example analyses. The file Flow.java contains the interfaces you have to implement and the main program. |
parun/src/test/ |
Contains several tests for your dataflow implementation. More info below. |
parun/src/submit/ |
Contains the stubs for the code you have to write - MySolver.java and ReachingDefs.java |
Your Task
Your task is twofold:
- Create a class MySolver that implements the interface Flow.Solver. Use it to run the constant propagation and liveness algorithms we provide.
- Create a class ReachingDefs that implements the interface Flow.Analysis and executes the reaching definitions analysis.
Running Analyses
To run the PrintQuads example from the joeq tutorial that printed out the basic blocks of the ExprTest class using the parun environment, simply make the environment and invoke the parun script on the PrintQuads and ExprTest:
myth:~$ cd parun myth:~/parun$ make myth:~/parun$ bin/parun examples.PrintQuads examples.ExprTest
To run MySolver using the ConstantProp analysis over a test program called Test, invoke the parun script on these four classes:
myth:~/parun$ bin/parun flow.Flow submit.MySolver flow.ConstantProp test.Test
Testing your code
The test package contains a Test class that you can use to test your implementation of MySolver and ReachingDefs. The parun/src/test/ directory contains Test.cp.out, Test.lv.out, and Test.rd.out which are output files for running the ConstantProp, Liveness, and ReachingDefs analyses over the Test class.
Diff the output of running your MySolver with these out files to test your implementation.
Submission
We ONLY want the java files in your src/submit directory, do not submit the rest of the framework.
To submit your assignment, please follow the following steps:
- Copy your hw2's
src/submitdirectory to myth.stanford.edu (keep it in it's own directory) - Login to myth.stanford.edu
- cd to the directory containing only the java files you want to submit
- run
/usr/class/cs243/dataflow/submit_hw2.shin this directory.
OR, if you're working with a partner, type:/usr/class/cs243/dataflow/submit_hw2.sh partner_SUID - (ex: ./submit_hw2.sh jongsoo)
Hints
Get started early. This is a sizable project, and you need to familiarize yourself with joeq at the same time. If you wait until the last minute, you will not be able to finish.
Look at the ConstantProp and Liveness classes. You will find techniques that will be useful to you when you formulate ReachingDefs.
Read the joeq documentation carefully, and don't hesitate to look at the full javadocs if you get stuck. Joeq is still very much an experimental system; if you wish to attempt something particularly tricky, you may find it enlightening to sourcedive.
Study the QuadIterator interface carefully. It does a great deal of the work for you. But please take note: if you construct a backward QuadIterator, you must iterate over it with hasPrevious() and previous().
DataflowObjects are mutable; when in doubt, copy them. When writing reaching definitions, be sure to implement an equals() method, or your code will loop forever.
The iterator returned by Quad.successors() (resp. Quad.predecessors()) generates null to indicate that the current object has the exit node (resp. entry node) as a successor (resp. predecessor).
Joeq doesn't work with Java 1.6 class files. The provided Makefile deals with this for you, but if you invoke javac yourself, be sure to pass -target 1.5 and make sure everything compiles with the provided Makefile