edu.wisc.cs.stego.modules
Class Unprofile

java.lang.Object
  |
  +--edu.wisc.cs.stego.CodeEditor
        |
        +--edu.wisc.cs.stego.modules.Unprofile
Direct Known Subclasses:
GenericEditor

public class Unprofile
extends CodeEditor

This implementation of CodeEditor does not add code to build a watermark graph, but simply locates and removes the calls to the profiling methods. This class may be used as a super class for further implementations of CodeEditors, to take advantage of the profile point location and code removal capability.


Field Summary
protected  WatermarkGraph graph
          The watermark graph to be built in the run-time heap.
protected static java.lang.String INIT_DESC
          The descriptor of the profile initialization method.
protected static java.lang.String INIT_METHOD
          The name of the profile initialization method.
protected static int INIT_POINT
           
protected static java.lang.String NO_ARGS_VOID
          The descriptor of the profile point recorder method with no parameters.
protected  int num_points
          The number of profile points across which the graph code will be distributed.
protected static int POINT
           
protected static java.lang.String PROFILE_CLASS
          The fully qualified name of the profiling class.
protected static java.lang.String RECORD_POINT
          The name of the profile point recorder method.
 
Constructor Summary
protected Unprofile()
          Constructs a new Unprofile object.
 
Method Summary
protected  void addDefaultConstructor(ClassFile node)
          Given a class, add a constructor with no parameters if there isn't already a constructor with that signature.
static CodeEditor buildCodeEditor(java.lang.String[] params)
          Returns a new instance of an Unprofile object.
protected  int getProfilingMethodIndex(ConstantPool cpool, int which)
          Given a constant pool for a class, locates the specified method_ref constant and returns its index.
protected  void insertWatermarkCode(ClassFile cls, CodeAttribute code, int where)
          This method does nothing.
 void instrumentClasses(WatermarkGraph graph, ProfilePoint[] profile, java.util.Map classes, java.lang.String nodec)
          Looks in the classes referenced in the profile points and removes calls to the profiling methods.
protected  void instrumentNodeClass(ClassFile node, WatermarkGraph graph)
          This method does nothing.
protected  int removeProfilePoint(int cpindex, CodeAttribute code, ProfilePoint point)
          Given a CodeAttribute and a ProfilePoint, remove the bytecode which implements the profile point from the code.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INIT_POINT

protected static final int INIT_POINT

POINT

protected static final int POINT

PROFILE_CLASS

protected static final java.lang.String PROFILE_CLASS
The fully qualified name of the profiling class.

INIT_METHOD

protected static final java.lang.String INIT_METHOD
The name of the profile initialization method.

INIT_DESC

protected static final java.lang.String INIT_DESC
The descriptor of the profile initialization method.

RECORD_POINT

protected static final java.lang.String RECORD_POINT
The name of the profile point recorder method.

NO_ARGS_VOID

protected static final java.lang.String NO_ARGS_VOID
The descriptor of the profile point recorder method with no parameters.

graph

protected WatermarkGraph graph
The watermark graph to be built in the run-time heap. This is initizlized when the instrumentClasses method is invoked.

num_points

protected int num_points
The number of profile points across which the graph code will be distributed. This is inialized when the instrumentClasses method is invoked.
Constructor Detail

Unprofile

protected Unprofile()
Constructs a new Unprofile object. No parameters are required. All data needed by this class is provided by the CodeEditor interface methods.
Method Detail

buildCodeEditor

public static CodeEditor buildCodeEditor(java.lang.String[] params)
Returns a new instance of an Unprofile object. Parameters are ignored. This method is a factory method for instantiating Unprofile instances.
Parameters:
params - array of parameters to the Unprofile constructor.
Returns:
a new instance of a Unprofile object.
See Also:
CodeEditor.buildCodeEditor(java.lang.String[])

instrumentClasses

public void instrumentClasses(WatermarkGraph graph,
                              ProfilePoint[] profile,
                              java.util.Map classes,
                              java.lang.String nodec)
Looks in the classes referenced in the profile points and removes calls to the profiling methods. The nodec parameter is ignored. All classes which are referenced in the profile are expected to be in the map.
Overrides:
instrumentClasses in class CodeEditor
Parameters:
graph - the watermark graph.
profile - the array of profile points.
classes - a map containing the classfiles, keyed on the classnames.
nodec - the name of the class to be used as the nodes in the graph.

instrumentNodeClass

protected void instrumentNodeClass(ClassFile node,
                                   WatermarkGraph graph)
This method does nothing. It is a place holder to be overridden by subclasses. It is not abstract so that the Unprofile class may be used on it's own. If this implementation is invoked an exception is thrown.
Parameters:
node - the classfile representing the node class.
fields - the names of the pointer fields to add to the class.
Throws:
UnsupportedOperationException - if this method is called from a subclass.

addDefaultConstructor

protected void addDefaultConstructor(ClassFile node)
Given a class, add a constructor with no parameters if there isn't already a constructor with that signature. If a constructor is added, this assumes that the superclass also has a default constructor. There is no way around this assumption, since there is potentially no way to find the super class and modify it, since it may be in a package that is not known to the current runtime system.
Parameters:
node - the class to which to add a default constructor.

insertWatermarkCode

protected void insertWatermarkCode(ClassFile cls,
                                   CodeAttribute code,
                                   int where)
This method does nothing. It is a place holder to be overridden by subclasses. It is not abstract so that the Unprofile class may be used on it's own. If this implementation is invoked an exception is thrown.
Parameters:
code - the code attribute in which to insert code.
where - the index at which to insert the code.
Throws:
UnsupportedOperationException - if this method is called from a subclass.

getProfilingMethodIndex

protected int getProfilingMethodIndex(ConstantPool cpool,
                                      int which)
Given a constant pool for a class, locates the specified method_ref constant and returns its index.
Parameters:
cpool - the constant pool of the class in which to search.
which - either INIT_POINT or POINT.
Returns:
the index of the method_ref constant.
Throws:
java.util.NoSuchElementException - if the constant isn't found.

removeProfilePoint

protected int removeProfilePoint(int cpindex,
                                 CodeAttribute code,
                                 ProfilePoint point)
Given a CodeAttribute and a ProfilePoint, remove the bytecode which implements the profile point from the code. Return the position of the code.

If the profile point to be removed is the initialization point, this method attempts to remove the expression that loads the reference to the filename string onto the stack. The algorithm currently in use will remove a simple load from a local or static variable, or a constant from the constant pool. Future versions may attempt to remove more complex operations. If the expression cannot be removed by this simple algorithm, the invokestatic instruction will simply be replaced with a pop.

Parameters:
cpindex - the constant pool index of the method to which calls should be removed.
code - the code attribute which contains the profile point.
point - the profile point which should be removed from the code.
Returns:
the index of bytecode which formerly was the first instruction implementing the profile point.