Changeset 57829 in webkit for trunk/JavaScriptCore/wtf


Ignore:
Timestamp:
Apr 19, 2010, 1:05:53 PM (15 years ago)
Author:
[email protected]
Message:

https://bugs.webkit.org/show_bug.cgi?id=37745
Move string uniquing tables to (new) WTFThreadData class.

Reviewed by Sam Weinig.

Remove AtomicString's dependency on ThreadGlobalData so that we can move
WebCore's string classes up to WTF.

JavaScriptCore:

WTFThreadData.cpp/.h are based on ThreadGlobalData from WebCore.
Moved JSC & WebCore's string uniquing tables to this class.

This patch introduces a temporary layering violation in providing forward
declarations of classes from JSC and WTF; this will be resolved as we move
more string code up to WTF.

  • API/APIShims.h:

(JSC::APIEntryShimWithoutLock::APIEntryShimWithoutLock):
(JSC::APIEntryShimWithoutLock::~APIEntryShimWithoutLock):
(JSC::APICallbackShim::APICallbackShim):
(JSC::APICallbackShim::~APICallbackShim):

(JSC::checkSyntax):
(JSC::evaluate):

  • runtime/Identifier.cpp:

(JSC::Identifier::remove):
(JSC::Identifier::checkCurrentIdentifierTable):

  • runtime/Identifier.h:
  • runtime/InitializeThreading.cpp:

(JSC::initializeThreadingOnce):

  • runtime/JSGlobalData.cpp:

(JSC::JSGlobalData::create):

  • wtf/WTFThreadData.cpp: Copied from WebCore/platform/ThreadGlobalData.cpp.

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

  • wtf/WTFThreadData.h: Copied from WebCore/platform/ThreadGlobalData.h.

(WTF::WTFThreadData::atomicStringTable):
(WTF::WTFThreadData::initializeIdentifierTable):
(WTF::WTFThreadData::currentIdentifierTable):
(WTF::WTFThreadData::setCurrentIdentifierTable):
(WTF::WTFThreadData::resetCurrentIdentifierTable):
(WTF::wtfThreadData):

JavaScriptGlue:

  • ForwardingHeaders/wtf/WTFThreadData.h: Added.
  • JSUtils.cpp: Update

(JSGlueAPIEntry::JSGlueAPIEntry):
(JSGlueAPIEntry::~JSGlueAPIEntry):
(JSGlueAPICallback::JSGlueAPICallback):
(JSGlueAPICallback::~JSGlueAPICallback):

WebCore:

  • ForwardingHeaders/wtf/WTFThreadData.h: Added.
  • platform/ThreadGlobalData.cpp: Remove m_atomicStringTable, all wtfThreadData() to ensure threadsafely initialized.

(WebCore::ThreadGlobalData::ThreadGlobalData):
(WebCore::ThreadGlobalData::~ThreadGlobalData):

  • platform/ThreadGlobalData.h: Remove m_atomicStringTable.

(WebCore::ThreadGlobalData::eventNames):

  • platform/text/AtomicString.cpp:

(WebCore::AtomicStringTable::create):
(WebCore::AtomicStringTable::table):
(WebCore::AtomicStringTable::destroy):
(WebCore::stringTable): Access the AtomicStringTable on wtfThreadData() rather then threadGlobalData().

Location:
trunk/JavaScriptCore/wtf
Files:
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/WTFThreadData.cpp

    r57765 r57829  
    11/*
    2  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
     2 * Copyright (C) 2008, 2010 Apple Inc. All Rights Reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2626
    2727#include "config.h"
    28 #include "ThreadGlobalData.h"
     28#include "WTFThreadData.h"
    2929
    30 #include "EventNames.h"
    31 #include "StringImpl.h"
    32 #include "ThreadTimers.h"
    33 #include <wtf/UnusedParam.h>
     30namespace WTF {
    3431
    35 #if USE(ICU_UNICODE)
    36 #include "TextCodecICU.h"
     32#if WTFTHREADDATA_MULTITHREADED
     33ThreadSpecific<WTFThreadData>* WTFThreadData::staticData;
     34#else
     35WTFThreadData* WTFThreadData::staticData;
    3736#endif
    3837
    39 #if PLATFORM(MAC)
    40 #include "TextCodecMac.h"
    41 #endif
    42 
    43 #if ENABLE(WORKERS)
    44 #include <wtf/Threading.h>
    45 #include <wtf/ThreadSpecific.h>
    46 using namespace WTF;
    47 #endif
    48 
    49 namespace WebCore {
    50 
    51 #if ENABLE(WORKERS)
    52 ThreadSpecific<ThreadGlobalData>* ThreadGlobalData::staticData;
    53 #else
    54 ThreadGlobalData* ThreadGlobalData::staticData;
    55 #endif
    56 
    57 ThreadGlobalData::ThreadGlobalData()
    58     : m_atomicStringTable(new HashSet<StringImpl*>)
    59     , m_eventNames(new EventNames)
    60     , m_threadTimers(new ThreadTimers)
    61 #ifndef NDEBUG
    62     , m_isMainThread(isMainThread())
    63 #endif
    64 #if USE(ICU_UNICODE)
    65     , m_cachedConverterICU(new ICUConverterWrapper)
    66 #endif
    67 #if PLATFORM(MAC)
    68     , m_cachedConverterTEC(new TECConverterWrapper)
     38WTFThreadData::WTFThreadData()
     39    : m_atomicStringTable(0)
     40    , m_atomicStringTableDestructor(0)
     41#if USE(JSC)
     42    , m_defaultIdentifierTable(0)
     43    , m_currentIdentifierTable(0)
    6944#endif
    7045{
    71     // StringImpl::empty() does not construct its static string in a threadsafe fashion,
    72     // so ensure it has been initialized from here.
    73     //
    74     // This constructor will have been called on the main thread before being called on
    75     // any other thread, and is only called once per thread.
    76     StringImpl::empty();
    7746}
    7847
    79 ThreadGlobalData::~ThreadGlobalData()
     48WTFThreadData::~WTFThreadData()
    8049{
    81 #if PLATFORM(MAC)
    82     delete m_cachedConverterTEC;
    83 #endif
    84 #if USE(ICU_UNICODE)
    85     delete m_cachedConverterICU;
    86 #endif
    87     delete m_eventNames;
    88     delete m_atomicStringTable;
    89     delete m_threadTimers;
     50    if (m_atomicStringTableDestructor)
     51        m_atomicStringTableDestructor(m_atomicStringTable);
    9052}
    9153
  • trunk/JavaScriptCore/wtf/WTFThreadData.h

    r57765 r57829  
    2525 */
    2626
    27 #ifndef ThreadGlobalData_h
    28 #define ThreadGlobalData_h
     27#ifndef WTFThreadData_h
     28#define WTFThreadData_h
    2929
    30 #include "StringHash.h"
    3130#include <wtf/HashMap.h>
    3231#include <wtf/HashSet.h>
    3332#include <wtf/Noncopyable.h>
    3433
    35 #if ENABLE(WORKERS)
     34// This was ENABLE(WORKERS) in WebCore, but this is not defined when compiling JSC.
     35// However this check was not correct anyway, re this comment:
     36//    // FIXME: Workers are not necessarily the only feature that make per-thread global data necessary.
     37//    // We need to check for e.g. database objects manipulating strings on secondary threads.
     38// Always enabling this is safe, and should be a better option until we can come up
     39// with a better define.
     40#define WTFTHREADDATA_MULTITHREADED 1
     41
     42#if WTFTHREADDATA_MULTITHREADED
    3643#include <wtf/ThreadSpecific.h>
    3744#include <wtf/Threading.h>
    38 using WTF::ThreadSpecific;
    3945#endif
    4046
     47// FIXME: This is a temporary layering violation while we move more string code to WTF.
     48namespace JSC {
     49class IdentifierTable;
     50}
     51
     52// FIXME: This is a temporary layering violation while we move more string code to WTF.
    4153namespace WebCore {
     54class AtomicStringTable;
     55}
    4256
    43     class EventNames;
    44     struct ICUConverterWrapper;
    45     struct TECConverterWrapper;
    46     class ThreadTimers;
     57typedef void (*AtomicStringTableDestructor)(WebCore::AtomicStringTable*);
    4758
    48     class ThreadGlobalData : public Noncopyable {
    49     public:
    50         ThreadGlobalData();
    51         ~ThreadGlobalData();
     59namespace WTF {
    5260
    53         EventNames& eventNames() { return *m_eventNames; }
    54         HashSet<StringImpl*>& atomicStringTable() { return *m_atomicStringTable; }
    55         ThreadTimers& threadTimers() { return *m_threadTimers; }
     61class WTFThreadData : public Noncopyable {
     62public:
     63    WTFThreadData();
     64    ~WTFThreadData();
    5665
    57 #if USE(ICU_UNICODE)
    58         ICUConverterWrapper& cachedConverterICU() { return *m_cachedConverterICU; }
     66    WebCore::AtomicStringTable* atomicStringTable()
     67    {
     68        return m_atomicStringTable;
     69    }
     70
     71#if USE(JSC)
     72    void initializeIdentifierTable(JSC::IdentifierTable* identifierTable)
     73    {
     74        m_defaultIdentifierTable = identifierTable;
     75        m_currentIdentifierTable = identifierTable;
     76    }
     77
     78    JSC::IdentifierTable* currentIdentifierTable()
     79    {
     80        return m_currentIdentifierTable;
     81    }
     82
     83    JSC::IdentifierTable* setCurrentIdentifierTable(JSC::IdentifierTable* identifierTable)
     84    {
     85        JSC::IdentifierTable* oldIdentifierTable = m_currentIdentifierTable;
     86        m_currentIdentifierTable = identifierTable;
     87        return oldIdentifierTable;
     88    }
     89
     90    void resetCurrentIdentifierTable()
     91    {
     92        m_currentIdentifierTable = m_defaultIdentifierTable;
     93    }
    5994#endif
    6095
    61 #if PLATFORM(MAC)
    62         TECConverterWrapper& cachedConverterTEC() { return *m_cachedConverterTEC; }
     96private:
     97    WebCore::AtomicStringTable* m_atomicStringTable;
     98    AtomicStringTableDestructor m_atomicStringTableDestructor;
     99
     100#if USE(JSC)
     101    JSC::IdentifierTable* m_defaultIdentifierTable;
     102    JSC::IdentifierTable* m_currentIdentifierTable;
    63103#endif
    64104
    65     private:
    66         HashSet<StringImpl*>* m_atomicStringTable;
    67         EventNames* m_eventNames;
    68         ThreadTimers* m_threadTimers;
     105#if WTFTHREADDATA_MULTITHREADED
     106    static ThreadSpecific<WTFThreadData>* staticData;
     107#else
     108    static WTFThreadData* staticData;
     109#endif
     110    friend WTFThreadData& wtfThreadData();
     111    friend class WebCore::AtomicStringTable;
     112};
    69113
    70 #ifndef NDEBUG
    71         bool m_isMainThread;
    72 #endif
    73 
    74 #if USE(ICU_UNICODE)
    75         ICUConverterWrapper* m_cachedConverterICU;
    76 #endif
    77 
    78 #if PLATFORM(MAC)
    79         TECConverterWrapper* m_cachedConverterTEC;
    80 #endif
    81 
    82 #if ENABLE(WORKERS)
    83         static ThreadSpecific<ThreadGlobalData>* staticData;
     114inline WTFThreadData& wtfThreadData()
     115{
     116#if WTFTHREADDATA_MULTITHREADED
     117    // WRT WebCore:
     118    //    WTFThreadData is used on main thread before it could possibly be used
     119    //    on secondary ones, so there is no need for synchronization here.
     120    // WRT JavaScriptCore:
     121    //    wtfThreadData() is initially called from initializeThreading(), ensuring
     122    //    this is initially called in a pthread_once locked context.
     123    if (!WTFThreadData::staticData)
     124        WTFThreadData::staticData = new ThreadSpecific<WTFThreadData>;
     125    return **WTFThreadData::staticData;
    84126#else
    85         static ThreadGlobalData* staticData;
    86 #endif
    87         friend ThreadGlobalData& threadGlobalData();
    88     };
    89 
    90 inline ThreadGlobalData& threadGlobalData()
    91 {
    92     // FIXME: Workers are not necessarily the only feature that make per-thread global data necessary.
    93     // We need to check for e.g. database objects manipulating strings on secondary threads.
    94 
    95 #if ENABLE(WORKERS)
    96     // ThreadGlobalData is used on main thread before it could possibly be used on secondary ones, so there is no need for synchronization here.
    97     if (!ThreadGlobalData::staticData)
    98         ThreadGlobalData::staticData = new ThreadSpecific<ThreadGlobalData>;
    99     return **ThreadGlobalData::staticData;
    100 #else
    101     if (!ThreadGlobalData::staticData) {
    102         ThreadGlobalData::staticData = static_cast<ThreadGlobalData*>(fastMalloc(sizeof(ThreadGlobalData)));
    103         // ThreadGlobalData constructor indirectly uses staticData, so we need to set up the memory before invoking it.
    104         new (ThreadGlobalData::staticData) ThreadGlobalData;
     127    if (!WTFThreadData::staticData) {
     128        WTFThreadData::staticData = static_cast<WTFThreadData*>(fastMalloc(sizeof(WTFThreadData)));
     129        // WTFThreadData constructor indirectly uses staticData, so we need to set up the memory before invoking it.
     130        new (WTFThreadData::staticData) WTFThreadData;
    105131    }
    106     return *ThreadGlobalData::staticData;
     132    return *WTFThreadData::staticData;
    107133#endif
    108134}
    109    
    110 } // namespace WebCore
    111135
    112 #endif // ThreadGlobalData_h
     136} // namespace WTF
     137
     138using WTF::WTFThreadData;
     139using WTF::wtfThreadData;
     140
     141#endif // WTFThreadData_h
Note: See TracChangeset for help on using the changeset viewer.