org.softevo.ample.instrument
Class AmpleInstrumenter

java.lang.Object
  extended by org.softevo.ample.instrument.AmpleInstrumenter

public class AmpleInstrumenter
extends java.lang.Object

This class contains contains the entry point for the instrumentation of bytecode.


Field Summary
private  java.io.File classDirectory
          The directory that contains the classes that should be instrumented.
private  InstrumentationConfiguration config
          Instrumentation configuration for instrumenter run.
private  org.softevo.sibrelib.classfilter.ClassFilter filter
          The filter to be used.
private  java.util.HashSet instrumentClassNames
          The set of class names that are instrumented.
private  org.eclipse.jdt.launching.IVMInstall vmInstall
          The virtual machine used for running instrumented files.
private  java.io.File workingDirectory
          The directory used as working directory by the virtual machine instance.
 
Constructor Summary
AmpleInstrumenter(InstrumentationConfiguration config, java.io.File classDirectory, java.io.File workingDirectory, org.softevo.sibrelib.classfilter.ClassFilter filter, org.eclipse.jdt.launching.IVMInstall vmInstall)
          Creates a new instrumenter for a set of classes.
 
Method Summary
private  java.util.HashSet getCoreClassSet()
          Gets the set of core classes to be used by te instrumentation.
 java.util.HashSet getInstrumentClassNames()
           
private  java.util.HashSet getInstrumentClassNames(org.softevo.sibrelib.source.ClassFileSource source)
          Calculates the names of all classes that shall be instrumented.
private  java.util.Vector getTraceExtensions(org.softevo.sibrelib.InstrumentationContext context)
          Determines which instrumentation extensions are needed by the given configuration.
 void instrument()
          Instruments all files in the class file source.
private  java.util.HashSet readFromCache(java.io.File cacheFile)
          This method tries to read the core class set from the cache.
private  void writeToCache(java.io.File cacheFile, java.util.HashSet coreClassSet)
          Saves a set of core classes into the cache directory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

config

private InstrumentationConfiguration config
Instrumentation configuration for instrumenter run.


workingDirectory

private java.io.File workingDirectory
The directory used as working directory by the virtual machine instance.


classDirectory

private java.io.File classDirectory
The directory that contains the classes that should be instrumented.


filter

private org.softevo.sibrelib.classfilter.ClassFilter filter
The filter to be used.


vmInstall

private org.eclipse.jdt.launching.IVMInstall vmInstall
The virtual machine used for running instrumented files.


instrumentClassNames

private java.util.HashSet instrumentClassNames
The set of class names that are instrumented.

Constructor Detail

AmpleInstrumenter

public AmpleInstrumenter(InstrumentationConfiguration config,
                         java.io.File classDirectory,
                         java.io.File workingDirectory,
                         org.softevo.sibrelib.classfilter.ClassFilter filter,
                         org.eclipse.jdt.launching.IVMInstall vmInstall)
Creates a new instrumenter for a set of classes.

Parameters:
config - the instrumentation configuration
classDirectory - the class directory
workingDirectory - the working directory of the virtual machine
filter - a filter for classes that shouldn't be instrumented
vmInstall - the virtual machine
Method Detail

getTraceExtensions

private java.util.Vector getTraceExtensions(org.softevo.sibrelib.InstrumentationContext context)
Determines which instrumentation extensions are needed by the given configuration.

Parameters:
context - the instrumentation context
Returns:
the list of trace extensions

getInstrumentClassNames

private java.util.HashSet getInstrumentClassNames(org.softevo.sibrelib.source.ClassFileSource source)
Calculates the names of all classes that shall be instrumented.

Parameters:
source - the class file source
Returns:
the set of all classes in the source

writeToCache

private void writeToCache(java.io.File cacheFile,
                          java.util.HashSet coreClassSet)
                   throws java.io.IOException
Saves a set of core classes into the cache directory.

Parameters:
cacheFile - the file the cached core class set should be stored in
coreClassSet - the class set to cache
Throws:
java.io.IOException - if an exception occurs writing the cache file

readFromCache

private java.util.HashSet readFromCache(java.io.File cacheFile)
                                 throws java.io.IOException,
                                        java.lang.ClassNotFoundException
This method tries to read the core class set from the cache.

Parameters:
cacheFile - the file that is supposed to contain the cached values
Returns:
the core class set or null if not found
Throws:
java.io.IOException - if an exception occurs reading from the cache
java.lang.ClassNotFoundException

getCoreClassSet

private java.util.HashSet getCoreClassSet()
                                   throws org.softevo.sibrelib.InstrumentationException,
                                          java.io.IOException,
                                          java.lang.ClassNotFoundException
Gets the set of core classes to be used by te instrumentation.
This method tries to locate the runtime class set from the virtual machine installation. If this succeeds, the method tries to locate the set in the cache. If this fails, the runtime jar file is analysed in order to find all the classes.

Returns:
the core class set
Throws:
org.softevo.sibrelib.InstrumentationException - if the runtime jar file was not found
java.io.IOException - if an exception occurs reading from or writing to the cache
java.lang.ClassNotFoundException

instrument

public void instrument()
                throws java.io.IOException,
                       org.softevo.sibrelib.InstrumentationException,
                       java.lang.ClassNotFoundException
Instruments all files in the class file source.
If a run of this method finishes successfully, all classes in the source were instrumented.

Throws:
java.io.IOException - if an exception occurs reading/writing cached results
org.softevo.sibrelib.InstrumentationException - if the runtime jar file cannot be found
java.lang.ClassNotFoundException

getInstrumentClassNames

public java.util.HashSet getInstrumentClassNames()