Changeset 13304 in webkit for trunk/JavaScriptCore/kjs/nodes.h


Ignore:
Timestamp:
Mar 15, 2006, 2:21:48 AM (19 years ago)
Author:
mjs
Message:

Reviewed by Anders.


The memory usage of Node was reduced by 2 machine words per node:

  • sourceURL was removed and only kept on FunctionBodyNode. The source URL can only be distinct per function or top-level program node, and you always have one.


  • refcount was removed and kept in a separate hashtable when greater than 1. newNodes set represents floating nodes with refcount of 0. This helps because almost all nodes have a refcount of 1 for almost all of their lifetime.


  • bindings/runtime_method.cpp: (RuntimeMethod::RuntimeMethod): Pass null body, added FIXME.
  • kjs/Parser.cpp: (KJS::clearNewNodes): New nodes are tracked in nodes.cpp now, but still clear them at the appropriate time.
  • kjs/context.h: (KJS::ContextImp::currentBody): added; used to retrieve source URL and sid for current code. (KJS::ContextImp::pushIteration): moved here from LabelStack (KJS::ContextImp::popIteration): ditto (KJS::ContextImp::inIteration): ditto (KJS::ContextImp::pushSwitch): ditto (KJS::ContextImp::popSwitch): ditto (KJS::ContextImp::inSwitch): ditto
  • kjs/function.cpp: (KJS::FunctionImp::FunctionImp): Add FunctionBodyNode* parameter. (KJS::FunctionImp::callAsFunction): Pass body to ContextImp. (KJS::FunctionImp::argumentsGetter): _context renamed to m_context. (KJS::DeclaredFunctionImp::DeclaredFunctionImp): Pass body to superclass constructor. (KJS::GlobalFuncImp::callAsFunction): Pass progNode as body for ContextImp in eval.
  • kjs/function.h: Move body field from DeclaredFunctionImp to FunctionImp.
  • kjs/grammar.y: Change DBG; statements no longer have a sourceid.
  • kjs/internal.cpp: (KJS::ContextImp::ContextImp): Initialize new m_currentBody, m_iterationDepth and m_switchDepth data members. New FunctionBodyNode* parameter - the function body provides source URL and SourceId. (KJS::InterpreterImp::mark): Use exception() function, not _exception directly. (KJS::InterpreterImp::evaluate): Pass progNode to ContextImp constructor to use as the body.
  • kjs/internal.h: (KJS::LabelStack::LabelStack): Remove iteration depth and switch depth; statement label stacks don't need these and it bloats their size. Put them in the ContextImp instead.
  • kjs/interpreter.cpp: (KJS::ExecState::lexicalInterpreter): Renamed _context to m_context.
  • kjs/interpreter.h: (KJS::ExecState::dynamicInterpreter): Renamed _context to m_context. (KJS::ExecState::context): ditto (KJS::ExecState::setException): Renamed _exception to m_exception (KJS::ExecState::clearException): ditto (KJS::ExecState::exception): ditto (KJS::ExecState::hadException): ditto (KJS::ExecState::ExecState): ditto both above renames
  • kjs/nodes.cpp: (Node::Node): Removed initialization of line, source URL and refcount. Add to local newNodes set instead of involving parser. (Node::ref): Instead of managing refcount directly, story refcount over 1 in a HashCountedSet, and keep a separate HashSet of "floating" nodes with refcount 0. (Node::deref): ditto (Node::refcount): ditto (Node::clearNewNodes): Destroy anything left in the new nodes set. (currentSourceId): Inline helper to get sourceId from function body via context. (currentSourceURL): ditto for sourceURL. (Node::createErrorCompletion): use new helper (Node::throwError): ditto (Node::setExceptionDetailsIfNeeded): ditto (StatementNode::StatementNode): remove initialization of l0 and sid, rename l1 to m_lastLine. (StatementNode::setLoc): Set own m_lastLine and Node's m_line. (StatementNode::hitStatement): Get sid, first line, last line in the proper new ways. (StatListNode::StatListNode): updated for setLoc changes (BlockNode::BlockNode): ditto (DoWhileNode::execute): excpect iteraton counts on ContextImp, not LabelStack (WhileNode::execute): ditto (ForNode::execute): ditto (ForInNode::execute): ditto (ContinueNode::execute): excpect inIteration on ContextImp, not LabelStack (BreakNode::execute): excpect inIteration and inSwitch on ContextImp, not LabelStack (SwitchNode::execute): expect switch counts on ContextImp, not LabelStack (FunctionBodyNode::FunctionBodyNode): update for new setLoc (FunctionBodyNode::processFuncDecl): reindent (SourceElementsNode::SourceElementsNode): update for new setLoc
  • kjs/nodes.h: (KJS::Node::lineNo): Renamed _line to m_line (KJS::StatementNode::firstLine): Use lineNo() (KJS::StatementNode::lastLine): Renamed l1 to m_lastLine (KJS::FunctionBodyNode::sourceId): added (KJS::FunctionBodyNode::sourceURL): added
  • kjs/testkjs.cpp:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/nodes.h

    r13153 r13304  
    8181    virtual void streamTo(SourceStream &s) const = 0;
    8282    virtual void processVarDecls(ExecState *) {}
    83     int lineNo() const { return line; }
    84 
    85     // reference counting mechanism
    86     void ref() { ++m_refcount; }
    87     void deref() { --m_refcount; if (!m_refcount) delete this; }
    88     unsigned int refcount() { return m_refcount; }
     83    int lineNo() const { return m_line; }
     84
     85    void ref();
     86    void deref();
     87    unsigned int refcount();
     88    static void clearNewNodes();
    8989
    9090    virtual Node *nodeInsideAllParens();
     
    113113    void setExceptionDetailsIfNeeded(ExecState *);
    114114
    115     int line;
    116     UString sourceURL;
    117     unsigned int m_refcount;
    118     virtual int sourceId() const { return -1; }
    119 
     115    int m_line;
    120116  private:
    121117    // disallow assignment
     
    127123  public:
    128124    StatementNode();
    129     void setLoc(int line0, int line1, int sourceId);
    130     int firstLine() const { return l0; }
    131     int lastLine() const { return l1; }
    132     int sourceId() const { return sid; }
     125    void setLoc(int line0, int line1);
     126    int firstLine() const { return lineNo(); }
     127    int lastLine() const { return m_lastLine; }
    133128    bool hitStatement(ExecState *exec);
    134129    virtual Completion execute(ExecState *exec) = 0;
     
    139134  private:
    140135    JSValue *evaluate(ExecState */*exec*/) { return jsUndefined(); }
    141     int l0, l1;
    142     int sid;
     136    int m_lastLine;
    143137  };
    144138
     
    10541048  class FunctionBodyNode : public BlockNode {
    10551049  public:
    1056     FunctionBodyNode(SourceElementsNode *s);
    1057     void processFuncDecl(ExecState *exec);
     1050    FunctionBodyNode(SourceElementsNode *);
     1051    virtual void processFuncDecl(ExecState *exec);
     1052    int sourceId() { return m_sourceId; }
     1053    const UString& sourceURL() { return m_sourceURL; }
     1054  private:
     1055    UString m_sourceURL;
     1056    int m_sourceId;
    10581057  };
    10591058
Note: See TracChangeset for help on using the changeset viewer.