Class ClassFileWriter.StackMapTable
- Enclosing class:
ClassFileWriter
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final booleanprivate int[]private intprivate byte[]private intprivate int[]private intprivate SuperBlock[]private booleanprivate SuperBlock[]private int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidprivate voidprivate voidCompute a space-optimal stack map table.(package private) intCompute the output size of the stack map table.private intexecute(int bci) Execute a single byte code instruction.private voidexecuteALoad(int localIndex) private voidexecuteAStore(int localIndex) private voidexecuteBlock(SuperBlock work) Simulate the local variable and op stack for a super block.private voidexecuteStore(int localIndex, int typeInfo) private voidprivate voidflowInto(SuperBlock sb) Perform a merge of type state and add the super block to the work list if the merge changed anything.(package private) voidgenerate()private SuperBlockgetBranchTarget(int bci) Get the target super block of a branch instruction.private intgetLocal(int localIndex) private intgetOperand(int offset) private intgetOperand(int start, int size) Extract a logical operand from the byte code.private SuperBlockgetSuperBlockFromOffset(int offset) private intGet the worst case write size of the stack map table.private voidinitializeTypeInfo(int prevType, int newType) Change an UNINITIALIZED_OBJECT or UNINITIALIZED_THIS to the proper type of the object.private voidinitializeTypeInfo(int prevType, int newType, int[] data, int dataTop) private booleanisBranch(int opcode) Determine whether or not an opcode is a conditional or unconditional jump.private booleanisSuperBlockEnd(int opcode) Determine whether or not an opcode is an actual end to a super block.private voidReplace the contents of a super block with no-ops.private intpop()private longpop2()Pop two words from the op stack.private voidpush(int typeInfo) private voidpush2(long typeInfo) Push two words onto the op stack.private voidsetLocal(int localIndex, int typeInfo) private voidverify()Calculate initial local variable and op stack types for each super block in the method.(package private) intwrite(byte[] data, int offset) private voidwriteAppendFrame(int[] locals, int localsDelta, int offsetDelta) private voidwriteChopFrame(int localsDelta, int offsetDelta) private voidwriteFullFrame(int[] locals, int[] stack, int offsetDelta) private voidwriteSameFrame(int offsetDelta) private voidwriteSameLocalsOneStackItemFrame(int[] stack, int offsetDelta) private intwriteType(int type) private intwriteTypes(int[] types) private intwriteTypes(int[] types, int start)
-
Field Details
-
locals
private int[] locals -
localsTop
private int localsTop -
stack
private int[] stack -
stackTop
private int stackTop -
workList
-
workListTop
private int workListTop -
superBlocks
-
rawStackMap
private byte[] rawStackMap -
rawStackMapTop
private int rawStackMapTop -
wide
private boolean wide -
DEBUGSTACKMAP
static final boolean DEBUGSTACKMAP- See Also:
-
-
Constructor Details
-
StackMapTable
StackMapTable()
-
-
Method Details
-
generate
void generate() -
getSuperBlockFromOffset
-
isSuperBlockEnd
private boolean isSuperBlockEnd(int opcode) Determine whether or not an opcode is an actual end to a super block. This includes any returns or unconditional jumps. -
getBranchTarget
Get the target super block of a branch instruction.- Parameters:
bci- the index of the branch instruction in the code buffer
-
isBranch
private boolean isBranch(int opcode) Determine whether or not an opcode is a conditional or unconditional jump. -
getOperand
private int getOperand(int offset) -
getOperand
private int getOperand(int start, int size) Extract a logical operand from the byte code.This is used, for example, to get branch offsets.
-
verify
private void verify()Calculate initial local variable and op stack types for each super block in the method. -
killSuperBlock
Replace the contents of a super block with no-ops.The above description is not strictly true; the last instruction is an athrow instruction. This technique is borrowed from ASM's developer guide: http://asm.ow2.org/doc/developer-guide.html#deadcode
The proposed algorithm fills a block with nop, ending it with an athrow. The stack map generated would be empty locals with an exception on the stack. In theory, it shouldn't matter what the locals are, as long as the stack has an exception for the athrow bit. However, it turns out that if the code being modified falls into an exception handler, it causes problems. Therefore, if it does, then we steal the locals from the exception block.
If the block itself is an exception handler, we remove it from the exception table to simplify block dependencies.
-
executeWorkList
private void executeWorkList() -
executeBlock
Simulate the local variable and op stack for a super block. -
flowInto
Perform a merge of type state and add the super block to the work list if the merge changed anything. -
addToWorkList
-
execute
private int execute(int bci) Execute a single byte code instruction.- Parameters:
bci- the index of the byte code instruction to execute- Returns:
- the length of the byte code instruction
-
executeALoad
private void executeALoad(int localIndex) -
executeAStore
private void executeAStore(int localIndex) -
executeStore
private void executeStore(int localIndex, int typeInfo) -
initializeTypeInfo
private void initializeTypeInfo(int prevType, int newType) Change an UNINITIALIZED_OBJECT or UNINITIALIZED_THIS to the proper type of the object. This occurs when the proper constructor is invoked. -
initializeTypeInfo
private void initializeTypeInfo(int prevType, int newType, int[] data, int dataTop) -
getLocal
private int getLocal(int localIndex) -
setLocal
private void setLocal(int localIndex, int typeInfo) -
push
private void push(int typeInfo) -
pop
private int pop() -
push2
private void push2(long typeInfo) Push two words onto the op stack.This is only meant to be used as a complement to pop2(), and both methods are helpers for the more complex DUP operations.
-
pop2
private long pop2()Pop two words from the op stack.If the top of the stack is a DOUBLE or LONG, then the bottom 32 bits reflects the appropriate type and the top 32 bits are 0. Otherwise, the top 32 bits are the first word on the stack and the lower 32 bits are the second word on the stack.
-
clearStack
private void clearStack() -
computeWriteSize
int computeWriteSize()Compute the output size of the stack map table.Because this would share much in common with actual writing of the stack map table, we instead just write the stack map table to a buffer and return the size from it. The buffer is later used in the actual writing of bytecode.
-
write
int write(byte[] data, int offset) -
computeRawStackMap
private void computeRawStackMap()Compute a space-optimal stack map table. -
getWorstCaseWriteSize
private int getWorstCaseWriteSize()Get the worst case write size of the stack map table.This computes how much full frames would take, if each full frame contained the maximum number of locals and stack operands, and each verification type was 3 bytes.
-
writeSameFrame
private void writeSameFrame(int offsetDelta) -
writeSameLocalsOneStackItemFrame
private void writeSameLocalsOneStackItemFrame(int[] stack, int offsetDelta) -
writeFullFrame
private void writeFullFrame(int[] locals, int[] stack, int offsetDelta) -
writeAppendFrame
private void writeAppendFrame(int[] locals, int localsDelta, int offsetDelta) -
writeChopFrame
private void writeChopFrame(int localsDelta, int offsetDelta) -
writeTypes
private int writeTypes(int[] types) -
writeTypes
private int writeTypes(int[] types, int start) -
writeType
private int writeType(int type)
-