Changeset 52856 in webkit for trunk/JavaScriptCore/runtime


Ignore:
Timestamp:
Jan 6, 2010, 11:33:29 AM (15 years ago)
Author:
[email protected]
Message:

https://bugs.webkit.org/show_bug.cgi?id=33236
Remove m_identifierTable pointer from UString

Reviewed by Sam Weinig.

JavaScriptCore:

Currently every string holds a pointer so that during destruction,
if a string has been used as an identifier, it can remove itself
from the table. By instead accessing the identifierTable via a
thread specific tracking the table associated with the current
globaldata, we can save the memory cost of this pointer.

  • API/APIShims.h:

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

  • change the API shims to track the identifierTable of the current JSGlobalData.
  • API/JSContextRef.cpp:

(JSContextGroupCreate):

  • update creation of JSGlobalData for API usage to use new create method.
  • fix shim instanciation bug in JSGlobalContextCreateInGroup.

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

  • add asserts to check the identifierTable is being tracked correctly.
  • runtime/Identifier.cpp:

(JSC::IdentifierTable::~IdentifierTable):
(JSC::IdentifierTable::add):
(JSC::Identifier::remove):
(JSC::Identifier::checkSameIdentifierTable):
(JSC::createIdentifierTableSpecificCallback):
(JSC::createIdentifierTableSpecific):
(JSC::createDefaultDataSpecific):

  • Use currentIdentifierTable() instead of UStringImpl::m_identifierTable.
  • Define methods to access the thread specific identifier tables.
  • runtime/Identifier.h:

(JSC::ThreadIdentifierTableData::ThreadIdentifierTableData):
(JSC::defaultIdentifierTable):
(JSC::setDefaultIdentifierTable):
(JSC::currentIdentifierTable):
(JSC::setCurrentIdentifierTable):
(JSC::resetCurrentIdentifierTable):

  • Declare methods to access the thread specific identifier tables.
  • runtime/JSGlobalData.cpp:

(JSC::JSGlobalData::createNonDefault):
(JSC::JSGlobalData::create):
(JSC::JSGlobalData::sharedInstance):

  • creation of JSGlobalData objects, other than for API usage, associate themselves with the current thread.
  • runtime/JSGlobalData.h:
  • runtime/UStringImpl.cpp:

(JSC::UStringImpl::destroy):

  • destroy() method should be using isIdentifier().
  • runtime/UStringImpl.h:

(JSC::UStringImpl::isIdentifier):
(JSC::UStringImpl::setIsIdentifier):
(JSC::UStringImpl::checkConsistency):
(JSC::UStringImpl::UStringImpl):

  • replace m_identifierTable with a single m_isIdentifier bit.
  • wtf/StringHashFunctions.h:

(WTF::stringHash):

  • change string hash result from 32-bit to 31-bit, to free a bit in UStringImpl for m_isIdentifier.

JavaScriptGlue:

Add API shims similar to those used in the JSC API to track the current identifierTable.

  • JSBase.cpp:

(JSBase::Release):

  • JSUtils.cpp:

(JSObjectKJSValue):
(KJSValueToCFTypeInternal):
(unprotectGlobalObject):
(JSGlueAPIEntry::JSGlueAPIEntry):
(JSGlueAPIEntry::~JSGlueAPIEntry):
(JSGlueAPICallback::JSGlueAPICallback):
(JSGlueAPICallback::~JSGlueAPICallback):

  • JSUtils.h:
  • JSValueWrapper.cpp:

(JSValueWrapper::JSObjectCopyPropertyNames):
(JSValueWrapper::JSObjectCopyProperty):
(JSValueWrapper::JSObjectSetProperty):
(JSValueWrapper::JSObjectCallFunction):
(JSValueWrapper::JSObjectCopyCFValue):

  • JavaScriptGlue.cpp:

(JSRunCreate):
(JSRunEvaluate):
(JSRunCheckSyntax):
(JSCollect):

  • JavaScriptGlue.xcodeproj/project.pbxproj:
  • UserObjectImp.cpp:

(UserObjectImp::callAsFunction):

Location:
trunk/JavaScriptCore/runtime
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/Completion.cpp

    r48905 r52856  
    3737{
    3838    JSLock lock(exec);
     39    ASSERT(exec->globalData().identifierTable == currentIdentifierTable());
    3940
    4041    RefPtr<ProgramExecutable> program = ProgramExecutable::create(exec, source);
     
    4950{
    5051    JSLock lock(exec);
     52    ASSERT(exec->globalData().identifierTable == currentIdentifierTable());
    5153
    5254    RefPtr<ProgramExecutable> program = ProgramExecutable::create(exec, source);
  • trunk/JavaScriptCore/runtime/Identifier.cpp

    r52762 r52856  
    2929#include <wtf/HashSet.h>
    3030
     31using WTF::ThreadSpecific;
     32
    3133namespace JSC {
    3234
     
    3941        HashSet<UString::Rep*>::iterator end = m_table.end();
    4042        for (HashSet<UString::Rep*>::iterator iter = m_table.begin(); iter != end; ++iter)
    41             (*iter)->setIdentifierTable(0);
     43            (*iter)->setIsIdentifier(false);
    4244    }
    4345   
     
    4547    {
    4648        std::pair<HashSet<UString::Rep*>::iterator, bool> result = m_table.add(value);
    47         (*result.first)->setIdentifierTable(this);
     49        (*result.first)->setIsIdentifier(true);
    4850        return result;
    4951    }
     
    5355    {
    5456        std::pair<HashSet<UString::Rep*>::iterator, bool> result = m_table.add<U, V>(value);
    55         (*result.first)->setIdentifierTable(this);
     57        (*result.first)->setIsIdentifier(true);
    5658        return result;
    5759    }
     
    239241void Identifier::remove(UString::Rep* r)
    240242{
    241     r->identifierTable()->remove(r);
     243    currentIdentifierTable()->remove(r);
    242244}
    243245
    244246#ifndef NDEBUG
    245247
    246 void Identifier::checkSameIdentifierTable(ExecState* exec, UString::Rep* rep)
    247 {
    248     ASSERT(rep->identifierTable() == exec->globalData().identifierTable);
    249 }
    250 
    251 void Identifier::checkSameIdentifierTable(JSGlobalData* globalData, UString::Rep* rep)
    252 {
    253     ASSERT(rep->identifierTable() == globalData->identifierTable);
     248void Identifier::checkSameIdentifierTable(ExecState* exec, UString::Rep*)
     249{
     250    ASSERT(exec->globalData().identifierTable == currentIdentifierTable());
     251}
     252
     253void Identifier::checkSameIdentifierTable(JSGlobalData* globalData, UString::Rep*)
     254{
     255    ASSERT(globalData->identifierTable == currentIdentifierTable());
    254256}
    255257
     
    266268#endif
    267269
     270ThreadSpecific<ThreadIdentifierTableData>* g_identifierTableSpecific = 0;
     271
     272#if ENABLE(JSC_MULTIPLE_THREADS)
     273
     274pthread_once_t createIdentifierTableSpecificOnce = PTHREAD_ONCE_INIT;
     275void createIdentifierTableSpecificCallback()
     276{
     277    ASSERT(!g_identifierTableSpecific);
     278    g_identifierTableSpecific = new ThreadSpecific<ThreadIdentifierTableData>();
     279}
     280void createIdentifierTableSpecific()
     281{
     282    pthread_once(&createIdentifierTableSpecificOnce, createIdentifierTableSpecificCallback);
     283    ASSERT(g_identifierTableSpecific);
     284}
     285
     286#else
     287
     288void createDefaultDataSpecific()
     289{
     290    ASSERT(!g_identifierTableSpecific);
     291    g_identifierTableSpecific = new ThreadSpecific<ThreadIdentifierTableData>();
     292}
     293
     294#endif
     295
    268296} // namespace JSC
  • trunk/JavaScriptCore/runtime/Identifier.h

    r52762 r52856  
    2323
    2424#include "JSGlobalData.h"
     25#include "ThreadSpecific.h"
    2526#include "UString.h"
    2627
     
    142143    void deleteIdentifierTable(IdentifierTable*);
    143144
     145    struct ThreadIdentifierTableData {
     146        ThreadIdentifierTableData()
     147            : defaultIdentifierTable(0)
     148            , currentIdentifierTable(0)
     149        {
     150        }
     151
     152        IdentifierTable* defaultIdentifierTable;
     153        IdentifierTable* currentIdentifierTable;
     154    };
     155
     156    extern WTF::ThreadSpecific<ThreadIdentifierTableData>* g_identifierTableSpecific;
     157    void createIdentifierTableSpecific();
     158
     159    inline IdentifierTable* defaultIdentifierTable()
     160    {
     161        if (!g_identifierTableSpecific)
     162            createIdentifierTableSpecific();
     163        ThreadIdentifierTableData& data = **g_identifierTableSpecific;
     164
     165        return data.defaultIdentifierTable;
     166    }
     167
     168    inline void setDefaultIdentifierTable(IdentifierTable* identifierTable)
     169    {
     170        if (!g_identifierTableSpecific)
     171            createIdentifierTableSpecific();
     172        ThreadIdentifierTableData& data = **g_identifierTableSpecific;
     173
     174        data.defaultIdentifierTable = identifierTable;
     175    }
     176
     177    inline IdentifierTable* currentIdentifierTable()
     178    {
     179        if (!g_identifierTableSpecific)
     180            createIdentifierTableSpecific();
     181        ThreadIdentifierTableData& data = **g_identifierTableSpecific;
     182
     183        return data.currentIdentifierTable;
     184    }
     185
     186    inline IdentifierTable* setCurrentIdentifierTable(IdentifierTable* identifierTable)
     187    {
     188        if (!g_identifierTableSpecific)
     189            createIdentifierTableSpecific();
     190        ThreadIdentifierTableData& data = **g_identifierTableSpecific;
     191
     192        IdentifierTable* oldIdentifierTable = data.currentIdentifierTable;
     193        data.currentIdentifierTable = identifierTable;
     194        return oldIdentifierTable;
     195    }
     196
     197    inline void resetCurrentIdentifierTable()
     198    {
     199        if (!g_identifierTableSpecific)
     200            createIdentifierTableSpecific();
     201        ThreadIdentifierTableData& data = **g_identifierTableSpecific;
     202
     203        data.currentIdentifierTable = data.defaultIdentifierTable;
     204    }
     205
    144206} // namespace JSC
    145207
  • trunk/JavaScriptCore/runtime/JSGlobalData.cpp

    r52082 r52856  
    4646#include "JSPropertyNameIterator.h"
    4747#include "JSStaticScopeObject.h"
    48 #include "Parser.h"
    4948#include "Lexer.h"
    5049#include "Lookup.h"
    5150#include "Nodes.h"
     51#include "Parser.h"
    5252
    5353#if ENABLE(JSC_MULTIPLE_THREADS)
     
    203203}
    204204
    205 PassRefPtr<JSGlobalData> JSGlobalData::create(bool isShared)
    206 {
    207     return adoptRef(new JSGlobalData(isShared, VPtrSet()));
     205PassRefPtr<JSGlobalData> JSGlobalData::createNonDefault()
     206{
     207    return adoptRef(new JSGlobalData(false, VPtrSet()));
     208}
     209
     210PassRefPtr<JSGlobalData> JSGlobalData::create()
     211{
     212    JSGlobalData* globalData = new JSGlobalData(false, VPtrSet());
     213    setDefaultIdentifierTable(globalData->identifierTable);
     214    setCurrentIdentifierTable(globalData->identifierTable);
     215    return adoptRef(globalData);
    208216}
    209217
     
    225233    JSGlobalData*& instance = sharedInstanceInternal();
    226234    if (!instance) {
    227         instance = create(true).releaseRef();
     235        instance = new JSGlobalData(true, VPtrSet());
    228236#if ENABLE(JSC_MULTIPLE_THREADS)
    229237        instance->makeUsableFromMultipleThreads();
  • trunk/JavaScriptCore/runtime/JSGlobalData.h

    r52082 r52856  
    9494        static JSGlobalData& sharedInstance();
    9595
    96         static PassRefPtr<JSGlobalData> create(bool isShared = false);
     96        static PassRefPtr<JSGlobalData> create();
    9797        static PassRefPtr<JSGlobalData> createLeaked();
     98        static PassRefPtr<JSGlobalData> createNonDefault();
    9899        ~JSGlobalData();
    99100
  • trunk/JavaScriptCore/runtime/UStringImpl.cpp

    r52776 r52856  
    6565    checkConsistency();
    6666
    67     if (identifierTable())
     67    if (isIdentifier())
    6868        Identifier::remove(this);
    6969
  • trunk/JavaScriptCore/runtime/UStringImpl.h

    r52776 r52856  
    138138    unsigned computedHash() const { ASSERT(m_hash); return m_hash; } // fast path for Identifiers
    139139    void setHash(unsigned hash) { ASSERT(hash == computeHash(data(), m_length)); m_hash = hash; } // fast path for Identifiers
    140     bool isIdentifier() const { return m_identifierTable; }
    141     IdentifierTable* identifierTable() const { return m_identifierTable; }
    142     void setIdentifierTable(IdentifierTable* table) { ASSERT(!isStatic()); m_identifierTable = table; }
     140    bool isIdentifier() const { return m_isIdentifier; }
     141    void setIsIdentifier(bool isIdentifier) { m_isIdentifier = isIdentifier; }
    143142
    144143    UStringImpl* ref() { m_refCount += s_refCountIncrement; return this; }
     
    174173        ASSERT(bufferOwnerString()->bufferOwnership() != BufferSubstring);
    175174        // Static strings cannot be put in identifier tables, because they are globally shared.
    176         ASSERT(!isStatic() || !identifierTable());
     175        ASSERT(!isStatic() || !isIdentifier());
    177176    }
    178177
     
    194193        , m_refCount(s_refCountIncrement)
    195194        , m_hash(0)
    196         , m_identifierTable(0)
     195        , m_isIdentifier(false)
    197196        , m_dataBuffer(0, ownership)
    198197    {
     
    210209        , m_refCount(s_staticRefCountInitialValue)
    211210        , m_hash(0)
    212         , m_identifierTable(0)
     211        , m_isIdentifier(false)
    213212        , m_dataBuffer(0, BufferOwned)
    214213    {
     
    222221        , m_refCount(s_refCountIncrement)
    223222        , m_hash(0)
    224         , m_identifierTable(0)
     223        , m_isIdentifier(false)
    225224        , m_dataBuffer(base.releaseRef(), BufferSubstring)
    226225    {
     
    239238        , m_refCount(s_refCountIncrement)
    240239        , m_hash(0)
    241         , m_identifierTable(0)
     240        , m_isIdentifier(false)
    242241        , m_dataBuffer(sharedBuffer.releaseRef(), BufferShared)
    243242    {
     
    269268    int m_length;
    270269    unsigned m_refCount;
    271     mutable unsigned m_hash;
    272     IdentifierTable* m_identifierTable;
     270    mutable unsigned m_hash : 31;
     271    mutable unsigned m_isIdentifier : 1;
    273272    UntypedPtrAndBitfield m_dataBuffer;
    274273
Note: See TracChangeset for help on using the changeset viewer.