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):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.