Class BBlock
java.lang.Object
org.jboss.byteman.agent.adapter.cfg.BBlock
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
FieldsModifier and TypeFieldDescriptionprivate List
<TryCatchDetails> details of all try catch blocks which are active inside this block.private int
an index for the block allocated by the CFG starting from 0 in block orderprivate CFG
private List
<TryCatchDetails> a list of all try catch blocks whose handlers start in this blockprivate InstructionSequence
the sequence of instructions contained in this basic blockprivate LinkedList
<CodeLocation> 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 blockprivate LinkedList
<CodeLocation> a list of the location of all monitor exit instructions contained in this blockprivate FanOut
private List
<TryCatchDetails> a list of all try catch blocks which end in this blockprivate List
<TryCatchDetails> details of all try catch blocks which start in this block -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addHandlerStarts
(List<TryCatchDetails> details) record details of a try catch block handler which starts in this blockvoid
addTryEnds
(List<TryCatchDetails> details) record details of a try catch block which ends in this blockvoid
addTryStarts
(List<TryCatchDetails> details) record details of a try catch block which starts in this blockint
append
(int instruction) add an instruction to the sequence in the blockint
append
(int instruction, int operand) add an instruction with one int operand to thhe sequence in the blockint
append
(int instruction, int[] operands) add an instruction with an arbitrary number of int operands to thhe sequence in the blockint
append
(int instruction, int operand1, int operand2) add an instruction with two int operands to the sequence in the blockint
append
(int instruction, int operand1, int operand2, int operand3) add an instruction with three int operands to thhe sequence in the blockint
append
(int instruction, int operand1, int operand2, int operand3, int operand4) add an instruction with four int operands to the sequence in the blockvoid
append
(org.objectweb.asm.Label label) install an outgoing normal control flow linkorg.objectweb.asm.Label
firstOut()
return the label of the first normal control flow linkretrieve details of all try catch blocks which are capable of generating an exception in this blockint
retrieve the index of this block in the block sequence.getCFG()
obtain the control flow graph to which this block belongsretrieve details of all try catch block handlers whcih start in this blockint
getInstruction
(int index) return the instruction at a given index.int
getInstructionArg
(int index, int argIndex) retrieve the integer operand or encoded name associated with a particular instructionint
return the number of instructions in the blocks instructuion sequence equivalent to the index of the next instruction added to the block.org.objectweb.asm.Label
getLabel()
get the primary label which idenitfies this block.int
retrieve a count of all monitor enter instruction locations occurring in this blockretrieve a list of all monitor enter instruction locations occurring in this blockint
retrieve a count of all monitor exit instruction locations occuring in this blockretrieve a list of all monitor exit instruction locations occurring in this blockretrieve details of all try catch blocks which end in this blockorg.objectweb.asm.Label
next()
return the label of the next block in line in the block sequence in bytecode order.private int
nextBCPos
(int opcode, int insnIdx, int currentPos) int
nOuts()
return a count of the normal control flow links from this block.org.objectweb.asm.Label
nthOut
(int n) return the label of the nth normal control flow linkvoid
printLabelOffset
(StringBuffer buf, org.objectweb.asm.Label l, boolean appendBlockPos, Object altText) (package private) void
printTo
(StringBuffer buf) write a string representation of this block to the bufferorg.objectweb.asm.Label
return the label of the second normal control flow linkvoid
setActiveTryStarts
(List<TryCatchDetails> active) set the list of try starts which are active somewhere in this block.toString()
return a string representation of this block
-
Field Details
-
cfg
-
instructions
the sequence of instructions contained in this basic block -
outGoing
-
blockIdx
private int blockIdxan index for the block allocated by the CFG starting from 0 in block order -
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
details of all try catch blocks which start in this block -
tryEnds
a list of all try catch blocks which end in this block -
handlerStarts
a list of all try catch blocks whose handlers start in this block -
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
a list of the location of all monitor exit instructions contained in this block
-
-
Constructor Details
-
BBlock
construct a new basic block- Parameters:
cfg
- the control flow graph it belongs tostart
- the label for the start of the blockblockIdx
- the index of the block which respects the order of the bytecode segments contained in each block.
-
-
Method Details
-
getCFG
obtain the control flow graph to which this block belongs- Returns:
- the control flow graph
-
getLabel
public org.objectweb.asm.Label getLabel()get the primary label which idenitfies this block. It will be located in the block at offset 0.- Returns:
- the primary label
-
getBlockIdx
public int getBlockIdx()retrieve the index of this block in the block sequence.- Returns:
- the block index
-
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 Opcodeoperand
- 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 Opcodeoperand1
- an int operand or the code for a String operand lcoated in the cfg name tableoperand2
- 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 Opcodeoperand1
- an int operand or the code for a String operand lcoated in the cfg name tableoperand2
- an int operand or the code for a String operand lcoated in the cfg name tableoperand3
- 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, int operand4) add an instruction with four int operands to the sequence in the block- Parameters:
instruction
- an Opcodeoperand1
- an int operand or the code for a String operand lcoated in the cfg name tableoperand2
- an int operand or the code for a String operand lcoated in the cfg name tableoperand3
- an int operand or the code for a String operand lcoated in the cfg name tableoperand4
- 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 Opcodeoperands
- 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
record details of a try catch block which starts in this block- Parameters:
details
- list of try catch block details
-
addTryEnds
record details of a try catch block which ends in this block- Parameters:
details
- list of try catch block details
-
addHandlerStarts
record details of a try catch block handler which starts in this block- Parameters:
details
- list of try catch block details
-
setActiveTryStarts
set the list of try starts which are active somewhere in this block.- Parameters:
active
- list of active try catch block details
-
getTryEnds
retrieve details of all try catch blocks which end in this block- Returns:
- list of try catch block details
-
getHandlerStarts
retrieve details of all try catch block handlers whcih start in this block- Returns:
- list of try catch block details
-
getActiveTryStarts
retrieve details of all try catch blocks which are capable of generating an exception in this block- Returns:
- list of active try catch block details
-
getMonitorEnters
retrieve a list of all monitor enter instruction locations occurring in this block- Returns:
- list of monitor enter locations
-
getMonitorExits
retrieve a list of all monitor exit instruction locations occurring in this block- Returns:
- list of monitor exit locations
-
getMonitorEnterCount
public int getMonitorEnterCount()retrieve a count of all monitor enter instruction locations occurring in this block- Returns:
- count of monitor enter locations
-
getMonitorExitCount
public int getMonitorExitCount()retrieve a count of all monitor exit instruction locations occuring in this block- Returns:
- count of monitor exit locations
-
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:
- the next instruction count
-
getInstruction
public int getInstruction(int index) return the instruction at a given index.- Parameters:
index
- the index for the instruction- Returns:
- the instruction at index
-
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 blockargIndex
- the index of the argument in the sequence of arguments presented when the instruction was inserted into the block.- Returns:
- the arg
-
append
public void append(org.objectweb.asm.Label label) install an outgoing normal control flow link- Parameters:
label
- the control flow destination
-
next
public org.objectweb.asm.Label next()return the label of the next block in line in the block sequence in bytecode order.- Returns:
- the label of the next block
-
firstOut
public org.objectweb.asm.Label firstOut()return the label of the first normal control flow link- Returns:
- the label
-
secondOut
public org.objectweb.asm.Label secondOut()return the label of the second normal control flow link- Returns:
- the label
-
nthOut
public org.objectweb.asm.Label nthOut(int n) return the label of the nth normal control flow link- Parameters:
n
- the index of the link- Returns:
- the label
-
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
return a string representation of this block -
printLabelOffset
public void printLabelOffset(StringBuffer buf, org.objectweb.asm.Label l, boolean appendBlockPos, Object altText) -
printTo
write a string representation of this block to the buffer- Parameters:
buf
- the buffer to be written to
-
nextBCPos
private int nextBCPos(int opcode, int insnIdx, int currentPos)
-