Class BodyCodegen
java.lang.Object
org.mozilla.javascript.optimizer.BodyCodegen
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classManages 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) CompilerEnvironsprivate shortprivate static final intprivate intprivate intprivate static final intprivate static final intprivate BodyCodegen.ExceptionManagerprivate static final intprivate Map<Node, BodyCodegen.FinallyReturnPoint> private shortprivate OptFunctionNodeprivate short(package private) static final int(package private) static final int(package private) static final intprivate shortprivate intprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate intprivate shortprivate shortprivate static final intprivate int[]private shortprivate static final intprivate intprivate intprivate shortprivate shortprivate int(package private) ScriptNodeintprivate shortprivate static final intprivate intprivate IdentityHashMap<Node, String> private shortprivate short[] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidprivate voidprivate voidaddGotoWithReturn(Node target) private voidGenerate calls to ScriptRuntime.addInstructionCount to keep track of executed instructions and callobserveInstructionCount()if a threshold is exceeded.
Calculates the count from getCurrentCodeOffset - savedCodeOffsetprivate voidaddInstructionCount(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 voidaddJumpedBooleanWrap(int trueLabel, int falseLabel) private voidaddLoadPropertyIds(Object[] properties, int count) load array with property idsprivate voidaddLoadPropertyValues(Node node, Node child, int count) load array with property valuesprivate voidaddNewObjectArray(int size) private voidprivate voidprivate voidaddOptRuntimeInvoke(String methodName, String methodSignature) private voidaddScriptRuntimeInvoke(String methodName, String methodSignature) private voiddcpLoadAsNumber(int dcp_register) private voiddcpLoadAsObject(int dcp_register) private voiddecReferenceWordLocal(short local) private static StringexceptionTypeToName(int exceptionType) private NodefindNestedYield(Node node) private voidprivate voidgenerateArrayLiteralFactory(Node node, int count) (package private) voidprivate voidgenerateCallArgArray(Node node, Node argChild, boolean directCall) private voidgenerateCatchBlock(int exceptionType, short savedVariableObject, int catchLabel, int exceptionLocal, int handler) private voidgenerateCheckForThrowOrClose(int label, boolean hasLocals, int nextState) private voidprivate voidgenerateExpression(Node node, Node parent) private voidgenerateFunctionAndThisObj(Node node, Node parent) private voidprivate voidprivate voidprivate voidprivate voidgenerateIfJump(Node node, Node parent, int trueLabel, int falseLabel) private voidprivate voidprivate voidgenerateLocalYieldPoint(Node node, boolean exprContext) private voidprivate voidgenerateObjectLiteralFactory(Node node, int count) private voidGenerate the prologue for a function or script.private booleangenerateSaveLocals(Node node) private voidgenerateSetGeneratorResumptionPoint(int nextState) private voidprivate voidgenerateStatement(Node node) private voidprivate voidgenerateYieldPoint(Node node, boolean exprContext) private voidgenSimpleCompare(int type, int trueGOTO, int falseGOTO) private static NodegetFinallyAtTarget(Node node) Get a FINALLY node at a point in the IR.private static intgetLocalBlockRegister(Node node) private shortgetNewWordIntern(int count) private shortprivate shortgetNewWordLocal(boolean isConst) private shortgetNewWordPairLocal(boolean isConst) Const locals use an extra slot to hold the has-been-assigned-once flag at runtime.private intgetNextGeneratorState(Node node) private intgetTargetLabel(Node target) private voidincReferenceWordLocal(short local) private voidprivate voidinlineFinally(Node finallyTarget) private voidinlineFinally(Node finallyTarget, int finallyStart, int finallyEnd) Inline a FINALLY node into the method bytecode.private static booleanisArithmeticNode(Node node) private intprivate voidreleaseWordLocal(short local) private voidSave the current code offset.private voidupdateLineNumber(Node node) private booleanvarIsDirectCallParameter(int varIndex) private voidvisitArithmetic(Node node, int type, Node child, Node parent) private voidvisitArrayLiteral(Node node, Node child, boolean topLevel) private voidvisitBitNot(Node node, Node child) private voidvisitBitOp(Node node, int type, Node child) private voidvisitDotQuery(Node node, Node child) private voidvisitExponentiation(Node node, Node child, Node parent) private voidvisitFunction(OptFunctionNode ofn, int functionType) private voidvisitGetProp(Node node, Node child) private voidvisitGetVar(Node node) private voidprivate voidvisitIfJumpEqOp(Node node, Node child, int trueGOTO, int falseGOTO) private voidvisitIfJumpRelOp(Node node, Node child, int trueGOTO, int falseGOTO) private voidvisitIncDec(Node node) private voidvisitObjectLiteral(Node node, Node child, boolean topLevel) private voidvisitOptimizedCall(Node node, OptFunctionNode target, int type, Node child) private voidvisitSetConst(Node node, Node child) private voidvisitSetConstVar(Node node, Node child, boolean needValue) private voidvisitSetElem(int type, Node node, Node child) private voidvisitSetName(Node node, Node child) private voidvisitSetProp(int type, Node node, Node child) private voidvisitSetVar(Node node, Node child, boolean needValue) private voidvisitSpecialCall(Node node, int type, int specialType, Node child) private voidvisitStandardCall(Node node, Node child) private voidvisitStandardNew(Node node, Node child) private voidvisitStrictSetName(Node node, Node child) private voidvisitSwitch(Jump switchNode, Node child) private voidvisitTemplateLiteral(Node node) private voidvisitTryCatchFinally(Jump node, Node child) private voidvisitTypeofname(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
-
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
-
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)
-