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/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.