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

public Class Gen

extends Visitor
Class Inheritance
Imports
java.util.HashMap, .Map, .Set, com.sun.tools.javac.jvm.PoolConstant.LoadableConstant, com.sun.tools.javac.jvm.Code.*, com.sun.tools.javac.jvm.Items.*, com.sun.tools.javac.tree.TreeInfo.PosKind, com.sun.tools.javac.tree.*, com.sun.tools.javac.tree.JCTree.*, com.sun.tools.javac.util.*, .JCDiagnostic.DiagnosticPosition, .List, com.sun.tools.javac.code.*, .Attribute.TypeCompound, .Symbol.VarSymbol, com.sun.tools.javac.code.Symbol.*, com.sun.tools.javac.code.Type.*, com.sun.tools.javac.comp.*, com.sun.tools.javac.resources.CompilerProperties.Errors

This pass maps flat Java (i.e. without inner classes) to bytecodes.

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
pack-priv class
Gen.ClassReferenceVisitor

Visitor class for expressions which might be constant expressions.

public static class
Gen.CodeSizeOverflow

Thrown when the byte code size exceeds limit.

pack-priv class
Gen.GenContext

code generation contexts, to be used as type parameter for environments.

pack-priv abstract class
Gen.GenFinalizer

An abstract class for finalizer generation.

pack-priv static record

Field Summary

Modifier and TypeField and Description
private final String
private final Annotate
private Env<AttrContext>
attrEnv

Environment for symbol lookup, set by genClass

private final Check
private Gen.ClassReferenceVisitor
private Code
code

Code buffer, set by genMethod.

private final StringConcat
private final boolean
private boolean
pack-priv Env<Gen.GenContext>
env

Visitor argument: The current environment.

private final boolean
protected static final Context.Key<Gen>
pack-priv boolean
private Items
items

Items structure, set by genMethod.

private final boolean
lineDebugInfo

Switches

private final Log
private final Lower
private final TreeMaker
private final Type
methodType

A type that serves as the expected type for all method expressions.

private final Names
private int
nerrs

The number of code-gen errors in this class.

pack-priv Gen.PatternMatchingCatchConfiguration
pack-priv final PoolWriter
poolWriter

Constant pool writer, set by genClass.

pack-priv Type
pt

Visitor argument: The expected type (prototype).

pack-priv Map<Type, Symbol>
qualifiedSymbolCache

Cache the symbol to reflect the qualifying type.

pack-priv Items.Item
result

Visitor result: The item representing the computed value.

private final Resolve
pack-priv List<Items.LocalItem>
private final Code.StackMapFormat
stackMap

Format of stackmap tables to be generated.

pack-priv Code.Chain
pack-priv Code.Chain
pack-priv Items.LocalItem
private final Symtab
private final Target
private JCTree.JCCompilationUnit
toplevel

The top level tree.

private final Types
private final boolean

Constructor Summary

AccessConstructor and Description
protected
Gen(Context context)

Method Summary

Modifier and TypeMethod and Description
pack-priv Symbol
binaryQualifier(Symbol
The accessed symbol
sym
,
Type
The qualifier's type.
site
)

Construct a symbol to reflect the qualifying type that should appear in the byte code as per JLS 13.1.

pack-priv void
callMethod(JCDiagnostic.DiagnosticPosition
Position to be used for error reporting.
pos
,
Type
The type of which the method is a member.
site
,
Name
The method's name.
name
,
List<Type>
The method's argument types.
argtypes
,
boolean
A flag that indicates whether we call a static or instance method.
isStatic
)

Generate code to call a non-private method or constructor.

pack-priv List<Pair<List<Attribute.TypeCompound>, JCTree.JCExpression>>
pack-priv List<Pair<List<Attribute.TypeCompound>, JCTree.JCExpression>>
private Type
checkDimension(JCDiagnostic.DiagnosticPosition pos, Type t)

Check if the given type is an array with too many dimensions.

private void
private void
checkStringConstant(JCDiagnostic.DiagnosticPosition pos, Object constValue)

Check a constant value and report if it is a string that is too large.

pack-priv Items.Item
completeBinop(JCTree
The tree representing the left operand.
lhs
,
JCTree
The tree representing the right operand.
rhs
,
Symbol.OperatorSymbol
The operator symbol.
operator
)

Complete generating code for operation, with left operand already on stack.

private void
pack-priv void
emitMinusOne(int
The given type code (see (ByteCode).
tc
)

Generate code to load -1 of the given type code (either int or long).

pack-priv void
endFinalizerGap(Env<Gen.GenContext>
the environment which might contain the finalizer (if it does, env.info.gaps != null).
env
)

Mark end of gap in catch-all range for finalizer.

pack-priv void
endFinalizerGaps(Env<Gen.GenContext>
the most deeply nested environment to mark
from
,
Env<Gen.GenContext>
the least deeply nested environment to mark
to
)

Mark end of all gaps in catch-all ranges for finalizers of environments lying between, and including to two environments.

public void
genArgs(List<JCTree.JCExpression>
The argument expressions to be visited.
trees
,
List<Type>
The expression's expected types (i.e. the formal parameter types of the invoked method).
pts
)

Derived visitor method: generate code for a list of method arguments.

pack-priv void
genCatch(JCTree.JCCatch
The catch clause.
tree
,
Env<Gen.GenContext>
The environment current in the enclosing try.
env
,
int
Start pc of try-block.
startpc
,
int
End pc of try-block.
endpc
,
List<Integer> gaps)

Generate code for a catch clause.

pack-priv void
public boolean

Returns:

True if code is generated with no errors.
genClass
(Env<AttrContext>
The attribution environment that belongs to the outermost class containing this class definition. We need this for resolving some additional symbols.
env
,
JCTree.JCClassDecl
The tree representing the class definition.
cdef
)

Generate code for a class definition.

public Items.CondItem
genCond(JCTree
The tree to be visited.
tree
,
int
The CharacterRangeTable flags indicating type of the entry.
crtFlags
)

Derived visitor method: check whether CharacterRangeTable should be emitted, if so, put a new entry into CRTable and call method to generate bytecode.

public Items.CondItem
genCond(JCTree
The expression to be visited.
_tree
,
boolean
The flag to indicate that the condition is a flow controller so produced conditions should contain a proper tree to generate CharacterRangeTable branches for them.
markBranches
)

Derived visitor method: generate code for a boolean expression in a control-flow context.

public void
genDef(JCTree
The definition to be visited.
tree
,
Env<Gen.GenContext>
The environment current at the definition.
env
)

Visitor method: generate code for a definition, catching and reporting any completion failures.

private void
private void
public Items.Item
genExpr(JCTree
The expression to be visited.
tree
,
Type
The expression's expected type (proto-type).
pt
)

Visitor method: generate code for an expression, catching and reporting any completion failures.

pack-priv void
genFinalizer(Env<Gen.GenContext> env)

Generate code to invoke the finalizer associated with given environment.

private void
genLoop(JCTree.JCStatement
The tree representing the loop.
loop
,
JCTree.JCStatement
The loop's body.
body
,
JCTree.JCExpression
The loop's controlling condition.
cond
,
List<JCTree.JCExpressionStatement>
"Step" statements to be inserted at end of each iteration.
step
,
boolean
True if the loop test belongs before the body.
testFirst
)

Generate code for a loop.

pack-priv void
genMethod(JCTree.JCMethodDecl
The tree representing the method definition.
tree
,
Env<Gen.GenContext>
The environment current for the method body.
env
,
boolean
A flag that indicates whether all jumps are within 32K. We first invoke this method under the assumption that fatcode == false, i.e. all jumps are within 32K. If this fails, fatcode is set to true and we try again.
fatcode
)

Generate code for a method.

private void
genNullCheck(JCTree tree)

Generate a null check from the object value at stack top.

pack-priv void
public void
genStat(JCTree
The tree to be visited.
tree
,
Env<Gen.GenContext>
The environment to use.
env
,
int
The CharacterRangeTable flags indicating type of the entry.
crtFlags
)

Derived visitor method: check whether CharacterRangeTable should be emitted, if so, put a new entry into CRTable and call method to generate bytecode.

public void
genStat(JCTree tree, Env<Gen.GenContext> env)

Derived visitor method: generate code for a statement.

public void
genStats(List<JCTree.JCStatement>
The list of trees to be visited.
trees
,
Env<Gen.GenContext>
The environment to use.
env
,
int
The CharacterRangeTable flags indicating type of the entry.
crtFlags
)

Derived visitor method: check whether CharacterRangeTable should be emitted, if so, put a new entry into CRTable and call method to generate bytecode.

public void
genStats(List<? extends JCTree> trees, Env<Gen.GenContext> env)

Derived visitor method: generate code for a list of statements.

pack-priv void
genTry(JCTree
The body of the try or synchronized statement.
body
,
List<JCTree.JCCatch>
The list of catch clauses.
catchers
,
Env<Gen.GenContext>
The current environment of the body.
env
)

Generate code for a try or synchronized statement

private List<Attribute.TypeCompound>
public Env<AttrContext>
public Code
public Items
private void
handleSwitch(JCTree swtch, JCTree.JCExpression selector, List<JCTree.JCCase> cases, boolean patternSwitch)

pack-priv boolean
hasFinally(JCTree
The tree representing the structure that's aborted
target
,
Env<Gen.GenContext>
The environment current at the non-local exit.
env
)

Do any of the structures aborted by a non-local exit have finalizers that require an empty stack?

private boolean
private int
initCode(JCTree.JCMethodDecl tree, Env<Gen.GenContext> env, boolean fatcode)

public static Gen
instance(Context context)

private void
private boolean
isAccessSuper(JCTree.JCMethodDecl enclMethod)

Is the given method definition an access method resulting from a qualified super?

public boolean
public boolean
private boolean
isOddAccessName(Name name)

Does given name start with "access$" and end in an odd digit?

pack-priv void
loadIntConst(int
The integer to be loaded.
n
)

Generate code to load an integer constant.

pack-priv Items.Item
makeNewArray(JCDiagnostic.DiagnosticPosition pos, Type type, int ndims)

Generate code to create an array with given element type and number of dimensions.

pack-priv int
makeRef(JCDiagnostic.DiagnosticPosition pos, Type
The type for which a reference is inserted.
type
)

Insert a reference to given type in the constant pool, checking for an array with too many dimensions; return the reference's index.

pack-priv Items.LocalItem
makeTemp(Type
The variable's type.
type
)

Create a temporary variable.

private boolean
pack-priv List<JCTree>
normalizeDefs(List<JCTree>
The list of class member declarations.
defs
,
Symbol.ClassSymbol
The enclosing class.
c
)

Distribute member initializer code into constructors and <clinit> method.

pack-priv void
normalizeMethod(JCTree.JCMethodDecl
The tree potentially representing a constructor's definition.
md
,
List<JCTree.JCStatement>
The list of instance initializer statements.
initCode
,
List<Attribute.TypeCompound>
Type annotations from the initializer expression.
initTAs
)

Insert instance initializer code into constructors prior to the super() call.

public static int
one(int
The given type code (see (ByteCode).
tc
)

The opcode that loads a one constant of a given type code.

pack-priv static void
qsort2(int[] keys, int[] values, int lo, int hi)

Sort (int) arrays of keys and values

pack-priv void
registerCatch(JCDiagnostic.DiagnosticPosition pos, int startpc, int endpc, int handler_pc, int catch_type)

Register a catch clause in the "Exceptions" code-attribute.

private void
private void
private void
undefineVariablesInChain(Code.Chain toClear, int limit)

pack-priv Env<Gen.GenContext>
unwind(JCTree
The tree representing the structure that's aborted
target
,
Env<Gen.GenContext>
The environment current at the non-local exit.
env
)

Generate code to call all finalizers of structures aborted by a non-local exit.

private Env<Gen.GenContext>
unwindBreak(JCTree target)

As side-effect, might mark code as dead disabling any further emission.

public void
public void
public void
public void
public void
private void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public static int
zero(int
The given type code (see (ByteCode).
tc
)

The opcode that loads a zero constant of a given type code.

Inherited from com.sun.tools.javac.tree.JCTree.Visitor:
visitAnnotatedTypevisitAnnotationvisitAnyPatternvisitAssertvisitBindingPatternvisitCasevisitCatchvisitClassDefvisitConstantCaseLabelvisitDefaultCaseLabelvisitErroneousvisitExportsvisitImportvisitLambdavisitModifiersvisitModuleDefvisitModuleImportvisitOpensvisitPackageDefvisitPatternCaseLabelvisitProvidesvisitRecordPatternvisitReferencevisitRequiresvisitTopLevelvisitTreevisitTypeApplyvisitTypeArrayvisitTypeBoundKindvisitTypeIdentvisitTypeIntersectionvisitTypeParametervisitTypeUnionvisitUsesvisitVarType