Class InstructionsBuilder


  • class InstructionsBuilder
    extends java.lang.Object
    Stateful builder for the Instructions of a method. All instructions of a method must be added in their original sequence along with additional information like line numbers. Afterwards the instructions can be obtained with the getInstructions() method.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  InstructionsBuilder.Jump  
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Instruction currentInsn
      The last instruction which has been added.
      private java.util.List<org.objectweb.asm.Label> currentLabel
      The labels which mark the subsequent instructions.
      private int currentLine
      The line which belong to subsequently added instructions.
      private java.util.Map<org.objectweb.asm.tree.AbstractInsnNode,​Instruction> instructions
      All instructions of a method mapped from the ASM node to the corresponding Instruction instance.
      private java.util.List<InstructionsBuilder.Jump> jumps
      List of all jumps within the control flow.
      private boolean[] probes
      Probe array of the class the analyzed method belongs to.
    • Constructor Summary

      Constructors 
      Constructor Description
      InstructionsBuilder​(boolean[] probes)
      Creates a new builder instance which can be used to analyze a single method.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) void addInstruction​(org.objectweb.asm.tree.AbstractInsnNode node)
      Adds a new instruction.
      (package private) void addJump​(org.objectweb.asm.Label target, int branch)
      Adds a jump from the last added instruction.
      (package private) void addLabel​(org.objectweb.asm.Label label)
      Adds a label which applies to the subsequently added instruction.
      (package private) void addProbe​(int probeId, int branch)
      Adds a new probe for the last instruction.
      (package private) java.util.Map<org.objectweb.asm.tree.AbstractInsnNode,​Instruction> getInstructions()
      Returns the status for all instructions of this method.
      (package private) void noSuccessor()
      Declares that the next instruction will not be a successor of the current instruction.
      (package private) void setCurrentLine​(int line)
      Sets the current source line.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • probes

        private final boolean[] probes
        Probe array of the class the analyzed method belongs to.
      • currentLine

        private int currentLine
        The line which belong to subsequently added instructions.
      • currentInsn

        private Instruction currentInsn
        The last instruction which has been added.
      • instructions

        private final java.util.Map<org.objectweb.asm.tree.AbstractInsnNode,​Instruction> instructions
        All instructions of a method mapped from the ASM node to the corresponding Instruction instance.
      • currentLabel

        private final java.util.List<org.objectweb.asm.Label> currentLabel
        The labels which mark the subsequent instructions. Due to ASM issue #315745 there can be more than one label per instruction
      • jumps

        private final java.util.List<InstructionsBuilder.Jump> jumps
        List of all jumps within the control flow. We need to store jumps temporarily as the target Instruction may not been known yet.
    • Constructor Detail

      • InstructionsBuilder

        InstructionsBuilder​(boolean[] probes)
        Creates a new builder instance which can be used to analyze a single method.
        Parameters:
        probes - probe array of the corresponding class used to determine the coverage status of every instruction.
    • Method Detail

      • setCurrentLine

        void setCurrentLine​(int line)
        Sets the current source line. All subsequently added instructions will be assigned to this line. If no line is set (e.g. for classes compiled without debug information) ISourceNode.UNKNOWN_LINE is assigned to the instructions.
      • addLabel

        void addLabel​(org.objectweb.asm.Label label)
        Adds a label which applies to the subsequently added instruction. Due to ASM internals multiple Labels can be added to an instruction.
      • addInstruction

        void addInstruction​(org.objectweb.asm.tree.AbstractInsnNode node)
        Adds a new instruction. Instructions are by default linked with the previous instruction unless specified otherwise.
      • noSuccessor

        void noSuccessor()
        Declares that the next instruction will not be a successor of the current instruction. This is the case with an unconditional jump or technically when a probe was inserted before.
      • addJump

        void addJump​(org.objectweb.asm.Label target,
                     int branch)
        Adds a jump from the last added instruction.
        Parameters:
        target - jump target
        branch - unique branch number
      • addProbe

        void addProbe​(int probeId,
                      int branch)
        Adds a new probe for the last instruction.
        Parameters:
        probeId - index in the probe array
        branch - unique branch number for the last instruction
      • getInstructions

        java.util.Map<org.objectweb.asm.tree.AbstractInsnNode,​Instruction> getInstructions()
        Returns the status for all instructions of this method. This method must be called exactly once after the instructions have been added.
        Returns:
        map of ASM instruction nodes to corresponding Instruction instances