|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.sun.tools.javac.tree.JCTree.Visitor
com.sun.tools.javac.jvm.Gen
public class Gen
This pass maps flat Java (i.e. without inner classes) to bytecodes.
This is NOT part of any API supported by Sun Microsystems. 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 Class Summary | |
|---|---|
static class |
Gen.CodeSizeOverflow
Thrown when the byte code size exceeds limit. |
(package private) static class |
Gen.GenContext
code generation contexts, to be used as type parameter for environments. |
(package private) class |
Gen.GenFinalizer
An abstract class for finalizer generation. |
| Field Summary | |
|---|---|
private Name |
accessDollar
|
private boolean |
allowGenerics
Switch: GJ mode? |
private Env<AttrContext> |
attrEnv
Environment for symbol lookup, set by genClass |
private Check |
chk
|
private Code |
code
Code buffer, set by genMethod. |
private boolean |
debugCode
|
private java.util.Map<JCTree,java.lang.Integer> |
endPositions
A hash table mapping syntax trees to their ending source positions. |
(package private) Env<Gen.GenContext> |
env
Visitor argument: The current environment. |
private boolean |
genCrt
|
private boolean |
generateIproxies
Set when Miranda method stubs are to be generated. |
protected static Context.Key<Gen> |
genKey
|
private Items |
items
Items structure, set by genMethod. |
private int |
jsrlimit
Default limit of (approximate) size of finalizer to inline. |
private boolean |
lineDebugInfo
Switches |
private Log |
log
|
private TreeMaker |
make
|
private Type |
methodType
A type that serves as the expected type for all method expressions. |
private Names |
names
|
private int |
nerrs
The number of code-gen errors in this class. |
private Pool |
pool
|
(package private) Type |
pt
Visitor argument: The expected type (prototype). |
(package private) Items.Item |
result
Visitor result: The item representing the computed value. |
private Resolve |
rs
|
private Code.StackMapFormat |
stackMap
Format of stackmap tables to be generated. |
private java.util.Map<Type,Symbol> |
stringBufferAppend
|
private Type |
stringBufferType
|
private Symtab |
syms
|
private Target |
target
|
private JCTree.JCCompilationUnit |
toplevel
The top level tree. |
private Types |
types
|
private boolean |
useJsrLocally
True if jsr is used. |
private boolean |
varDebugInfo
|
| Constructor Summary | |
|---|---|
protected |
Gen(Context context)
|
| Method Summary | |
|---|---|
private void |
addAbstractMethod(Symbol.ClassSymbol c,
Symbol.MethodSymbol m)
Add an abstract methods to a class which implicitly implements a method defined in some interface implemented by the class. |
private void |
adjustAbstractMethod(Symbol.ClassSymbol c,
Symbol.MethodSymbol pm,
Symbol.MethodSymbol im)
|
(package private) void |
appendString(JCTree tree)
Append value (on tos) to string buffer (on tos - 1). |
(package private) void |
appendStrings(JCTree tree)
Add all strings in tree to string buffer. |
(package private) Symbol |
binaryQualifier(Symbol sym,
Type site)
Construct a symbol to reflect the qualifying type that should appear in the byte code as per JLS 13.1. |
(package private) void |
bufferToString(JCDiagnostic.DiagnosticPosition pos)
Convert string buffer on tos to string. |
(package private) void |
callMethod(JCDiagnostic.DiagnosticPosition pos,
Type site,
Name name,
List<Type> argtypes,
boolean isStatic)
Generate code to call a non-private method or constructor. |
private void |
checkDimension(JCDiagnostic.DiagnosticPosition pos,
Type t)
Check if the given type is an array with too many dimensions. |
private void |
checkStringConstant(JCDiagnostic.DiagnosticPosition pos,
java.lang.Object constValue)
Check a constant value and report if it is a string that is too large. |
(package private) Items.Item |
completeBinop(JCTree lhs,
JCTree rhs,
Symbol.OperatorSymbol operator)
Complete generating code for operation, with left operand already on stack. |
(package private) void |
emitMinusOne(int tc)
Generate code to load -1 of the given type code (either int or long). |
(package private) void |
endFinalizerGap(Env<Gen.GenContext> env)
Mark end of gap in catch-all range for finalizer. |
(package private) void |
endFinalizerGaps(Env<Gen.GenContext> from,
Env<Gen.GenContext> to)
Mark end of all gaps in catch-all ranges for finalizers of environments lying between, and including to two environments. |
(package private) int |
estimateCodeComplexity(JCTree tree)
Very roughly estimate the number of instructions needed for the given tree. |
void |
genArgs(List<JCTree.JCExpression> trees,
List<Type> pts)
Derived visitor method: generate code for a list of method arguments. |
(package private) void |
genCatch(JCTree.JCCatch tree,
Env<Gen.GenContext> env,
int startpc,
int endpc,
List<java.lang.Integer> gaps)
Generate code for a catch clause. |
boolean |
genClass(Env<AttrContext> env,
JCTree.JCClassDecl cdef)
Generate code for a class definition. |
Items.CondItem |
genCond(JCTree _tree,
boolean markBranches)
Derived visitor method: generate code for a boolean expression in a control-flow context. |
Items.CondItem |
genCond(JCTree tree,
int crtFlags)
Derived visitor method: check whether CharacterRangeTable should be emitted, if so, put a new entry into CRTable and call method to generate bytecode. |
void |
genDef(JCTree tree,
Env<Gen.GenContext> env)
Visitor method: generate code for a definition, catching and reporting any completion failures. |
Items.Item |
genExpr(JCTree tree,
Type pt)
Visitor method: generate code for an expression, catching and reporting any completion failures. |
(package private) void |
genFinalizer(Env<Gen.GenContext> env)
Generate code to invoke the finalizer associated with given environment. |
private void |
genLoop(JCTree.JCStatement loop,
JCTree.JCStatement body,
JCTree.JCExpression cond,
List<JCTree.JCExpressionStatement> step,
boolean testFirst)
Generate code for a loop. |
(package private) void |
genMethod(JCTree.JCMethodDecl tree,
Env<Gen.GenContext> env,
boolean fatcode)
Generate code for a method. |
private void |
genNullCheck(JCDiagnostic.DiagnosticPosition pos)
Generate a null check from the object value at stack top. |
void |
genStat(JCTree tree,
Env<Gen.GenContext> env)
Derived visitor method: generate code for a statement. |
void |
genStat(JCTree tree,
Env<Gen.GenContext> env,
int crtFlags)
Derived visitor method: check whether CharacterRangeTable should be emitted, if so, put a new entry into CRTable and call method to generate bytecode. |
void |
genStats(List<? extends JCTree> trees,
Env<Gen.GenContext> env)
Derived visitor method: generate code for a list of statements. |
void |
genStats(List<JCTree.JCStatement> trees,
Env<Gen.GenContext> env,
int crtFlags)
Derived visitor method: check whether CharacterRangeTable should be emitted, if so, put a new entry into CRTable and call method to generate bytecode. |
(package private) void |
genTry(JCTree body,
List<JCTree.JCCatch> catchers,
Env<Gen.GenContext> env)
Generate code for a try or synchronized statement |
(package private) Symbol |
getStringBufferAppend(JCTree tree,
Type t)
|
(package private) boolean |
hasFinally(JCTree target,
Env<Gen.GenContext> env)
Do any of the structures aborted by a non-local exit have finalizers that require an empty stack? |
(package private) void |
implementInterfaceMethods(Symbol.ClassSymbol c)
Add abstract methods for all methods defined in one of the interfaces of a given class, provided they are not already implemented in the class. |
(package private) void |
implementInterfaceMethods(Symbol.ClassSymbol c,
Symbol.ClassSymbol site)
Add abstract methods for all methods defined in one of the interfaces of a given class, provided they are not already implemented in the class. |
private int |
initCode(JCTree.JCMethodDecl tree,
Env<Gen.GenContext> env,
boolean fatcode)
|
static Gen |
instance(Context context)
|
private boolean |
isAccessSuper(JCTree.JCMethodDecl enclMethod)
Is the given method definition an access method resulting from a qualified super? This is signified by an odd access code. |
private boolean |
isOddAccessName(Name name)
Does given name start with "access$" and end in an odd digit? |
(package private) void |
loadIntConst(int n)
Generate code to load an integer constant. |
(package private) Items.Item |
makeNewArray(JCDiagnostic.DiagnosticPosition pos,
Type type,
int ndims)
Generate code to create an array with given element type and number of dimensions. |
(package private) int |
makeRef(JCDiagnostic.DiagnosticPosition pos,
Type type)
Insert a reference to given type in the constant pool, checking for an array with too many dimensions; return the reference's index. |
(package private) void |
makeStringBuffer(JCDiagnostic.DiagnosticPosition pos)
Make a new string buffer. |
(package private) Items.LocalItem |
makeTemp(Type type)
Create a tempory variable. |
(package private) List<JCTree> |
normalizeDefs(List<JCTree> defs,
Symbol.ClassSymbol c)
Distribute member initializer code into constructors and |
(package private) void |
normalizeMethod(JCTree.JCMethodDecl md,
List<JCTree.JCStatement> initCode)
Insert instance initializer code into initial constructor. |
static int |
one(int tc)
The opcode that loads a one constant of a given type code. |
(package private) static void |
qsort2(int[] keys,
int[] values,
int lo,
int hi)
Sort (int) arrays of keys and values |
(package private) void |
registerCatch(JCDiagnostic.DiagnosticPosition pos,
int startpc,
int endpc,
int handler_pc,
int catch_type)
Register a catch clause in the "Exceptions" code-attribute. |
(package private) Env<Gen.GenContext> |
unwind(JCTree target,
Env<Gen.GenContext> env)
Generate code to call all finalizers of structures aborted by a non-local exit. |
void |
visitApply(JCTree.JCMethodInvocation tree)
|
void |
visitAssign(JCTree.JCAssign tree)
|
void |
visitAssignop(JCTree.JCAssignOp tree)
|
void |
visitBinary(JCTree.JCBinary tree)
|
void |
visitBlock(JCTree.JCBlock tree)
|
void |
visitBreak(JCTree.JCBreak tree)
|
void |
visitConditional(JCTree.JCConditional tree)
|
void |
visitContinue(JCTree.JCContinue tree)
|
void |
visitDoLoop(JCTree.JCDoWhileLoop tree)
|
void |
visitExec(JCTree.JCExpressionStatement tree)
|
void |
visitForeachLoop(JCTree.JCEnhancedForLoop tree)
|
void |
visitForLoop(JCTree.JCForLoop tree)
|
void |
visitIdent(JCTree.JCIdent tree)
|
void |
visitIf(JCTree.JCIf tree)
|
void |
visitIndexed(JCTree.JCArrayAccess tree)
|
void |
visitLabelled(JCTree.JCLabeledStatement tree)
|
void |
visitLetExpr(JCTree.LetExpr tree)
|
void |
visitLiteral(JCTree.JCLiteral tree)
|
void |
visitMethodDef(JCTree.JCMethodDecl tree)
|
void |
visitNewArray(JCTree.JCNewArray tree)
|
void |
visitNewClass(JCTree.JCNewClass tree)
|
void |
visitParens(JCTree.JCParens tree)
|
void |
visitReturn(JCTree.JCReturn tree)
|
void |
visitSelect(JCTree.JCFieldAccess tree)
|
void |
visitSkip(JCTree.JCSkip tree)
|
void |
visitSwitch(JCTree.JCSwitch tree)
|
void |
visitSynchronized(JCTree.JCSynchronized tree)
|
void |
visitThrow(JCTree.JCThrow tree)
|
void |
visitTry(JCTree.JCTry tree)
|
void |
visitTypeCast(JCTree.JCTypeCast tree)
|
void |
visitTypeTest(JCTree.JCInstanceOf tree)
|
void |
visitUnary(JCTree.JCUnary tree)
|
void |
visitVarDef(JCTree.JCVariableDecl tree)
|
void |
visitWhileLoop(JCTree.JCWhileLoop tree)
|
void |
visitWildcard(JCTree.JCWildcard tree)
|
static int |
zero(int tc)
The opcode that loads a zero constant of a given type code. |
| Methods inherited from class com.sun.tools.javac.tree.JCTree.Visitor |
|---|
visitAnnotation, visitAssert, visitBracketExpr, visitBracketStat, visitCase, visitCatch, visitClassDef, visitErroneous, visitEscapeExpr, visitEscapeStat, visitImport, visitModifiers, visitTopLevel, visitTree, visitTypeApply, visitTypeArray, visitTypeBoundKind, visitTypeIdent, visitTypeParameter |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final Context.Key<Gen> genKey
private final Log log
private final Symtab syms
private final Check chk
private final Resolve rs
private final TreeMaker make
private final Names names
private final Target target
private final Type stringBufferType
private final java.util.Map<Type,Symbol> stringBufferAppend
private Name accessDollar
private final Types types
private final boolean allowGenerics
private final boolean generateIproxies
private final Code.StackMapFormat stackMap
private final Type methodType
private final boolean lineDebugInfo
private final boolean varDebugInfo
private final boolean genCrt
private final boolean debugCode
private final int jsrlimit
private boolean useJsrLocally
private Pool pool
private Code code
private Items items
private Env<AttrContext> attrEnv
private JCTree.JCCompilationUnit toplevel
private int nerrs
private java.util.Map<JCTree,java.lang.Integer> endPositions
Env<Gen.GenContext> env
Type pt
Items.Item result
| Constructor Detail |
|---|
protected Gen(Context context)
| Method Detail |
|---|
public static Gen instance(Context context)
void loadIntConst(int n)
n - The integer to be loaded.public static int zero(int tc)
tc - The given type code (@see ByteCode).public static int one(int tc)
tc - The given type code (@see ByteCode).void emitMinusOne(int tc)
tc - The given type code (@see ByteCode).
Symbol binaryQualifier(Symbol sym,
Type site)
sym - The accessed symbolsite - The qualifier's type.
int makeRef(JCDiagnostic.DiagnosticPosition pos,
Type type)
type - The type for which a reference is inserted.
private void checkDimension(JCDiagnostic.DiagnosticPosition pos,
Type t)
Items.LocalItem makeTemp(Type type)
type - The variable's type.
void callMethod(JCDiagnostic.DiagnosticPosition pos,
Type site,
Name name,
List<Type> argtypes,
boolean isStatic)
pos - Position to be used for error reporting.site - The type of which the method is a member.name - The method's name.argtypes - The method's argument types.isStatic - A flag that indicates whether we call a
static or instance method.private boolean isAccessSuper(JCTree.JCMethodDecl enclMethod)
private boolean isOddAccessName(Name name)
void genFinalizer(Env<Gen.GenContext> env)
Env<Gen.GenContext> unwind(JCTree target,
Env<Gen.GenContext> env)
target - The tree representing the structure that's abortedenv - The environment current at the non-local exit.void endFinalizerGap(Env<Gen.GenContext> env)
env - the environment which might contain the finalizer
(if it does, env.info.gaps != null).
void endFinalizerGaps(Env<Gen.GenContext> from,
Env<Gen.GenContext> to)
from - the most deeply nested environment to markto - the least deeply nested environment to mark
boolean hasFinally(JCTree target,
Env<Gen.GenContext> env)
target - The tree representing the structure that's abortedenv - The environment current at the non-local exit.
List<JCTree> normalizeDefs(List<JCTree> defs,
Symbol.ClassSymbol c)
defs - The list of class member declarations.c - The enclosing class.
private void checkStringConstant(JCDiagnostic.DiagnosticPosition pos,
java.lang.Object constValue)
void normalizeMethod(JCTree.JCMethodDecl md,
List<JCTree.JCStatement> initCode)
md - The tree potentially representing a
constructor's definition.initCode - The list of instance initializer statements.void implementInterfaceMethods(Symbol.ClassSymbol c)
c - The class whose interfaces are searched for methods
for which Miranda methods should be added.
void implementInterfaceMethods(Symbol.ClassSymbol c,
Symbol.ClassSymbol site)
c - The class whose interfaces are searched for methods
for which Miranda methods should be added.site - The class in which a definition may be needed.
private void addAbstractMethod(Symbol.ClassSymbol c,
Symbol.MethodSymbol m)
c - The class to which the Miranda method is added.m - The interface method symbol for which a Miranda method
is added.
private void adjustAbstractMethod(Symbol.ClassSymbol c,
Symbol.MethodSymbol pm,
Symbol.MethodSymbol im)
public void genDef(JCTree tree,
Env<Gen.GenContext> env)
tree - The definition to be visited.env - The environment current at the definition.
public void genStat(JCTree tree,
Env<Gen.GenContext> env,
int crtFlags)
tree - The tree to be visited.env - The environment to use.crtFlags - The CharacterRangeTable flags
indicating type of the entry.#genStat(Tree, Env)
public void genStat(JCTree tree,
Env<Gen.GenContext> env)
public void genStats(List<JCTree.JCStatement> trees,
Env<Gen.GenContext> env,
int crtFlags)
trees - The list of trees to be visited.env - The environment to use.crtFlags - The CharacterRangeTable flags
indicating type of the entry.genStats(List, Env)
public void genStats(List<? extends JCTree> trees,
Env<Gen.GenContext> env)
public Items.CondItem genCond(JCTree tree,
int crtFlags)
tree - The tree to be visited.crtFlags - The CharacterRangeTable flags
indicating type of the entry.#genCond(Tree,boolean)
public Items.CondItem genCond(JCTree _tree,
boolean markBranches)
_tree - The expression to be visited.markBranches - 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.
public Items.Item genExpr(JCTree tree,
Type pt)
tree - The expression to be visited.pt - The expression's expected type (proto-type).
public void genArgs(List<JCTree.JCExpression> trees,
List<Type> pts)
trees - The argument expressions to be visited.pts - The expression's expected types (i.e. the formal parameter
types of the invoked method).public void visitMethodDef(JCTree.JCMethodDecl tree)
visitMethodDef in class JCTree.Visitor
void genMethod(JCTree.JCMethodDecl tree,
Env<Gen.GenContext> env,
boolean fatcode)
tree - The tree representing the method definition.env - The environment current for the method body.fatcode - 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.
private int initCode(JCTree.JCMethodDecl tree,
Env<Gen.GenContext> env,
boolean fatcode)
public void visitVarDef(JCTree.JCVariableDecl tree)
visitVarDef in class JCTree.Visitorpublic void visitSkip(JCTree.JCSkip tree)
visitSkip in class JCTree.Visitorpublic void visitBlock(JCTree.JCBlock tree)
visitBlock in class JCTree.Visitorpublic void visitDoLoop(JCTree.JCDoWhileLoop tree)
visitDoLoop in class JCTree.Visitorpublic void visitWhileLoop(JCTree.JCWhileLoop tree)
visitWhileLoop in class JCTree.Visitorpublic void visitForLoop(JCTree.JCForLoop tree)
visitForLoop in class JCTree.Visitor
private void genLoop(JCTree.JCStatement loop,
JCTree.JCStatement body,
JCTree.JCExpression cond,
List<JCTree.JCExpressionStatement> step,
boolean testFirst)
loop - The tree representing the loop.body - The loop's body.cond - The loop's controling condition.step - "Step" statements to be inserted at end of
each iteration.testFirst - True if the loop test belongs before the body.public void visitForeachLoop(JCTree.JCEnhancedForLoop tree)
visitForeachLoop in class JCTree.Visitorpublic void visitLabelled(JCTree.JCLabeledStatement tree)
visitLabelled in class JCTree.Visitorpublic void visitSwitch(JCTree.JCSwitch tree)
visitSwitch in class JCTree.Visitor
static void qsort2(int[] keys,
int[] values,
int lo,
int hi)
public void visitSynchronized(JCTree.JCSynchronized tree)
visitSynchronized in class JCTree.Visitorpublic void visitTry(JCTree.JCTry tree)
visitTry in class JCTree.Visitor
void genTry(JCTree body,
List<JCTree.JCCatch> catchers,
Env<Gen.GenContext> env)
body - The body of the try or synchronized statement.catchers - The lis of catch clauses.env - the environment current for the body.
void genCatch(JCTree.JCCatch tree,
Env<Gen.GenContext> env,
int startpc,
int endpc,
List<java.lang.Integer> gaps)
tree - The catch clause.env - The environment current in the enclosing try.startpc - Start pc of try-block.endpc - End pc of try-block.
void registerCatch(JCDiagnostic.DiagnosticPosition pos,
int startpc,
int endpc,
int handler_pc,
int catch_type)
int estimateCodeComplexity(JCTree tree)
public void visitIf(JCTree.JCIf tree)
visitIf in class JCTree.Visitorpublic void visitExec(JCTree.JCExpressionStatement tree)
visitExec in class JCTree.Visitorpublic void visitBreak(JCTree.JCBreak tree)
visitBreak in class JCTree.Visitorpublic void visitContinue(JCTree.JCContinue tree)
visitContinue in class JCTree.Visitorpublic void visitReturn(JCTree.JCReturn tree)
visitReturn in class JCTree.Visitorpublic void visitThrow(JCTree.JCThrow tree)
visitThrow in class JCTree.Visitorpublic void visitApply(JCTree.JCMethodInvocation tree)
visitApply in class JCTree.Visitorpublic void visitConditional(JCTree.JCConditional tree)
visitConditional in class JCTree.Visitorpublic void visitNewClass(JCTree.JCNewClass tree)
visitNewClass in class JCTree.Visitorpublic void visitNewArray(JCTree.JCNewArray tree)
visitNewArray in class JCTree.Visitor
Items.Item makeNewArray(JCDiagnostic.DiagnosticPosition pos,
Type type,
int ndims)
public void visitParens(JCTree.JCParens tree)
visitParens in class JCTree.Visitorpublic void visitAssign(JCTree.JCAssign tree)
visitAssign in class JCTree.Visitorpublic void visitAssignop(JCTree.JCAssignOp tree)
visitAssignop in class JCTree.Visitorpublic void visitUnary(JCTree.JCUnary tree)
visitUnary in class JCTree.Visitorprivate void genNullCheck(JCDiagnostic.DiagnosticPosition pos)
public void visitBinary(JCTree.JCBinary tree)
visitBinary in class JCTree.Visitorvoid makeStringBuffer(JCDiagnostic.DiagnosticPosition pos)
void appendString(JCTree tree)
Symbol getStringBufferAppend(JCTree tree,
Type t)
void appendStrings(JCTree tree)
void bufferToString(JCDiagnostic.DiagnosticPosition pos)
Items.Item completeBinop(JCTree lhs,
JCTree rhs,
Symbol.OperatorSymbol operator)
lhs - The tree representing the left operand.rhs - The tree representing the right operand.operator - The operator symbol.public void visitTypeCast(JCTree.JCTypeCast tree)
visitTypeCast in class JCTree.Visitorpublic void visitWildcard(JCTree.JCWildcard tree)
visitWildcard in class JCTree.Visitorpublic void visitTypeTest(JCTree.JCInstanceOf tree)
visitTypeTest in class JCTree.Visitorpublic void visitIndexed(JCTree.JCArrayAccess tree)
visitIndexed in class JCTree.Visitorpublic void visitIdent(JCTree.JCIdent tree)
visitIdent in class JCTree.Visitorpublic void visitSelect(JCTree.JCFieldAccess tree)
visitSelect in class JCTree.Visitorpublic void visitLiteral(JCTree.JCLiteral tree)
visitLiteral in class JCTree.Visitorpublic void visitLetExpr(JCTree.LetExpr tree)
visitLetExpr in class JCTree.Visitor
public boolean genClass(Env<AttrContext> env,
JCTree.JCClassDecl cdef)
env - The attribution environment that belongs to the
outermost class containing this class definition.
We need this for resolving some additional symbols.cdef - The tree representing the class definition.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||