[JSC] Remove getTypedArrayImpl
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Jul 2018 05:00:13 +0000 (05:00 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Jul 2018 05:00:13 +0000 (05:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=187338

Reviewed by Mark Lam.

getTypedArrayImpl is overridden only by typed arrays and DataView. Since the number of these classes
are limited, we do not need to add this function to MethodTable: dispatching it in JSArrayBufferView is fine.
This patch removes getTypedArrayImpl from MethodTable, and moves it to JSArrayBufferView.

* runtime/ClassInfo.h:
* runtime/GenericTypedArrayView.h:
(JSC::GenericTypedArrayView::data const): Deleted.
(JSC::GenericTypedArrayView::set): Deleted.
(JSC::GenericTypedArrayView::setRange): Deleted.
(JSC::GenericTypedArrayView::zeroRange): Deleted.
(JSC::GenericTypedArrayView::zeroFill): Deleted.
(JSC::GenericTypedArrayView::length const): Deleted.
(JSC::GenericTypedArrayView::item const): Deleted.
(JSC::GenericTypedArrayView::set const): Deleted.
(JSC::GenericTypedArrayView::setNative const): Deleted.
(JSC::GenericTypedArrayView::getRange): Deleted.
(JSC::GenericTypedArrayView::checkInboundData const): Deleted.
(JSC::GenericTypedArrayView::internalByteLength const): Deleted.
* runtime/JSArrayBufferView.cpp:
(JSC::JSArrayBufferView::possiblySharedImpl):
* runtime/JSArrayBufferView.h:
* runtime/JSArrayBufferViewInlines.h:
(JSC::JSArrayBufferView::possiblySharedImpl): Deleted.
* runtime/JSCell.cpp:
(JSC::JSCell::getTypedArrayImpl): Deleted.
* runtime/JSCell.h:
* runtime/JSDataView.cpp:
(JSC::JSDataView::getTypedArrayImpl): Deleted.
* runtime/JSDataView.h:
* runtime/JSGenericTypedArrayView.h:
* runtime/JSGenericTypedArrayViewInlines.h:
(JSC::JSGenericTypedArrayView<Adaptor>::getTypedArrayImpl): Deleted.

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

14 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/ClassInfo.h
Source/JavaScriptCore/runtime/GenericTypedArrayView.h
Source/JavaScriptCore/runtime/JSArrayBufferView.cpp
Source/JavaScriptCore/runtime/JSArrayBufferView.h
Source/JavaScriptCore/runtime/JSArrayBufferViewInlines.h
Source/JavaScriptCore/runtime/JSCell.cpp
Source/JavaScriptCore/runtime/JSCell.h
Source/JavaScriptCore/runtime/JSDataView.cpp
Source/JavaScriptCore/runtime/JSDataView.h
Source/JavaScriptCore/runtime/JSGenericTypedArrayView.h
Source/JavaScriptCore/runtime/JSGenericTypedArrayViewInlines.h
Source/JavaScriptCore/runtime/JSType.h
Source/JavaScriptCore/runtime/TypedArrayType.h

index 112dde5..89ca52e 100644 (file)
@@ -1,3 +1,43 @@
+2018-07-05  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        [JSC] Remove getTypedArrayImpl
+        https://bugs.webkit.org/show_bug.cgi?id=187338
+
+        Reviewed by Mark Lam.
+
+        getTypedArrayImpl is overridden only by typed arrays and DataView. Since the number of these classes
+        are limited, we do not need to add this function to MethodTable: dispatching it in JSArrayBufferView is fine.
+        This patch removes getTypedArrayImpl from MethodTable, and moves it to JSArrayBufferView.
+
+        * runtime/ClassInfo.h:
+        * runtime/GenericTypedArrayView.h:
+        (JSC::GenericTypedArrayView::data const): Deleted.
+        (JSC::GenericTypedArrayView::set): Deleted.
+        (JSC::GenericTypedArrayView::setRange): Deleted.
+        (JSC::GenericTypedArrayView::zeroRange): Deleted.
+        (JSC::GenericTypedArrayView::zeroFill): Deleted.
+        (JSC::GenericTypedArrayView::length const): Deleted.
+        (JSC::GenericTypedArrayView::item const): Deleted.
+        (JSC::GenericTypedArrayView::set const): Deleted.
+        (JSC::GenericTypedArrayView::setNative const): Deleted.
+        (JSC::GenericTypedArrayView::getRange): Deleted.
+        (JSC::GenericTypedArrayView::checkInboundData const): Deleted.
+        (JSC::GenericTypedArrayView::internalByteLength const): Deleted.
+        * runtime/JSArrayBufferView.cpp:
+        (JSC::JSArrayBufferView::possiblySharedImpl):
+        * runtime/JSArrayBufferView.h:
+        * runtime/JSArrayBufferViewInlines.h:
+        (JSC::JSArrayBufferView::possiblySharedImpl): Deleted.
+        * runtime/JSCell.cpp:
+        (JSC::JSCell::getTypedArrayImpl): Deleted.
+        * runtime/JSCell.h:
+        * runtime/JSDataView.cpp:
+        (JSC::JSDataView::getTypedArrayImpl): Deleted.
+        * runtime/JSDataView.h:
+        * runtime/JSGenericTypedArrayView.h:
+        * runtime/JSGenericTypedArrayViewInlines.h:
+        (JSC::JSGenericTypedArrayView<Adaptor>::getTypedArrayImpl): Deleted.
+
 2018-07-10  Keith Miller  <keith_miller@apple.com>
 
         hasOwnProperty returns true for out of bounds property index on TypedArray
index f0faf34..d5cffb6 100644 (file)
@@ -101,9 +101,6 @@ struct MethodTable {
     using DefineOwnPropertyFunctionPtr = bool (*)(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool);
     DefineOwnPropertyFunctionPtr WTF_METHOD_TABLE_ENTRY(defineOwnProperty);
 
-    using GetTypedArrayImpl = RefPtr<ArrayBufferView> (*)(JSArrayBufferView*);
-    GetTypedArrayImpl WTF_METHOD_TABLE_ENTRY(getTypedArrayImpl);
-
     using PreventExtensionsFunctionPtr = bool (*)(JSObject*, ExecState*);
     PreventExtensionsFunctionPtr WTF_METHOD_TABLE_ENTRY(preventExtensions);
 
@@ -171,7 +168,6 @@ struct MethodTable {
         &ClassName::toStringName, \
         &ClassName::customHasInstance, \
         &ClassName::defineOwnProperty, \
-        &ClassName::getTypedArrayImpl, \
         &ClassName::preventExtensions, \
         &ClassName::isExtensible, \
         &ClassName::setPrototype, \
index fc62249..e5fd4bb 100644 (file)
@@ -31,7 +31,7 @@
 namespace JSC {
 
 template<typename Adaptor>
-class GenericTypedArrayView : public ArrayBufferView {
+class GenericTypedArrayView final : public ArrayBufferView {
 protected:
     GenericTypedArrayView(RefPtr<ArrayBuffer>&&, unsigned byteOffset, unsigned length);
 
index 79c88c2..a900dae 100644 (file)
 #include "config.h"
 #include "JSArrayBufferView.h"
 
+#include "GenericTypedArrayViewInlines.h"
 #include "JSArrayBuffer.h"
 #include "JSCInlines.h"
+#include "JSGenericTypedArrayViewInlines.h"
 #include "JSTypedArrays.h"
 #include "TypeError.h"
 #include "TypedArrayController.h"
+#include "TypedArrays.h"
 #include <wtf/Gigacage.h>
 
 namespace JSC {
@@ -219,26 +222,14 @@ void JSArrayBufferView::neuter()
 }
 
 static const constexpr size_t ElementSizeData[] = {
-    sizeof(typename Int8Adaptor::Type), // Int8ArrayType
-    sizeof(typename Uint8Adaptor::Type), // Uint8ArrayType
-    sizeof(typename Uint8ClampedAdaptor::Type), // Uint8ClampedArrayType
-    sizeof(typename Int16Adaptor::Type), // Int16ArrayType
-    sizeof(typename Uint16Adaptor::Type), // Uint16ArrayType
-    sizeof(typename Int32Adaptor::Type), // Int32ArrayType
-    sizeof(typename Uint32Adaptor::Type), // Uint32ArrayType
-    sizeof(typename Float32Adaptor::Type), // Float32ArrayType
-    sizeof(typename Float64Adaptor::Type), // Float64ArrayType
+#define FACTORY(type) sizeof(typename type ## Adaptor::Type),
+    FOR_EACH_TYPED_ARRAY_TYPE_EXCLUDING_DATA_VIEW(FACTORY)
+#undef FACTORY
 };
 
-static_assert(std::is_final<JSInt8Array>::value, "");
-static_assert(std::is_final<JSUint8Array>::value, "");
-static_assert(std::is_final<JSUint8ClampedArray>::value, "");
-static_assert(std::is_final<JSInt16Array>::value, "");
-static_assert(std::is_final<JSUint16Array>::value, "");
-static_assert(std::is_final<JSInt32Array>::value, "");
-static_assert(std::is_final<JSUint32Array>::value, "");
-static_assert(std::is_final<JSFloat32Array>::value, "");
-static_assert(std::is_final<JSFloat64Array>::value, "");
+#define FACTORY(type) static_assert(std::is_final<JS ## type ## Array>::value, "");
+FOR_EACH_TYPED_ARRAY_TYPE_EXCLUDING_DATA_VIEW(FACTORY)
+#undef FACTORY
 
 static inline size_t elementSize(JSType type)
 {
@@ -304,6 +295,27 @@ ArrayBuffer* JSArrayBufferView::slowDownAndWasteMemory()
     return buffer.get();
 }
 
+// Allocates the full-on native buffer and moves data into the C heap if
+// necessary. Note that this never allocates in the GC heap.
+RefPtr<ArrayBufferView> JSArrayBufferView::possiblySharedImpl()
+{
+    ArrayBuffer* buffer = possiblySharedBuffer();
+    unsigned byteOffset = this->byteOffset();
+    unsigned length = this->length();
+    switch (type()) {
+#define FACTORY(type) \
+    case type ## ArrayType: \
+        return type ## Array::create(buffer, byteOffset, length);
+    FOR_EACH_TYPED_ARRAY_TYPE_EXCLUDING_DATA_VIEW(FACTORY)
+#undef FACTORY
+    case DataViewType:
+        return DataView::create(buffer, byteOffset, length);
+    default:
+        RELEASE_ASSERT_NOT_REACHED();
+        return nullptr;
+    }
+}
+
 } // namespace JSC
 
 namespace WTF {
index 1c0d90a..ef7ebe1 100644 (file)
@@ -163,7 +163,7 @@ public:
     JSArrayBuffer* unsharedJSBuffer(ExecState* exec);
     JSArrayBuffer* possiblySharedJSBuffer(ExecState* exec);
     RefPtr<ArrayBufferView> unsharedImpl();
-    RefPtr<ArrayBufferView> possiblySharedImpl();
+    JS_EXPORT_PRIVATE RefPtr<ArrayBufferView> possiblySharedImpl();
     bool isNeutered() { return hasArrayBuffer() && !vector(); }
     void neuter();
     
index 7622349..9aaeb00 100644 (file)
@@ -64,11 +64,6 @@ inline ArrayBuffer* JSArrayBufferView::existingBufferInButterfly()
     return butterfly()->indexingHeader()->arrayBuffer();
 }
 
-inline RefPtr<ArrayBufferView> JSArrayBufferView::possiblySharedImpl()
-{
-    return methodTable()->getTypedArrayImpl(this);
-}
-
 inline RefPtr<ArrayBufferView> JSArrayBufferView::unsharedImpl()
 {
     RefPtr<ArrayBufferView> result = possiblySharedImpl();
index 94532ff..7059ab8 100644 (file)
@@ -256,12 +256,6 @@ bool JSCell::defineOwnProperty(JSObject*, ExecState*, PropertyName, const Proper
     return false;
 }
 
-RefPtr<ArrayBufferView> JSCell::getTypedArrayImpl(JSArrayBufferView*)
-{
-    RELEASE_ASSERT_NOT_REACHED();
-    return nullptr;
-}
-
 uint32_t JSCell::getEnumerableLength(ExecState*, JSObject*)
 {
     RELEASE_ASSERT_NOT_REACHED();
index e5e888d..9ea70fd 100644 (file)
@@ -265,7 +265,6 @@ protected:
     static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool shouldThrow);
     static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
     static bool getOwnPropertySlotByIndex(JSObject*, ExecState*, unsigned propertyName, PropertySlot&);
-    JS_EXPORT_PRIVATE static RefPtr<ArrayBufferView> getTypedArrayImpl(JSArrayBufferView*);
 
 private:
     friend class LLIntOffsetsExtractor;
index 6225878..9aa81b3 100644 (file)
@@ -180,12 +180,6 @@ void JSDataView::getOwnNonIndexPropertyNames(
     Base::getOwnNonIndexPropertyNames(thisObject, exec, array, mode);
 }
 
-RefPtr<ArrayBufferView> JSDataView::getTypedArrayImpl(JSArrayBufferView* object)
-{
-    JSDataView* thisObject = jsCast<JSDataView*>(object);
-    return thisObject->possiblySharedTypedImpl();
-}
-
 Structure* JSDataView::createStructure(
     VM& vm, JSGlobalObject* globalObject, JSValue prototype)
 {
index 920eb28..84f9d3b 100644 (file)
@@ -70,8 +70,6 @@ protected:
 
     static void getOwnNonIndexPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
 
-    static RefPtr<ArrayBufferView> getTypedArrayImpl(JSArrayBufferView*);
-    
 public:
     static Structure* createStructure(VM&, JSGlobalObject*, JSValue prototype);
     
index 544b669..ffdd8e4 100644 (file)
@@ -288,10 +288,6 @@ protected:
     static size_t estimatedSize(JSCell*);
     static void visitChildren(JSCell*, SlotVisitor&);
 
-    // Allocates the full-on native buffer and moves data into the C heap if
-    // necessary. Note that this never allocates in the GC heap.
-    static RefPtr<ArrayBufferView> getTypedArrayImpl(JSArrayBufferView*);
-
 private:
     // Returns true if successful, and false on error; it will throw on error.
     template<typename OtherAdaptor>
@@ -332,14 +328,6 @@ private:
     }
 
     template<typename IntegralType>
-    static bool ALWAYS_INLINE sortComparison(IntegralType a, IntegralType b)
-    {
-        if (a >= 0 || b >= 0)
-            return a < b;
-        return a > b;
-    }
-
-    template<typename IntegralType>
     void sortFloat()
     {
         ASSERT(sizeof(IntegralType) == sizeof(ElementType));
@@ -352,7 +340,11 @@ private:
         purifyArray();
 
         IntegralType* array = reinterpret_cast_ptr<IntegralType*>(typedVector());
-        std::sort(array, array + m_length, sortComparison<IntegralType>);
+        std::sort(array, array + m_length, [] (IntegralType a, IntegralType b) {
+            if (a >= 0 || b >= 0)
+                return a < b;
+            return a > b;
+        });
 
     }
 
index fbafd88..144773f 100644 (file)
@@ -550,11 +550,4 @@ void JSGenericTypedArrayView<Adaptor>::visitChildren(JSCell* cell, SlotVisitor&
     }
 }
 
-template<typename Adaptor>
-RefPtr<ArrayBufferView> JSGenericTypedArrayView<Adaptor>::getTypedArrayImpl(JSArrayBufferView* object)
-{
-    JSGenericTypedArrayView* thisObject = jsCast<JSGenericTypedArrayView*>(object);
-    return thisObject->possiblySharedTypedImpl();
-}
-
 } // namespace JSC
index afa7dc2..0cccfac 100644 (file)
@@ -71,7 +71,7 @@ enum JSType : uint8_t {
     DerivedArrayType,
     // End JSArray types.
 
-    // Start JSArrayBufferView types.
+    // Start JSArrayBufferView types. Keep in sync with the order of FOR_EACH_TYPED_ARRAY_TYPE_EXCLUDING_DATA_VIEW.
     Int8ArrayType,
     Uint8ArrayType,
     Uint8ClampedArrayType,
index 5230d75..07d1753 100644 (file)
@@ -32,6 +32,7 @@ namespace JSC {
 
 struct ClassInfo;
 
+// Keep in sync with the order of JSType.
 #define FOR_EACH_TYPED_ARRAY_TYPE_EXCLUDING_DATA_VIEW(macro) \
     macro(Int8) \
     macro(Uint8) \