|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--edu.ucsb.ccs.jcontractor.jInstrument
Utility to read in class files and instrument class methods to
enforce jContractor contracts. Instrumented class files are
written to a destination directory which defaults to the current
working directory. The program may be run from the command line by
passing the names of files to instrument as arguments, or by
invoking the instrumentClassFile(String) method.
If specified, the instrumentation file controls the instrumentation
level of each class in the system. The available instrumentation
levels are:
None - No contracts checked. Pre - Preconditions checked. Post - Preconditions and postconditions checked. All - Preconditions, postconditions, and invariants checked.The instrumentation file contains class names followed by instrumentation levels, and separated by whitespace. For example:
* none edu.* pre edu.ucsb.ccs.jcontractor.jInstrument allThis file says the the jInstrument class should be instrumented completetly and the other classes in edu and all subpackages should have precondition checks. Wildcard matching works as in Java import statements, except that the wildcard matches any class in the package or any subpackage. More specific filters override general filters (edu.ccs.jcontractor.jInstrument overrides edu.*). jInstrument also includes a "strip mode" which removes contract methods from bytecode in order to decrease the file size. While jContractor contracts have no runtime effect when the class is run without jContractor, they do increase the size of the bytecode. The "-s" flag on the command line tells jInstrument to remove contract methods instead of adding calls to them. Once contract checks are inserted, the class becomes dependent on its contract methods to run correctly. For this reason it is not possible remove the contract methods from an instrumented class.
Usage: jInstrument [-options] classfile1 classfile2 classfile3 ...
Options:
-s Strip contract code to decrease file size.
-d Specify destination directory for
instrumented files.
-f Specify the instrumentation file.
-v, --verbose Enable verbose logging. Prints name of each
class as it is instrumented.
-e, --version Print version number and exit.
jContractor| Field Summary | |
static java.lang.String |
JCONTRACTOR_FLAG_CONSTANT
The prefix of a constant that will be inserted into the constant pool of classes that jInstrument instruments to mark them as instrumented. |
static java.lang.String |
USAGE_MESSAGE
Usage message to be printed if the command line arguments do not match the specification. |
static java.lang.String |
VERSION
Constant for the version number that is printed when the --version command line argument is given. |
| Constructor Summary | |
jInstrument()
Create a default instance that will check all contracts on all classes, in non-verbose mode. |
|
| Method Summary | |
java.lang.String |
getDestination()
Get the destination directory of files written by instrumentClassFile(String). |
InstrumentationFilter |
getInstrumentationFilter()
Get the instrumentation filter that determines which classes are instrumented and to what level. |
boolean |
getVerbose()
Get the value of the verbose flag. |
byte[] |
instrumentClass(org.apache.bcel.classfile.JavaClass javaclass)
Instrument a class to enforce jContractor contracts. |
void |
instrumentClassFile(java.lang.String classFilename)
Instrument a class file to enforce jContractor contracts, and write the instrumented file to the directory specified by destination. |
static boolean |
isInstrumented(org.apache.bcel.classfile.JavaClass javaclass)
Determine if a class has been instrumented. |
static void |
main(java.lang.String[] argv)
Instrument all the classes specified on the command line. |
static void |
parseInstrumentationFile(java.lang.String filename,
CompositeInstrumentationFilter filter)
Parse an instrumentation file. |
static void |
parseInstrumentationList(java.lang.String packageNames,
int instrumentationLevel,
CompositeInstrumentationFilter filter)
Parse a comma separated list of packages to instrument and create instrumentation filters. |
boolean |
setDestination_Precondition(java.lang.String path,
java.lang.Void RESULT)
|
void |
setDestination(java.lang.String path)
Set the destination directory of files written by instrumentClassFile(String). |
void |
setInstrumentationFilter(InstrumentationFilter filter)
Set the instrumentation filter that determines which classes are instrumented and to what level. |
void |
setVerbose(boolean flag)
Set the value of the verbose flag. |
void |
stripContracts(java.lang.String classFilename)
Remove contract methods from a class file, to decrease the file size. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final java.lang.String JCONTRACTOR_FLAG_CONSTANT
MarkInstrumentedTransformation,
Constant Field Valuespublic static final java.lang.String USAGE_MESSAGE
public static final java.lang.String VERSION
| Constructor Detail |
public jInstrument()
| Method Detail |
public void instrumentClassFile(java.lang.String classFilename)
throws java.io.IOException,
InstrumentationException
destination.
java.io.IOException - if there are problems reading from the
class file.
InstrumentationException
public byte[] instrumentClass(org.apache.bcel.classfile.JavaClass javaclass)
throws InstrumentationException
javaclass - a class to instrument.
InstrumentationException - if jInstrument is unable to
instrument the class.
public void stripContracts(java.lang.String classFilename)
throws java.io.IOException,
InstrumentationException
java.io.IOException
InstrumentationExceptionpublic void setInstrumentationFilter(InstrumentationFilter filter)
filter - the new filter.getInstrumentationFilter()public InstrumentationFilter getInstrumentationFilter()
setInstrumentationFilter(InstrumentationFilter)
public static void parseInstrumentationFile(java.lang.String filename,
CompositeInstrumentationFilter filter)
throws java.io.IOException
* none edu.* pre edu.ucsb.ccs.jcontractor.jInstrument allThis file says the the jInstrument class should be instrumented completetly and the other classes in edu and all subpackages should have precondition checks. Wildcard matching works as in Java import statements, except that the wildcard matches any class in the package or any subpackage. More specific filters override general filters (edu.ccs.jcontractor.jInstrument overrides edu.*).
This method parses the file and creates a PackageLevelInstrumentationFilter for each entry. These filters are appended to a CompositeInstrumentationFilter.
filename - the name of the file to parse. The file must
exist and contain text in the format described
above.filter - a CompositeInstrumentationFilter to which filters
will be appended. After execution, this filter
will include filters to enforce the rules described
in the file.
java.io.IOException
public static void parseInstrumentationList(java.lang.String packageNames,
int instrumentationLevel,
CompositeInstrumentationFilter filter)
packageNames - a comma separated list of package names,
including class names and possibly wildcards.
See the
PackageLevelInstrumentationFilter.setPackageAndClass()
for details on the accepted format.instrumentationLevel - the instrumentation level to assign
to classes in these packages.filter - a composite filter to which the new filters will be
added.PackageLevelInstrumentationFilter#setClassName(),
PackageLevelInstrumentationFilter#setPackageClassName()public void setVerbose(boolean flag)
flag - the new value of the verbose flag.getVerbose()public boolean getVerbose()
setVerbose(boolean)public void setDestination(java.lang.String path)
instrumentClassFile(String).
path - the new destination. If the directory does not
exist, it will be created.instrumentClassFile(String),
getDestination()
public boolean setDestination_Precondition(java.lang.String path,
java.lang.Void RESULT)
public java.lang.String getDestination()
instrumentClassFile(String).
instrumentClassFile(String),
setDestination(String)public static boolean isInstrumented(org.apache.bcel.classfile.JavaClass javaclass)
javaclass - a class to test.
javaclass has already been
instrumented.public static void main(java.lang.String[] argv)
argv - command line arguments. These are the names of the
class files to instrument.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||