org.jboss.byteman.agent.adapter.cfg
Class BBlock

java.lang.Object
  extended by org.jboss.byteman.agent.adapter.cfg.BBlock

public class BBlock
extends java.lang.Object

A Basic Block represents a segment of bytecode in a control flow graph. Basic blocks divide up the code at control flow branch points and hence there is no normal control flow internal to a block. Normal control flow will only transfer control from the end of one basic block to the start of another basic block or to the caller (via a return or throw).

If the block overlaps a try/catch region then exception control flow may transfer control from any instruction lying within the try/catch region to the the start of another basic block which handles the instruction. So, exception control flow may exit a block at a location preceding the block end but may only enter at block start.


Field Summary
private  java.util.List<TryCatchDetails> activeTryStarts
          details of all try catch blocks which are active inside this block.
private  int blockIdx
          an index for the block allocated by the CFG starting from 0 in block order
private  CFG cfg
           
private  java.util.List<TryCatchDetails> handlerStarts
          a list of all try catch blocks whose handlers start in this block
private  InstructionSequence instructions
          the sequence of instructions contained in this basic block
private  java.util.LinkedList<CodeLocation> monitorEnters
          a stack (reverse order list) containing the locations of all monitor enter instructions contained in this block excluding those which have been closed by a corresponding exit in this block
private  java.util.LinkedList<CodeLocation> monitorExits
          a list of the location of all monitor exit instructions contained in this block
private  FanOut outGoing
           
private  java.util.List<TryCatchDetails> tryEnds
          a list of all try catch blocks which end in this block
private  java.util.List<TryCatchDetails> tryStarts
          details of all try catch blocks which start in this block
 
Constructor Summary
BBlock(CFG cfg, Label start, int blockIdx)
          construct a new basic block
 
Method Summary
 void addHandlerStarts(java.util.List<TryCatchDetails> details)
          record details of a try catch block handler which starts in this block
 void addTryEnds(java.util.List<TryCatchDetails> details)
          record details of a try catch block which ends in this block
 void addTryStarts(java.util.List<TryCatchDetails> details)
          record details of a try catch block which starts in this block
 int append(int instruction)
          add an instruction to the sequence in the block
 int append(int instruction, int operand)
          add an instruction with one int operand to thhe sequence in the block
 int append(int instruction, int[] operands)
          add an instruction with an arbitrary number of int operands to thhe sequence in the block
 int append(int instruction, int operand1, int operand2)
          add an instruction with two int operands to the sequence in the block
 int append(int instruction, int operand1, int operand2, int operand3)
          add an instruction with three int operands to thhe sequence in the block
 void append(Label label)
          install an outgoing normal control flow link
 Label firstOut()
          return the label of the first normal control flow link
 java.util.List<TryCatchDetails> getActiveTryStarts()
          retrieve details of all try catch blocks which are capable of generating an exception in this block
 int getBlockIdx()
          retrieve the index of this block in the block sequence.
 CFG getCFG()
          obtain the control flow graph to which this block belongs
 java.util.Iterator<TryCatchDetails> getHandlerStarts()
          retrieve details of all try catch block handlers whcih start in this block
 int getInstruction(int index)
          retirn the instruction at a given index.
 int getInstructionArg(int index, int argIndex)
          retrieve the integer operand or encoded name associated with a particular instruction
 int getInstructionCount()
          return the number of instructions in the blocks instructuion sequence equivalent to the index of the next instruction added to the block.
 Label getLabel()
          get the primary label which idenitfies tis block.
 int getMonitorEnterCount()
          retrieve a count of all monitor enter instruction locations occurring in this block
 java.util.Iterator<CodeLocation> getMonitorEnters()
          retrieve a list of all monitor enter instruction locations occurring in this block
 int getMonitorExitCount()
          retrieve a count of all monitor exit instruction locations occuring in this block
 java.util.Iterator<CodeLocation> getMonitorExits()
          retrieve a list of all monitor exit instruction locations occurring in this block
 java.util.Iterator<TryCatchDetails> getTryEnds()
          retrieve details of all try catch blocks which end in this block
 Label next()
          return the label of the next block in line in the block sequence in bytecode order.
 int nOuts()
          return a count of the normal control flow links from this block.
 Label nthOut(int n)
          return the label of the nth normal control flow link
(package private)  void printTo(java.lang.StringBuffer buf)
          write a string represenattion of this block to the buffer
 Label secondOut()
          return the label of the second normal control flow link
 void setActiveTryStarts(java.util.List<TryCatchDetails> active)
          set the list of try starts which are active somewhere in this block.
 java.lang.String toString()
          return a string represenattion of this block
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

cfg

private CFG cfg

instructions

private InstructionSequence instructions
the sequence of instructions contained in this basic block


outGoing

private FanOut outGoing

blockIdx

private int blockIdx
an index for the block allocated by the CFG starting from 0 in block order


activeTryStarts

private java.util.List<TryCatchDetails> activeTryStarts
details of all try catch blocks which are active inside this block. n.b. this must omit try catch blocks which are open when the block is created then subsequently closed at offset 0.


tryStarts

private java.util.List<TryCatchDetails> tryStarts
details of all try catch blocks which start in this block


tryEnds

private java.util.List<TryCatchDetails> tryEnds
a list of all try catch blocks which end in this block


handlerStarts

private java.util.List<TryCatchDetails> handlerStarts
a list of all try catch blocks whose handlers start in this block


monitorEnters

private java.util.LinkedList<CodeLocation> monitorEnters
a stack (reverse order list) containing the locations of all monitor enter instructions contained in this block excluding those which have been closed by a corresponding exit in this block


monitorExits

private java.util.LinkedList<CodeLocation> monitorExits
a list of the location of all monitor exit instructions contained in this block

Constructor Detail

BBlock

public BBlock(CFG cfg,
              Label start,
              int blockIdx)
construct a new basic block

Parameters:
cfg - the control flow graph it belongs to
start - the label for the start of the block
blockIdx - the index of the block which respects the order of the bytecode segments contained in each block.
Method Detail

getCFG

public CFG getCFG()
obtain the control flow graph to which this block belongs

Returns:

getLabel

public Label getLabel()
get the primary label which idenitfies tis block. It will be located in the block at offset 0.

Returns:

getBlockIdx

public int getBlockIdx()
retrieve the index of this block in the block sequence.

Returns:

append

public int append(int instruction)
add an instruction to the sequence in the block

Parameters:
instruction - an Opcode
Returns:
the index of the newly added instruction

append

public int append(int instruction,
                  int operand)
add an instruction with one int operand to thhe sequence in the block

Parameters:
instruction - an Opcode
operand - an int operand or the code for a String operand lcoated in the cfg name table
Returns:
the index of the newly added instruction

append

public int append(int instruction,
                  int operand1,
                  int operand2)
add an instruction with two int operands to the sequence in the block

Parameters:
instruction - an Opcode
operand1 - an int operand or the code for a String operand lcoated in the cfg name table
operand2 - an int operand or the code for a String operand lcoated in the cfg name table
Returns:
the index of the newly added instruction

append

public int append(int instruction,
                  int operand1,
                  int operand2,
                  int operand3)
add an instruction with three int operands to thhe sequence in the block

Parameters:
instruction - an Opcode
operand1 - an int operand or the code for a String operand lcoated in the cfg name table
operand2 - an int operand or the code for a String operand lcoated in the cfg name table
operand3 - an int operand or the code for a String operand lcoated in the cfg name table
Returns:
the index of the newly added instruction

append

public int append(int instruction,
                  int[] operands)
add an instruction with an arbitrary number of int operands to thhe sequence in the block

Parameters:
instruction - an Opcode
operands - an array containing int operands or codes for String operands lcoated in the cfg name table
Returns:
the index of the newly added instruction

addTryStarts

public void addTryStarts(java.util.List<TryCatchDetails> details)
record details of a try catch block which starts in this block

Parameters:
details -

addTryEnds

public void addTryEnds(java.util.List<TryCatchDetails> details)
record details of a try catch block which ends in this block

Parameters:
details -

addHandlerStarts

public void addHandlerStarts(java.util.List<TryCatchDetails> details)
record details of a try catch block handler which starts in this block

Parameters:
details -

setActiveTryStarts

public void setActiveTryStarts(java.util.List<TryCatchDetails> active)
set the list of try starts which are active somewhere in this block.

Parameters:
active -

getTryEnds

public java.util.Iterator<TryCatchDetails> getTryEnds()
retrieve details of all try catch blocks which end in this block

Returns:

getHandlerStarts

public java.util.Iterator<TryCatchDetails> getHandlerStarts()
retrieve details of all try catch block handlers whcih start in this block

Returns:

getActiveTryStarts

public java.util.List<TryCatchDetails> getActiveTryStarts()
retrieve details of all try catch blocks which are capable of generating an exception in this block

Returns:

getMonitorEnters

public java.util.Iterator<CodeLocation> getMonitorEnters()
retrieve a list of all monitor enter instruction locations occurring in this block

Returns:

getMonitorExits

public java.util.Iterator<CodeLocation> getMonitorExits()
retrieve a list of all monitor exit instruction locations occurring in this block

Returns:

getMonitorEnterCount

public int getMonitorEnterCount()
retrieve a count of all monitor enter instruction locations occurring in this block

Returns:

getMonitorExitCount

public int getMonitorExitCount()
retrieve a count of all monitor exit instruction locations occuring in this block

Returns:

getInstructionCount

public int getInstructionCount()
return the number of instructions in the blocks instructuion sequence equivalent to the index of the next instruction added to the block.

Returns:

getInstruction

public int getInstruction(int index)
retirn the instruction at a given index.

Parameters:
index -
Returns:

getInstructionArg

public int getInstructionArg(int index,
                             int argIndex)
retrieve the integer operand or encoded name associated with a particular instruction

Parameters:
index - the index of the instruction in the block
argIndex - the index of the argument in the sequence of arguments presented when the instruction was inserted intot he block.
Returns:

append

public void append(Label label)
install an outgoing normal control flow link

Parameters:
label -

next

public Label next()
return the label of the next block in line in the block sequence in bytecode order.

Returns:

firstOut

public Label firstOut()
return the label of the first normal control flow link

Returns:

secondOut

public Label secondOut()
return the label of the second normal control flow link

Returns:

nthOut

public Label nthOut(int n)
return the label of the nth normal control flow link

Returns:

nOuts

public int nOuts()
return a count of the normal control flow links from this block.

Returns:
the number of outgoingnormalcontrol flow links. n.b. iterations over the links should count from 1 to nOuts() inclusive. this is the size of a 1-based collection

toString

public java.lang.String toString()
return a string represenattion of this block

Overrides:
toString in class java.lang.Object
Returns:

printTo

void printTo(java.lang.StringBuffer buf)
write a string represenattion of this block to the buffer

Parameters:
buf - the buffer to be written to