Class BodyCodegen
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
Manages placement of exception handlers for non-generator functions.(package private) static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate short
(package private) ClassFileWriter
(package private) Codegen
(package private) CompilerEnvirons
private short
private static final int
private int
private int
private static final int
private static final int
private BodyCodegen.ExceptionManager
private static final int
private Map<Node,
BodyCodegen.FinallyReturnPoint> private short
private OptFunctionNode
private short
(package private) static final int
(package private) static final int
(package private) static final int
private short
private int
private boolean
private boolean
private boolean
private boolean
private boolean
private int
private short
private short
private static final int
private int[]
private short
private static final int
private int
private int
private short
private short
private int
(package private) ScriptNode
int
private short
private static final int
private int
private IdentityHashMap<Node,
String> private short
private short[]
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
private void
private void
addGotoWithReturn
(Node target) private void
Generate calls to ScriptRuntime.addInstructionCount to keep track of executed instructions and callobserveInstructionCount()
if a threshold is exceeded.
Calculates the count from getCurrentCodeOffset - savedCodeOffsetprivate void
addInstructionCount
(int count) Generate calls to ScriptRuntime.addInstructionCount to keep track of executed instructions and callobserveInstructionCount()
if a threshold is exceeded.
Takes the count as a parameter - used to add monitoring to loops and other blocks that don't have any ops - this allows for monitoring/killing of while(true) loops and such.private void
addJumpedBooleanWrap
(int trueLabel, int falseLabel) private void
addLoadPropertyIds
(Object[] properties, int count) load array with property idsprivate void
addLoadPropertyValues
(Node node, Node child, int count) load array with property valuesprivate void
addNewObjectArray
(int size) private void
private void
private void
addOptRuntimeInvoke
(String methodName, String methodSignature) private void
addScriptRuntimeInvoke
(String methodName, String methodSignature) private void
dcpLoadAsNumber
(int dcp_register) private void
dcpLoadAsObject
(int dcp_register) private void
decReferenceWordLocal
(short local) private static String
exceptionTypeToName
(int exceptionType) private Node
findNestedYield
(Node node) private void
private void
generateArrayLiteralFactory
(Node node, int count) (package private) void
private void
generateCallArgArray
(Node node, Node argChild, boolean directCall) private void
generateCatchBlock
(int exceptionType, short savedVariableObject, int catchLabel, int exceptionLocal, int handler) private void
generateCheckForThrowOrClose
(int label, boolean hasLocals, int nextState) private void
private void
generateExpression
(Node node, Node parent) private void
generateFunctionAndThisObj
(Node node, Node parent) private void
private void
private void
private void
private void
generateIfJump
(Node node, Node parent, int trueLabel, int falseLabel) private void
private void
private void
generateLocalYieldPoint
(Node node, boolean exprContext) private void
private void
generateObjectLiteralFactory
(Node node, int count) private void
Generate the prologue for a function or script.private boolean
generateSaveLocals
(Node node) private void
generateSetGeneratorResumptionPoint
(int nextState) private void
private void
generateStatement
(Node node) private void
private void
generateYieldPoint
(Node node, boolean exprContext) private void
genSimpleCompare
(int type, int trueGOTO, int falseGOTO) private static Node
getFinallyAtTarget
(Node node) Get a FINALLY node at a point in the IR.private static int
getLocalBlockRegister
(Node node) private short
getNewWordIntern
(int count) private short
private short
getNewWordLocal
(boolean isConst) private short
getNewWordPairLocal
(boolean isConst) Const locals use an extra slot to hold the has-been-assigned-once flag at runtime.private int
getNextGeneratorState
(Node node) private int
getTargetLabel
(Node target) private void
incReferenceWordLocal
(short local) private void
private void
inlineFinally
(Node finallyTarget) private void
inlineFinally
(Node finallyTarget, int finallyStart, int finallyEnd) Inline a FINALLY node into the method bytecode.private static boolean
isArithmeticNode
(Node node) private int
private void
releaseWordLocal
(short local) private void
Save the current code offset.private void
updateLineNumber
(Node node) private boolean
varIsDirectCallParameter
(int varIndex) private void
visitArithmetic
(Node node, int type, Node child, Node parent) private void
visitArrayLiteral
(Node node, Node child, boolean topLevel) private void
visitBitNot
(Node node, Node child) private void
visitBitOp
(Node node, int type, Node child) private void
visitDotQuery
(Node node, Node child) private void
visitExponentiation
(Node node, Node child, Node parent) private void
visitFunction
(OptFunctionNode ofn, int functionType) private void
visitGetProp
(Node node, Node child) private void
visitGetVar
(Node node) private void
private void
visitIfJumpEqOp
(Node node, Node child, int trueGOTO, int falseGOTO) private void
visitIfJumpRelOp
(Node node, Node child, int trueGOTO, int falseGOTO) private void
visitIncDec
(Node node) private void
visitObjectLiteral
(Node node, Node child, boolean topLevel) private void
visitOptimizedCall
(Node node, OptFunctionNode target, int type, Node child) private void
visitSetConst
(Node node, Node child) private void
visitSetConstVar
(Node node, Node child, boolean needValue) private void
visitSetElem
(int type, Node node, Node child) private void
visitSetName
(Node node, Node child) private void
visitSetProp
(int type, Node node, Node child) private void
visitSetVar
(Node node, Node child, boolean needValue) private void
visitSpecialCall
(Node node, int type, int specialType, Node child) private void
visitStandardCall
(Node node, Node child) private void
visitStandardNew
(Node node, Node child) private void
visitStrictSetName
(Node node, Node child) private void
visitSwitch
(Jump switchNode, Node child) private void
visitTemplateLiteral
(Node node) private void
visitTryCatchFinally
(Jump node, Node child) private void
visitTypeofname
(Node node)
-
Field Details
-
JAVASCRIPT_EXCEPTION
private static final int JAVASCRIPT_EXCEPTION- See Also:
-
EVALUATOR_EXCEPTION
private static final int EVALUATOR_EXCEPTION- See Also:
-
ECMAERROR_EXCEPTION
private static final int ECMAERROR_EXCEPTION- See Also:
-
THROWABLE_EXCEPTION
private static final int THROWABLE_EXCEPTION- See Also:
-
FINALLY_EXCEPTION
private static final int FINALLY_EXCEPTION- See Also:
-
EXCEPTION_MAX
private static final int EXCEPTION_MAX- See Also:
-
exceptionManager
-
GENERATOR_TERMINATE
static final int GENERATOR_TERMINATE- See Also:
-
GENERATOR_START
static final int GENERATOR_START- See Also:
-
GENERATOR_YIELD_START
static final int GENERATOR_YIELD_START- See Also:
-
cfw
ClassFileWriter cfw -
codegen
Codegen codegen -
compilerEnv
CompilerEnvirons compilerEnv -
scriptOrFn
ScriptNode scriptOrFn -
scriptOrFnIndex
public int scriptOrFnIndex -
savedCodeOffset
private int savedCodeOffset -
fnCurrent
-
MAX_LOCALS
private static final int MAX_LOCALS- See Also:
-
locals
private int[] locals -
firstFreeLocal
private short firstFreeLocal -
localsMax
private short localsMax -
itsLineNumber
private int itsLineNumber -
hasVarsInRegs
private boolean hasVarsInRegs -
varRegisters
private short[] varRegisters -
inDirectCallFunction
private boolean inDirectCallFunction -
itsForcedObjectParameters
private boolean itsForcedObjectParameters -
enterAreaStartLabel
private int enterAreaStartLabel -
epilogueLabel
private int epilogueLabel -
inLocalBlock
private boolean inLocalBlock -
variableObjectLocal
private short variableObjectLocal -
popvLocal
private short popvLocal -
contextLocal
private short contextLocal -
argsLocal
private short argsLocal -
operationLocal
private short operationLocal -
thisObjLocal
private short thisObjLocal -
funObjLocal
private short funObjLocal -
itsZeroArgArray
private short itsZeroArgArray -
itsOneArgArray
private short itsOneArgArray -
generatorStateLocal
private short generatorStateLocal -
isGenerator
private boolean isGenerator -
generatorSwitch
private int generatorSwitch -
maxLocals
private int maxLocals -
maxStack
private int maxStack -
finallys
-
literals
-
unnestedYieldCount
private int unnestedYieldCount -
unnestedYields
-
-
Constructor Details
-
BodyCodegen
BodyCodegen()
-
-
Method Details
-
generateBodyCode
void generateBodyCode() -
generateGenerator
private void generateGenerator() -
generateNestedFunctionInits
private void generateNestedFunctionInits() -
initBodyGeneration
private void initBodyGeneration() -
generatePrologue
private void generatePrologue()Generate the prologue for a function or script. -
generateGetGeneratorResumptionPoint
private void generateGetGeneratorResumptionPoint() -
generateSetGeneratorResumptionPoint
private void generateSetGeneratorResumptionPoint(int nextState) -
generateGetGeneratorStackState
private void generateGetGeneratorStackState() -
generateEpilogue
private void generateEpilogue() -
generateGetGeneratorLocalsState
private void generateGetGeneratorLocalsState() -
generateSetGeneratorReturnValue
private void generateSetGeneratorReturnValue() -
generateActivationExit
private void generateActivationExit() -
generateStatement
-
generateIntegerWrap
private void generateIntegerWrap() -
generateIntegerUnwrap
private void generateIntegerUnwrap() -
generateThrowJavaScriptException
private void generateThrowJavaScriptException() -
getNextGeneratorState
-
generateExpression
-
findNestedYield
-
generateYieldPoint
-
generateLocalYieldPoint
-
generateCheckForThrowOrClose
private void generateCheckForThrowOrClose(int label, boolean hasLocals, int nextState) -
visitTemplateLiteral
-
generateIfJump
-
visitFunction
-
getTargetLabel
-
visitGoto
-
addGotoWithReturn
-
generateArrayLiteralFactory
-
generateObjectLiteralFactory
-
visitArrayLiteral
-
addLoadPropertyIds
load array with property ids -
addLoadPropertyValues
load array with property values -
visitObjectLiteral
-
visitSpecialCall
-
visitStandardCall
-
visitStandardNew
-
visitOptimizedCall
-
generateCallArgArray
-
generateFunctionAndThisObj
-
updateLineNumber
-
visitTryCatchFinally
-
generateCatchBlock
private void generateCatchBlock(int exceptionType, short savedVariableObject, int catchLabel, int exceptionLocal, int handler) -
exceptionTypeToName
-
inlineFinally
Inline a FINALLY node into the method bytecode.This method takes a label that points to the real start of the finally block as implemented in the bytecode. This is because in some cases, the finally block really starts before any of the code in the Node. For example, the catch-all-rethrow finally block has a few instructions prior to the finally block made by the user.
In addition, an end label that should be unmarked is given as a method parameter. It is the responsibility of any callers of this method to mark the label.
The start and end labels of the finally block are used to exclude the inlined block from the proper exception handler. For example, an inlined finally block should not be handled by a catch-all-rethrow.
- Parameters:
finallyTarget
- a TARGET node directly preceding a FINALLY node or a FINALLY node itselffinallyStart
- a pre-marked label that indicates the actual start of the finally block in the bytecode.finallyEnd
- an unmarked label that will indicate the actual end of the finally block in the bytecode.
-
inlineFinally
-
getFinallyAtTarget
Get a FINALLY node at a point in the IR.This is strongly dependent on the generated IR. If the node is a TARGET, it only check the next node to see if it is a FINALLY node.
-
generateSaveLocals
-
visitSwitch
-
visitTypeofname
-
saveCurrentCodeOffset
private void saveCurrentCodeOffset()Save the current code offset. This saved code offset is used to compute instruction counts in subsequent calls toaddInstructionCount()
. -
addInstructionCount
private void addInstructionCount()Generate calls to ScriptRuntime.addInstructionCount to keep track of executed instructions and callobserveInstructionCount()
if a threshold is exceeded.
Calculates the count from getCurrentCodeOffset - savedCodeOffset -
addInstructionCount
private void addInstructionCount(int count) Generate calls to ScriptRuntime.addInstructionCount to keep track of executed instructions and callobserveInstructionCount()
if a threshold is exceeded.
Takes the count as a parameter - used to add monitoring to loops and other blocks that don't have any ops - this allows for monitoring/killing of while(true) loops and such. -
visitIncDec
-
isArithmeticNode
-
visitArithmetic
-
visitExponentiation
-
visitBitNot
-
visitBitOp
-
nodeIsDirectCallParameter
-
varIsDirectCallParameter
private boolean varIsDirectCallParameter(int varIndex) -
genSimpleCompare
private void genSimpleCompare(int type, int trueGOTO, int falseGOTO) -
visitIfJumpRelOp
-
visitIfJumpEqOp
-
visitSetName
-
visitStrictSetName
-
visitSetConst
-
visitGetVar
-
visitSetVar
-
visitSetConstVar
-
visitGetProp
-
visitSetProp
-
visitSetElem
-
visitDotQuery
-
getLocalBlockRegister
-
dcpLoadAsNumber
private void dcpLoadAsNumber(int dcp_register) -
dcpLoadAsObject
private void dcpLoadAsObject(int dcp_register) -
addGoto
-
addObjectToDouble
private void addObjectToDouble() -
addObjectToNumeric
private void addObjectToNumeric() -
addNewObjectArray
private void addNewObjectArray(int size) -
addScriptRuntimeInvoke
-
addOptRuntimeInvoke
-
addJumpedBooleanWrap
private void addJumpedBooleanWrap(int trueLabel, int falseLabel) -
addDoubleWrap
private void addDoubleWrap() -
getNewWordPairLocal
private short getNewWordPairLocal(boolean isConst) Const locals use an extra slot to hold the has-been-assigned-once flag at runtime.- Parameters:
isConst
- true iff the variable is const- Returns:
- the register for the word pair (double/long)
-
getNewWordLocal
private short getNewWordLocal(boolean isConst) -
getNewWordLocal
private short getNewWordLocal() -
getNewWordIntern
private short getNewWordIntern(int count) -
incReferenceWordLocal
private void incReferenceWordLocal(short local) -
decReferenceWordLocal
private void decReferenceWordLocal(short local) -
releaseWordLocal
private void releaseWordLocal(short local)
-