[JSC] JSPropertyNameEnumerator could be destructorless.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Nov 2015 15:59:27 +0000 (15:59 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Nov 2015 15:59:27 +0000 (15:59 +0000)
<https://webkit.org/b/151242>

Reviewed by Mark Lam.

Make JSPropertyNameEnumerator destructorless and have it store the property names
cache in CopiedSpace. This was the most popular occupant of 64-byte destructor cells
in MarkedSpace, so making it destructorless gets rid of some ill-filled MarkedBlocks.

* heap/CopyToken.h:
* runtime/JSPropertyNameEnumerator.cpp:
(JSC::JSPropertyNameEnumerator::finishCreation):
(JSC::JSPropertyNameEnumerator::visitChildren):
(JSC::JSPropertyNameEnumerator::copyBackingStore):
(JSC::JSPropertyNameEnumerator::destroy): Deleted.
* runtime/JSPropertyNameEnumerator.h:

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

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/heap/CopyToken.h
Source/JavaScriptCore/runtime/JSPropertyNameEnumerator.cpp
Source/JavaScriptCore/runtime/JSPropertyNameEnumerator.h

index 7097449..26ba93e 100644 (file)
@@ -1,3 +1,22 @@
+2015-11-13  Andreas Kling  <akling@apple.com>
+
+        [JSC] JSPropertyNameEnumerator could be destructorless.
+        <https://webkit.org/b/151242>
+
+        Reviewed by Mark Lam.
+
+        Make JSPropertyNameEnumerator destructorless and have it store the property names
+        cache in CopiedSpace. This was the most popular occupant of 64-byte destructor cells
+        in MarkedSpace, so making it destructorless gets rid of some ill-filled MarkedBlocks.
+
+        * heap/CopyToken.h:
+        * runtime/JSPropertyNameEnumerator.cpp:
+        (JSC::JSPropertyNameEnumerator::finishCreation):
+        (JSC::JSPropertyNameEnumerator::visitChildren):
+        (JSC::JSPropertyNameEnumerator::copyBackingStore):
+        (JSC::JSPropertyNameEnumerator::destroy): Deleted.
+        * runtime/JSPropertyNameEnumerator.h:
+
 2015-11-12  Benjamin Poulain  <bpoulain@apple.com>
 
         [JSC] Do not generate an Add when adding a zero immediate to something
index e8f8109..d79038a 100644 (file)
@@ -32,7 +32,8 @@ enum CopyToken {
     ButterflyCopyToken,
     TypedArrayVectorCopyToken,
     MapBackingStoreCopyToken,
-    DirectArgumentsOverridesCopyToken
+    DirectArgumentsOverridesCopyToken,
+    JSPropertyNameEnumeratorCopyToken,
 };
 
 } // namespace JSC
index 690920f..a0d6c62 100644 (file)
@@ -26,6 +26,8 @@
 #include "config.h"
 #include "JSPropertyNameEnumerator.h"
 
+#include "CopiedBlockInlines.h"
+#include "CopyVisitorInlines.h"
 #include "JSCInlines.h"
 #include "StrongInlines.h"
 
@@ -70,25 +72,45 @@ void JSPropertyNameEnumerator::finishCreation(VM& vm, uint32_t indexedLength, ui
     m_endStructurePropertyIndex = endStructurePropertyIndex;
     m_endGenericPropertyIndex = vector.size();
 
-    m_propertyNames.resizeToFit(vector.size());
-    for (unsigned i = 0; i < vector.size(); ++i) {
-        const Identifier& identifier = vector[i];
-        m_propertyNames[i].set(vm, this, jsString(&vm, identifier.string()));
-    }
-}
+    if (!vector.isEmpty()) {
+        void* backingStore;
+        RELEASE_ASSERT(vm.heap.tryAllocateStorage(this, vector.size() * sizeof(WriteBarrier<JSString>), &backingStore));
+        WriteBarrier<JSString>* propertyNames = reinterpret_cast<WriteBarrier<JSString>*>(backingStore);
+        m_propertyNames.set(vm, this, propertyNames);
 
-void JSPropertyNameEnumerator::destroy(JSCell* cell)
-{
-    jsCast<JSPropertyNameEnumerator*>(cell)->JSPropertyNameEnumerator::~JSPropertyNameEnumerator();
+        for (unsigned i = 0; i < vector.size(); ++i)
+            propertyNames[i].set(vm, this, jsString(&vm, vector[i].string()));
+    }
 }
 
 void JSPropertyNameEnumerator::visitChildren(JSCell* cell, SlotVisitor& visitor)
 {
     Base::visitChildren(cell, visitor);
     JSPropertyNameEnumerator* thisObject = jsCast<JSPropertyNameEnumerator*>(cell);
-    for (unsigned i = 0; i < thisObject->m_propertyNames.size(); ++i)
-        visitor.append(&thisObject->m_propertyNames[i]);
     visitor.append(&thisObject->m_prototypeChain);
+
+    if (thisObject->cachedPropertyNameCount()) {
+        visitor.appendValues(reinterpret_cast<WriteBarrier<Unknown>*>(thisObject->m_propertyNames.getWithoutBarrier()), thisObject->cachedPropertyNameCount());
+        visitor.copyLater(
+            thisObject, JSPropertyNameEnumeratorCopyToken,
+            thisObject->m_propertyNames.getWithoutBarrier(), thisObject->cachedPropertyNameCount() * sizeof(JSString*));
+    }
+}
+
+void JSPropertyNameEnumerator::copyBackingStore(JSCell* cell, CopyVisitor& visitor, CopyToken token)
+{
+    JSPropertyNameEnumerator* thisObject = jsCast<JSPropertyNameEnumerator*>(cell);
+    ASSERT_GC_OBJECT_INHERITS(thisObject, info());
+
+    RELEASE_ASSERT(token == JSPropertyNameEnumeratorCopyToken);
+
+    void* oldPropertyNames = thisObject->m_propertyNames.getWithoutBarrier();
+    if (visitor.checkIfShouldCopy(oldPropertyNames)) {
+        WriteBarrier<JSString>* newPropertyNames = static_cast<WriteBarrier<JSString>*>(visitor.allocateNewSpace(thisObject->cachedPropertyNameCount() * sizeof(WriteBarrier<JSString>)));
+        memcpy(newPropertyNames, oldPropertyNames, thisObject->cachedPropertyNameCount() * sizeof(JSString*));
+        thisObject->m_propertyNames.setWithoutBarrier(newPropertyNames);
+        visitor.didCopy(oldPropertyNames, thisObject->cachedPropertyNameCount() * sizeof(JSString*));
+    }
 }
 
 } // namespace JSC
index 8406c46..7f48655 100644 (file)
@@ -43,9 +43,6 @@ public:
     static JSPropertyNameEnumerator* create(VM&);
     static JSPropertyNameEnumerator* create(VM&, Structure*, uint32_t, uint32_t, PropertyNameArray&);
 
-    static const bool needsDestruction = true;
-    static void destroy(JSCell*);
-
     static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
     {
         return Structure::create(vm, globalObject, prototype, TypeInfo(CellType, StructureFlags), info());
@@ -55,9 +52,9 @@ public:
 
     JSString* propertyNameAtIndex(uint32_t index) const
     {
-        if (index >= m_propertyNames.size())
+        if (index >= cachedPropertyNameCount())
             return nullptr;
-        return m_propertyNames[index].get();
+        return m_propertyNames.get(this)[index].get();
     }
 
     StructureChain* cachedPrototypeChain() const { return m_prototypeChain.get(); }
@@ -81,18 +78,25 @@ public:
     static ptrdiff_t cachedInlineCapacityOffset() { return OBJECT_OFFSETOF(JSPropertyNameEnumerator, m_cachedInlineCapacity); }
     static ptrdiff_t cachedPropertyNamesVectorOffset()
     {
-        return OBJECT_OFFSETOF(JSPropertyNameEnumerator, m_propertyNames) + Vector<WriteBarrier<JSString>>::dataMemoryOffset();
+        return OBJECT_OFFSETOF(JSPropertyNameEnumerator, m_propertyNames);
     }
 
     static void visitChildren(JSCell*, SlotVisitor&);
+    static void copyBackingStore(JSCell*, CopyVisitor&, CopyToken);
+
+    uint32_t cachedPropertyNameCount() const
+    {
+        // Note that this depends on m_endGenericPropertyIndex being the number of entries in m_propertyNames.
+        return m_endGenericPropertyIndex;
+    }
 
 private:
     JSPropertyNameEnumerator(VM&, StructureID, uint32_t);
     void finishCreation(VM&, uint32_t, uint32_t, PassRefPtr<PropertyNameArrayData>);
 
-    Vector<WriteBarrier<JSString>> m_propertyNames;
-    StructureID m_cachedStructureID;
+    CopyBarrier<WriteBarrier<JSString>> m_propertyNames;
     WriteBarrier<StructureChain> m_prototypeChain;
+    StructureID m_cachedStructureID;
     uint32_t m_indexedLength;
     uint32_t m_endStructurePropertyIndex;
     uint32_t m_endGenericPropertyIndex;