Class BodyCodegen

java.lang.Object
org.mozilla.javascript.optimizer.BodyCodegen

class BodyCodegen extends Object
  • 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

      private BodyCodegen.ExceptionManager 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

    • 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:
    • 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

      private List<Node> literals
    • unnestedYieldCount

      private int unnestedYieldCount
    • unnestedYields

      private IdentityHashMap<Node,String> 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

      private void generateStatement(Node node)
    • generateIntegerWrap

      private void generateIntegerWrap()
    • generateIntegerUnwrap

      private void generateIntegerUnwrap()
    • generateThrowJavaScriptException

      private void generateThrowJavaScriptException()
    • getNextGeneratorState

      private int getNextGeneratorState(Node node)
    • generateExpression

      private void generateExpression(Node node, Node parent)
    • findNestedYield

      private Node findNestedYield(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)
    • generateIfJump

      private void generateIfJump(Node node, Node parent, int trueLabel, int falseLabel)
    • visitFunction

      private void visitFunction(OptFunctionNode ofn, int functionType)
    • getTargetLabel

      private int getTargetLabel(Node target)
    • visitGoto

      private void visitGoto(Jump node, int type, Node child)
    • addGotoWithReturn

      private void addGotoWithReturn(Node target)
    • generateArrayLiteralFactory

      private void generateArrayLiteralFactory(Node node, int count)
    • generateObjectLiteralFactory

      private void generateObjectLiteralFactory(Node node, int count)
    • visitArrayLiteral

      private void visitArrayLiteral(Node node, Node child, boolean topLevel)
    • addLoadPropertyIds

      private void addLoadPropertyIds(Object[] properties, int count)
      load array with property ids
    • addLoadPropertyValues

      private void addLoadPropertyValues(Node node, Node child, int count)
      load array with property values
    • visitObjectLiteral

      private void visitObjectLiteral(Node node, Node child, boolean topLevel)
    • visitSpecialCall

      private void visitSpecialCall(Node node, int type, int specialType, Node child)
    • visitStandardCall

      private void visitStandardCall(Node node, Node child)
    • visitStandardNew

      private void visitStandardNew(Node node, Node child)
    • visitOptimizedCall

      private void visitOptimizedCall(Node node, OptFunctionNode target, int type, Node child)
    • generateCallArgArray

      private void generateCallArgArray(Node node, Node argChild, boolean directCall)
    • generateFunctionAndThisObj

      private void generateFunctionAndThisObj(Node node, Node parent)
    • updateLineNumber

      private void updateLineNumber(Node node)
    • visitTryCatchFinally

      private void visitTryCatchFinally(Jump node, Node child)
    • generateCatchBlock

      private void generateCatchBlock(int exceptionType, short savedVariableObject, int catchLabel, int exceptionLocal, int handler)
    • exceptionTypeToName

      private static 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 itself
      finallyStart - 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)
    • visitSwitch

      private void visitSwitch(Jump switchNode, Node child)
    • 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 to addInstructionCount().
    • addInstructionCount

      private void addInstructionCount()
      Generate calls to ScriptRuntime.addInstructionCount to keep track of executed instructions and call observeInstructionCount() 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 call observeInstructionCount() 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)
    • visitArithmetic

      private void visitArithmetic(Node node, int type, Node child, Node parent)
    • visitExponentiation

      private void visitExponentiation(Node node, Node child, Node parent)
    • visitBitNot

      private void visitBitNot(Node node, Node child)
    • visitBitOp

      private void visitBitOp(Node node, int type, Node child)
    • nodeIsDirectCallParameter

      private int nodeIsDirectCallParameter(Node node)
    • varIsDirectCallParameter

      private boolean varIsDirectCallParameter(int varIndex)
    • genSimpleCompare

      private void genSimpleCompare(int type, int trueGOTO, int falseGOTO)
    • visitIfJumpRelOp

      private void visitIfJumpRelOp(Node node, Node child, int trueGOTO, int falseGOTO)
    • visitIfJumpEqOp

      private void visitIfJumpEqOp(Node node, Node child, int trueGOTO, int falseGOTO)
    • visitSetName

      private void visitSetName(Node node, Node child)
    • visitStrictSetName

      private void visitStrictSetName(Node node, Node child)
    • visitSetConst

      private void visitSetConst(Node node, Node child)
    • visitGetVar

      private void visitGetVar(Node node)
    • visitSetVar

      private void visitSetVar(Node node, Node child, boolean needValue)
    • visitSetConstVar

      private void visitSetConstVar(Node node, Node child, boolean needValue)
    • visitGetProp

      private void visitGetProp(Node node, Node child)
    • visitSetProp

      private void visitSetProp(int type, Node node, Node child)
    • visitSetElem

      private void visitSetElem(int type, Node node, Node child)
    • visitDotQuery

      private void visitDotQuery(Node node, Node child)
    • 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(String methodName, String methodSignature)
    • addOptRuntimeInvoke

      private void addOptRuntimeInvoke(String methodName, 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)