Ignore:
Timestamp:
Jul 3, 2008, 12:44:43 AM (17 years ago)
Author:
[email protected]
Message:

Reviewed by Geoff.

Don't create unnecessary JSGlobalData instances.

  • kjs/JSGlobalData.h:
  • kjs/JSGlobalData.cpp: (KJS::JSGlobalData::threadInstanceExists): (KJS::JSGlobalData::sharedInstanceExists): (KJS::JSGlobalData::threadInstance): (KJS::JSGlobalData::sharedInstance): (KJS::JSGlobalData::threadInstanceInternal): (KJS::JSGlobalData::sharedInstanceInternal): Added methods to query instance existence.
  • kjs/InitializeThreading.cpp: (KJS::initializeThreadingOnce): Initialize thread instance static in a new way.
  • API/JSBase.cpp: (JSGarbageCollect):
  • kjs/collector.cpp: (KJS::Heap::collect): Check for instance existence before accessing it.
File:
1 edited

Legend:

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

    r34974 r34977  
    3232#include "collector.h"
    3333#include "CommonIdentifiers.h"
     34#include "JSLock.h"
    3435#include "lexer.h"
    3536#include "list.h"
     
    120121}
    121122
     123bool JSGlobalData::threadInstanceExists()
     124{
     125    return threadInstanceInternal();
     126}
     127
     128bool JSGlobalData::sharedInstanceExists()
     129{
     130    return sharedInstanceInternal();
     131}
     132
    122133JSGlobalData& JSGlobalData::threadInstance()
    123134{
    124 #if USE(MULTIPLE_THREADS)
    125     static ThreadSpecific<JSGlobalData> sharedInstance;
    126     return *sharedInstance;
    127 #else
    128     static JSGlobalData sharedInstance;
    129     return sharedInstance;
    130 #endif
     135    JSGlobalData*& instance = threadInstanceInternal();
     136    if (!instance)
     137        instance = new JSGlobalData;
     138    return *instance;
    131139}
    132140
    133141JSGlobalData& JSGlobalData::sharedInstance()
    134142{
     143    JSGlobalData*& instance = sharedInstanceInternal();
     144    if (!instance)
     145        instance = new JSGlobalData(true);
     146    return *instance;
     147}
     148
     149JSGlobalData*& JSGlobalData::threadInstanceInternal()
     150{
    135151#if USE(MULTIPLE_THREADS)
    136     MutexLocker locker(*atomicallyInitializedStaticMutex);
     152    static ThreadSpecific<DataInstance> threadInstance;
     153    return *threadInstance;
     154#else
     155    static JSGlobalData threadInstance;
     156    return &threadInstance;
    137157#endif
     158}
     159
     160JSGlobalData*& JSGlobalData::sharedInstanceInternal()
     161{
     162    ASSERT(JSLock::currentThreadIsHoldingLock());
    138163    static JSGlobalData* sharedInstance;
    139     if (!sharedInstance)
    140         sharedInstance = new JSGlobalData(true);
    141     return *sharedInstance;
     164    return sharedInstance;
    142165}
    143166
Note: See TracChangeset for help on using the changeset viewer.