Ignore:
Timestamp:
Jul 3, 2012, 3:57:00 PM (13 years ago)
Author:
[email protected]
Message:

Enh: Hash Const JSString in Backing Stores to Save Memory
https://bugs.webkit.org/show_bug.cgi?id=86024

Reviewed by Oliver Hunt.

During garbage collection, each marking thread keeps a HashMap of
strings. While visiting via MarkStack::copyAndAppend(), we check to
see if the string we are visiting is already in the HashMap. If not
we add it. If so, we change the reference to the current string we're
visiting to the prior string.

To reduce the performance impact of this change, two throttles have
ben added. 1) We only try hash consting if a significant number of new
strings have been created since the last hash const. Currently this is
set at 100 strings. 2) If a string is unique at the end of a marking
it will not be checked during further GC phases. In some cases this
won't catch all duplicates, but we are trying to catch the growth of
duplicate strings.

  • heap/Heap.cpp:

(JSC::Heap::markRoots):

  • heap/MarkStack.cpp:

(JSC::MarkStackThreadSharedData::resetChildren):
(JSC::MarkStackThreadSharedData::MarkStackThreadSharedData):
(JSC::MarkStackThreadSharedData::reset):
(JSC::MarkStack::setup): Check to see if enough strings have been created
to hash const.
(JSC::MarkStack::reset): Added call to clear m_uniqueStrings.
(JSC::JSString::tryHashConstLock): New method to lock JSString for
hash consting.
(JSC::JSString::releaseHashConstLock): New unlock method.
(JSC::JSString::shouldTryHashConst): Set of checks to see if we should
try to hash const the string.
(JSC::MarkStack::internalAppend): New method that performs the hash consting.
(JSC::SlotVisitor::copyAndAppend): Changed to call the new hash
consting internalAppend().

  • heap/MarkStack.h:

(MarkStackThreadSharedData):
(MarkStack):

  • runtime/JSGlobalData.cpp:

(JSC::JSGlobalData::JSGlobalData):

  • runtime/JSGlobalData.h:

(JSGlobalData):
(JSC::JSGlobalData::haveEnoughNewStringsToHashConst):
(JSC::JSGlobalData::resetNewStringsSinceLastHashConst):

  • runtime/JSString.h:

(JSString): Changed from using bool flags to using an unsigned
m_flags field. This works better with the weakCompareAndSwap in
JSString::tryHashConstLock(). Changed the 8bitness setting and
checking to use new accessors.
(JSC::JSString::JSString):
(JSC::JSString::finishCreation):
(JSC::JSString::is8Bit): Updated for new m_flags.
(JSC::JSString::setIs8Bit): New setter.
New hash const flags accessors:
(JSC::JSString::isHashConstSingleton):
(JSC::JSString::clearHashConstSingleton):
(JSC::JSString::setHashConstSingleton):
(JSC::JSRopeString::finishCreation):
(JSC::JSRopeString::append):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/heap/MarkStack.h

    r121798 r121806  
    220220        MarkStackSegmentAllocator m_segmentAllocator;
    221221       
     222        bool m_shouldHashConst;
     223
    222224        Vector<ThreadIdentifier> m_markingThreads;
    223225        Vector<MarkStack*> m_markingThreadsMarkStack;
     
    260262        bool isEmpty() { return m_stack.isEmpty(); }
    261263
     264        void setup();
    262265        void reset();
    263266
     
    293296        void internalAppend(JSCell*);
    294297        void internalAppend(JSValue);
     298        void internalAppend(JSValue*);
    295299       
    296300        JS_EXPORT_PRIVATE void mergeOpaqueRoots();
     
    325329       
    326330        MarkStackThreadSharedData& m_shared;
     331
     332        bool m_shouldHashConst; // Local per-thread copy of shared flag for performance reasons
     333        typedef HashMap<StringImpl*, JSValue> UniqueStringMap;
     334        UniqueStringMap m_uniqueStrings;
    327335
    328336#if ENABLE(OBJECT_MARK_LOGGING)
     
    340348        , m_isInParallelMode(false)
    341349        , m_shared(shared)
     350        , m_shouldHashConst(false)
    342351    {
    343352    }
Note: See TracChangeset for help on using the changeset viewer.