Class BodyCodegen
- java.lang.Object
-
- org.htmlunit.corejs.javascript.optimizer.BodyCodegen
-
class BodyCodegen extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
BodyCodegen.ExceptionManager
Manages placement of exception handlers for non-generator functions.(package private) static class
BodyCodegen.FinallyReturnPoint
-
Field Summary
Fields Modifier and Type Field Description private short
argsLocal
(package private) ClassFileWriter
cfw
(package private) Codegen
codegen
(package private) CompilerEnvirons
compilerEnv
private short
contextLocal
private static int
ECMAERROR_EXCEPTION
private int
enterAreaStartLabel
private int
epilogueLabel
private static int
EVALUATOR_EXCEPTION
private static int
EXCEPTION_MAX
private BodyCodegen.ExceptionManager
exceptionManager
private static int
FINALLY_EXCEPTION
private java.util.Map<Node,BodyCodegen.FinallyReturnPoint>
finallys
private short
firstFreeLocal
private OptFunctionNode
fnCurrent
private short
funObjLocal
(package private) static int
GENERATOR_START
(package private) static int
GENERATOR_TERMINATE
(package private) static int
GENERATOR_YIELD_START
private short
generatorStateLocal
private int
generatorSwitch
private boolean
hasVarsInRegs
private boolean
inDirectCallFunction
private boolean
inLocalBlock
private boolean
isGenerator
private boolean
itsForcedObjectParameters
private int
itsLineNumber
private short
itsOneArgArray
private short
itsZeroArgArray
private static int
JAVASCRIPT_EXCEPTION
private java.util.List<Node>
literals
private int[]
locals
private short
localsMax
private static int
MAX_LOCALS
private int
maxLocals
private int
maxStack
private short
operationLocal
private short
popvLocal
private int
savedCodeOffset
(package private) ScriptNode
scriptOrFn
int
scriptOrFnIndex
private short
thisObjLocal
private static int
THROWABLE_EXCEPTION
private int
unnestedYieldCount
private java.util.IdentityHashMap<Node,java.lang.String>
unnestedYields
private short
variableObjectLocal
private short[]
varRegisters
-
Constructor Summary
Constructors Constructor Description BodyCodegen()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addDoubleWrap()
private void
addGoto(Node target, int jumpcode)
private void
addGotoWithReturn(Node target)
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 - 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(java.lang.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
addObjectToDouble()
private void
addObjectToNumeric()
private void
addOptRuntimeInvoke(java.lang.String methodName, java.lang.String methodSignature)
private void
addScriptRuntimeInvoke(java.lang.String methodName, java.lang.String methodSignature)
private void
dcpLoadAsNumber(int dcp_register)
private void
dcpLoadAsObject(int dcp_register)
private void
decReferenceWordLocal(short local)
private static java.lang.String
exceptionTypeToName(int exceptionType)
private Node
findNestedYield(Node node)
private void
generateActivationExit()
private void
generateArrayLiteralFactory(Node node, int count)
(package private) void
generateBodyCode()
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
generateEpilogue()
private void
generateExpression(Node node, Node parent)
private void
generateFunctionAndThisObj(Node node, Node parent)
private void
generateGenerator()
private void
generateGetGeneratorLocalsState()
private void
generateGetGeneratorResumptionPoint()
private void
generateGetGeneratorStackState()
private void
generateIfJump(Node node, Node parent, int trueLabel, int falseLabel)
private void
generateIntegerUnwrap()
private void
generateIntegerWrap()
private void
generateLocalYieldPoint(Node node, boolean exprContext)
private void
generateNestedFunctionInits()
private void
generateObjectLiteralFactory(Node node, int count)
private void
generatePrologue()
Generate the prologue for a function or script.private boolean
generateSaveLocals(Node node)
private void
generateSetGeneratorResumptionPoint(int nextState)
private void
generateSetGeneratorReturnValue()
private void
generateStatement(Node node)
private void
generateThrowJavaScriptException()
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
getNewWordLocal()
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
initBodyGeneration()
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
nodeIsDirectCallParameter(Node node)
private void
releaseWordLocal(short local)
private void
saveCurrentCodeOffset()
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
visitGoto(Jump node, int type, Node child)
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 Detail
-
JAVASCRIPT_EXCEPTION
private static final int JAVASCRIPT_EXCEPTION
- See Also:
- Constant Field Values
-
EVALUATOR_EXCEPTION
private static final int EVALUATOR_EXCEPTION
- See Also:
- Constant Field Values
-
ECMAERROR_EXCEPTION
private static final int ECMAERROR_EXCEPTION
- See Also:
- Constant Field Values
-
THROWABLE_EXCEPTION
private static final int THROWABLE_EXCEPTION
- See Also:
- Constant Field Values
-
FINALLY_EXCEPTION
private static final int FINALLY_EXCEPTION
- See Also:
- Constant Field Values
-
EXCEPTION_MAX
private static final int EXCEPTION_MAX
- See Also:
- Constant Field Values
-
exceptionManager
private BodyCodegen.ExceptionManager exceptionManager
-
GENERATOR_TERMINATE
static final int GENERATOR_TERMINATE
- See Also:
- Constant Field Values
-
GENERATOR_START
static final int GENERATOR_START
- See Also:
- Constant Field Values
-
GENERATOR_YIELD_START
static final int GENERATOR_YIELD_START
- See Also:
- Constant Field Values
-
cfw
ClassFileWriter cfw
-
codegen
Codegen codegen
-
compilerEnv
CompilerEnvirons compilerEnv
-
scriptOrFn
ScriptNode scriptOrFn
-
scriptOrFnIndex
public int scriptOrFnIndex
-
savedCodeOffset
private int savedCodeOffset
-
fnCurrent
private OptFunctionNode fnCurrent
-
MAX_LOCALS
private static final int MAX_LOCALS
- See Also:
- Constant Field Values
-
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
private java.util.Map<Node,BodyCodegen.FinallyReturnPoint> finallys
-
literals
private java.util.List<Node> literals
-
unnestedYieldCount
private int unnestedYieldCount
-
unnestedYields
private java.util.IdentityHashMap<Node,java.lang.String> unnestedYields
-
-
Method Detail
-
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
private void generateStatement(Node node)
-
generateIntegerWrap
private void generateIntegerWrap()
-
generateIntegerUnwrap
private void generateIntegerUnwrap()
-
generateThrowJavaScriptException
private void generateThrowJavaScriptException()
-
getNextGeneratorState
private int getNextGeneratorState(Node node)
-
generateYieldPoint
private void generateYieldPoint(Node node, boolean exprContext)
-
generateLocalYieldPoint
private void generateLocalYieldPoint(Node node, boolean exprContext)
-
generateCheckForThrowOrClose
private void generateCheckForThrowOrClose(int label, boolean hasLocals, int nextState)
-
visitTemplateLiteral
private void visitTemplateLiteral(Node node)
-
visitFunction
private void visitFunction(OptFunctionNode ofn, int functionType)
-
getTargetLabel
private int getTargetLabel(Node target)
-
addGotoWithReturn
private void addGotoWithReturn(Node target)
-
generateArrayLiteralFactory
private void generateArrayLiteralFactory(Node node, int count)
-
generateObjectLiteralFactory
private void generateObjectLiteralFactory(Node node, int count)
-
addLoadPropertyIds
private void addLoadPropertyIds(java.lang.Object[] properties, int count)
load array with property ids
-
addLoadPropertyValues
private void addLoadPropertyValues(Node node, Node child, int count)
load array with property values
-
visitOptimizedCall
private void visitOptimizedCall(Node node, OptFunctionNode target, int type, Node child)
-
generateCallArgArray
private void generateCallArgArray(Node node, Node argChild, boolean directCall)
-
updateLineNumber
private void updateLineNumber(Node node)
-
generateCatchBlock
private void generateCatchBlock(int exceptionType, short savedVariableObject, int catchLabel, int exceptionLocal, int handler)
-
exceptionTypeToName
private static java.lang.String exceptionTypeToName(int exceptionType)
-
inlineFinally
private void inlineFinally(Node finallyTarget, int finallyStart, int finallyEnd)
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
private void inlineFinally(Node finallyTarget)
-
getFinallyAtTarget
private static Node getFinallyAtTarget(Node node)
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
private boolean generateSaveLocals(Node node)
-
visitTypeofname
private void visitTypeofname(Node node)
-
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
private void visitIncDec(Node node)
-
isArithmeticNode
private static boolean isArithmeticNode(Node node)
-
nodeIsDirectCallParameter
private int nodeIsDirectCallParameter(Node node)
-
varIsDirectCallParameter
private boolean varIsDirectCallParameter(int varIndex)
-
genSimpleCompare
private void genSimpleCompare(int type, int trueGOTO, int falseGOTO)
-
visitGetVar
private void visitGetVar(Node node)
-
getLocalBlockRegister
private static int getLocalBlockRegister(Node node)
-
dcpLoadAsNumber
private void dcpLoadAsNumber(int dcp_register)
-
dcpLoadAsObject
private void dcpLoadAsObject(int dcp_register)
-
addGoto
private void addGoto(Node target, int jumpcode)
-
addObjectToDouble
private void addObjectToDouble()
-
addObjectToNumeric
private void addObjectToNumeric()
-
addNewObjectArray
private void addNewObjectArray(int size)
-
addScriptRuntimeInvoke
private void addScriptRuntimeInvoke(java.lang.String methodName, java.lang.String methodSignature)
-
addOptRuntimeInvoke
private void addOptRuntimeInvoke(java.lang.String methodName, java.lang.String methodSignature)
-
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)
-
-