Changeset 2851 in webkit for trunk/JavaScriptCore
- Timestamp:
- Nov 24, 2002, 2:37:44 PM (23 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r2849 r2851 1 2002-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 1 26 2002-11-24 Maciej Stachowiak <[email protected]> 2 27 -
trunk/JavaScriptCore/ChangeLog-2002-12-03
r2849 r2851 1 2002-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 1 26 2002-11-24 Maciej Stachowiak <[email protected]> 2 27 -
trunk/JavaScriptCore/ChangeLog-2003-10-25
r2849 r2851 1 2002-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 1 26 2002-11-24 Maciej Stachowiak <[email protected]> 2 27 -
trunk/JavaScriptCore/kjs/context.h
r2824 r2851 38 38 ~ContextImp(); 39 39 40 const ScopeChain scopeChain() const { return scope; }40 const ScopeChain &scopeChain() const { return scope; } 41 41 Object variableObject() const { return variable; } 42 42 void setVariableObject(const Object &v) { variable = v; } -
trunk/JavaScriptCore/kjs/internal.cpp
r2845 r2851 414 414 { 415 415 for (ContextImp *context = this; context; context = context->_callingContext) { 416 context->scope.mark(); 416 417 context->_activationImp.mark(); 417 418 #if DEBUG_COLLECTOR -
trunk/JavaScriptCore/kjs/interpreter.cpp
r2821 r2851 42 42 // ------------------------------ Context -------------------------------------- 43 43 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 44 const ScopeChain &Context::scopeChain() const 75 45 { 76 46 return rep->scopeChain(); -
trunk/JavaScriptCore/kjs/interpreter.h
r2821 r2851 54 54 class Context { 55 55 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; } 63 59 64 60 /** … … 69 65 * @return The execution context's scope chain 70 66 */ 71 const ScopeChain scopeChain() const;67 const ScopeChain &scopeChain() const; 72 68 73 69 /** … … 105 101 */ 106 102 const Context callingContext() const; 103 107 104 private: 108 105 ContextImp *rep; … … 380 377 * @return The current execution state context 381 378 */ 382 constContext context() const { return _context; }379 Context context() const { return _context; } 383 380 384 381 void setException(const Value &e) { _exception = e; } -
trunk/JavaScriptCore/kjs/nodes.cpp
r2847 r2851 206 206 Value ThisNode::evaluate(ExecState *exec) 207 207 { 208 return exec->context(). thisValue();208 return exec->context().imp()->thisValue(); 209 209 } 210 210 … … 219 219 Reference ResolveNode::evaluateReference(ExecState *exec) 220 220 { 221 ScopeChain chain = exec->context(). scopeChain();221 ScopeChain chain = exec->context().imp()->scopeChain(); 222 222 223 223 while (!chain.isEmpty()) { … … 1633 1633 Value VarDeclNode::evaluate(ExecState *exec) 1634 1634 { 1635 Object variable = Object::dynamicCast(exec->context(). variableObject());1635 Object variable = Object::dynamicCast(exec->context().imp()->variableObject()); 1636 1636 1637 1637 Value val; … … 1657 1657 void VarDeclNode::processVarDecls(ExecState *exec) 1658 1658 { 1659 Object variable = exec->context(). variableObject();1659 Object variable = exec->context().imp()->variableObject(); 1660 1660 variable.put(exec,ident, Undefined(), DontDelete); 1661 1661 } … … 2780 2780 void FuncDeclNode::processFuncDecl(ExecState *exec) 2781 2781 { 2782 const ScopeChain sc = exec->context().imp()->scopeChain();2783 2784 2782 // 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()); 2786 2784 Object func(fimp); // protect from GC 2787 2785 … … 2835 2833 Value FuncExprNode::evaluate(ExecState *exec) 2836 2834 { 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()); 2839 2836 Value ret(fimp); 2840 2837 List empty; -
trunk/JavaScriptCore/kjs/object.cpp
r2824 r2851 365 365 } 366 366 367 const ScopeChain ObjectImp::scope() const368 {369 return _scope;370 }371 372 void ObjectImp::setScope(const ScopeChain &s)373 {374 _scope = s;375 }376 377 367 ReferenceList ObjectImp::propList(ExecState *exec, bool recursive) 378 368 { -
trunk/JavaScriptCore/kjs/object.h
r2846 r2851 320 320 * @return The function's scope 321 321 */ 322 const ScopeChain scope() const;322 const ScopeChain &scope() const; 323 323 void setScope(const ScopeChain &s); 324 324 … … 570 570 * @see Object::scope() 571 571 */ 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; } 574 574 575 575 ReferenceList propList(ExecState *exec, bool recursive = true); … … 604 604 ValueImp *_proto; 605 605 ValueImp *_internalValue; 606 NoRefScopeChain _scope;606 ScopeChain _scope; 607 607 }; 608 608 … … 707 707 { return imp()->hasInstance(exec,value); } 708 708 709 inline const ScopeChain Object::scope() const709 inline const ScopeChain &Object::scope() const 710 710 { return imp()->scope(); } 711 711 -
trunk/JavaScriptCore/kjs/scope_chain.cpp
r2824 r2851 26 26 namespace KJS { 27 27 28 ScopeChainNode::ScopeChainNode(ScopeChainNode *n, ObjectImp *o)29 : next(n), object(o), nodeAndObjectRefCount(1), nodeOnlyRefCount(0)30 {31 o->ref();32 }33 34 28 inline void ScopeChain::ref() const 35 29 { 36 30 for (ScopeChainNode *n = _node; n; n = n->next) { 37 if (n-> nodeAndObjectRefCount++ != 0)31 if (n->refCount++ != 0) 38 32 break; 39 n->object->ref();40 33 } 41 }42 43 ScopeChain::ScopeChain(const NoRefScopeChain &c)44 : _node(c._node)45 {46 ref();47 34 } 48 35 … … 67 54 _node = newNode; 68 55 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) { 77 57 if (newNode) 78 ++newNode-> nodeAndObjectRefCount;58 ++newNode->refCount; 79 59 } else { 80 oldNode->object->deref(); 81 if (oldNode->nodeOnlyRefCount == 0) 82 delete oldNode; 60 delete oldNode; 83 61 } 84 62 } … … 89 67 do { 90 68 ScopeChainNode *next = n->next; 91 n->object->deref(); 92 if (n->nodeOnlyRefCount == 0) 93 delete n; 69 delete n; 94 70 n = next; 95 } while (n && --n-> nodeAndObjectRefCount == 0);71 } while (n && --n->refCount == 0); 96 72 } 97 73 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() 74 void ScopeChain::mark() 114 75 { 115 76 for (ScopeChainNode *n = _node; n; n = n->next) { … … 120 81 } 121 82 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 133 83 } // namespace KJS -
trunk/JavaScriptCore/kjs/scope_chain.h
r2824 r2851 25 25 namespace KJS { 26 26 27 class NoRefScopeChain;28 27 class ObjectImp; 29 28 30 29 class ScopeChainNode { 31 30 public: 32 ScopeChainNode(ScopeChainNode *n, ObjectImp *o); 31 ScopeChainNode(ScopeChainNode *n, ObjectImp *o) 32 : next(n), object(o), refCount(1) { } 33 33 34 34 ScopeChainNode *next; 35 35 ObjectImp *object; 36 short nodeAndObjectRefCount; 37 short nodeOnlyRefCount; 36 int refCount; 38 37 }; 39 38 40 39 class ScopeChain { 41 friend class NoRefScopeChain;42 40 public: 43 41 ScopeChain() : _node(0) { } … … 45 43 46 44 ScopeChain(const ScopeChain &c) : _node(c._node) 47 { if (_node) ++_node->nodeAndObjectRefCount; } 48 ScopeChain(const NoRefScopeChain &); 45 { if (_node) ++_node->refCount; } 49 46 ScopeChain &operator=(const ScopeChain &); 50 47 … … 56 53 void pop(); 57 54 55 void mark(); 56 58 57 private: 59 58 ScopeChainNode *_node; 60 59 61 void deref() { if (_node && --_node-> nodeAndObjectRefCount == 0) release(); }60 void deref() { if (_node && --_node->refCount == 0) release(); } 62 61 void ref() const; 63 62 … … 65 64 }; 66 65 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 89 66 }; // namespace KJS 90 67
Note:
See TracChangeset
for help on using the changeset viewer.