Changeset 34977 in webkit for trunk/JavaScriptCore


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.
Location:
trunk/JavaScriptCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/JSBase.cpp

    r34947 r34977  
    8989    // and it may actually be garbage for some clients (most likely, because of JSGarbageCollect being called after releasing the context).
    9090
    91     // FIXME: It would be good to avoid creating a JSGlobalData instance if it didn't exist for this thread yet.
    92     Heap* heap = JSGlobalData::threadInstance().heap;
    93     if (!heap->isBusy())
    94         heap->collect();
     91    if (JSGlobalData::threadInstanceExists()) {
     92        Heap* heap = JSGlobalData::threadInstance().heap;
     93        if (!heap->isBusy())
     94            heap->collect();
     95    }
    9596
    9697    JSLock lock(true);
    9798
    98     // FIXME: Similarly, we shouldn't create a shared instance here.
    99     heap = JSGlobalData::sharedInstance().heap;
    100     if (!heap->isBusy())
    101         heap->collect();
     99    if (JSGlobalData::sharedInstanceExists()) {
     100        Heap* heap = JSGlobalData::sharedInstance().heap;
     101        if (!heap->isBusy())
     102            heap->collect();
     103    }
    102104
    103105    // FIXME: Perhaps we should trigger a second mark and sweep
  • trunk/JavaScriptCore/ChangeLog

    r34974 r34977  
     12008-07-02  Alexey Proskuryakov  <[email protected]>
     2
     3        Reviewed by Geoff.
     4
     5        Don't create unnecessary JSGlobalData instances.
     6
     7        * kjs/JSGlobalData.h:
     8        * kjs/JSGlobalData.cpp:
     9        (KJS::JSGlobalData::threadInstanceExists):
     10        (KJS::JSGlobalData::sharedInstanceExists):
     11        (KJS::JSGlobalData::threadInstance):
     12        (KJS::JSGlobalData::sharedInstance):
     13        (KJS::JSGlobalData::threadInstanceInternal):
     14        (KJS::JSGlobalData::sharedInstanceInternal):
     15        Added methods to query instance existence.
     16
     17        * kjs/InitializeThreading.cpp:
     18        (KJS::initializeThreadingOnce):
     19        Initialize thread instance static in a new way.
     20
     21        * API/JSBase.cpp:
     22        (JSGarbageCollect):
     23        * kjs/collector.cpp:
     24        (KJS::Heap::collect):
     25        Check for instance existence before accessing it.
     26
    1272008-07-02  Geoffrey Garen  <[email protected]>
    228
  • trunk/JavaScriptCore/kjs/InitializeThreading.cpp

    r34810 r34977  
    4949#if USE(MULTIPLE_THREADS)
    5050    s_dtoaP5Mutex = new Mutex;
    51     JSGlobalData::threadInstance();
     51    JSGlobalData::threadInstanceExists();
    5252    UString::null();
    5353    initDateMath();
  • 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
  • trunk/JavaScriptCore/kjs/JSGlobalData.h

    r34947 r34977  
    3434#include <wtf/HashSet.h>
    3535#include <wtf/Noncopyable.h>
    36 
    37 namespace WTF {
    38     template<typename> class ThreadSpecific;
    39 }
     36#include <wtf/OwnPtr.h>
    4037
    4138namespace KJS {
     
    5653    // JavaScriptCore clients, which all share a single JSGlobalData, and thus cannot run concurrently.
    5754    struct JSGlobalData : Noncopyable {
     55        static bool threadInstanceExists();
     56        static bool sharedInstanceExists();
    5857        static JSGlobalData& threadInstance();
    5958        static JSGlobalData& sharedInstance();
     
    8584
    8685    private:
    87         friend class WTF::ThreadSpecific<JSGlobalData>;
    88 
    8986        JSGlobalData(bool isShared = false);
    9087        ~JSGlobalData();
     88
     89        static JSGlobalData*& threadInstanceInternal();
     90        static JSGlobalData*& sharedInstanceInternal();
     91
     92        struct DataInstance {
     93            DataInstance() : m_data(0) {}
     94            ~DataInstance() { delete m_data; }
     95            operator JSGlobalData*&() { return m_data; }
     96
     97            JSGlobalData* m_data;
     98        };
    9199    };
    92100
  • trunk/JavaScriptCore/kjs/collector.cpp

    r34974 r34977  
    926926{
    927927#ifndef NDEBUG
    928     if (JSGlobalData::sharedInstance().heap == this) {
     928    if (JSGlobalData::sharedInstanceExists() && JSGlobalData::sharedInstance().heap == this) {
    929929        ASSERT(JSLock::lockCount() > 0);
    930930        ASSERT(JSLock::currentThreadIsHoldingLock());
Note: See TracChangeset for help on using the changeset viewer.