It's called "Hash Consing" not "Hash Consting"
authorfpizlo@apple.com <fpizlo@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Mar 2013 20:43:31 +0000 (20:43 +0000)
committerfpizlo@apple.com <fpizlo@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Mar 2013 20:43:31 +0000 (20:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=112768

Rubber stamped by Mark Hahnenberg.

See http://en.wikipedia.org/wiki/Hash_consing

* heap/GCThreadSharedData.cpp:
(JSC::GCThreadSharedData::GCThreadSharedData):
(JSC::GCThreadSharedData::reset):
* heap/GCThreadSharedData.h:
(GCThreadSharedData):
* heap/SlotVisitor.cpp:
(JSC::SlotVisitor::SlotVisitor):
(JSC::SlotVisitor::setup):
(JSC::SlotVisitor::reset):
(JSC::JSString::tryHashConsLock):
(JSC::JSString::releaseHashConsLock):
(JSC::JSString::shouldTryHashCons):
(JSC::SlotVisitor::internalAppend):
* heap/SlotVisitor.h:
(SlotVisitor):
* runtime/JSGlobalData.cpp:
(JSC::JSGlobalData::JSGlobalData):
* runtime/JSGlobalData.h:
(JSGlobalData):
(JSC::JSGlobalData::haveEnoughNewStringsToHashCons):
(JSC::JSGlobalData::resetNewStringsSinceLastHashCons):
* runtime/JSString.h:
(JSC::JSString::finishCreation):
(JSString):
(JSC::JSString::isHashConsSingleton):
(JSC::JSString::clearHashConsSingleton):
(JSC::JSString::setHashConsSingleton):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@146383 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/heap/GCThreadSharedData.cpp
Source/JavaScriptCore/heap/GCThreadSharedData.h
Source/JavaScriptCore/heap/SlotVisitor.cpp
Source/JavaScriptCore/heap/SlotVisitor.h
Source/JavaScriptCore/runtime/JSGlobalData.cpp
Source/JavaScriptCore/runtime/JSGlobalData.h
Source/JavaScriptCore/runtime/JSString.h

index ca2d2a6..27a75d6 100644 (file)
@@ -1,3 +1,40 @@
+2013-03-19  Filip Pizlo  <fpizlo@apple.com>
+
+        It's called "Hash Consing" not "Hash Consting"
+        https://bugs.webkit.org/show_bug.cgi?id=112768
+
+        Rubber stamped by Mark Hahnenberg.
+        
+        See http://en.wikipedia.org/wiki/Hash_consing
+
+        * heap/GCThreadSharedData.cpp:
+        (JSC::GCThreadSharedData::GCThreadSharedData):
+        (JSC::GCThreadSharedData::reset):
+        * heap/GCThreadSharedData.h:
+        (GCThreadSharedData):
+        * heap/SlotVisitor.cpp:
+        (JSC::SlotVisitor::SlotVisitor):
+        (JSC::SlotVisitor::setup):
+        (JSC::SlotVisitor::reset):
+        (JSC::JSString::tryHashConsLock):
+        (JSC::JSString::releaseHashConsLock):
+        (JSC::JSString::shouldTryHashCons):
+        (JSC::SlotVisitor::internalAppend):
+        * heap/SlotVisitor.h:
+        (SlotVisitor):
+        * runtime/JSGlobalData.cpp:
+        (JSC::JSGlobalData::JSGlobalData):
+        * runtime/JSGlobalData.h:
+        (JSGlobalData):
+        (JSC::JSGlobalData::haveEnoughNewStringsToHashCons):
+        (JSC::JSGlobalData::resetNewStringsSinceLastHashCons):
+        * runtime/JSString.h:
+        (JSC::JSString::finishCreation):
+        (JSString):
+        (JSC::JSString::isHashConsSingleton):
+        (JSC::JSString::clearHashConsSingleton):
+        (JSC::JSString::setHashConsSingleton):
+
 2013-03-20  Filip Pizlo  <fpizlo@apple.com>
 
         DFG implementation of op_strcat should inline rope allocations
index 5d2e908..e59cc1d 100644 (file)
@@ -55,7 +55,7 @@ size_t GCThreadSharedData::childVisitCount()
 GCThreadSharedData::GCThreadSharedData(JSGlobalData* globalData)
     : m_globalData(globalData)
     , m_copiedSpace(&globalData->heap.m_storageSpace)
-    , m_shouldHashConst(false)
+    , m_shouldHashCons(false)
     , m_sharedMarkStack(globalData->heap.blockAllocator())
     , m_numberOfActiveParallelMarkers(0)
     , m_parallelMarkersShouldExit(false)
@@ -115,9 +115,9 @@ void GCThreadSharedData::reset()
 #endif
     m_weakReferenceHarvesters.removeAll();
 
-    if (m_shouldHashConst) {
-        m_globalData->resetNewStringsSinceLastHashConst();
-        m_shouldHashConst = false;
+    if (m_shouldHashCons) {
+        m_globalData->resetNewStringsSinceLastHashCons();
+        m_shouldHashCons = false;
     }
 }
 
index dbc11b5..b2ea4b5 100644 (file)
@@ -80,7 +80,7 @@ private:
     JSGlobalData* m_globalData;
     CopiedSpace* m_copiedSpace;
     
-    bool m_shouldHashConst;
+    bool m_shouldHashCons;
 
     Vector<GCThread*> m_gcThreads;
 
index f3f4915..0e5b19d 100644 (file)
@@ -21,7 +21,7 @@ SlotVisitor::SlotVisitor(GCThreadSharedData& shared)
     , m_visitCount(0)
     , m_isInParallelMode(false)
     , m_shared(shared)
-    , m_shouldHashConst(false)
+    , m_shouldHashCons(false)
 #if !ASSERT_DISABLED
     , m_isCheckingForDefaultMarkViolation(false)
     , m_isDraining(false)
@@ -36,11 +36,11 @@ SlotVisitor::~SlotVisitor()
 
 void SlotVisitor::setup()
 {
-    m_shared.m_shouldHashConst = m_shared.m_globalData->haveEnoughNewStringsToHashConst();
-    m_shouldHashConst = m_shared.m_shouldHashConst;
+    m_shared.m_shouldHashCons = m_shared.m_globalData->haveEnoughNewStringsToHashCons();
+    m_shouldHashCons = m_shared.m_shouldHashCons;
 #if ENABLE(PARALLEL_GC)
     for (unsigned i = 0; i < m_shared.m_gcThreads.size(); ++i)
-        m_shared.m_gcThreads[i]->slotVisitor()->m_shouldHashConst = m_shared.m_shouldHashConst;
+        m_shared.m_gcThreads[i]->slotVisitor()->m_shouldHashCons = m_shared.m_shouldHashCons;
 #endif
 }
 
@@ -53,9 +53,9 @@ void SlotVisitor::reset()
 #else
     m_opaqueRoots.clear();
 #endif
-    if (m_shouldHashConst) {
+    if (m_shouldHashCons) {
         m_uniqueStrings.clear();
-        m_shouldHashConst = false;
+        m_shouldHashCons = false;
     }
 }
 
@@ -241,15 +241,15 @@ void SlotVisitor::mergeOpaqueRoots()
     m_opaqueRoots.clear();
 }
 
-ALWAYS_INLINE bool JSString::tryHashConstLock()
+ALWAYS_INLINE bool JSString::tryHashConsLock()
 {
 #if ENABLE(PARALLEL_GC)
     unsigned currentFlags = m_flags;
 
-    if (currentFlags & HashConstLock)
+    if (currentFlags & HashConsLock)
         return false;
 
-    unsigned newFlags = currentFlags | HashConstLock;
+    unsigned newFlags = currentFlags | HashConsLock;
 
     if (!WTF::weakCompareAndSwap(&m_flags, currentFlags, newFlags))
         return false;
@@ -257,26 +257,26 @@ ALWAYS_INLINE bool JSString::tryHashConstLock()
     WTF::memoryBarrierAfterLock();
     return true;
 #else
-    if (isHashConstSingleton())
+    if (isHashConsSingleton())
         return false;
 
-    m_flags |= HashConstLock;
+    m_flags |= HashConsLock;
 
     return true;
 #endif
 }
 
-ALWAYS_INLINE void JSString::releaseHashConstLock()
+ALWAYS_INLINE void JSString::releaseHashConsLock()
 {
 #if ENABLE(PARALLEL_GC)
     WTF::memoryBarrierBeforeUnlock();
 #endif
-    m_flags &= ~HashConstLock;
+    m_flags &= ~HashConsLock;
 }
 
-ALWAYS_INLINE bool JSString::shouldTryHashConst()
+ALWAYS_INLINE bool JSString::shouldTryHashCons()
 {
-    return ((length() > 1) && !isRope() && !isHashConstSingleton());
+    return ((length() > 1) && !isRope() && !isHashConsSingleton());
 }
 
 ALWAYS_INLINE void SlotVisitor::internalAppend(JSValue* slot)
@@ -298,21 +298,21 @@ ALWAYS_INLINE void SlotVisitor::internalAppend(JSValue* slot)
 
     validate(cell);
 
-    if (m_shouldHashConst && cell->isString()) {
+    if (m_shouldHashCons && cell->isString()) {
         JSString* string = jsCast<JSString*>(cell);
-        if (string->shouldTryHashConst() && string->tryHashConstLock()) {
+        if (string->shouldTryHashCons() && string->tryHashConsLock()) {
             UniqueStringMap::AddResult addResult = m_uniqueStrings.add(string->string().impl(), value);
             if (addResult.isNewEntry)
-                string->setHashConstSingleton();
+                string->setHashConsSingleton();
             else {
                 JSValue existingJSValue = addResult.iterator->value;
                 if (value != existingJSValue)
-                    jsCast<JSString*>(existingJSValue.asCell())->clearHashConstSingleton();
+                    jsCast<JSString*>(existingJSValue.asCell())->clearHashConsSingleton();
                 *slot = existingJSValue;
-                string->releaseHashConstLock();
+                string->releaseHashConsLock();
                 return;
             }
-            string->releaseHashConstLock();
+            string->releaseHashConsLock();
         }
     }
 
index 7d16dc2..6092f9f 100644 (file)
@@ -124,7 +124,7 @@ private:
     
     GCThreadSharedData& m_shared;
 
-    bool m_shouldHashConst; // Local per-thread copy of shared flag for performance reasons
+    bool m_shouldHashCons; // Local per-thread copy of shared flag for performance reasons
     typedef HashMap<StringImpl*, JSValue> UniqueStringMap;
     UniqueStringMap m_uniqueStrings;
 
index 7ff2de1..2499181 100644 (file)
@@ -182,7 +182,7 @@ JSGlobalData::JSGlobalData(GlobalDataType globalDataType, HeapType heapType)
 #if CPU(X86) && ENABLE(JIT)
     , m_timeoutCount(512)
 #endif
-    , m_newStringsSinceLastHashConst(0)
+    , m_newStringsSinceLastHashCons(0)
 #if ENABLE(ASSEMBLER)
     , m_canUseAssembler(enableAssembler(executableAllocator))
 #endif
index 9a59d14..15eb83a 100644 (file)
@@ -420,12 +420,12 @@ namespace JSC {
         unsigned m_timeoutCount;
 #endif
 
-        unsigned m_newStringsSinceLastHashConst;
+        unsigned m_newStringsSinceLastHashCons;
 
-        static const unsigned s_minNumberOfNewStringsToHashConst = 100;
+        static const unsigned s_minNumberOfNewStringsToHashCons = 100;
 
-        bool haveEnoughNewStringsToHashConst() { return m_newStringsSinceLastHashConst > s_minNumberOfNewStringsToHashConst; }
-        void resetNewStringsSinceLastHashConst() { m_newStringsSinceLastHashConst = 0; }
+        bool haveEnoughNewStringsToHashCons() { return m_newStringsSinceLastHashCons > s_minNumberOfNewStringsToHashCons; }
+        void resetNewStringsSinceLastHashCons() { m_newStringsSinceLastHashCons = 0; }
 
 #define registerTypedArrayFunction(type, capitalizedType) \
         void registerTypedArrayDescriptor(const capitalizedType##Array*, const TypedArrayDescriptor& descriptor) \
index a0bd28b..4cc689d 100644 (file)
@@ -95,7 +95,7 @@ namespace JSC {
             Base::finishCreation(globalData);
             m_length = length;
             setIs8Bit(m_value.impl()->is8Bit());
-            globalData.m_newStringsSinceLastHashConst++;
+            globalData.m_newStringsSinceLastHashCons++;
         }
 
         void finishCreation(JSGlobalData& globalData, size_t length, size_t cost)
@@ -105,7 +105,7 @@ namespace JSC {
             m_length = length;
             setIs8Bit(m_value.impl()->is8Bit());
             Heap::heap(this)->reportExtraMemoryCost(cost);
-            globalData.m_newStringsSinceLastHashConst++;
+            globalData.m_newStringsSinceLastHashCons++;
         }
 
     protected:
@@ -114,7 +114,7 @@ namespace JSC {
             Base::finishCreation(globalData);
             m_length = 0;
             setIs8Bit(true);
-            globalData.m_newStringsSinceLastHashConst++;
+            globalData.m_newStringsSinceLastHashCons++;
         }
         
     public:
@@ -167,8 +167,8 @@ namespace JSC {
         static void visitChildren(JSCell*, SlotVisitor&);
 
         enum {
-            HashConstLock = 1u << 2,
-            IsHashConstSingleton = 1u << 1,
+            HashConsLock = 1u << 2,
+            IsHashConsSingleton = 1u << 1,
             Is8Bit = 1u
         };
 
@@ -184,12 +184,12 @@ namespace JSC {
             else
                 m_flags &= ~Is8Bit;
         }
-        bool shouldTryHashConst();
-        bool isHashConstSingleton() const { return m_flags & IsHashConstSingleton; }
-        void clearHashConstSingleton() { m_flags &= ~IsHashConstSingleton; }
-        void setHashConstSingleton() { m_flags |= IsHashConstSingleton; }
-        bool tryHashConstLock();
-        void releaseHashConstLock();
+        bool shouldTryHashCons();
+        bool isHashConsSingleton() const { return m_flags & IsHashConsSingleton; }
+        void clearHashConsSingleton() { m_flags &= ~IsHashConsSingleton; }
+        void setHashConsSingleton() { m_flags |= IsHashConsSingleton; }
+        bool tryHashConsLock();
+        void releaseHashConsLock();
 
         unsigned m_flags;