Klasse InstructionList

java.lang.Object
org.aspectj.apache.bcel.generic.InstructionList
Alle implementierten Schnittstellen:
Serializable

public class InstructionList extends Object implements Serializable
This class is a container for a list of Instruction objects. Instructions can be appended, inserted, moved, deleted, etc.. Instructions are being wrapped into InstructionHandles objects that are returned upon append/insert operations. They give the user (read only) access to the list structure, such that it can be traversed and manipulated in a controlled way. A list is finally dumped to a byte code array with getByteCode.
Version:
$Id: InstructionList.java,v 1.12 2011/09/02 22:33:04 aclement Exp $
Autor:
M. Dahm, Abraham Nevado
Siehe auch:
  • Konstruktordetails

    • InstructionList

      public InstructionList()
    • InstructionList

      public InstructionList(Instruction i)
    • InstructionList

      public InstructionList(byte[] code)
      Initialize instruction list from byte array.
      Parameter:
      code - byte array containing the instructions
  • Methodendetails

    • isEmpty

      public boolean isEmpty()
    • findHandle

      public static InstructionHandle findHandle(InstructionHandle[] ihs, int[] pos, int count, int target)
    • findHandle

      public static InstructionHandle findHandle(InstructionHandle[] ihs, int[] pos, int count, int target, boolean returnClosestIfNoExactMatch)
      Find the target instruction (handle) that corresponds to the given target position (byte code offset).
      Parameter:
      ihs - array of instruction handles, i.e. il.getInstructionHandles()
      pos - array of positions corresponding to ihs, i.e. il.getInstructionPositions()
      count - length of arrays
      target - target position to search for
      Gibt zurück:
      target position's instruction handle if available
    • findHandle

      public InstructionHandle findHandle(int pos)
      Get instruction handle for instruction at byte code position pos. This only works properly, if the list is freshly initialized from a byte array or setPositions() has been called before this method.
      Parameter:
      pos - byte code position to search for
      Gibt zurück:
      target position's instruction handle if available
    • getInstructionsAsArray

      public InstructionHandle[] getInstructionsAsArray()
    • findHandle

      public InstructionHandle findHandle(int pos, InstructionHandle[] instructionArray)
    • findHandle

      public InstructionHandle findHandle(int pos, InstructionHandle[] instructionArray, boolean useClosestApproximationIfNoExactFound)
    • append

      public InstructionHandle append(InstructionHandle appendTo, InstructionList appendee)
      Append another list after instruction (handle) ih contained in this list. Consumes argument list, i.e., it becomes empty.
      Parameter:
      appendTo - where to append the instruction list
      appendee - Instruction list to append to this one
      Gibt zurück:
      instruction handle pointing to the first appended instruction
    • append

      Append another list after instruction i contained in this list. Consumes argument list, i.e., it becomes empty.
      Parameter:
      i - where to append the instruction list
      il - Instruction list to append to this one
      Gibt zurück:
      instruction handle pointing to the first appended instruction
    • append

      public InstructionHandle append(InstructionList il)
      Append another list to this one. Consumes argument list, i.e., it becomes empty.
      Parameter:
      il - list to append to end of this list
      Gibt zurück:
      instruction handle of the first appended instruction
    • append

      public InstructionHandle append(Instruction i)
      Append an instruction to the end of this list.
      Parameter:
      i - instruction to append
      Gibt zurück:
      instruction handle of the appended instruction
    • appendDUP

      public InstructionHandle appendDUP()
    • appendNOP

      public InstructionHandle appendNOP()
    • appendPOP

      public InstructionHandle appendPOP()
    • append

      public BranchHandle append(InstructionBranch i)
      Append a branch instruction to the end of this list.
      Parameter:
      i - branch instruction to append
      Gibt zurück:
      branch instruction handle of the appended instruction
    • append

      public InstructionHandle append(Instruction i, Instruction j)
      Append a single instruction j after another instruction i, which must be in this list of course!
      Parameter:
      i - Instruction in list
      j - Instruction to append after i in list
      Gibt zurück:
      instruction handle of the first appended instruction
    • append

      Append an instruction after instruction (handle) ih contained in this list.
      Parameter:
      ih - where to append the instruction list
      i - Instruction to append
      Gibt zurück:
      instruction handle pointing to the first appended instruction
    • append

      Append an instruction after instruction (handle) ih contained in this list.
      Parameter:
      ih - where to append the instruction list
      i - Instruction to append
      Gibt zurück:
      instruction handle pointing to the first appended instruction
    • insert

      Insert another list before Instruction handle ih contained in this list. Consumes argument list, i.e., it becomes empty.
      Parameter:
      il - Instruction list to insert
      i - where to append the instruction list
      Gibt zurück:
      instruction handle of the first inserted instruction
    • insert

      public InstructionHandle insert(InstructionList il)
      Insert another list.
      Parameter:
      il - list to insert before start of this list
      Gibt zurück:
      instruction handle of the first inserted instruction
    • insert

      Insert another list before Instruction i contained in this list. Consumes argument list, i.e., it becomes empty.
      Parameter:
      i - where to append the instruction list
      il - Instruction list to insert
      Gibt zurück:
      instruction handle pointing to the first inserted instruction, i.e., il.getStart()
    • insert

      public InstructionHandle insert(Instruction i)
      Insert an instruction at start of this list.
      Parameter:
      i - instruction to insert
      Gibt zurück:
      instruction handle of the inserted instruction
    • insert

      public BranchHandle insert(InstructionBranch i)
      Insert a branch instruction at start of this list.
      Parameter:
      i - branch instruction to insert
      Gibt zurück:
      branch instruction handle of the appended instruction
    • insert

      public InstructionHandle insert(Instruction i, Instruction j)
      Insert a single instruction j before another instruction i, which must be in this list of course!
      Parameter:
      i - Instruction in list
      j - Instruction to insert before i in list
      Gibt zurück:
      instruction handle of the first inserted instruction
    • insert

      Insert an instruction before instruction (handle) ih contained in this list.
      Parameter:
      ih - where to insert to the instruction list
      i - Instruction to insert
      Gibt zurück:
      instruction handle of the first inserted instruction
    • insert

      Insert an instruction before instruction (handle) ih contained in this list.
      Parameter:
      ih - where to insert to the instruction list
      i - Instruction to insert
      Gibt zurück:
      instruction handle of the first inserted instruction
    • move

      public void move(InstructionHandle start, InstructionHandle end, InstructionHandle target)
      Take all instructions (handles) from "start" to "end" and append them after the new location "target". Of course, "end" must be after "start" and target must not be located withing this range. If you want to move something to the start of the list use null as value for target.
      Any instruction targeters pointing to handles within the block, keep their targets.
      Parameter:
      start - of moved block
      end - of moved block
      target - of moved block
    • move

      public void move(InstructionHandle ih, InstructionHandle target)
      Move a single instruction (handle) to a new location.
      Parameter:
      ih - moved instruction
      target - new location of moved instruction
    • delete

      public void delete(InstructionHandle ih) throws TargetLostException
      Remove instruction from this list. The corresponding Instruction handles must not be reused!
      Parameter:
      ih - instruction (handle) to remove
      Löst aus:
      TargetLostException
    • delete

      public void delete(InstructionHandle from, InstructionHandle to) throws TargetLostException
      Remove instructions from instruction `from' to instruction `to' contained in this list. The user must ensure that `from' is an instruction before `to', or risk havoc. The corresponding Instruction handles must not be reused!
      Parameter:
      from - where to start deleting (inclusive)
      to - where to end deleting (inclusive)
      Löst aus:
      TargetLostException
    • delete

      public void delete(Instruction from, Instruction to) throws TargetLostException
      Remove instructions from instruction `from' to instruction `to' contained in this list. The user must ensure that `from' is an instruction before `to', or risk havoc. The corresponding Instruction handles must not be reused!
      Parameter:
      from - where to start deleting (inclusive)
      to - where to end deleting (inclusive)
      Löst aus:
      TargetLostException
    • contains

      public boolean contains(InstructionHandle i)
    • contains

      public boolean contains(Instruction i)
    • setPositions

      public void setPositions()
    • setPositions

      public void setPositions(boolean check)
      Give all instructions their position number (offset in byte stream), i.e., make the list ready to be dumped.
      Parameter:
      check - Perform sanity checks, e.g. if all targeted instructions really belong to this list
    • getByteCode

      public byte[] getByteCode()
      When everything is finished, use this method to convert the instruction list into an array of bytes.
      Gibt zurück:
      the byte code ready to be dumped
    • getInstructions

      public Instruction[] getInstructions()
      Gibt zurück:
      an array of instructions without target information for branch instructions.
    • toString

      public String toString()
      Setzt außer Kraft:
      toString in Klasse Object
    • toString

      public String toString(boolean verbose)
      Parameter:
      verbose - toggle output format
      Gibt zurück:
      String containing all instructions in this list.
    • iterator

      public Iterator iterator()
      Gibt zurück:
      Enumeration that lists all instructions (handles)
    • getInstructionHandles

      public InstructionHandle[] getInstructionHandles()
      Gibt zurück:
      array containing all instructions (handles)
    • getInstructionPositions

      public int[] getInstructionPositions()
      Get positions (offsets) of all instructions in the list. This relies on that the list has been freshly created from an byte code array, or that setPositions() has been called. Otherwise this may be inaccurate.
      Gibt zurück:
      array containing all instruction's offset in byte code
    • copy

      public InstructionList copy()
      Gibt zurück:
      complete, i.e., deep copy of this list
    • replaceConstantPool

      public void replaceConstantPool(ConstantPool old_cp, ConstantPool new_cp)
      Replace all references to the old constant pool with references to the new constant pool
    • dispose

      public void dispose()
      Delete contents of list. Provides better memory utilization, because the system then may reuse the instruction handles. This method is typically called right after Ungültige Eingabe: "<"href="MethodGen.html#getMethod()">MethodGen.getMethod().
    • getStart

      public InstructionHandle getStart()
      Gibt zurück:
      start of list
    • getEnd

      public InstructionHandle getEnd()
      Gibt zurück:
      end of list
    • getLength

      public int getLength()
      Gibt zurück:
      length of list (Number of instructions, not bytes)
    • size

      public int size()
      Gibt zurück:
      length of list (Number of instructions, not bytes)
    • redirectBranches

      public void redirectBranches(InstructionHandle old_target, InstructionHandle new_target)
      Redirect all references from old_target to new_target, i.e., update targets of branch instructions.
      Parameter:
      old_target - the old target instruction handle
      new_target - the new target instruction handle
    • redirectLocalVariables

      public void redirectLocalVariables(LocalVariableGen[] lg, InstructionHandle old_target, InstructionHandle new_target)
      Redirect all references of local variables from old_target to new_target.
      Parameter:
      lg - array of local variables
      old_target - the old target instruction handle
      new_target - the new target instruction handle
      Siehe auch:
    • redirectExceptionHandlers

      public void redirectExceptionHandlers(CodeExceptionGen[] exceptions, InstructionHandle old_target, InstructionHandle new_target)
      Redirect all references of exception handlers from old_target to new_target.
      Parameter:
      exceptions - array of exception handlers
      old_target - the old target instruction handle
      new_target - the new target instruction handle
      Siehe auch: