Package daikon.dcomp

Class DCInstrument


  • public class DCInstrument
    extends InstructionListUtils
    Instruments a class file to perform Dynamic Comparability.

    The DCInstrument class is responsible for modifying another class's bytecodes. Specifically, its main task is to add calls into the DynComp Runtime to calculate comparability values. These added calls are sometimes referred to as "hooks".

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected static class  DCInstrument.JUnitState
      Possible states of JUnit test discovery.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean constructor_is_initialized
      Has an <init> method completed initialization?
      protected ObjectType dcomp_marker  
      protected @DotSeparatedIdentifiers String dcomp_prefix
      Either "java.lang" or "daikon.dcomp".
      protected @DotSeparatedIdentifiers String dcompRuntimeClassName
      Either "daikon.dcomp.DCRuntime" or "java.lang.DCRuntime".
      protected static SimpleLog debug_dup
      Log file if debug_dup is enabled.
      protected static SimpleLog debug_native
      Log file if debug_native is enabled.
      protected static SimpleLog debug_transform
      Debug information about which classes and/or methods are transformed and why.
      protected static boolean debugGetDefiningInterface
      If true, enable getDefiningInterface(org.apache.bcel.classfile.JavaClass, java.lang.String, org.apache.bcel.generic.Type[]) debugging.
      protected static boolean debugHandleInvoke
      If true, enable handleInvoke(org.apache.bcel.generic.InvokeInstruction) debugging.
      protected static boolean debugJUnitAnalysis
      If true, enable JUnit analysis debugging.
      protected ClassGen gen
      ClassGen for the current class.
      protected static InstructionList global_catch_il  
      protected static CodeExceptionGen global_exception_handler  
      protected InstructionFactory ifact
      The BCEL InstructionFactory for generating byte code instructions.
      protected boolean in_jdk
      Is the current class a member of the JDK?
      protected static Type[] integer_arg
      Type array with an int.
      protected static Type javalangClass
      ObjectType for "java.lang.Class".
      protected static ObjectType javalangObject  
      protected static boolean junit_parse_seen
      Have we seen 'JUnitCommandLineParseResult.parse'?
      protected static DCInstrument.JUnitState junit_state
      Current state of JUnit test discovery.
      protected static Set<String> junitTestClasses
      Set of JUnit test classes.
      protected @Nullable ClassLoader loader
      The loader that loaded the Class to instrument.
      protected MethodGen mgen
      MethodGen for the current method.
      protected static DCInstrument.MethodDef[] obj_methods
      List of Object methods.
      protected static Type[] object_arg
      Type array with an object.
      protected static Type object_arr  
      protected static Type[] object_int
      Type array with an object and an int.
      protected JavaClass orig_class
      Unmodified version of input class.
      static boolean quit_if_error
      Used when testing to continue processing if an error occurs.
      protected List<String> skipped_methods
      Keeps track of the methods that were not successfully instrumented.
      protected static Type[] string_arg
      Type array with a string.
      protected LocalVariableGen tag_frame_local
      Local that stores the tag frame for the current method.
      protected static ObjectType throwable  
      protected static Type[] two_objects
      Type array with two objects.
      protected static String[] uninit_classes
      Array of classes whose fields are not initialized from java.
      • Fields inherited from class StackMapUtils

        debugInstrument, firstLocalIndex, initialLocalsCount, initialTypeList, liveRangeEnd, liveRangeOperandSize, liveRangeStart, liveRangeType, needStackMap, numberActiveLocals, pool, runningOffset, smta, stackMapTable, stackTypes
    • Constructor Summary

      Constructors 
      Constructor Description
      DCInstrument​(JavaClass orig_class, boolean in_jdk, @Nullable ClassLoader loader)
      Initialize with the original class and whether or not the class is part of the JDK.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add_create_tag_frame​(MethodGen mg)
      Adds the code to create the tag frame to the beginning of the method.
      void add_enter​(MethodGen mg, MethodInfo mi, int method_info_index)
      Adds the call to DCRuntime.enter to the beginning of the method.
      void add_exception_handler​(MethodGen mg, InstructionList catch_il)
      Adds a try/catch block around the entire method.
      void build_exception_handler​(MethodGen mg)
      Adds a try/catch block around the entire method.
      protected String full_name​(JavaClass jc, Field f)
      Return the fully qualified fieldname of the specified field.
      List<String> get_skipped_methods()
      Returns the list of uninstrumented methods.
      void install_exception_handler​(MethodGen mg)
      Adds a try/catch block around the entire method.
      JavaClass instrument()
      Instruments the original class to perform dynamic comparabilty and returns the new class definition.
      JavaClass instrument_jdk()
      Instruments a JDK class to perform dynamic comparability and returns the new class definition.
      void instrument_method​(MethodGen mg)
      Instrument the specified method for dynamic comparability.
      protected String simplify_method_name​(Method m)
      Return simplified name of a method.
      • Methods inherited from class InstructionListUtils

        append_inst, build_il, calculateLiveLocalTypes, calculateLiveStackTypes, delete_instructions, insertAtMethodStart, insertBeforeHandle, replaceInstructions
      • Methods inherited from class StackMapUtils

        addNewParameter, addString, adjust_code_for_locals_change, bcelCalcStackTypes, buildUninitializedNewMap, create_local_from_live_range, create_method_scope_local, createNewStackMapAttribute, findStackMapEqual, findStackMapIndexAfter, findStackMapIndexBefore, fixLocalVariableTable, gen_locals, gen_locals_from_byte_codes, gen_locals_from_byte_codes, generate_Type_from_StackMapType, generateStackMapTypeFromType, get_attribute_name, get_local_variable_type_table_attribute, getSize, getStackMapTable_attribute, is_local_variable_type_table, isStackMapTable, modifyStackMapsForSwitches, printStackMapTable, remove_local_variable_type_table, set_method_stackTypes, setCurrentStackMapTable, typeToClassGetName, update_full_frameStackMap_entries, updateStackMapOffset, updateUninitializedNewOffsets
    • Field Detail

      • quit_if_error

        public static boolean quit_if_error
        Used when testing to continue processing if an error occurs. Currently, This flag is only used by BuildJDK.
      • orig_class

        protected JavaClass orig_class
        Unmodified version of input class.
      • gen

        protected ClassGen gen
        ClassGen for the current class.
      • mgen

        protected MethodGen mgen
        MethodGen for the current method.
      • in_jdk

        protected boolean in_jdk
        Is the current class a member of the JDK?
      • ifact

        protected InstructionFactory ifact
        The BCEL InstructionFactory for generating byte code instructions.
      • loader

        protected @Nullable ClassLoader loader
        The loader that loaded the Class to instrument.
      • tag_frame_local

        protected LocalVariableGen tag_frame_local
        Local that stores the tag frame for the current method.
      • two_objects

        protected static Type[] two_objects
        Type array with two objects.
      • object_int

        protected static Type[] object_int
        Type array with an object and an int.
      • string_arg

        protected static Type[] string_arg
        Type array with a string.
      • integer_arg

        protected static Type[] integer_arg
        Type array with an int.
      • object_arg

        protected static Type[] object_arg
        Type array with an object.
      • javalangClass

        protected static Type javalangClass
        ObjectType for "java.lang.Class".
      • throwable

        protected static ObjectType throwable
      • debug_native

        protected static SimpleLog debug_native
        Log file if debug_native is enabled.
      • debug_dup

        protected static SimpleLog debug_dup
        Log file if debug_dup is enabled.
      • debug_transform

        protected static SimpleLog debug_transform
        Debug information about which classes and/or methods are transformed and why. Use debugInstrument for actual instrumentation details.
      • debugGetDefiningInterface

        protected static final boolean debugGetDefiningInterface
        If true, enable getDefiningInterface(org.apache.bcel.classfile.JavaClass, java.lang.String, org.apache.bcel.generic.Type[]) debugging.
        See Also:
        Constant Field Values
      • skipped_methods

        protected List<String> skipped_methods
        Keeps track of the methods that were not successfully instrumented.
      • dcomp_prefix

        protected @DotSeparatedIdentifiers String dcomp_prefix
        Either "java.lang" or "daikon.dcomp".
      • dcompRuntimeClassName

        protected @DotSeparatedIdentifiers String dcompRuntimeClassName
        Either "daikon.dcomp.DCRuntime" or "java.lang.DCRuntime".
      • junit_parse_seen

        protected static boolean junit_parse_seen
        Have we seen 'JUnitCommandLineParseResult.parse'?
      • uninit_classes

        protected static String[] uninit_classes
        Array of classes whose fields are not initialized from java. Since the fields are not initialized from java, their tag storage is not allocated as part of a store, but rather must be allocated as part of a load. We call a special runtime method for this so that we can check for this in other cases.
      • obj_methods

        protected static DCInstrument.MethodDef[] obj_methods
        List of Object methods. Since we can't instrument Object, none of these can be instrumented, and most of them don't provide useful comparability information anyway. The equals method and the clone method are special-cased in the handleInvoke(org.apache.bcel.generic.InvokeInstruction) routine.
    • Constructor Detail

      • DCInstrument

        public DCInstrument​(JavaClass orig_class,
                            boolean in_jdk,
                            @Nullable ClassLoader loader)
        Initialize with the original class and whether or not the class is part of the JDK.
    • Method Detail

      • instrument

        public JavaClass instrument()
        Instruments the original class to perform dynamic comparabilty and returns the new class definition.
        Returns:
        the modified JavaClass
      • instrument_jdk

        public JavaClass instrument_jdk()
        Instruments a JDK class to perform dynamic comparability and returns the new class definition. A second version of each method in the class is created which is instrumented for comparability.
        Returns:
        the modified JavaClass
      • instrument_method

        public void instrument_method​(MethodGen mg)
        Instrument the specified method for dynamic comparability.
        Parameters:
        mg - MethodGen for the method to be instrumented
      • get_skipped_methods

        public List<Stringget_skipped_methods()
        Returns the list of uninstrumented methods. (Note: instrument_jdk() needs to have been called first.)
      • build_exception_handler

        public void build_exception_handler​(MethodGen mg)
        Adds a try/catch block around the entire method. If an exception occurs, the tag stack is cleaned up and the exception is rethrown.
      • add_exception_handler

        public void add_exception_handler​(MethodGen mg,
                                          InstructionList catch_il)
        Adds a try/catch block around the entire method.
      • install_exception_handler

        public void install_exception_handler​(MethodGen mg)
        Adds a try/catch block around the entire method.
      • add_create_tag_frame

        public void add_create_tag_frame​(MethodGen mg)
        Adds the code to create the tag frame to the beginning of the method. This needs to be before the call to DCRuntime.enter (since it passed to that method).
      • add_enter

        public void add_enter​(MethodGen mg,
                              MethodInfo mi,
                              int method_info_index)
        Adds the call to DCRuntime.enter to the beginning of the method.
        Parameters:
        mg - method to modify
        mi - MethodInfo for method
        method_info_index - index for MethodInfo
      • full_name

        protected String full_name​(JavaClass jc,
                                   Field f)
        Return the fully qualified fieldname of the specified field.
        Parameters:
        jc - class containing the field
        f - the field
        Returns:
        string containing the fully qualified name
      • simplify_method_name

        protected String simplify_method_name​(Method m)
        Return simplified name of a method. Both exceptions and annotations are removed.
        Parameters:
        m - the method
        Returns:
        string containing the simplified method name