Title: [192416] trunk/Source/_javascript_Core
Revision
192416
Author
akl...@apple.com
Date
2015-11-13 07:59:27 -0800 (Fri, 13 Nov 2015)

Log Message

[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:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (192415 => 192416)


--- trunk/Source/_javascript_Core/ChangeLog	2015-11-13 12:50:42 UTC (rev 192415)
+++ trunk/Source/_javascript_Core/ChangeLog	2015-11-13 15:59:27 UTC (rev 192416)
@@ -1,3 +1,22 @@
+2015-11-13  Andreas Kling  <akl...@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  <bpoul...@apple.com>
 
         [JSC] Do not generate an Add when adding a zero immediate to something

Modified: trunk/Source/_javascript_Core/heap/CopyToken.h (192415 => 192416)


--- trunk/Source/_javascript_Core/heap/CopyToken.h	2015-11-13 12:50:42 UTC (rev 192415)
+++ trunk/Source/_javascript_Core/heap/CopyToken.h	2015-11-13 15:59:27 UTC (rev 192416)
@@ -32,7 +32,8 @@
     ButterflyCopyToken,
     TypedArrayVectorCopyToken,
     MapBackingStoreCopyToken,
-    DirectArgumentsOverridesCopyToken
+    DirectArgumentsOverridesCopyToken,
+    JSPropertyNameEnumeratorCopyToken,
 };
 
 } // namespace JSC

Modified: trunk/Source/_javascript_Core/runtime/JSPropertyNameEnumerator.cpp (192415 => 192416)


--- trunk/Source/_javascript_Core/runtime/JSPropertyNameEnumerator.cpp	2015-11-13 12:50:42 UTC (rev 192415)
+++ trunk/Source/_javascript_Core/runtime/JSPropertyNameEnumerator.cpp	2015-11-13 15:59:27 UTC (rev 192416)
@@ -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 @@
     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);
+
+        for (unsigned i = 0; i < vector.size(); ++i)
+            propertyNames[i].set(vm, this, jsString(&vm, vector[i].string()));
     }
 }
 
-void JSPropertyNameEnumerator::destroy(JSCell* cell)
-{
-    jsCast<JSPropertyNameEnumerator*>(cell)->JSPropertyNameEnumerator::~JSPropertyNameEnumerator();
-}
-
 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

Modified: trunk/Source/_javascript_Core/runtime/JSPropertyNameEnumerator.h (192415 => 192416)


--- trunk/Source/_javascript_Core/runtime/JSPropertyNameEnumerator.h	2015-11-13 12:50:42 UTC (rev 192415)
+++ trunk/Source/_javascript_Core/runtime/JSPropertyNameEnumerator.h	2015-11-13 15:59:27 UTC (rev 192416)
@@ -43,9 +43,6 @@
     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 @@
 
     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 @@
     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;
+    CopyBarrier<WriteBarrier<JSString>> m_propertyNames;
+    WriteBarrier<StructureChain> m_prototypeChain;
     StructureID m_cachedStructureID;
-    WriteBarrier<StructureChain> m_prototypeChain;
     uint32_t m_indexedLength;
     uint32_t m_endStructurePropertyIndex;
     uint32_t m_endGenericPropertyIndex;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to