Top Description Inners Fields Constructors Methods
org.codehaus.janino

public Class CodeContext

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Arrays, .Collections, .HashMap, .HashSet, .Iterator, .List, .Map, .Set, org.codehaus.commons.compiler.InternalCompilerException, org.codehaus.commons.nullanalysis.Nullable, org.codehaus.janino.util.ClassFile, .ClassFile.ConstantClassInfo, .ClassFile.StackMapTableAttribute, .ClassFile.StackMapTableAttribute.AppendFrame, .ClassFile.StackMapTableAttribute.ChopFrame, .ClassFile.StackMapTableAttribute.FullFrame, .ClassFile.StackMapTableAttribute.ObjectVariableInfo, .ClassFile.StackMapTableAttribute.SameFrame, .ClassFile.StackMapTableAttribute.SameFrameExtended, .ClassFile.StackMapTableAttribute.SameLocals1StackItemFrame, .ClassFile.StackMapTableAttribute.SameLocals1StackItemFrameExtended, .ClassFile.StackMapTableAttribute.StackMapFrame, .ClassFile.StackMapTableAttribute.UninitializedVariableInfo, .ClassFile.StackMapTableAttribute.VerificationTypeInfo

The context of the compilation of a function (constructor or method). Manages generation of byte code, the exception table, generation of line number tables, allocation of local variables, determining of stack size and local variable table size and flow analysis.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public class
CodeContext.BasicBlock

This Offset marks the first byte of a "basic block" in the sense of JLS 17 "4.10.1 Verification by Type Checking": The intent is that a stack map frame must appear at the beginning of each basic block in a method.

private class
private static class
CodeContext.ExceptionTableEntry

Representation of an entry in the "exception_table" of a "Code" attribute (see JVMS 4.7.3).

public static interface
CodeContext.FixUp

A throw-in interface that marks CodeContext.Offsets as "fix-ups": During the execution of CodeContext#fixUp, all "fix-ups" are invoked and can do last touches to the code attribute.

private class
public class
CodeContext.Inserter

A class that implements an insertion point into a "Code" attribute.

public class
CodeContext.LineNumberOffset

An Offset who's sole purpose is to later create a 'LineNumberTable' attribute.

pack-priv static class
public class
CodeContext.Offset

A class that represents an offset within a "Code" attribute.

private class
private abstract class

Field Summary

Modifier and TypeField and Description
private final List<Java.LocalVariableSlot>
allLocalVars

All the local variables that are allocated in any block in this CodeContext.

private final CodeContext.Offset
private static final Map<Integer, Integer>
private final ClassFile
private byte[]
private CodeContext.Inserter
private CodeContext.LocalScope
currentLocalScope

Each List of Java.LocalVariableSlot is the local variables allocated for a block.

private final CodeContext.Inserter
private final List<CodeContext.ExceptionTableEntry>
private static final int
private short
private int
private short
private final List<CodeContext.Relocatable>
private static final boolean

Constructor Summary

AccessConstructor and Description
public
CodeContext(ClassFile classFile)

Creates an empty "Code" attribute.

Method Summary

Modifier and TypeMethod and Description
public void
addExceptionTableEntry(CodeContext.Offset startPc, CodeContext.Offset endPc, CodeContext.Offset handlerPc, String
null means finally clause
catchTypeFd
)

Adds another entry to the "exception_table" of this code attribute (see JVMS 4.7.3).

public void
addLineNumberOffset(int lineNumber)

public short

Returns:

The slot index of the allocated variable
allocateLocalVariable
(short
The number of slots to allocate (1 or 2)
size
)

Allocates space for a local variable of the given size (1 or 2) on the local variable array.

public Java.LocalVariableSlot
allocateLocalVariable(short
Number of slots to use (1 or 2)
size
,
String
The variable name; if null, then the variable won't be written to the LocalVariableTable
name
,
IType
The variable type; if the name is not null, then the type is needed to write to the LocalVariableTable
type
)

Allocates space for a local variable of the given size (1 or 2) on the local variable array.

private static Map<Integer, Integer>
public CodeContext.Inserter

Returns:

The current inserter
currentInserter
()

private void
fixUp()

Fixes up all offsets.

public void
fixUpAndRelocate()

Fixes up all of the offsets and relocate() all relocatables.

public List<Java.LocalVariableSlot>

Returns:

All the local variables that are allocated in any block in this CodeContext
getAllLocalVars
()

public ClassFile
getClassFile()

The ClassFile this context is related to.

private static int
invertBranchOpcode(int branchOpcode)

E.g. Opcode#IFLT ("less than") inverts to Opcode#IFGE ("greater than or equal to").

public int

Returns:

The offset of the first inserted byte
makeSpace
(final int
The number of NUL bytes to inject
size
)

Inserts size NUL bytes at the current inserter's offset, advances the current inserter's offset by size, creates LineNumberOffsets as necessary, and returns the current inserter's original offset (the offset of the first NUL byte that was inserted).

private void
maybeGrow()

Grow the code if relocatables are required to.

private static final StackMap
public CodeContext.Offset
public ClassFile.CodeAttribute
newCodeAttribute(int
The number of parameters, plus one iff there is a "this" parameter
initialLocalsCount
,
boolean debugLines, boolean debugVars)

public CodeContext.Inserter
newInserter()

Allocates an Inserter, set it to the current offset, and inserts it before the current offset.

private ClassFile.LineNumberTableAttribute
protected ClassFile.LocalVariableTableAttribute
public CodeContext.Offset
newOffset()

Creates and inserts an CodeContext.Offset at the current inserter's current position.

private ClassFile.StackMapTableAttribute

Returns:

null iff the stack map is empty
newStackMapTableAttribute
(int initialLocalsCount)

public boolean

Returns:

Whether the top operand is a null_variable_info
peekNullOperand
()

public boolean

Returns:

Whether the top operand is a object_variable_info
peekObjectOperand
()

public ClassFile.StackMapTableAttribute.VerificationTypeInfo

Returns:

The verification type of the top operand
peekOperand
()

public void
popInserter()

Replaces the current Inserter with the remembered one (see pushInserter(CodeContext.Inserter)).

public void
popIntOperand()

Asserts that the top operand is an integer_variable_info and pops it.

public ClassFile.StackMapTableAttribute.VerificationTypeInfo
popIntOrLongOperand()

Asserts that the top operand is an int_variable_info or long_variable_info, then pops and returns it.

public void
popLongOperand()

Asserts that the top operand is a long_variable_info and pops it.

public void
public String

Returns:

The field descriptor of the popped object operand
popObjectOperand
()

Asserts that the top operand is an object_variable_info, and pops it.

public ClassFile.StackMapTableAttribute.VerificationTypeInfo
popObjectOrUninitializedOrUninitializedThisOperand()

Asserts that the top operand is an object_variable_info, uninitialized_variable_info or uninitializedThis_variable_info, and pops it.

public ClassFile.StackMapTableAttribute.VerificationTypeInfo
popOperand()

Pops one entry from the current inserter's operand stack.

public void
popOperand(ClassFile.StackMapTableAttribute.VerificationTypeInfo expected)

Pops the top entry from the operand stack and assert that it equals expected.

public void
popOperand(String expectedFd)

Pops the top operand, asserts that it is an integer_variable_info, long_variable_info, float_variable_info, double_variable_info or variable_object_info, and asserts that it matches the given field descriptor.

public void
public void
popReferenceOperand()

Asserts that the top operand is an object_variable_info or a null_variable_info and pops it.

public void
popUninitializedThisOperand()

Asserts that the top operand is an uninitializedThis_variable_info and pops it.

public void
popUninitializedVariableOperand()

Asserts that the top operand is an uninitialized_variable_info and pops it.

public void
public void
public void
pushInserter(CodeContext.Inserter ins)

Remembers the current Inserter, then replaces it with the new one.

public void
public void
public void
public void
pushObjectOperand(String fieldDescriptor)

public void
pushOperand(String fieldDescriptor)

Pushes one object_variable_info, integer_variable_info, double_variable_info, float_variable_info or long_variable_info entry onto the current inserter's operand stack.

public void
public void
public void
public void
private static IClass
private void
relocate()

Relocates all relocatables.

public void
removeCode(CodeContext.Offset from, CodeContext.Offset to)

Removes all code between from and to.

public void
restoreLocalVariables()

Restores the previous size of the local variables array.

public List<Java.LocalVariableSlot>
saveLocalVariables()

Remembers the current size of the local variables array.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public void
write(byte[] b)

Inserts a sequence of bytes at the current insertion position.

public void
write(byte b1)

Inserts a byte at the current insertion position.

public void
write(byte b1, byte b2)

Inserts bytes at the current insertion position.

public void
write(byte b1, byte b2, byte b3)

Inserts bytes at the current insertion position.

public void
write(byte b1, byte b2, byte b3, byte b4)

Inserts bytes at the current insertion position.

public void
write(byte b1, byte b2, byte b3, byte b4, byte b5)

Inserts bytes at the current insertion position.

public void
writeBranch(int
One of Opcode#GOTO, Opcode#JSR and Opcode.IF*
opcode
,
final CodeContext.Offset
Where to branch
dst
)

Generates a "branch" instruction.

public void
writeOffset(CodeContext.Offset src, final CodeContext.Offset dst)

Writes a four-byte offset (as it is used in TABLESWITCH and LOOKUPSWITCH) into this code context.

public void
writeShort(int v)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait