EDA045F Program Analysis: Homework 4

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.

Dynamic Analysis

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

Resources

Submission

1. Profiling Instrumentation with AspectJ (1.5 points)

While some developers use AspectJ for aspect-oriented software development, another use of the system is in instrumentation. In this task, you will work with AspectJ to instrument the well-known benchmark fop. Note that the fop.tar.gz package comes with a bash script run-fop.sh that runs fop in the same style as in the DaCapo benchmark suite; this script should be sufficient for you to execute the program and measure its execution time (e.g., using the command line tool time).

Note that the run-fop.sh script takes an optional parameter, which is a classpath. You can use this to pass in a modified jar file (plus the AspectJ runtime support library aspectjrt.jar). To perform static AspectJ weaving, you can use the following (given a file MyInstrumentation.aj that you have to provide):

    ajc -warn:none -Xlint:ignore MyInstrumentation.aj  -outjar fop-instr.jar -inpath ./fop-all.jar
  
The extra parameters suppress warnings and errors due to references to dependencies on external libraries from unused code.

Note: Depending on your installation of ajc, you may have to increase the amount of heap space available to the program. For example, here is the ajc script that I use (note the -Xmx8G, which increases the heap space):

#!/bin/sh

AJPATH=/usr/share/java/aspectjrt.jar:/usr/share/java/aspectjtools.jar

exec "${JAVACMD:=java}" -classpath "$AJPATH${CLASSPATH:+:$CLASSPATH}" \
  "${JAVA_OPTS:=-Xmx8G}" \
  org.aspectj.tools.ajc.Main "$@"
  

2. Hardware Performance Counters (1.5 point)

On most modern operating systems, performance counters can be accessed programmatically (e.g., using PAPI on Linux). On Linux, we can even use a helper command line program, called perf, to analyse performance counters without having to write our own code. Such performance counters can report on operating system statistics (network / paging / harddisk activity), but also on CPU statistics (number of CPU instructions retired, number of cycles executed etc).

3. Call-Graph Instrumentation with Soot (2 points)

The static call graph computations that we have examined so far have been attempts to approximate the actual program call graph. In this exercise, we compute the dynamic call graph of a program (our fop benchmark from Task 1) and compare it against a statically computed callgraph.

Soot can be instructed to transform Java code by using the -outjar option and writing a suitable BodyTransformer. The compiled transformer can then be executed e.g. by running:

    java Stub4 -w -cp ./fop-all.jar:./xlog.jar:/opt/jdk1.8.0_144/jre/lib/rt.jar -process-dir ./fop-all.jar  -outjar -allow-phantom-refs
  
This will produce the file sootOutput/out.jar by processing fop-all.jar. (Note that the output jar will not include auxiliary data such as graphics and some system class files stored in fop-all.jar). The produced output jar file will then have been transformed as per the instructions in Stub4.