|
Jode 1.90-CVS Build Aug 6, 2004 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.jode.bytecode.BinaryInfo
net.sf.jode.bytecode.BasicBlocks
Represents the byte code of a method in form of basic blocks. A basic block is a bunch of instructions, that must always execute in sequential order. Every basic block is represented by an Block object.
All jump instructions must be at the end of the block, and the
jump instructions doesn't have to remember where they jump to.
Instead this information is stored inside the blocks. See
Block
for details.
Exception Handlers are represented by the Handler class. Their start/end range must span over some consecutive BasicBlocks and there handler must be another basic block.
When the code is written to a class file, the blocks are written in the given order. Goto and return instructions are inserted as necessary, you don't need to care about that.
If you want to create a new BasicBlocks object, first create the Block objects, then initialize them (you need to have all successor blocks created for this). Afterwards create a new BasicBlock and fill its sub blocks:
MethodInfo myMethod = new MethodInfo("foo", "()V", PUBLIC); Block blocks = new Block[10]; for (int i = 0; i < 10; i++) blocks[i] = new Block(); blocks[0].setCode(new Instruction[] {...}, new Block[] {blocks[3], blocks[1]}); ... Handler[] excHandlers = new Handler[1]; excHandlers[0] = new Handler(blocks[2], blocks[5], blocks[6], "java.lang.NullPointerException"); BasicBlocks bb = new BasicBlocks(myMethod); bb.setCode(blocks, blocks[0], excHandlers); classInfo.setMethods(new MethodInfo[] { myMethod });
Block
,
Instruction
Field Summary |
Fields inherited from class net.sf.jode.bytecode.BinaryInfo |
ACC_ABSTRACT, ACC_ANNOTATION, ACC_BRIDGE, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_VARARGS, ACC_VOLATILE |
Constructor Summary | |
BasicBlocks(MethodInfo mi)
|
Method Summary | |
void |
dumpCode(java.io.PrintWriter output)
|
protected int |
getAttributeCount()
Returns the number of attributes of this class. |
Block[] |
getBlocks()
|
Handler[] |
getExceptionHandlers()
|
int |
getMaxLocals()
|
int |
getMaxStack()
|
MethodInfo |
getMethodInfo()
|
int |
getParamCount()
|
LocalVariableInfo |
getParamInfo(int i)
|
Block |
getStartBlock()
|
protected void |
readAttribute(java.lang.String name,
int length,
ConstantPool cp,
java.io.DataInputStream input,
int howMuch)
Reads in an attributes of this class. |
void |
setBlocks(Block[] blocks,
Block startBlock,
Handler[] handlers)
|
void |
setParamInfo(LocalVariableInfo info)
Sets the name and type of a method parameter. |
java.lang.String |
toString()
|
void |
updateMaxStackLocals()
Updates the maxStack and maxLocals according to the current code. |
protected void |
writeAttributes(GrowableConstantPool gcp,
java.io.DataOutputStream output)
Writes the attributes to the output stream. |
Methods inherited from class net.sf.jode.bytecode.BinaryInfo |
addAttribute, drop, findAttribute, getAttributes, getAttributeSize, prepareAttributes, removeAllAttributes, removeAttribute |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public BasicBlocks(MethodInfo mi)
Method Detail |
public int getMaxStack()
public int getMaxLocals()
public MethodInfo getMethodInfo()
public Block getStartBlock()
public Block[] getBlocks()
public Handler[] getExceptionHandlers()
public LocalVariableInfo getParamInfo(int i)
public int getParamCount()
public void updateMaxStackLocals()
public void setBlocks(Block[] blocks, Block startBlock, Handler[] handlers)
public void setParamInfo(LocalVariableInfo info)
info
- a local variable info mapping a slot nr to a name
and a type.protected void readAttribute(java.lang.String name, int length, ConstantPool cp, java.io.DataInputStream input, int howMuch) throws java.io.IOException
BinaryInfo
readAttribute
in class BinaryInfo
name
- the attribute name.length
- the length of the attribute.cp
- the constant pool of the class.input
- a data input stream where you can read the attribute
from. It will protect you to read more over the attribute boundary.howMuch
- the constant that was given to the ClassInfo.load(int)
function when loading this class.
java.io.IOException
protected int getAttributeCount()
BinaryInfo
getAttributeCount
in class BinaryInfo
protected void writeAttributes(GrowableConstantPool gcp, java.io.DataOutputStream output) throws java.io.IOException
BinaryInfo
Writes the attributes to the output stream.
Overwrite this method if you want to add your own attributes.
All constants you need from the growable constant pool must
have been previously registered by the BinaryInfo.prepareAttributes(net.sf.jode.bytecode.GrowableConstantPool)
method. This method must not add new constants to the pool
writeAttributes
in class BinaryInfo
gcp
- The growable constant pool, which is not
growable anymore (see above).output
- the data output stream. You must write exactly
as many bytes to it as you have told with the BinaryInfo.getAttributeSize()
method.
java.io.IOException
public void dumpCode(java.io.PrintWriter output)
public java.lang.String toString()
|
Jode 1.90-CVS Build Aug 6, 2004 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |