randoop.instrument
Class Instrument

Object
  extended by Instrument
All Implemented Interfaces:
ClassFileTransformer

public class Instrument
extends Object
implements ClassFileTransformer

The Instrument class is responsible for modifying another class's bytecode. It changes calls to specified functions into static calls to user functions. This allows a user of Randoop to capture arbitrary calls and modify them as desired. For example, all calls to JOptionPane.showConfirmDialog (which would otherwise hang a regressions test) can be changed to throw an exception, or simply print a message and continue.


Field Summary
Modifier and Type Field and Description
static SimpleLog debug_instrument
           
static SimpleLog debug_instrument_inst
           
static SimpleLog debug_map
          Debug information on method maping
static SimpleLog debug_transform
          Debug information about which classes are transformed and why
protected  InstructionFactory ifact
           
static List<Instrument.MethodMapInfo> map_list
          List of all classname regexs and their corresponding method maps
 
Constructor Summary
Constructor and Description
Instrument()
           
 
Method Summary
Modifier and Type Method and Description
 void add_map_file_shutdown_hook()
          Adds a shutdown hook that prints out the results of the method maps
static void dump_map_list()
          Dumps out the map list to the debug_map logger
 String get_attribute_name(Attribute a)
          Returns the attribute name for the specified attribute
 void instrument_method(Method m, MethodGen mg)
          Instrument the specified method to replace mapped calls.
 boolean is_local_variable_type_table(Attribute a)
           
 void read_map_file(File map_file)
          Reads the file that specifies method calls that should be replaced by other method calls.
protected static void replace_instructions(InstructionList il, InstructionHandle ih, InstructionList new_il)
          Replace instruction ih in list il with the instructions in new_il.
 byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer)
          Given another class, return a transformed version of the class which replaces specified calls with alternative static implementations
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ifact

protected InstructionFactory ifact

debug_transform

public static SimpleLog debug_transform
Debug information about which classes are transformed and why


debug_instrument

public static SimpleLog debug_instrument

debug_instrument_inst

public static SimpleLog debug_instrument_inst

debug_map

public static SimpleLog debug_map
Debug information on method maping


map_list

public static List<Instrument.MethodMapInfo> map_list
List of all classname regexs and their corresponding method maps

Constructor Detail

Instrument

public Instrument()
Method Detail

transform

public byte[] transform(ClassLoader loader,
                        String className,
                        Class<?> classBeingRedefined,
                        ProtectionDomain protectionDomain,
                        byte[] classfileBuffer)
                 throws IllegalClassFormatException
Given another class, return a transformed version of the class which replaces specified calls with alternative static implementations

Specified by:
transform in interface ClassFileTransformer
Throws:
IllegalClassFormatException

instrument_method

public void instrument_method(Method m,
                              MethodGen mg)
Instrument the specified method to replace mapped calls.


replace_instructions

protected static void replace_instructions(InstructionList il,
                                           InstructionHandle ih,
                                           InstructionList new_il)
Replace instruction ih in list il with the instructions in new_il. If new_il is null, do nothing


is_local_variable_type_table

public boolean is_local_variable_type_table(Attribute a)

get_attribute_name

public String get_attribute_name(Attribute a)
Returns the attribute name for the specified attribute


read_map_file

public void read_map_file(File map_file)
                   throws IOException
Reads the file that specifies method calls that should be replaced by other method calls. The file is of the form: [regex] [orig-method-def] [new-method-name] where the orig_method-def is of the form: fully-qualified-method-name (args) Blank lines and // comments are ignored. The orig-method-def is replaced by a call to new-method-name with the same arguments in any classfile that matches the regular expressions. All method names and argument types should be fully qualified.

Throws:
IOException

dump_map_list

public static void dump_map_list()
Dumps out the map list to the debug_map logger


add_map_file_shutdown_hook

public void add_map_file_shutdown_hook()
Adds a shutdown hook that prints out the results of the method maps