Top Description Inners Fields Constructors Methods
com.sun.tools.javac.jvm

public Class Code

extends Object
Class Inheritance
Imports
com.sun.tools.javac.code.*, com.sun.tools.javac.code.Symbol.*, com.sun.tools.javac.resources.CompilerProperties.Errors, com.sun.tools.javac.util.*, .JCDiagnostic.DiagnosticPosition, java.util.function.ToIntBiFunction, .ToIntFunction, java.util.Arrays

An internal structure that corresponds to the code attribute of methods in a classfile. The class also provides some utility operations to generate bytecode instructions.

This is NOT part of any supported API. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Code.Chain

A chain represents a list of unresolved jumps.

pack-priv static class
Code.LocalVar

A live range of a local variable.

private static class
public static enum
pack-priv static class
Code.StackMapFrame

An entry in the stack map.

pack-priv class

Field Summary

Modifier and TypeField and Description
private boolean
alive

Code generation enabled?

pack-priv ListBuffer<char[]>
catchInfo

A buffer for expression catch data.

public byte[]
code

The code buffer.

public int
cp

the current code pointer.

public CRTable
crt

The CharacterRangeTable

public final boolean
public boolean
fatcode

Are we generating code with jumps ≥ 32K?

private boolean
fixedPc

Is it forbidden to compactify code, because something is pointing to current location?

pack-priv Code.StackMapFrame
frameBeforeLast

The stack map frame before the last one.

pack-priv static final Type
pack-priv Code.StackMapFrame
lastFrame

The last stack map frame in StackMapTable.

pack-priv int
lastStackMapPC

The last PC at which we generated a stack map.

private int
pack-priv boolean
lineDebugInfo

Switch: emit line number info.

pack-priv List<char[]>
lineInfo

A buffer for line number information.

pack-priv Position.LineMap
lineMap

Emit line number info if map supplied

pack-priv Code.LocalVar[]
lvar

Local variables, indexed by register.

public int
max_locals

The maximum number of local variable slots.

public int
max_stack

The maximum stack size.

pack-priv final Symbol.MethodSymbol
public final boolean
public int
nextreg

The next available register.

pack-priv Code.Chain
pendingJumps

A chain for jumps to be resolved before the next opcode is emitted.

pack-priv boolean
pendingStackMap

Set true when a stackMap is needed at the current PC.

pack-priv int
pendingStatPos

The position of the currently statement, if we are at the start of this statement, NOPOS otherwise.

pack-priv final PoolWriter
pack-priv Code.StackMapFormat
stackMap

The stack map format to be generated.

pack-priv Code.StackMapFrame[]
stackMapBuffer

A buffer of cldc stack map entries.

pack-priv int
pack-priv ClassWriter.StackMapTableFrame[]
stackMapTableBuffer

A buffer of compressed StackMapTable entries.

pack-priv Code.State
state

The current machine state (registers and stack).

pack-priv final Symtab
pack-priv final Types
pack-priv Code.LocalVar[]
varBuffer

Previously live local variables, to be put into the variable table.

pack-priv int
pack-priv boolean
varDebugInfo

Switch: emit variable debug info.

Constructor Summary

AccessConstructor and Description
public
Code(Symbol.MethodSymbol meth, boolean fatcode, Position.LineMap lineMap, boolean varDebugInfo, Code.StackMapFormat stackMap, boolean debugCode, CRTable crt, Symtab syms, Types types, PoolWriter poolWriter)

Construct a code object, given the settings of the fatcode, debugging info switches and the CharacterRangeTable.

Method Summary

Modifier and TypeMethod and Description
public void
addCatch(char startPc, char endPc, char handlerPc, char catchType)

Add a catch clause to code.

public void
addLineNumber(char startPc, char lineNumber)

Add a line number entry.

private void
addLocalVar(Symbol.VarSymbol v)

Add a new local variable.

pack-priv void
adjustAliveRanges(int oldCP, int delta)

public void
align(int incr)

Align code pointer to next `incr' boundary.

private int[]
appendArray(int[] source, int[] append)

public static int
arraycode(Type type)

Given a type, return its code for allocating arrays of that type.

public Code.Chain
branch(int opcode)

Emit a branch with given opcode; return its chain.

public boolean
checkLimits(JCDiagnostic.DiagnosticPosition pos, Log log)

Check the code against VM spec limits; if problems report them and return true.

public void
public int
curCP()

The current output code pointer.

private void
emit1(int od)

Emit a byte of code.

private void
emit2(int od)

Emit two bytes of code.

public void
emit4(int od)

Emit four bytes of code.

public void
emitAnewarray(int od, Type arrayType)

Emit anewarray.

pack-priv void
emitCLDCStackMap(int pc, int localsSize)

Emit a CLDC stack map frame.

public void
emitInvokedynamic(Symbol.DynamicMethodSymbol dynMember, Type mtype)

Emit an invokedynamic instruction.

public void
emitInvokeinterface(Symbol member, Type mtype)

Emit an invokeinterface instruction.

public void
emitInvokespecial(Symbol member, Type mtype)

Emit an invokespecial instruction.

public void
emitInvokestatic(Symbol member, Type mtype)

Emit an invokestatic instruction.

public void
emitInvokevirtual(Symbol member, Type mtype)

Emit an invokevirtual instruction.

public int
emitJump(int opcode)

Emit a jump instruction.

public void
emitLdc(PoolConstant.LoadableConstant constant)

Emit a ldc (or ldc_w) instruction, taking into account operand size

public void
emitMultianewarray(int ndims, int type, Type arrayType)

Emit a multinewarray instruction.

public void
emitNewarray(int elemcode, Type arrayType)

Emit newarray.

private void
emitop(int op)

Emit an opcode.

public void
emitop0(int op)

Emit an opcode with no operand field.

public void
emitop1(int op, int od)

Emit an opcode with a one-byte operand field.

public void
emitop1(int op, int od, PoolConstant data)

public void
emitop1w(int op, int od)

Emit an opcode with a one-byte operand field; widen if field does not fit in a byte.

public void
emitop1w(int op, int od1, int od2)

Emit an opcode with two one-byte operand fields; widen if either field does not fit in a byte.

public <P extends PoolConstant> void
emitop2(int op, P constant, ToIntBiFunction<PoolWriter, P> poolFunc)

Emit an opcode with a two-byte operand field.

public void
emitop2(int op, int od)

public void
emitop2(int op, int od, PoolConstant data)

public void
emitop4(int op, int od)

Emit an opcode with a four-byte operand field.

public void
emitStackMap()

Emit a stack map entry.

pack-priv void
emitStackMapFrame(int pc, int localsSize)

private void
endScope(int adr)

End the scope of a variable.

public void
endScopes(int first)

End scopes of all variables with registers ≥ first.

public int
entryPoint()

Declare an entry point; return current code pointer

public int
entryPoint(Code.State state)

Declare an entry point with initial state; return current code pointer

public int
entryPoint(Code.State state, Type pushed)

Declare an entry point with initial state plus a pushed value; return current code pointer

public void
private void
private int
private int
get1(int pc)

Return code byte at position pc as an unsigned int.

private int
get2(int pc)

Return two code bytes at position pc as an unsigned int.

public int
get4(int pc)

Return four code bytes at position pc as an int.

pack-priv Code.StackMapFrame
private int
public int
getLVTSize()

Calculates the size of the LocalVariableTable.

public boolean
isAlive()

Is code generation currently enabled?

public boolean
public void
markDead()

Switch code generation on/off.

public void
markStatBegin()

Force stat begin eagerly

public static Code.Chain
mergeChains(Code.Chain chain1, Code.Chain chain2)

Merge the jumps in of two chains into one.

public static String
mnem(int opcode)

public static int
negate(int opcode)

Negate a branch opcode.

private int
newLocal(int typecode)

Create a new local variable address and return it.

private int
newLocal(Type type)

public int
public void
newRegSegment()

Start a set of fresh registers.

pack-priv void
private void
put1(int pc, int op)

Place a byte into code at address pc.

private void
put2(int pc, int od)

Place two bytes into code at address pc.

public void
put4(int pc, int od)

Place four bytes into code at address pc.

pack-priv void
putVar(Code.LocalVar var)

Put a live variable range into the buffer to be output to the class file.

public void
resolve(Code.Chain chain, int target)

Resolve chain to point to given target.

public void
resolve(Code.Chain chain)

Resolve chain to point to current code pointer.

public void
resolvePending()

Resolve any pending jumps.

public void
setDefined(Bits newDefined)

Set the current variable defined state.

public void
setDefined(int adr)

Mark a register as being (possibly) defined.

public int
public void
setUndefined(int adr)

Mark a register as being undefined.

public void
statBegin(int pos)

Mark beginning of statement.

public static int
truncate(int tc)

Collapse type code for subtypes of int to INTcode.

public static int
typecode(Type type)

Given a type, return its type code (used implicitly in the JVM architecture).

public static int
width(int typecode)

The width in bytes of objects of the type.

public static int
width(Type type)

public static int
width(List<Type> types)

The total width taken up by a vector of objects.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait