Ignore:
Timestamp:
May 3, 2010, 4:03:37 PM (15 years ago)
Author:
[email protected]
Message:

Rolling out r58114 - this introduced memory leaks of
AtomicStrings then workers terminated.

Reviewed by NOBODY (reverting previous commit).

(JSC::ThunkHelpers::stringImplDataOffset):

  • runtime/Identifier.cpp:

(JSC::IdentifierTable::~IdentifierTable):
(JSC::IdentifierTable::add):
(JSC::IdentifierCStringTranslator::hash):
(JSC::IdentifierCStringTranslator::equal):
(JSC::IdentifierCStringTranslator::translate):
(JSC::Identifier::add):
(JSC::IdentifierUCharBufferTranslator::hash):
(JSC::IdentifierUCharBufferTranslator::equal):
(JSC::IdentifierUCharBufferTranslator::translate):
(JSC::Identifier::addSlowCase):

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

(JSC::JSGlobalData::JSGlobalData):
(JSC::JSGlobalData::~JSGlobalData):

  • runtime/JSGlobalData.h:
  • wtf/WTFThreadData.cpp:

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

  • wtf/WTFThreadData.h:

(JSC::IdentifierTable::remove):
(JSC::IdentifierTable::literalTable):
(WTF::WTFThreadData::atomicStringTable):

  • wtf/text/AtomicString.cpp:

(WebCore::AtomicStringTable::create):
(WebCore::AtomicStringTable::table):
(WebCore::AtomicStringTable::destroy):
(WebCore::stringTable):
(WebCore::CStringTranslator::hash):
(WebCore::CStringTranslator::equal):
(WebCore::CStringTranslator::translate):
(WebCore::operator==):
(WebCore::AtomicString::add):
(WebCore::equal):
(WebCore::UCharBufferTranslator::hash):
(WebCore::UCharBufferTranslator::equal):
(WebCore::UCharBufferTranslator::translate):
(WebCore::HashAndCharactersTranslator::hash):
(WebCore::HashAndCharactersTranslator::equal):
(WebCore::HashAndCharactersTranslator::translate):
(WebCore::AtomicString::find):
(WebCore::AtomicString::remove):

  • wtf/text/AtomicStringTable.h: Removed.
  • wtf/text/StringImpl.cpp:

(WebCore::StringImpl::~StringImpl):

  • wtf/text/StringImpl.h:

(WebCore::StringImpl::inTable):
(WebCore::StringImpl::setInTable):
(WebCore::equal):

  • wtf/text/StringImplBase.h:

(WTF::StringImplBase::StringImplBase):

File:
1 edited

Legend:

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

    r58114 r58712  
    3030#include <wtf/HashSet.h>
    3131#include <wtf/WTFThreadData.h>
    32 #include <wtf/text/AtomicStringTable.h>
    3332#include <wtf/text/StringHash.h>
    3433
     
    3736namespace JSC {
    3837
    39 class LiteralTable : public HashMap<const char*, RefPtr<StringImpl>, PtrHash<const char*> > {};
    40 
    41 LiteralTable* createLiteralTable()
    42 {
    43     return new LiteralTable;
    44 }
    45 
    46 void deleteLiteralTable(LiteralTable* table)
    47 {
    48     delete table;
     38IdentifierTable::~IdentifierTable()
     39{
     40    HashSet<StringImpl*>::iterator end = m_table.end();
     41    for (HashSet<StringImpl*>::iterator iter = m_table.begin(); iter != end; ++iter)
     42        (*iter)->setIsIdentifier(false);
     43}
     44std::pair<HashSet<StringImpl*>::iterator, bool> IdentifierTable::add(StringImpl* value)
     45{
     46    std::pair<HashSet<StringImpl*>::iterator, bool> result = m_table.add(value);
     47    (*result.first)->setIsIdentifier(true);
     48    return result;
     49}
     50template<typename U, typename V>
     51std::pair<HashSet<StringImpl*>::iterator, bool> IdentifierTable::add(U value)
     52{
     53    std::pair<HashSet<StringImpl*>::iterator, bool> result = m_table.add<U, V>(value);
     54    (*result.first)->setIsIdentifier(true);
     55    return result;
    4956}
    5057
     
    8087}
    8188
     89struct IdentifierCStringTranslator {
     90    static unsigned hash(const char* c)
     91    {
     92        return UString::Rep::computeHash(c);
     93    }
     94
     95    static bool equal(UString::Rep* r, const char* s)
     96    {
     97        return Identifier::equal(r, s);
     98    }
     99
     100    static void translate(UString::Rep*& location, const char* c, unsigned hash)
     101    {
     102        size_t length = strlen(c);
     103        UChar* d;
     104        UString::Rep* r = UString::Rep::createUninitialized(length, d).releaseRef();
     105        for (size_t i = 0; i != length; i++)
     106            d[i] = static_cast<unsigned char>(c[i]); // use unsigned char to zero-extend instead of sign-extend
     107        r->setHash(hash);
     108        location = r;
     109    }
     110};
     111
    82112PassRefPtr<UString::Rep> Identifier::add(JSGlobalData* globalData, const char* c)
    83113{
     
    89119        return add(globalData, globalData->smallStrings.singleCharacterStringRep(static_cast<unsigned char>(c[0])));
    90120
    91     LiteralTable* literalTable = globalData->literalTable;
    92     pair<LiteralTable::iterator, bool> result = literalTable->add(c, 0);
    93     if (!result.second) // pre-existing entry
    94         return result.first->second;
    95 
    96     RefPtr<StringImpl> addedString = globalData->identifierTable->add(c);
    97     result.first->second = addedString.get();
     121    IdentifierTable& identifierTable = *globalData->identifierTable;
     122    LiteralIdentifierTable& literalIdentifierTable = identifierTable.literalTable();
     123
     124    const LiteralIdentifierTable::iterator& iter = literalIdentifierTable.find(c);
     125    if (iter != literalIdentifierTable.end())
     126        return iter->second;
     127
     128    pair<HashSet<UString::Rep*>::iterator, bool> addResult = identifierTable.add<const char*, IdentifierCStringTranslator>(c);
     129
     130    // If the string is newly-translated, then we need to adopt it.
     131    // The boolean in the pair tells us if that is so.
     132    RefPtr<UString::Rep> addedString = addResult.second ? adoptRef(*addResult.first) : *addResult.first;
     133
     134    literalIdentifierTable.add(c, addedString.get());
    98135
    99136    return addedString.release();
     
    104141    return add(&exec->globalData(), c);
    105142}
     143
     144struct UCharBuffer {
     145    const UChar* s;
     146    unsigned int length;
     147};
     148
     149struct IdentifierUCharBufferTranslator {
     150    static unsigned hash(const UCharBuffer& buf)
     151    {
     152        return UString::Rep::computeHash(buf.s, buf.length);
     153    }
     154
     155    static bool equal(UString::Rep* str, const UCharBuffer& buf)
     156    {
     157        return Identifier::equal(str, buf.s, buf.length);
     158    }
     159
     160    static void translate(UString::Rep*& location, const UCharBuffer& buf, unsigned hash)
     161    {
     162        UChar* d;
     163        UString::Rep* r = UString::Rep::createUninitialized(buf.length, d).releaseRef();
     164        for (unsigned i = 0; i != buf.length; i++)
     165            d[i] = buf.s[i];
     166        r->setHash(hash);
     167        location = r;
     168    }
     169};
    106170
    107171PassRefPtr<UString::Rep> Identifier::add(JSGlobalData* globalData, const UChar* s, int length)
     
    114178    if (!length)
    115179        return UString::Rep::empty();
    116 
    117     return globalData->identifierTable->add(s, length);
     180    UCharBuffer buf = {s, length};
     181    pair<HashSet<UString::Rep*>::iterator, bool> addResult = globalData->identifierTable->add<UCharBuffer, IdentifierUCharBufferTranslator>(buf);
     182
     183    // If the string is newly-translated, then we need to adopt it.
     184    // The boolean in the pair tells us if that is so.
     185    return addResult.second ? adoptRef(*addResult.first) : *addResult.first;
    118186}
    119187
     
    138206    }
    139207
    140     return globalData->identifierTable->add(r);
     208    return *globalData->identifierTable->add(r).first;
    141209}
    142210
Note: See TracChangeset for help on using the changeset viewer.