jef.dna.instructions.impl
Class InstructionAncestor

java.lang.Object
  extended by jef.dna.instructions.impl.InstructionAncestor
All Implemented Interfaces:
java.lang.Cloneable, Instruction, BytesCountable
Direct Known Subclasses:
AALoad, AAStore, AConst_Null, ALoad, ALoad_0, ALoad_1, ALoad_2, ALoad_3, AReturn, ArrayLength, AStore, AStore_0, AStore_1, AStore_2, AStore_3, AThrow, BALoad, BAStore, BiPush, CALoad, CAStore, D2f, D2i, D2l, DAdd, DALoad, DAStore, DCmpg, DCmpl, DConst_0, DConst_1, DDiv, DLoad, DLoad_0, DLoad_1, DLoad_2, DLoad_3, DMul, DNeg, DRem, DReturn, DStore, DStore_0, DStore_1, DStore_2, DStore_3, DSub, Dup, Dup_X1, Dup_X2, Dup2, Dup2_X1, Dup2_X2, F2d, F2i, F2l, FAdd, FALoad, FAStore, FCmpg, FCmpl, FConst_0, FConst_1, FConst_2, FDiv, FLoad, FLoad_0, FLoad_1, FLoad_2, FLoad_3, FMul, FNeg, FRem, FReturn, FStore, FStore_0, FStore_1, FStore_2, FStore_3, FSub, Goto, Goto_W, I2b, I2c, I2d, I2f, I2l, I2s, IAdd, IALoad, IAnd, IAStore, IConst_0, IConst_1, IConst_2, IConst_3, IConst_4, IConst_5, IConst_M1, IDiv, If_ACmpEq, If_ACmpNe, IF_ICmpeq, IF_ICmpge, IF_ICmpgt, IF_ICmple, IF_ICmplt, IF_ICmpne, Ifeq, IfNoNull, IfNull, IInc, ILoad, ILoad_0, ILoad_1, ILoad_2, ILoad_3, IMul, INeg, InstructionAncestorRefsCpt, IOr, IRem, IReturn, IShl, IShr, IStore, IStore_0, IStore_1, IStore_2, IStore_3, ISub, Iushr, IXOr, Jsr, Jsr_W, L2d, L2f, L2i, LAdd, LALoad, LAnd, LAStore, Lcmp, LConst_0, LConst_1, LDiv, LLoad, LLoad_0, LLoad_1, LLoad_2, LLoad_3, LMul, LNeg, LookupSwitch, LOr, LRem, LReturn, LShl, LShr, LStore, LStore_0, LStore_1, LStore_2, LStore_3, LSub, Lushr, LXOr, MonitorEnter, MonitorExit, NewArray, Nop, Pop, Pop2, Ret, Return, SALoad, SAStore, SiPush, Swap, TableSwitch, Wide

public abstract class InstructionAncestor
extends java.lang.Object
implements Instruction

This class is the ancestor of all the concrete instruction classes, and provides all these methods common to every instruction.

Author:
Francesco Russo (frusso@cs.unibo.it)

Field Summary
protected static Logger logger
           
protected  int opCode
           
protected  int[] operands
           
protected  int operandsCount
           
 
Constructor Summary
InstructionAncestor()
           
 
Method Summary
 java.lang.Object clone()
          Performs the cloning of the current Instruction implementation.
 int fromArray(int[] bytecode, int startFrom)
          This method populates all the attributes of an Instruction implementation
 int getBytesCount()
          This method must return the overall number of bytes required by the component implementing this interface.
 int getOpCode()
          This method returns the instruction's numeric operation code as a byte.
 int[] getOperands()
          This method returns the current operation operand stack.
 int getOperandsCount()
          This method returns the number of operands required by the bytecode instruction.
 void setOpCode(int opCode)
          This method sets the current operation code to the specified byte.
 void setOperands(int[] operands)
          This method sets the current operation's operand stack.
 void setOperandsCountPosticipated(int[] bytecode, int startFrom)
          This method should be implemented by those classes wrapping JVM instructions whose number of operands is variable.
 int[] toArray()
          This method returns the method's bytecode as an array.
 int updateRefs(int offset)
          This method must implement the logic necessary to update all the references to constant pool table's entries contained within the bytecode instruction.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final Logger logger

opCode

protected int opCode

operands

protected int[] operands

operandsCount

protected int operandsCount
Constructor Detail

InstructionAncestor

public InstructionAncestor()
Method Detail

fromArray

public int fromArray(int[] bytecode,
                     int startFrom)
This method populates all the attributes of an Instruction implementation

Specified by:
fromArray in interface Instruction
Parameters:
bytecode - The bytecode array
startFrom - The index of the current instruction's mnemonic (opcode)
Returns:
int The number of the processed operands plus one, the instruction's mnemonic

setOperandsCountPosticipated

public void setOperandsCountPosticipated(int[] bytecode,
                                         int startFrom)
This method should be implemented by those classes wrapping JVM instructions whose number of operands is variable. This method is called by the fromArray method defined in the InstructionAncestor class. InstructionAncestor already contains an empty implementation of this method, useful for those classes exposing a prefixed number of operands. In such a case there is no need to override the setOperandsCountPosticipated method

Specified by:
setOperandsCountPosticipated in interface Instruction
Parameters:
bytecode - The method's bytecode
startFrom - The index of the current instruction's mnemonic (opcode)

toArray

public int[] toArray()
This method returns the method's bytecode as an array.

Specified by:
toArray in interface Instruction
Returns:
int[] The method's bytecode

getOpCode

public int getOpCode()
This method returns the instruction's numeric operation code as a byte.

Specified by:
getOpCode in interface Instruction
Returns:
byte The operation code of the Java VM instruction represented as a byte.

setOpCode

public void setOpCode(int opCode)
This method sets the current operation code to the specified byte.

Specified by:
setOpCode in interface Instruction
Parameters:
opCode - The byte representation of the operation code.

getOperands

public int[] getOperands()
This method returns the current operation operand stack.

Specified by:
getOperands in interface Instruction
Returns:
The byte[] containing the operands this instruction has to deal with.

setOperands

public void setOperands(int[] operands)
This method sets the current operation's operand stack.

Specified by:
setOperands in interface Instruction
Parameters:
operands - The operand stack as a byte array.

updateRefs

public int updateRefs(int offset)
This method must implement the logic necessary to update all the references to constant pool table's entries contained within the bytecode instruction.

Specified by:
updateRefs in interface Instruction
Parameters:
offset - The offset used for updating expressed as number of cpt's entries to be skipped
Returns:
int The number of processed words within the current bytecode instruction

getOperandsCount

public int getOperandsCount()
This method returns the number of operands required by the bytecode instruction. This information is useful for calling the setOperands method with the right number of bytes as input parametr.

Specified by:
getOperandsCount in interface Instruction
Returns:
int The number of operands.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Description copied from interface: Instruction
Performs the cloning of the current Instruction implementation.

Specified by:
clone in interface Instruction
Overrides:
clone in class java.lang.Object
Returns:
The clone
Throws:
java.lang.CloneNotSupportedException

getBytesCount

public int getBytesCount()
Description copied from interface: BytesCountable
This method must return the overall number of bytes required by the component implementing this interface.

Specified by:
getBytesCount in interface BytesCountable