Changeset 32822 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
May 2, 2008, 1:05:47 PM (17 years ago)
Author:
[email protected]
Message:

Reviewed by Geoffrey Garen.

Get rid of static data in nodes.cpp (well, at least of non-debug one).

No measurable change on SunSpider.

  • kjs/InitializeThreading.cpp: (KJS::initializeThreadingOnce):
  • kjs/nodes.cpp: (KJS::newTrackedObjects): (KJS::trackedObjectExtraRefCounts): (KJS::initializeNodesThreading): (KJS::ParserRefCounted::ParserRefCounted): (KJS::ParserRefCounted::ref): (KJS::ParserRefCounted::deref): (KJS::ParserRefCounted::refcount): (KJS::ParserRefCounted::deleteNewObjects):
  • kjs/nodes.h: Made newTrackedObjects and trackedObjectExtraRefCounts per-thread.
Location:
trunk/JavaScriptCore/kjs
Files:
3 edited

Legend:

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

    r32808 r32822  
    3636#include "JSGlobalObject.h"
    3737#include "lexer.h"
     38#include "nodes.h"
    3839#include "Parser.h"
    3940#include "ustring.h"
     
    5960    JSGlobalObject::threadClassInfoHashTables();
    6061    JSGlobalObject::head();
     62    initializeNodesThreading();
    6163#endif
    6264}
  • trunk/JavaScriptCore/kjs/nodes.cpp

    r32807 r32822  
    4242#include <wtf/HashSet.h>
    4343#include <wtf/MathExtras.h>
     44#if USE(MULTIPLE_THREADS)
     45#include <wtf/ThreadSpecific.h>
     46#endif
     47
     48using namespace WTF;
    4449
    4550namespace KJS {
     
    118123#define LOG_CHANNEL_PREFIX Log
    119124#endif
     125
    120126static WTFLogChannel LogKJSNodeLeaks = { 0x00000000, "", WTFLogChannelOn };
    121127
     
    132138#endif
    133139
    134 static HashSet<ParserRefCounted*>* newTrackedObjects;
    135 static HashCountedSet<ParserRefCounted*>* trackedObjectExtraRefCounts;
     140static HashSet<ParserRefCounted*>* newTrackedObjects()
     141{
     142#if USE(MULTIPLE_THREADS)
     143    static ThreadSpecific<HashSet<ParserRefCounted*> > sharedInstance;
     144    return sharedInstance;
     145#else
     146    static HashSet<ParserRefCounted*> sharedInstance;
     147    return &sharedInstance;
     148#endif
     149}
     150
     151static HashCountedSet<ParserRefCounted*>* trackedObjectExtraRefCounts()
     152{
     153#if USE(MULTIPLE_THREADS)
     154    static ThreadSpecific<HashCountedSet<ParserRefCounted*> > sharedInstance;
     155    return sharedInstance;
     156#else
     157    static HashCountedSet<ParserRefCounted*> sharedInstance;
     158    return &sharedInstance;
     159#endif
     160}
     161
     162void initializeNodesThreading()
     163{
     164    newTrackedObjects();
     165    trackedObjectExtraRefCounts();
     166}
    136167
    137168ParserRefCounted::ParserRefCounted()
     
    140171    ++ParserRefCountedCounter::count;
    141172#endif
    142     if (!newTrackedObjects)
    143         newTrackedObjects = new HashSet<ParserRefCounted*>;
    144     newTrackedObjects->add(this);
    145     ASSERT(newTrackedObjects->contains(this));
     173    newTrackedObjects()->add(this);
     174    ASSERT(newTrackedObjects()->contains(this));
    146175}
    147176
     
    155184void ParserRefCounted::ref()
    156185{
     186    HashSet<ParserRefCounted*>* localNewTrackedObjects = newTrackedObjects();
     187
    157188    // bumping from 0 to 1 is just removing from the new nodes set
    158     if (newTrackedObjects) {
    159         HashSet<ParserRefCounted*>::iterator it = newTrackedObjects->find(this);
    160         if (it != newTrackedObjects->end()) {
    161             newTrackedObjects->remove(it);
    162             ASSERT(!trackedObjectExtraRefCounts || !trackedObjectExtraRefCounts->contains(this));
    163             return;
    164         }
    165     }
    166 
    167     ASSERT(!newTrackedObjects || !newTrackedObjects->contains(this));
    168 
    169     if (!trackedObjectExtraRefCounts)
    170         trackedObjectExtraRefCounts = new HashCountedSet<ParserRefCounted*>;
    171     trackedObjectExtraRefCounts->add(this);
     189    HashSet<ParserRefCounted*>::iterator it = localNewTrackedObjects->find(this);
     190    if (it != localNewTrackedObjects->end()) {
     191        localNewTrackedObjects->remove(it);
     192        ASSERT(!trackedObjectExtraRefCounts()->contains(this));
     193        return;
     194    }
     195
     196    ASSERT(!localNewTrackedObjects->contains(this));
     197
     198    trackedObjectExtraRefCounts()->add(this);
    172199}
    173200
    174201void ParserRefCounted::deref()
    175202{
    176     ASSERT(!newTrackedObjects || !newTrackedObjects->contains(this));
    177 
    178     if (!trackedObjectExtraRefCounts) {
    179         delete this;
    180         return;
    181     }
    182 
    183     HashCountedSet<ParserRefCounted*>::iterator it = trackedObjectExtraRefCounts->find(this);
    184     if (it == trackedObjectExtraRefCounts->end())
     203    ASSERT(!newTrackedObjects()->contains(this));
     204    HashCountedSet<ParserRefCounted*>* localTrackedObjectExtraRefCounts = trackedObjectExtraRefCounts();
     205
     206    HashCountedSet<ParserRefCounted*>::iterator it = localTrackedObjectExtraRefCounts->find(this);
     207    if (it == localTrackedObjectExtraRefCounts->end())
    185208        delete this;
    186209    else
    187         trackedObjectExtraRefCounts->remove(it);
     210        localTrackedObjectExtraRefCounts->remove(it);
    188211}
    189212
    190213unsigned ParserRefCounted::refcount()
    191214{
    192     if (newTrackedObjects && newTrackedObjects->contains(this)) {
    193         ASSERT(!trackedObjectExtraRefCounts || !trackedObjectExtraRefCounts->contains(this));
     215    HashCountedSet<ParserRefCounted*>* localTrackedObjectExtraRefCounts = trackedObjectExtraRefCounts();
     216
     217    if (newTrackedObjects()->contains(this)) {
     218        ASSERT(!localTrackedObjectExtraRefCounts->contains(this));
    194219        return 0;
    195220    }
    196221
    197     ASSERT(!newTrackedObjects || !newTrackedObjects->contains(this));
    198 
    199     if (!trackedObjectExtraRefCounts)
     222    ASSERT(!newTrackedObjects()->contains(this));
     223
     224    if (!localTrackedObjectExtraRefCounts)
    200225        return 1;
    201226
    202     return 1 + trackedObjectExtraRefCounts->count(this);
     227    return 1 + localTrackedObjectExtraRefCounts->count(this);
    203228}
    204229
    205230void ParserRefCounted::deleteNewObjects()
    206231{
    207     if (!newTrackedObjects)
    208         return;
    209 
     232    HashSet<ParserRefCounted*>* localNewTrackedObjects = newTrackedObjects();
    210233#ifndef NDEBUG
    211     HashSet<ParserRefCounted*>::iterator end = newTrackedObjects->end();
    212     for (HashSet<ParserRefCounted*>::iterator it = newTrackedObjects->begin(); it != end; ++it)
    213         ASSERT(!trackedObjectExtraRefCounts || !trackedObjectExtraRefCounts->contains(*it));
     234    HashSet<ParserRefCounted*>::iterator end = localNewTrackedObjects->end();
     235    for (HashSet<ParserRefCounted*>::iterator it = localNewTrackedObjects->begin(); it != end; ++it)
     236        ASSERT(!trackedObjectExtraRefCounts()->contains(*it));
    214237#endif
    215     deleteAllValues(*newTrackedObjects);
    216     delete newTrackedObjects;
    217     newTrackedObjects = 0;
     238    deleteAllValues(*localNewTrackedObjects);
     239    localNewTrackedObjects->clear();
    218240}
    219241
  • trunk/JavaScriptCore/kjs/nodes.h

    r31991 r32822  
    30103010    };
    30113011
     3012    void initializeNodesThreading();
     3013
    30123014} // namespace KJS
    30133015
Note: See TracChangeset for help on using the changeset viewer.