Changeset 28937 in webkit for trunk/JavaScriptCore/kjs/nodes.cpp


Ignore:
Timestamp:
Dec 21, 2007, 1:54:51 PM (17 years ago)
Author:
Darin Adler
Message:

Reviewed by Eric.

1.022x as fast on SunSpider.

  • kjs/NodeInfo.h: Renamed SourceElementsStub to SourceElements, since that more accurately describes the role of this object, which is a reference-counted wrapper for a Vector.
  • kjs/Parser.cpp: (KJS::Parser::didFinishParsing): Changed parameter type to SourceElements, and use plain assignment instead of set.
  • kjs/Parser.h: Changed parameter type of didFinishParsing to a SourceElements. Also changed m_sourceElements; we now use a RefPtr instead of an OwnPtr as well.
  • kjs/grammar.y: Got rid of all the calls to release() on SourceElements. That's now handed inside the constructors for various node types, since we now use vector swapping instead.
  • kjs/nodes.cpp: (KJS::Node::rethrowException): Added NEVER_INLINE, because this was getting inlined and we want exception handling out of the normal code flow. (KJS::SourceElements::append): Moved here from the header. This now handles creating a BreakpointCheckStatement for each statement in the debugger case. That way we can get breakpoint handling without having it in every execute function. (KJS::BreakpointCheckStatement::BreakpointCheckStatement): Added. (KJS::BreakpointCheckStatement::execute): Added. Contains the code that was formerly in the StatementNode::hitStatement function and the KJS_BREAKPOINT macro. (KJS::BreakpointCheckStatement::streamTo): Added. (KJS::ArgumentListNode::evaluateList): Use KJS_CHECKEXCEPTIONVOID since the return type is void. (KJS::VarStatementNode::execute): Removed KJS_BREAKPOINT. (KJS::BlockNode::BlockNode): Changed parameter type to SourceElements. Changed code to use release since the class now contains a vector rather than a vector point. (KJS::BlockNode::optimizeVariableAccess): Updated since member is now a vector rather than a vector pointer. (KJS::BlockNode::execute): Ditto. (KJS::ExprStatementNode::execute): Removed KJS_BREAKPOINT. (KJS::IfNode::execute): Ditto. (KJS::IfElseNode::execute): Ditto. (KJS::DoWhileNode::execute): Ditto. (KJS::WhileNode::execute): Ditto. (KJS::ContinueNode::execute): Ditto. (KJS::BreakNode::execute): Ditto. (KJS::ReturnNode::execute): Ditto. (KJS::WithNode::execute): Ditto. (KJS::CaseClauseNode::optimizeVariableAccess): Updated since member is now a vector rather than a vector pointer. (KJS::CaseClauseNode::executeStatements): Ditto. (KJS::SwitchNode::execute): Removed KJS_BREAKPOINT. (KJS::ThrowNode::execute): Ditto. (KJS::TryNode::execute): Ditto. (KJS::ScopeNode::ScopeNode): Changed parameter type to SourceElements. (KJS::ProgramNode::ProgramNode): Ditto. (KJS::EvalNode::EvalNode): Ditto. (KJS::FunctionBodyNode::FunctionBodyNode): Ditto. (KJS::ScopeNode::optimizeVariableAccess): Updated since member is now a vector rather than a vector pointer.
  • kjs/nodes.h: Removed hitStatement. Renamed SourceElements to StatementVector. Renamed SourceElementsStub to SourceElements and made it derive from ParserRefCounted rather than from Node, hold a vector rather than a pointer to a vector, and changed the release function to swap with another vector rather than the pointer idiom. Updated BlockNode and CaseClauseNode to hold actual vectors instead of pointers to vectors. Added BreakpointCheckStatement.
  • kjs/nodes2string.cpp: (KJS::statementListStreamTo): Changed to work on a vector instead of a pointer to a vector. (KJS::BlockNode::streamTo): Ditto. (KJS::CaseClauseNode::streamTo): Ditto.
  • wtf/AlwaysInline.h: Added NEVER_INLINE.
  • wtf/PassRefPtr.h: Tweaked formatting. Added clear() function that matches the ones in OwnPtr and auto_ptr.
  • wtf/RefPtr.h: Ditto.
File:
1 edited

Legend:

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

    r28935 r28937  
    4545namespace KJS {
    4646
    47 #define KJS_BREAKPOINT \
    48   if (Debugger::debuggersPresent > 0 && !hitStatement(exec)) \
    49     return 0;
    50 
    5147#define KJS_CHECKEXCEPTION \
    5248  if (exec->hadException()) \
     
    6965    handleException(exec); \
    7066    return false; \
    71   }
    72 
    73 #define KJS_CHECKEXCEPTIONLIST \
    74   if (exec->hadException()) { \
    75     handleException(exec); \
    76     return; \
    7767  }
    7868
     
    212202    : m_expectedReturnType(ObjectType)
    213203{
    214   m_line = lexer().lineNo();
     204    m_line = lexer().lineNo();
    215205}
    216206
     
    365355}
    366356
    367 JSValue* Node::rethrowException(ExecState* exec)
     357NEVER_INLINE JSValue* Node::rethrowException(ExecState* exec)
    368358{
    369359    JSValue* exception = exec->exception();
     
    387377}
    388378
    389 // Set normal completion and return false if the debugger wants us to stop at this point.
    390 // FIXME: This seems like poor naming and strange design. Why false to stop? Why "hit statement"?
    391 bool StatementNode::hitStatement(ExecState* exec)
    392 {
    393     Debugger* debugger = exec->dynamicGlobalObject()->debugger();
    394     if (!debugger || debugger->atStatement(exec, currentSourceId(exec), firstLine(), lastLine()))
    395         return true;
    396     exec->setCompletionType(Normal);
    397     return false;
     379// ------------------------------ SourceElements --------------------------------
     380
     381void SourceElements::append(PassRefPtr<StatementNode> statement)
     382{
     383    if (Debugger::debuggersPresent)
     384        m_statements.append(new BreakpointCheckStatement(statement));
     385    else
     386        m_statements.append(statement);
     387}
     388
     389// ------------------------------ BreakpointCheckStatement --------------------------------
     390
     391BreakpointCheckStatement::BreakpointCheckStatement(PassRefPtr<StatementNode> statement)
     392    : m_statement(statement)
     393{
     394    ASSERT(m_statement);
     395}
     396
     397JSValue* BreakpointCheckStatement::execute(ExecState* exec)
     398{
     399    if (Debugger* debugger = exec->dynamicGlobalObject()->debugger())
     400        if (!debugger->atStatement(exec, currentSourceId(exec), m_statement->firstLine(), m_statement->lastLine()))
     401            return exec->setNormalCompletion();
     402    return m_statement->execute(exec);
     403}
     404
     405void BreakpointCheckStatement::streamTo(SourceStream& stream) const
     406{
     407    m_statement->streamTo(stream);
    398408}
    399409
     
    839849  for (ArgumentListNode *n = this; n; n = n->next.get()) {
    840850    JSValue *v = n->expr->evaluate(exec);
    841     KJS_CHECKEXCEPTIONLIST
     851    KJS_CHECKEXCEPTIONVOID
    842852    list.append(v);
    843853  }
     
    35523562JSValue* VarStatementNode::execute(ExecState* exec)
    35533563{
    3554     KJS_BREAKPOINT
    3555 
    35563564    next->evaluate(exec);
    35573565    KJS_CHECKEXCEPTION
     
    35623570// ------------------------------ Helper functions for handling Vectors of StatementNode -------------------------------
    35633571
    3564 static inline void statementListPushFIFO(SourceElements& statements, DeclarationStacks::NodeStack& stack)
    3565 {
    3566     SourceElements::iterator it = statements.end();
    3567     SourceElements::iterator begin = statements.begin();
     3572static inline void statementListPushFIFO(StatementVector& statements, DeclarationStacks::NodeStack& stack)
     3573{
     3574    StatementVector::iterator it = statements.end();
     3575    StatementVector::iterator begin = statements.begin();
    35683576    while (it != begin) {
    35693577        --it;
     
    35723580}
    35733581
    3574 static inline Node* statementListInitializeVariableAccessStack(SourceElements& statements, DeclarationStacks::NodeStack& stack)
     3582static inline Node* statementListInitializeVariableAccessStack(StatementVector& statements, DeclarationStacks::NodeStack& stack)
    35753583{
    35763584    if (!statements.size())
    35773585        return 0;
    35783586
    3579     SourceElements::iterator it = statements.end();
    3580     SourceElements::iterator begin = statements.begin();
    3581     SourceElements::iterator beginPlusOne = begin + 1;
     3587    StatementVector::iterator it = statements.end();
     3588    StatementVector::iterator begin = statements.begin();
     3589    StatementVector::iterator beginPlusOne = begin + 1;
    35823590   
    35833591    while (it != beginPlusOne) {
     
    35893597}
    35903598
    3591 static inline JSValue* statementListExecute(SourceElements& statements, ExecState* exec)
     3599static inline JSValue* statementListExecute(StatementVector& statements, ExecState* exec)
    35923600{
    35933601    JSValue* value = 0;
     
    36063614
    36073615BlockNode::BlockNode(SourceElements* children)
    3608     : m_children(children ? children : new SourceElements)
    3609 {
    3610     ASSERT(m_children);
     3616{
     3617    if (children)
     3618        children->releaseContentsIntoVector(m_children);
    36113619}
    36123620
    36133621void BlockNode::optimizeVariableAccess(SymbolTable&, DeclarationStacks::NodeStack& nodeStack)
    36143622{
    3615     statementListPushFIFO(*m_children, nodeStack);
     3623    statementListPushFIFO(m_children, nodeStack);
    36163624}
    36173625
     
    36193627JSValue* BlockNode::execute(ExecState* exec)
    36203628{
    3621     return statementListExecute(*m_children, exec);
     3629    return statementListExecute(m_children, exec);
    36223630}
    36233631
     
    36413649JSValue* ExprStatementNode::execute(ExecState* exec)
    36423650{
    3643     KJS_BREAKPOINT
    3644 
    36453651    JSValue* value = expr->evaluate(exec);
    36463652    KJS_CHECKEXCEPTION
     
    36603666JSValue* IfNode::execute(ExecState* exec)
    36613667{
    3662     KJS_BREAKPOINT
    3663 
    36643668    bool b = m_condition->evaluateToBoolean(exec);
    36653669    KJS_CHECKEXCEPTION
     
    36793683JSValue* IfElseNode::execute(ExecState* exec)
    36803684{
    3681     KJS_BREAKPOINT;
    3682 
    36833685    bool b = m_condition->evaluateToBoolean(exec);
    36843686    KJS_CHECKEXCEPTION
     
    37013703JSValue* DoWhileNode::execute(ExecState* exec)
    37023704{
    3703     KJS_BREAKPOINT
    3704 
    37053705    JSValue* value = 0;
    37063706
     
    37453745JSValue* WhileNode::execute(ExecState* exec)
    37463746{
    3747     KJS_BREAKPOINT
    3748 
    37493747    JSValue* value = 0;
    37503748
     
    39493947JSValue* ContinueNode::execute(ExecState* exec)
    39503948{
    3951   KJS_BREAKPOINT
    3952 
    39533949  if (ident.isEmpty() && !exec->inIteration())
    39543950    return setErrorCompletion(exec, SyntaxError, "Invalid continue statement.");
     
    39633959JSValue* BreakNode::execute(ExecState *exec)
    39643960{
    3965   KJS_BREAKPOINT
    3966 
    39673961  if (ident.isEmpty() && !exec->inIteration() && !exec->inSwitch())
    39683962    return setErrorCompletion(exec, SyntaxError, "Invalid break statement.");
     
    39833977JSValue* ReturnNode::execute(ExecState* exec)
    39843978{
    3985   KJS_BREAKPOINT
    3986 
    39873979  CodeType codeType = exec->codeType();
    39883980  if (codeType != FunctionCode)
     
    40094001JSValue* WithNode::execute(ExecState *exec)
    40104002{
    4011   KJS_BREAKPOINT
    4012 
    40134003  JSValue *v = expr->evaluate(exec);
    40144004  KJS_CHECKEXCEPTION
     
    40284018    if (expr)
    40294019        nodeStack.append(expr.get());
    4030     if (m_children)
    4031         statementListPushFIFO(*m_children, nodeStack);
     4020    statementListPushFIFO(m_children, nodeStack);
    40324021}
    40334022
     
    40444033JSValue* CaseClauseNode::executeStatements(ExecState* exec)
    40454034{
    4046   if (m_children)
    4047     return statementListExecute(*m_children, exec);
    4048   return exec->setNormalCompletion();
     4035    return statementListExecute(m_children, exec);
    40494036}
    40504037
     
    41464133JSValue* SwitchNode::execute(ExecState* exec)
    41474134{
    4148   KJS_BREAKPOINT
    4149 
    41504135  JSValue *v = expr->evaluate(exec);
    41514136  KJS_CHECKEXCEPTION
     
    41904175JSValue* ThrowNode::execute(ExecState* exec)
    41914176{
    4192   KJS_BREAKPOINT
    4193 
    41944177  JSValue *v = expr->evaluate(exec);
    41954178  KJS_CHECKEXCEPTION
     
    42124195JSValue* TryNode::execute(ExecState *exec)
    42134196{
    4214   KJS_BREAKPOINT
    4215 
    42164197  JSValue* result = tryBlock->execute(exec);
    42174198
     
    43414322{
    43424323    DeclarationStacks::NodeStack nodeStack;
    4343     Node* node = statementListInitializeVariableAccessStack(*m_children, nodeStack);
     4324    Node* node = statementListInitializeVariableAccessStack(m_children, nodeStack);
    43444325    if (!node)
    43454326        return;
Note: See TracChangeset for help on using the changeset viewer.