Changeset 58133 in webkit


Ignore:
Timestamp:
Apr 22, 2010 5:11:37 PM (14 years ago)
Author:
barraclough@apple.com
Message:

https://bugs.webkit.org/show_bug.cgi?id=38006
Change lifetime of JSC::IdentifierTables used by WebCores to match AtomicStringTable

Reviewed by Geoff Garen.

Presently JSC's IdentifierTables are owned by the JSGlobalData. For
JSGlobalData objects created via the API this should continue to be the case,
but for the JSGlobalData objects used by WebCore (the main thread's common
global data, and those for workers) use a IdentifierTable provided (and owned)
by wtfThreadData. This allow the lifetime of these IdentifierTable to match
those of the corresponding AtomicStringTables.

  • API/APIShims.h:

(JSC::APIEntryShim::APIEntryShim):

  • API/JSContextRef.cpp:

(JSContextGroupCreate):

  • runtime/Collector.cpp:

(JSC::Heap::protect):
(JSC::Heap::unprotect):
(JSC::Heap::markRoots):

  • runtime/JSGlobalData.cpp:

(JSC::JSGlobalData::JSGlobalData):
(JSC::JSGlobalData::~JSGlobalData):
(JSC::JSGlobalData::createContextGroup):
(JSC::JSGlobalData::create):
(JSC::JSGlobalData::sharedInstance):

  • runtime/JSGlobalData.h:

(JSC::JSGlobalData::):
(JSC::JSGlobalData::isSharedInstance):

  • runtime/JSLock.cpp:

(JSC::JSLock::JSLock):
(JSC::JSLock::lock):
(JSC::JSLock::unlock):
(JSC::JSLock::DropAllLocks::DropAllLocks):

  • wtf/WTFThreadData.cpp:

(WTF::WTFThreadData::WTFThreadData):
(WTF::WTFThreadData::~WTFThreadData):

Location:
trunk/JavaScriptCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/APIShims.h

    r57879 r58133  
    6767    APIEntryShim(JSGlobalData* globalData, bool registerThread = true)
    6868        : APIEntryShimWithoutLock(globalData, registerThread)
    69         , m_lock(globalData->isSharedInstance ? LockForReal : SilenceAssertionsOnly)
     69        , m_lock(globalData->isSharedInstance() ? LockForReal : SilenceAssertionsOnly)
    7070    {
    7171    }
  • trunk/JavaScriptCore/API/JSContextRef.cpp

    r58012 r58133  
    4747{
    4848    initializeThreading();
    49     return toRef(JSGlobalData::createNonDefault(ThreadStackTypeSmall).releaseRef());
     49    return toRef(JSGlobalData::createContextGroup(ThreadStackTypeSmall).releaseRef());
    5050}
    5151
     
    8585
    8686    JSLock lock(LockForReal);
    87     RefPtr<JSGlobalData> globalData = group ? PassRefPtr<JSGlobalData>(toJS(group)) : JSGlobalData::createNonDefault(ThreadStackTypeSmall);
     87    RefPtr<JSGlobalData> globalData = group ? PassRefPtr<JSGlobalData>(toJS(group)) : JSGlobalData::createContextGroup(ThreadStackTypeSmall);
    8888
    8989    APIEntryShim entryShim(globalData.get(), false);
  • trunk/JavaScriptCore/ChangeLog

    r58118 r58133  
     12010-04-22  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Reviewed by Geoff Garen.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=38006
     6        Change lifetime of JSC::IdentifierTables used by WebCores to match AtomicStringTable
     7
     8        Presently JSC's IdentifierTables are owned by the JSGlobalData.  For
     9        JSGlobalData objects created via the API this should continue to be the case,
     10        but for the JSGlobalData objects used by WebCore (the main thread's common
     11        global data, and those for workers) use a IdentifierTable provided (and owned)
     12        by wtfThreadData.  This allow the lifetime of these IdentifierTable to match
     13        those of the corresponding AtomicStringTables.
     14
     15        * API/APIShims.h:
     16        (JSC::APIEntryShim::APIEntryShim):
     17        * API/JSContextRef.cpp:
     18        (JSContextGroupCreate):
     19        * runtime/Collector.cpp:
     20        (JSC::Heap::protect):
     21        (JSC::Heap::unprotect):
     22        (JSC::Heap::markRoots):
     23        * runtime/JSGlobalData.cpp:
     24        (JSC::JSGlobalData::JSGlobalData):
     25        (JSC::JSGlobalData::~JSGlobalData):
     26        (JSC::JSGlobalData::createContextGroup):
     27        (JSC::JSGlobalData::create):
     28        (JSC::JSGlobalData::sharedInstance):
     29        * runtime/JSGlobalData.h:
     30        (JSC::JSGlobalData::):
     31        (JSC::JSGlobalData::isSharedInstance):
     32        * runtime/JSLock.cpp:
     33        (JSC::JSLock::JSLock):
     34        (JSC::JSLock::lock):
     35        (JSC::JSLock::unlock):
     36        (JSC::JSLock::DropAllLocks::DropAllLocks):
     37        * wtf/WTFThreadData.cpp:
     38        (WTF::WTFThreadData::WTFThreadData):
     39        (WTF::WTFThreadData::~WTFThreadData):
     40
    1412010-04-22  Sheriff Bot  <webkit.review.bot@gmail.com>
    242
  • trunk/JavaScriptCore/runtime/Collector.cpp

    r58012 r58133  
    973973{
    974974    ASSERT(k);
    975     ASSERT(JSLock::currentThreadIsHoldingLock() || !m_globalData->isSharedInstance);
     975//    ASSERT(JSLock::currentThreadIsHoldingLock() || !m_globalData->isSharedInstance());
    976976
    977977    if (!k.isCell())
     
    984984{
    985985    ASSERT(k);
    986     ASSERT(JSLock::currentThreadIsHoldingLock() || !m_globalData->isSharedInstance);
     986//    ASSERT(JSLock::currentThreadIsHoldingLock() || !m_globalData->isSharedInstance());
    987987
    988988    if (!k.isCell())
     
    10651065{
    10661066#ifndef NDEBUG
    1067     if (m_globalData->isSharedInstance) {
     1067    if (m_globalData->isSharedInstance()) {
    10681068        ASSERT(JSLock::lockCount() > 0);
    10691069        ASSERT(JSLock::currentThreadIsHoldingLock());
  • trunk/JavaScriptCore/runtime/JSGlobalData.cpp

    r58114 r58133  
    104104}
    105105
    106 JSGlobalData::JSGlobalData(bool isShared, ThreadStackType threadStackType)
    107     : isSharedInstance(isShared)
     106JSGlobalData::JSGlobalData(GlobalDataType globalDataType, ThreadStackType threadStackType)
     107    : globalDataType(globalDataType)
    108108    , clientData(0)
    109109    , arrayTable(fastNew<HashTable>(JSC::arrayTable))
     
    129129    , numberStructure(JSNumberCell::createStructure(jsNull()))
    130130#endif
    131     , identifierTable(createIdentifierTable())
     131    , identifierTable(globalDataType == Default ? wtfThreadData().currentIdentifierTable() : createIdentifierTable())
    132132    , literalTable(createLiteralTable())
    133133    , propertyNames(new CommonIdentifiers(this))
     
    194194
    195195    delete propertyNames;
    196     deleteIdentifierTable(identifierTable);
     196    if (globalDataType != Default)
     197        deleteIdentifierTable(identifierTable);
    197198    deleteLiteralTable(literalTable);
    198199
     
    200201}
    201202
    202 PassRefPtr<JSGlobalData> JSGlobalData::createNonDefault(ThreadStackType type)
    203 {
    204     return adoptRef(new JSGlobalData(false, type));
     203PassRefPtr<JSGlobalData> JSGlobalData::createContextGroup(ThreadStackType type)
     204{
     205    return adoptRef(new JSGlobalData(APIContextGroup, type));
    205206}
    206207
    207208PassRefPtr<JSGlobalData> JSGlobalData::create(ThreadStackType type)
    208209{
    209     JSGlobalData* globalData = new JSGlobalData(false, type);
    210     wtfThreadData().initializeIdentifierTable(globalData->identifierTable);
    211     return adoptRef(globalData);
     210    return adoptRef(new JSGlobalData(Default, type));
    212211}
    213212
     
    229228    JSGlobalData*& instance = sharedInstanceInternal();
    230229    if (!instance) {
    231         instance = new JSGlobalData(true, ThreadStackTypeSmall);
     230        instance = new JSGlobalData(APIShared, ThreadStackTypeSmall);
    232231#if ENABLE(JSC_MULTIPLE_THREADS)
    233232        instance->makeUsableFromMultipleThreads();
  • trunk/JavaScriptCore/runtime/JSGlobalData.h

    r58114 r58133  
    9393    class JSGlobalData : public RefCounted<JSGlobalData> {
    9494    public:
     95        // WebCore has a one-to-one mapping of threads to JSGlobalDatas;
     96        // either create() or createLeaked() should only be called once
     97        // on a thread, this is the 'default' JSGlobalData (it uses the
     98        // thread's default string uniquing table from wtfThreadData).
     99        // API contexts created using the new context group aware interface
     100        // create APIContextGroup objects which require less locking of JSC
     101        // than the old singleton APIShared JSGlobalData created for use by
     102        // the original API.
     103        enum GlobalDataType { Default, APIContextGroup, APIShared };
     104
    95105        struct ClientData {
    96106            virtual ~ClientData() = 0;
    97107        };
    98108
     109        bool isSharedInstance() { return globalDataType == APIShared; }
    99110        static bool sharedInstanceExists();
    100111        static JSGlobalData& sharedInstance();
     
    102113        static PassRefPtr<JSGlobalData> create(ThreadStackType);
    103114        static PassRefPtr<JSGlobalData> createLeaked(ThreadStackType);
    104         static PassRefPtr<JSGlobalData> createNonDefault(ThreadStackType);
     115        static PassRefPtr<JSGlobalData> createContextGroup(ThreadStackType);
    105116        ~JSGlobalData();
    106117
     
    110121#endif
    111122
    112         bool isSharedInstance;
     123        GlobalDataType globalDataType;
    113124        ClientData* clientData;
    114125
     
    206217        void dumpSampleData(ExecState* exec);
    207218    private:
    208         JSGlobalData(bool isShared, ThreadStackType);
     219        JSGlobalData(GlobalDataType, ThreadStackType);
    209220        static JSGlobalData*& sharedInstanceInternal();
    210221        void createNativeThunk();
  • trunk/JavaScriptCore/runtime/JSLock.cpp

    r46436 r58133  
    6161
    6262JSLock::JSLock(ExecState* exec)
    63     : m_lockBehavior(exec->globalData().isSharedInstance ? LockForReal : SilenceAssertionsOnly)
     63    : m_lockBehavior(exec->globalData().isSharedInstance() ? LockForReal : SilenceAssertionsOnly)
    6464{
    6565    lock(m_lockBehavior);
     
    106106void JSLock::lock(ExecState* exec)
    107107{
    108     lock(exec->globalData().isSharedInstance ? LockForReal : SilenceAssertionsOnly);
     108    lock(exec->globalData().isSharedInstance() ? LockForReal : SilenceAssertionsOnly);
    109109}
    110110
    111111void JSLock::unlock(ExecState* exec)
    112112{
    113     unlock(exec->globalData().isSharedInstance ? LockForReal : SilenceAssertionsOnly);
     113    unlock(exec->globalData().isSharedInstance() ? LockForReal : SilenceAssertionsOnly);
    114114}
    115115
     
    163163
    164164JSLock::DropAllLocks::DropAllLocks(ExecState* exec)
    165     : m_lockBehavior(exec->globalData().isSharedInstance ? LockForReal : SilenceAssertionsOnly)
     165    : m_lockBehavior(exec->globalData().isSharedInstance() ? LockForReal : SilenceAssertionsOnly)
    166166{
    167167    pthread_once(&createJSLockCountOnce, createJSLockCount);
  • trunk/JavaScriptCore/wtf/WTFThreadData.cpp

    r58114 r58133  
    4040    : m_atomicStringTable(new WebCore::AtomicStringTable())
    4141#if USE(JSC)
    42     , m_defaultIdentifierTable(0)
    43     , m_currentIdentifierTable(0)
     42    , m_defaultIdentifierTable(new JSC::IdentifierTable())
     43    , m_currentIdentifierTable(m_defaultIdentifierTable)
    4444#endif
    4545{
     
    4949{
    5050    delete m_atomicStringTable;
     51#if USE(JSC)
     52    delete m_defaultIdentifierTable;
     53#endif
    5154}
    5255
Note: See TracChangeset for help on using the changeset viewer.