jreversepro.revengine
Class JBranchTable

java.lang.Object
  extended by jreversepro.revengine.JBranchTable
All Implemented Interfaces:
JJvmOpcodes, BranchConstants

public class JBranchTable
extends java.lang.Object
implements BranchConstants, JJvmOpcodes

JBranchTable manages the objects of JGotoEntry and JBranchEntry.

Author:
Karthik Kumar

Field Summary
 
Fields inherited from interface jreversepro.revengine.BranchConstants
TYPE_BRANCH, TYPE_CASE, TYPE_CATCH, TYPE_CATCH_ANY, TYPE_DO_WHILE, TYPE_ELSE, TYPE_ELSE_IF, TYPE_GOTO, TYPE_IF, TYPE_INVALID, TYPE_JSR, TYPE_RET, TYPE_SWITCH, TYPE_SYNC, TYPE_TRY, TYPE_TRY_ANY, TYPE_WHILE
 
Fields inherited from interface jreversepro.common.JJvmOpcodes
OPCODE_AALOAD, OPCODE_AASTORE, OPCODE_ACONST_NULL, OPCODE_ALOAD, OPCODE_ALOAD_0, OPCODE_ALOAD_1, OPCODE_ALOAD_2, OPCODE_ALOAD_3, OPCODE_ANEWARRAY, OPCODE_ARETURN, OPCODE_ARRAYLENGTH, OPCODE_ASTORE, OPCODE_ASTORE_0, OPCODE_ASTORE_1, OPCODE_ASTORE_2, OPCODE_ASTORE_3, OPCODE_ATHROW, OPCODE_BALOAD, OPCODE_BASTORE, OPCODE_BIPUSH, OPCODE_CALOAD, OPCODE_CASTORE, OPCODE_CHECKCAST, OPCODE_D2F, OPCODE_D2I, OPCODE_D2L, OPCODE_DADD, OPCODE_DALOAD, OPCODE_DASTORE, OPCODE_DCMPG, OPCODE_DCMPL, OPCODE_DCONST_0, OPCODE_DCONST_1, OPCODE_DDIV, OPCODE_DLOAD, OPCODE_DLOAD_0, OPCODE_DLOAD_1, OPCODE_DLOAD_2, OPCODE_DLOAD_3, OPCODE_DMUL, OPCODE_DNEG, OPCODE_DREM, OPCODE_DRETURN, OPCODE_DSTORE, OPCODE_DSTORE_0, OPCODE_DSTORE_1, OPCODE_DSTORE_2, OPCODE_DSTORE_3, OPCODE_DSUB, OPCODE_DUP, OPCODE_DUP_X1, OPCODE_DUP_X2, OPCODE_DUP2, OPCODE_DUP2_X1, OPCODE_DUP2_X2, OPCODE_F2D, OPCODE_F2I, OPCODE_F2L, OPCODE_FADD, OPCODE_FALOAD, OPCODE_FASTORE, OPCODE_FCMPG, OPCODE_FCMPL, OPCODE_FCONST_0, OPCODE_FCONST_1, OPCODE_FCONST_2, OPCODE_FDIV, OPCODE_FLOAD, OPCODE_FLOAD_0, OPCODE_FLOAD_1, OPCODE_FLOAD_2, OPCODE_FLOAD_3, OPCODE_FMUL, OPCODE_FNEG, OPCODE_FREM, OPCODE_FRETURN, OPCODE_FSTORE, OPCODE_FSTORE_0, OPCODE_FSTORE_1, OPCODE_FSTORE_2, OPCODE_FSTORE_3, OPCODE_FSUB, OPCODE_GETFIELD, OPCODE_GETSTATIC, OPCODE_GOTO, OPCODE_GOTOW, OPCODE_I2B, OPCODE_I2C, OPCODE_I2D, OPCODE_I2F, OPCODE_I2L, OPCODE_I2S, OPCODE_IADD, OPCODE_IALOAD, OPCODE_IAND, OPCODE_IASTORE, OPCODE_ICONST_0, OPCODE_ICONST_1, OPCODE_ICONST_2, OPCODE_ICONST_3, OPCODE_ICONST_4, OPCODE_ICONST_5, OPCODE_ICONST_M1, OPCODE_IDIV, OPCODE_IF_ACMPEQ, OPCODE_IF_ACMPNE, OPCODE_IF_ICMPEQ, OPCODE_IF_ICMPGE, OPCODE_IF_ICMPGT, OPCODE_IF_ICMPLE, OPCODE_IF_ICMPLT, OPCODE_IF_ICMPNE, OPCODE_IFEQ, OPCODE_IFGE, OPCODE_IFGT, OPCODE_IFLE, OPCODE_IFLT, OPCODE_IFNE, OPCODE_IFNONNULL, OPCODE_IFNULL, OPCODE_IINC, OPCODE_ILOAD, OPCODE_ILOAD_0, OPCODE_ILOAD_1, OPCODE_ILOAD_2, OPCODE_ILOAD_3, OPCODE_IMUL, OPCODE_INEG, OPCODE_INSTANCEOF, OPCODE_INVOKEINTERFACE, OPCODE_INVOKESPECIAL, OPCODE_INVOKESTATIC, OPCODE_INVOKEVIRTUAL, OPCODE_IOR, OPCODE_IREM, OPCODE_IRETURN, OPCODE_ISHL, OPCODE_ISHR, OPCODE_ISTORE, OPCODE_ISTORE_0, OPCODE_ISTORE_1, OPCODE_ISTORE_2, OPCODE_ISTORE_3, OPCODE_ISUB, OPCODE_IUSHR, OPCODE_IXOR, OPCODE_JSR, OPCODE_JSRW, OPCODE_L2D, OPCODE_L2F, OPCODE_L2I, OPCODE_LADD, OPCODE_LALOAD, OPCODE_LAND, OPCODE_LASTORE, OPCODE_LCMP, OPCODE_LCONST_0, OPCODE_LCONST_1, OPCODE_LDC, OPCODE_LDC_W, OPCODE_LDC2_W, OPCODE_LDIV, OPCODE_LLOAD, OPCODE_LLOAD_0, OPCODE_LLOAD_1, OPCODE_LLOAD_2, OPCODE_LLOAD_3, OPCODE_LMUL, OPCODE_LNEG, OPCODE_LOOKUPSWITCH, OPCODE_LOR, OPCODE_LREM, OPCODE_LRETURN, OPCODE_LSHL, OPCODE_LSHR, OPCODE_LSTORE, OPCODE_LSTORE_0, OPCODE_LSTORE_1, OPCODE_LSTORE_2, OPCODE_LSTORE_3, OPCODE_LSUB, OPCODE_LUSHR, OPCODE_LXOR, OPCODE_MONITORENTER, OPCODE_MONITOREXIT, OPCODE_MULTIANEWARRAY, OPCODE_NEW, OPCODE_NEWARRAY, OPCODE_NOP, OPCODE_POP, OPCODE_POP2, OPCODE_PUTFIELD, OPCODE_PUTSTATIC, OPCODE_RET, OPCODE_RETURN, OPCODE_SALOAD, OPCODE_SASTORE, OPCODE_SIPUSH, OPCODE_SWAP, OPCODE_TABLESWITCH, OPCODE_WIDE, OPCODE_XXXUNUSEDXXX
 
Constructor Summary
JBranchTable(JMethod method)
           
 
Method Summary
 void add(JBranchEntry ent)
          Adds a new branch entry to the list of branches.
 void addGotoEntry(int startPc, int targetPc)
          Adds a Goto entry to the internal data structure.
 void addJSRPc(int targetPc)
          This adds the pc given as input as a JSR target.
 void addMonitorPc(int aMonitorPc, java.lang.String aMonObject)
          Adds a monitor Pc.
 void addRetPc(int retPc)
          When a RET instruction is encountered we add a branch with the last element of the JSR target lists.
 void addSwitch(JSwitchTable switchEntry)
          Adds the switch entries and the case entries under the same to the branch table.
 void addTryBlocks(java.util.List<JException> excTryTable)
          List of JException entries.
 java.lang.String branchesToString()
          Stringifies the braches alone.
static JBranchEntry contains(java.util.List<JBranchEntry> listBranchEntries, int type)
          Returns the first branch in the mentioned branchlist that matches the particular type.
 void deleteElse(int startElse)
          Delete the branch that corresponds to a else ..
 java.lang.String doesMonitorBegin(int monitorBeginPc)
          Returns the monitor type for the monitor that begins with Pc.
protected  void finalize()
          Finalizer method.
 JInstruction findGotoIns(java.util.List<JInstruction> byteIns, int start, int end)
           
 int findGotoTarget(int startPc)
          For the given pc return the target of the instruction.
 java.util.Map<java.lang.Integer,java.lang.Integer> getGotoTable()
          Getter method for goto tables.
 void identifyMoreBranches()
          Identifies the else..if and else branches.
 boolean isJSRTarget(int currPc)
          Checks if the Pc passed as argument is the target for any JSR instructions.
 void setTables(java.util.List<JBranchEntry> aBranches)
          Setter method for the branch tables.
 void sort()
          This sorts the list containing branches such that no branch overlaps with the one previously existing.
 java.util.List<JBranchEntry> startsWith(int aInsIndex)
          Returns the list of branches that starts with the mentioned aInsIndex.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JBranchTable

public JBranchTable(JMethod method)
Parameters:
method - Method reference.
Method Detail

setTables

public void setTables(java.util.List<JBranchEntry> aBranches)
Setter method for the branch tables.

Parameters:
aBranches - Branches to be added.

getGotoTable

public java.util.Map<java.lang.Integer,java.lang.Integer> getGotoTable()
Getter method for goto tables.

Returns:
Map of goto table entries. key - goto pc. value - target of that goto table.

addGotoEntry

public void addGotoEntry(int startPc,
                         int targetPc)
Adds a Goto entry to the internal data structure.

Parameters:
startPc - StartPc of the goto statement.
targetPc - TargetPc of the goto statement.

finalize

protected void finalize()
Finalizer method.

Overrides:
finalize in class java.lang.Object

add

public void add(JBranchEntry ent)
Adds a new branch entry to the list of branches.

Parameters:
ent - branch entry to be added.

isJSRTarget

public boolean isJSRTarget(int currPc)
Checks if the Pc passed as argument is the target for any JSR instructions.

Parameters:
currPc - Pc for which it is to be checked if it is the target for any JSR instruction.
Returns:
true, if there exists a JSR instruction with its target currPc. false, otherwise.

addJSRPc

public void addJSRPc(int targetPc)
This adds the pc given as input as a JSR target.

Parameters:
targetPc - TargetPc for a JSR instruction that is to be added to the internal data structure ( list ).

addRetPc

public void addRetPc(int retPc)
When a RET instruction is encountered we add a branch with the last element of the JSR target lists. JSR instructions signify 'synchronized' and catch..all blocks.

Parameters:
retPc - PC of the instruction which is a RET.

sort

public void sort()
This sorts the list containing branches such that no branch overlaps with the one previously existing. See JBranchComparator for more details.


addMonitorPc

public void addMonitorPc(int aMonitorPc,
                         java.lang.String aMonObject)
Adds a monitor Pc.

Parameters:
aMonitorPc - Pc that is monitorenter.
aMonObject - Object that is 'monitored'. In the sense object for which lock is obtained before entering a 'synchronized' object.

doesMonitorBegin

public java.lang.String doesMonitorBegin(int monitorBeginPc)
Returns the monitor type for the monitor that begins with Pc.

Parameters:
monitorBeginPc - Pc that begins with the monitor.
Returns:
monitor object associated with this branch.

identifyMoreBranches

public void identifyMoreBranches()
                          throws RevEngineException
Identifies the else..if and else branches. Identifies catch.. branches.

Throws:
RevEngineException - Thrown in case of any error.

addSwitch

public void addSwitch(JSwitchTable switchEntry)
Adds the switch entries and the case entries under the same to the branch table.

Parameters:
switchEntry - switch table containing entries about switch statements.

addTryBlocks

public void addTryBlocks(java.util.List<JException> excTryTable)
List of JException entries.

Parameters:
excTryTable - Individual entries being JException.

findGotoTarget

public int findGotoTarget(int startPc)
For the given pc return the target of the instruction. The instruction is a goto statement.

Parameters:
startPc - Start Pc.
Returns:
the TargetPc for the goto instruction at the startPc

startsWith

public java.util.List<JBranchEntry> startsWith(int aInsIndex)
                                        throws RevEngineException
Returns the list of branches that starts with the mentioned aInsIndex.

Parameters:
aInsIndex - Instruction index.
Returns:
List of JBranchEntry - list of branches that starts with the mentioned instruction index.
Throws:
RevEngineException - thrown in case of an error.

deleteElse

public void deleteElse(int startElse)
Delete the branch that corresponds to a else .. branch starting with the given Pc

Parameters:
startElse - PC for which the else statement is to be deleted.

contains

public static JBranchEntry contains(java.util.List<JBranchEntry> listBranchEntries,
                                    int type)
Returns the first branch in the mentioned branchlist that matches the particular type.

Parameters:
listBranchEntries - list of branch entries.
type - Type that is to be searched for.
Returns:
first branch entry that matches the type mentioned in the list given.

findGotoIns

public JInstruction findGotoIns(java.util.List<JInstruction> byteIns,
                                int start,
                                int end)
Parameters:
byteIns - BytecodeInstruction List.
start - StartPc.
end - EndPc.
Returns:
Returns a JInstruction reference.

branchesToString

public java.lang.String branchesToString()
Stringifies the braches alone.

Returns:
Returns a Stringifed version of the branches alone.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
Stringified form of the class


Submit Feedback to akkumar@users.sourceforge.net