Changeset 2851 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Nov 24, 2002, 2:37:44 PM (23 years ago)
Author:
darin
Message:

JavaScriptCore:

  • changed ScopeChain to not ref each item in the chain, and use marking instead; gains 1% on JavaScript iBench
  • kjs/context.h: Return chain by reference.
  • kjs/internal.cpp: (ContextImp::mark): Mark the scope chain.
  • kjs/interpreter.cpp: (Context::scopeChain): Return chain by reference.
  • kjs/interpreter.h: Make some Context methods inline.
  • kjs/nodes.cpp: (ThisNode::evaluate): Get at ContextImp directly. (ResolveNode::evaluateReference): Ditto. (VarDeclNode::evaluate): Ditto. (VarDeclNode::processVarDecls): Ditto. (FuncDeclNode::processFuncDecl): Pass ScopeChain directly to avoid copying. (FuncExprNode::evaluate): Ditto.
  • kjs/object.cpp: Make scope and setScope inline.
  • kjs/object.h: Make scope return a chain by reference. Make scope and setScope both be inline. Use a normal ScopeChain instead of NoRefScopeChain since they are now one and the same.
  • kjs/scope_chain.cpp: Remove all the code to ref and deref objects. Merge NoRefScopeChain in with ScopeChain since they both work this way now.
  • kjs/scope_chain.h: Remove NoRefScopeChain and simplify the ref counts. Make more functions inline.

WebCore:

  • force-js-clean-timestamp: Touch for ScopeChain change.
Location:
trunk/JavaScriptCore
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r2849 r2851  
     12002-11-24  Darin Adler  <[email protected]>
     2
     3        - changed ScopeChain to not ref each item in the chain, and use
     4        marking instead; gains 1% on JavaScript iBench
     5
     6        * kjs/context.h: Return chain by reference.
     7        * kjs/internal.cpp: (ContextImp::mark): Mark the scope chain.
     8        * kjs/interpreter.cpp: (Context::scopeChain): Return chain by reference.
     9        * kjs/interpreter.h: Make some Context methods inline.
     10        * kjs/nodes.cpp:
     11        (ThisNode::evaluate): Get at ContextImp directly.
     12        (ResolveNode::evaluateReference): Ditto.
     13        (VarDeclNode::evaluate): Ditto.
     14        (VarDeclNode::processVarDecls): Ditto.
     15        (FuncDeclNode::processFuncDecl): Pass ScopeChain directly to avoid copying.
     16        (FuncExprNode::evaluate): Ditto.
     17        * kjs/object.cpp: Make scope and setScope inline.
     18        * kjs/object.h: Make scope return a chain by reference. Make scope and
     19        setScope both be inline. Use a normal ScopeChain instead of NoRefScopeChain
     20        since they are now one and the same.
     21        * kjs/scope_chain.cpp: Remove all the code to ref and deref objects.
     22        Merge NoRefScopeChain in with ScopeChain since they both work this way now.
     23        * kjs/scope_chain.h: Remove NoRefScopeChain and simplify the ref counts.
     24        Make more functions inline.
     25
    1262002-11-24  Maciej Stachowiak  <[email protected]>
    227
  • trunk/JavaScriptCore/ChangeLog-2002-12-03

    r2849 r2851  
     12002-11-24  Darin Adler  <[email protected]>
     2
     3        - changed ScopeChain to not ref each item in the chain, and use
     4        marking instead; gains 1% on JavaScript iBench
     5
     6        * kjs/context.h: Return chain by reference.
     7        * kjs/internal.cpp: (ContextImp::mark): Mark the scope chain.
     8        * kjs/interpreter.cpp: (Context::scopeChain): Return chain by reference.
     9        * kjs/interpreter.h: Make some Context methods inline.
     10        * kjs/nodes.cpp:
     11        (ThisNode::evaluate): Get at ContextImp directly.
     12        (ResolveNode::evaluateReference): Ditto.
     13        (VarDeclNode::evaluate): Ditto.
     14        (VarDeclNode::processVarDecls): Ditto.
     15        (FuncDeclNode::processFuncDecl): Pass ScopeChain directly to avoid copying.
     16        (FuncExprNode::evaluate): Ditto.
     17        * kjs/object.cpp: Make scope and setScope inline.
     18        * kjs/object.h: Make scope return a chain by reference. Make scope and
     19        setScope both be inline. Use a normal ScopeChain instead of NoRefScopeChain
     20        since they are now one and the same.
     21        * kjs/scope_chain.cpp: Remove all the code to ref and deref objects.
     22        Merge NoRefScopeChain in with ScopeChain since they both work this way now.
     23        * kjs/scope_chain.h: Remove NoRefScopeChain and simplify the ref counts.
     24        Make more functions inline.
     25
    1262002-11-24  Maciej Stachowiak  <[email protected]>
    227
  • trunk/JavaScriptCore/ChangeLog-2003-10-25

    r2849 r2851  
     12002-11-24  Darin Adler  <[email protected]>
     2
     3        - changed ScopeChain to not ref each item in the chain, and use
     4        marking instead; gains 1% on JavaScript iBench
     5
     6        * kjs/context.h: Return chain by reference.
     7        * kjs/internal.cpp: (ContextImp::mark): Mark the scope chain.
     8        * kjs/interpreter.cpp: (Context::scopeChain): Return chain by reference.
     9        * kjs/interpreter.h: Make some Context methods inline.
     10        * kjs/nodes.cpp:
     11        (ThisNode::evaluate): Get at ContextImp directly.
     12        (ResolveNode::evaluateReference): Ditto.
     13        (VarDeclNode::evaluate): Ditto.
     14        (VarDeclNode::processVarDecls): Ditto.
     15        (FuncDeclNode::processFuncDecl): Pass ScopeChain directly to avoid copying.
     16        (FuncExprNode::evaluate): Ditto.
     17        * kjs/object.cpp: Make scope and setScope inline.
     18        * kjs/object.h: Make scope return a chain by reference. Make scope and
     19        setScope both be inline. Use a normal ScopeChain instead of NoRefScopeChain
     20        since they are now one and the same.
     21        * kjs/scope_chain.cpp: Remove all the code to ref and deref objects.
     22        Merge NoRefScopeChain in with ScopeChain since they both work this way now.
     23        * kjs/scope_chain.h: Remove NoRefScopeChain and simplify the ref counts.
     24        Make more functions inline.
     25
    1262002-11-24  Maciej Stachowiak  <[email protected]>
    227
  • trunk/JavaScriptCore/kjs/context.h

    r2824 r2851  
    3838    ~ContextImp();
    3939
    40     const ScopeChain scopeChain() const { return scope; }
     40    const ScopeChain &scopeChain() const { return scope; }
    4141    Object variableObject() const { return variable; }
    4242    void setVariableObject(const Object &v) { variable = v; }
  • trunk/JavaScriptCore/kjs/internal.cpp

    r2845 r2851  
    414414{
    415415  for (ContextImp *context = this; context; context = context->_callingContext) {
     416    context->scope.mark();
    416417    context->_activationImp.mark();
    417418#if DEBUG_COLLECTOR
  • trunk/JavaScriptCore/kjs/interpreter.cpp

    r2821 r2851  
    4242// ------------------------------ Context --------------------------------------
    4343
    44 Context::Context(ContextImp *c)
    45 {
    46   rep = c;
    47 }
    48 
    49 Context::Context(const Context &c)
    50 {
    51   rep = c.rep;
    52 }
    53 
    54 Context& Context::operator=(const Context &c)
    55 {
    56   rep = c.rep;
    57   return *this;
    58 }
    59 
    60 Context::~Context()
    61 {
    62 }
    63 
    64 bool Context::isNull() const
    65 {
    66   return (rep == 0);
    67 }
    68 
    69 ContextImp *Context::imp() const
    70 {
    71   return rep;
    72 }
    73 
    74 const ScopeChain Context::scopeChain() const
     44const ScopeChain &Context::scopeChain() const
    7545{
    7646  return rep->scopeChain();
  • trunk/JavaScriptCore/kjs/interpreter.h

    r2821 r2851  
    5454  class Context {
    5555  public:
    56     Context(ContextImp *);
    57     Context(const Context &c);
    58     Context& operator=(const Context &c);
    59     virtual ~Context();
    60 
    61     bool isNull() const;
    62     ContextImp *imp() const;
     56    Context(ContextImp *i) : rep(i) { }
     57
     58    ContextImp *imp() const { return rep; }
    6359
    6460    /**
     
    6965     * @return The execution context's scope chain
    7066     */
    71     const ScopeChain scopeChain() const;
     67    const ScopeChain &scopeChain() const;
    7268
    7369    /**
     
    105101     */
    106102    const Context callingContext() const;
     103
    107104  private:
    108105    ContextImp *rep;
     
    380377     * @return The current execution state context
    381378     */
    382     const Context context() const { return _context; }
     379    Context context() const { return _context; }
    383380
    384381    void setException(const Value &e) { _exception = e; }
  • trunk/JavaScriptCore/kjs/nodes.cpp

    r2847 r2851  
    206206Value ThisNode::evaluate(ExecState *exec)
    207207{
    208   return exec->context().thisValue();
     208  return exec->context().imp()->thisValue();
    209209}
    210210
     
    219219Reference ResolveNode::evaluateReference(ExecState *exec)
    220220{
    221   ScopeChain chain = exec->context().scopeChain();
     221  ScopeChain chain = exec->context().imp()->scopeChain();
    222222
    223223  while (!chain.isEmpty()) {
     
    16331633Value VarDeclNode::evaluate(ExecState *exec)
    16341634{
    1635   Object variable = Object::dynamicCast(exec->context().variableObject());
     1635  Object variable = Object::dynamicCast(exec->context().imp()->variableObject());
    16361636
    16371637  Value val;
     
    16571657void VarDeclNode::processVarDecls(ExecState *exec)
    16581658{
    1659   Object variable = exec->context().variableObject();
     1659  Object variable = exec->context().imp()->variableObject();
    16601660  variable.put(exec,ident, Undefined(), DontDelete);
    16611661}
     
    27802780void FuncDeclNode::processFuncDecl(ExecState *exec)
    27812781{
    2782   const ScopeChain sc = exec->context().imp()->scopeChain();
    2783 
    27842782  // TODO: let this be an object with [[Class]] property "Function"
    2785   FunctionImp *fimp = new DeclaredFunctionImp(exec, ident, body, sc);
     2783  FunctionImp *fimp = new DeclaredFunctionImp(exec, ident, body, exec->context().imp()->scopeChain());
    27862784  Object func(fimp); // protect from GC
    27872785
     
    28352833Value FuncExprNode::evaluate(ExecState *exec)
    28362834{
    2837   const ScopeChain sc = exec->context().scopeChain();
    2838   FunctionImp *fimp = new DeclaredFunctionImp(exec, Identifier::null, body, sc);
     2835  FunctionImp *fimp = new DeclaredFunctionImp(exec, Identifier::null, body, exec->context().imp()->scopeChain());
    28392836  Value ret(fimp);
    28402837  List empty;
  • trunk/JavaScriptCore/kjs/object.cpp

    r2824 r2851  
    365365}
    366366
    367 const ScopeChain ObjectImp::scope() const
    368 {
    369   return _scope;
    370 }
    371 
    372 void ObjectImp::setScope(const ScopeChain &s)
    373 {
    374   _scope = s;
    375 }
    376 
    377367ReferenceList ObjectImp::propList(ExecState *exec, bool recursive)
    378368{
  • trunk/JavaScriptCore/kjs/object.h

    r2846 r2851  
    320320     * @return The function's scope
    321321     */
    322     const ScopeChain scope() const;
     322    const ScopeChain &scope() const;
    323323    void setScope(const ScopeChain &s);
    324324
     
    570570     * @see Object::scope()
    571571     */
    572     const ScopeChain scope() const;
    573     void setScope(const ScopeChain &s);
     572    const ScopeChain &scope() const { return _scope; }
     573    void setScope(const ScopeChain &s) { _scope = s; }
    574574
    575575    ReferenceList propList(ExecState *exec, bool recursive = true);
     
    604604    ValueImp *_proto;
    605605    ValueImp *_internalValue;
    606     NoRefScopeChain _scope;
     606    ScopeChain _scope;
    607607  };
    608608
     
    707707    { return imp()->hasInstance(exec,value); }
    708708
    709   inline const ScopeChain Object::scope() const
     709  inline const ScopeChain &Object::scope() const
    710710    { return imp()->scope(); }
    711711
  • trunk/JavaScriptCore/kjs/scope_chain.cpp

    r2824 r2851  
    2626namespace KJS {
    2727
    28 ScopeChainNode::ScopeChainNode(ScopeChainNode *n, ObjectImp *o)
    29     : next(n), object(o), nodeAndObjectRefCount(1), nodeOnlyRefCount(0)
    30 {
    31     o->ref();
    32 }
    33 
    3428inline void ScopeChain::ref() const
    3529{
    3630    for (ScopeChainNode *n = _node; n; n = n->next) {
    37         if (n->nodeAndObjectRefCount++ != 0)
     31        if (n->refCount++ != 0)
    3832            break;
    39         n->object->ref();
    4033    }
    41 }
    42 
    43 ScopeChain::ScopeChain(const NoRefScopeChain &c)
    44     : _node(c._node)
    45 {
    46     ref();
    4734}
    4835
     
    6754    _node = newNode;
    6855   
    69     // Three cases:
    70     //   1) This was not the last reference of the old node.
    71     //      In this case we move our ref from the old to the new node.
    72     //   2) This was the last reference of the old node, but there are garbage collected references.
    73     //      In this case, the new node doesn't get any new ref, and the object is deref'd.
    74     //   3) This was the last reference of the old node.
    75     //      In this case the object is deref'd and the entire node goes.
    76     if (--oldNode->nodeAndObjectRefCount != 0) {
     56    if (--oldNode->refCount != 0) {
    7757        if (newNode)
    78             ++newNode->nodeAndObjectRefCount;
     58            ++newNode->refCount;
    7959    } else {
    80         oldNode->object->deref();
    81         if (oldNode->nodeOnlyRefCount == 0)
    82             delete oldNode;
     60        delete oldNode;
    8361    }
    8462}
     
    8967    do {
    9068        ScopeChainNode *next = n->next;
    91         n->object->deref();
    92         if (n->nodeOnlyRefCount == 0)
    93             delete n;
     69        delete n;
    9470        n = next;
    95     } while (n && --n->nodeAndObjectRefCount == 0);
     71    } while (n && --n->refCount == 0);
    9672}
    9773
    98 inline void NoRefScopeChain::ref() const
    99 {
    100     for (ScopeChainNode *n = _node; n; n = n->next)
    101         if (n->nodeOnlyRefCount++ != 0)
    102             break;
    103 }
    104 
    105 NoRefScopeChain &NoRefScopeChain::operator=(const ScopeChain &c)
    106 {
    107     c.ref();
    108     deref();
    109     _node = c._node;
    110     return *this;
    111 }
    112 
    113 void NoRefScopeChain::mark()
     74void ScopeChain::mark()
    11475{
    11576    for (ScopeChainNode *n = _node; n; n = n->next) {
     
    12081}
    12182
    122 void NoRefScopeChain::release()
    123 {
    124     ScopeChainNode *n = _node;
    125     do {
    126         ScopeChainNode *next = n->next;
    127         if (n->nodeAndObjectRefCount == 0)
    128             delete n;
    129         n = next;
    130     } while (n && --n->nodeOnlyRefCount == 0);
    131 }
    132 
    13383} // namespace KJS
  • trunk/JavaScriptCore/kjs/scope_chain.h

    r2824 r2851  
    2525namespace KJS {
    2626
    27     class NoRefScopeChain;
    2827    class ObjectImp;
    2928   
    3029    class ScopeChainNode {
    3130    public:
    32         ScopeChainNode(ScopeChainNode *n, ObjectImp *o);
     31        ScopeChainNode(ScopeChainNode *n, ObjectImp *o)
     32            : next(n), object(o), refCount(1) { }
    3333
    3434        ScopeChainNode *next;
    3535        ObjectImp *object;
    36         short nodeAndObjectRefCount;
    37         short nodeOnlyRefCount;
     36        int refCount;
    3837    };
    3938
    4039    class ScopeChain {
    41         friend class NoRefScopeChain;
    4240    public:
    4341        ScopeChain() : _node(0) { }
     
    4543
    4644        ScopeChain(const ScopeChain &c) : _node(c._node)
    47             { if (_node) ++_node->nodeAndObjectRefCount; }
    48         ScopeChain(const NoRefScopeChain &);
     45            { if (_node) ++_node->refCount; }
    4946        ScopeChain &operator=(const ScopeChain &);
    5047
     
    5653        void pop();
    5754       
     55        void mark();
     56       
    5857    private:
    5958        ScopeChainNode *_node;
    6059       
    61         void deref() { if (_node && --_node->nodeAndObjectRefCount == 0) release(); }
     60        void deref() { if (_node && --_node->refCount == 0) release(); }
    6261        void ref() const;
    6362       
     
    6564    };
    6665
    67     class NoRefScopeChain {
    68         friend class ScopeChain;
    69     public:
    70         NoRefScopeChain() : _node(0) { }
    71         ~NoRefScopeChain() { deref(); }
    72 
    73         NoRefScopeChain &operator=(const ScopeChain &c);
    74 
    75         void mark();
    76 
    77     private:
    78         ScopeChainNode *_node;
    79        
    80         void deref() { if (_node && --_node->nodeOnlyRefCount == 0) release(); }
    81         void ref() const;
    82 
    83         void release();
    84 
    85         NoRefScopeChain(const NoRefScopeChain &);
    86         NoRefScopeChain &operator=(const NoRefScopeChain &);
    87     };
    88 
    8966}; // namespace KJS
    9067
Note: See TracChangeset for help on using the changeset viewer.