Ignore:
Timestamp:
May 5, 2009, 4:09:52 PM (16 years ago)
Author:
Darin Adler
Message:

2009-05-05 Darin Adler <Darin Adler>

Reviewed by Sam Weinig.

Bug 25569: make ParserRefCounted use conventional reference counting
https://bugs.webkit.org/show_bug.cgi?id=25569

SunSpider speedup of about 1.6%.

  • parser/Nodes.cpp: (JSC::NodeReleaser::releaseAllNodes): ALWAYS_INLINE. (JSC::NodeReleaser::adopt): Ditto. (JSC::ParserRefCounted::ParserRefCounted): Removed most of the code. Add the object to a Vector<RefPtr> that gets cleared after parsing. (JSC::ParserRefCounted::~ParserRefCounted): Removed most of the code.
  • parser/Nodes.h: Made ParserRefCounted inherit from RefCounted and made inline versions of the constructor and destructor. Made the Node constructor inline.
  • parser/Parser.cpp: (JSC::Parser::parse): Call globalData->parserObjects.shrink(0) after parsing, where it used to call ParserRefCounted::deleteNewObjects.
  • runtime/JSGlobalData.cpp: (JSC::JSGlobalData::JSGlobalData): Eliminated code to manage the newParserObjects and parserObjectExtraRefCounts. (JSC::JSGlobalData::~JSGlobalData): Ditto.
  • runtime/JSGlobalData.h: Replaced the HashSet and HashCountedSet with a Vector.
  • wtf/PassRefPtr.h: (WTF::PassRefPtr::~PassRefPtr): The most common thing to do with a PassRefPtr in hot code is to pass it and then destroy it once it's set to zero. Help the optimizer by telling it that's true.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/parser/Nodes.cpp

    r43230 r43259  
    2929#include "BytecodeGenerator.h"
    3030#include "CallFrame.h"
     31#include "Debugger.h"
    3132#include "JIT.h"
    3233#include "JSFunction.h"
     
    3435#include "JSStaticScopeObject.h"
    3536#include "LabelScope.h"
     37#include "Operations.h"
    3638#include "Parser.h"
    3739#include "PropertyNameArray.h"
    3840#include "RegExpObject.h"
    3941#include "SamplingTool.h"
    40 #include "Debugger.h"
    41 #include "Lexer.h"
    42 #include "Operations.h"
    43 #include <math.h>
    4442#include <wtf/Assertions.h>
    45 #include <wtf/HashCountedSet.h>
    46 #include <wtf/HashSet.h>
    47 #include <wtf/MathExtras.h>
    4843#include <wtf/RefCountedLeakCounter.h>
    4944#include <wtf/Threading.h>
     
    8176};
    8277
    83 void NodeReleaser::releaseAllNodes(ParserRefCounted* root)
     78ALWAYS_INLINE void NodeReleaser::releaseAllNodes(ParserRefCounted* root)
    8479{
    8580    ASSERT(root);
     
    9792}
    9893
    99 void NodeReleaser::adopt(PassRefPtr<ParserRefCounted> node)
     94ALWAYS_INLINE void NodeReleaser::adopt(PassRefPtr<ParserRefCounted> node)
    10095{
    10196    ASSERT(node);
     
    122117
    123118#ifndef NDEBUG
     119
    124120static RefCountedLeakCounter parserRefCountedCounter("JSC::Node");
     121
     122ALWAYS_INLINE ParserRefCounted::ParserRefCounted(JSGlobalData* globalData)
     123{
     124    globalData->parserObjects.append(adoptRef(this));
     125    parserRefCountedCounter.increment();
     126}
     127
     128ALWAYS_INLINE ParserRefCounted::~ParserRefCounted()
     129{
     130    parserRefCountedCounter.decrement();
     131}
     132
    125133#endif
    126134
    127 ParserRefCounted::ParserRefCounted(JSGlobalData* globalData)
    128     : m_globalData(globalData)
    129 {
    130 #ifndef NDEBUG
    131     parserRefCountedCounter.increment();
    132 #endif
    133     if (!m_globalData->newParserObjects)
    134         m_globalData->newParserObjects = new HashSet<ParserRefCounted*>;
    135     m_globalData->newParserObjects->add(this);
    136     ASSERT(m_globalData->newParserObjects->contains(this));
    137 }
    138 
    139 ParserRefCounted::~ParserRefCounted()
    140 {
    141 #ifndef NDEBUG
    142     parserRefCountedCounter.decrement();
    143 #endif
    144 }
    145 
    146135void ParserRefCounted::releaseNodes(NodeReleaser&)
    147136{
    148 }
    149 
    150 void ParserRefCounted::ref()
    151 {
    152     // bumping from 0 to 1 is just removing from the new nodes set
    153     if (m_globalData->newParserObjects) {
    154         HashSet<ParserRefCounted*>::iterator it = m_globalData->newParserObjects->find(this);
    155         if (it != m_globalData->newParserObjects->end()) {
    156             m_globalData->newParserObjects->remove(it);
    157             ASSERT(!m_globalData->parserObjectExtraRefCounts || !m_globalData->parserObjectExtraRefCounts->contains(this));
    158             return;
    159         }
    160     }
    161 
    162     ASSERT(!m_globalData->newParserObjects || !m_globalData->newParserObjects->contains(this));
    163 
    164     if (!m_globalData->parserObjectExtraRefCounts)
    165         m_globalData->parserObjectExtraRefCounts = new HashCountedSet<ParserRefCounted*>;
    166     m_globalData->parserObjectExtraRefCounts->add(this);
    167 }
    168 
    169 void ParserRefCounted::deref()
    170 {
    171     ASSERT(!m_globalData->newParserObjects || !m_globalData->newParserObjects->contains(this));
    172 
    173     if (!m_globalData->parserObjectExtraRefCounts) {
    174         delete this;
    175         return;
    176     }
    177 
    178     HashCountedSet<ParserRefCounted*>::iterator it = m_globalData->parserObjectExtraRefCounts->find(this);
    179     if (it == m_globalData->parserObjectExtraRefCounts->end())
    180         delete this;
    181     else
    182         m_globalData->parserObjectExtraRefCounts->remove(it);
    183 }
    184 
    185 bool ParserRefCounted::hasOneRef()
    186 {
    187     if (m_globalData->newParserObjects && m_globalData->newParserObjects->contains(this)) {
    188         ASSERT(!m_globalData->parserObjectExtraRefCounts || !m_globalData->parserObjectExtraRefCounts->contains(this));
    189         return false;
    190     }
    191 
    192     ASSERT(!m_globalData->newParserObjects || !m_globalData->newParserObjects->contains(this));
    193 
    194     if (!m_globalData->parserObjectExtraRefCounts)
    195         return true;
    196 
    197     return !m_globalData->parserObjectExtraRefCounts->contains(this);
    198 }
    199 
    200 void ParserRefCounted::deleteNewObjects(JSGlobalData* globalData)
    201 {
    202     if (!globalData->newParserObjects)
    203         return;
    204 
    205 #ifndef NDEBUG
    206     HashSet<ParserRefCounted*>::iterator end = globalData->newParserObjects->end();
    207     for (HashSet<ParserRefCounted*>::iterator it = globalData->newParserObjects->begin(); it != end; ++it)
    208         ASSERT(!globalData->parserObjectExtraRefCounts || !globalData->parserObjectExtraRefCounts->contains(*it));
    209 #endif
    210     deleteAllValues(*globalData->newParserObjects);
    211     delete globalData->newParserObjects;
    212     globalData->newParserObjects = 0;
    213 }
    214 
    215 // ------------------------------ Node --------------------------------
    216 
    217 Node::Node(JSGlobalData* globalData)
    218     : ParserRefCounted(globalData)
    219 {
    220     m_line = globalData->lexer->lineNumber();
    221137}
    222138
Note: See TracChangeset for help on using the changeset viewer.