Modify our dollar VM clflush intrinsic to aid in some perf testing
authorsbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Dec 2017 02:08:03 +0000 (02:08 +0000)
committersbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Dec 2017 02:08:03 +0000 (02:08 +0000)
https://bugs.webkit.org/show_bug.cgi?id=180559

Reviewed by Mark Lam.

* tools/JSDollarVM.cpp:
(JSC::functionCpuClflush):
(JSC::functionDeltaBetweenButterflies):
(JSC::JSDollarVM::finishCreation):

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

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/tools/JSDollarVM.cpp

index c0fb554..ad86235 100644 (file)
@@ -1,3 +1,15 @@
+2017-12-07  Saam Barati  <sbarati@apple.com>
+
+        Modify our dollar VM clflush intrinsic to aid in some perf testing
+        https://bugs.webkit.org/show_bug.cgi?id=180559
+
+        Reviewed by Mark Lam.
+
+        * tools/JSDollarVM.cpp:
+        (JSC::functionCpuClflush):
+        (JSC::functionDeltaBetweenButterflies):
+        (JSC::JSDollarVM::finishCreation):
+
 2017-12-07  Eric Carlson  <eric.carlson@apple.com>
 
         Simplify log channel configuration UI
index c132f56..1b61ad9 100644 (file)
@@ -1107,32 +1107,28 @@ static EncodedJSValue JSC_HOST_CALL functionCpuClflush(ExecState* exec)
         asm volatile ("clflush %0" :: "m"(*ptrToFlush) : "memory");
     };
 
+    Vector<void*> toFlush;
+
     uint32_t offset = exec->argument(1).asUInt32();
 
-    char* ptr = nullptr;
-    if (JSArrayBuffer* buffer = jsDynamicCast<JSArrayBuffer*>(vm, exec->argument(0))) {
-        if (ArrayBuffer* impl = buffer->impl()) {
-            if (offset < impl->byteLength()) {
-                clflush(impl);
-                ptr = bitwise_cast<char*>(impl) + offset;
-            }
-        }
-    } else if (JSArrayBufferView* view = jsDynamicCast<JSArrayBufferView*>(vm, exec->argument(0)))
-        ptr = bitwise_cast<char*>(view);
+    if (JSArrayBufferView* view = jsDynamicCast<JSArrayBufferView*>(vm, exec->argument(0)))
+        toFlush.append(bitwise_cast<char*>(view->vector()) + offset);
     else if (JSObject* object = jsDynamicCast<JSObject*>(vm, exec->argument(0))) {
         switch (object->indexingType()) {
         case ALL_INT32_INDEXING_TYPES:
         case ALL_CONTIGUOUS_INDEXING_TYPES:
         case ALL_DOUBLE_INDEXING_TYPES:
-            clflush(object);
-            ptr = bitwise_cast<char*>(object->butterfly()) + offset;
+            toFlush.append(bitwise_cast<char*>(object) + JSObject::butterflyOffset());
+            toFlush.append(bitwise_cast<char*>(object->butterfly()) + Butterfly::offsetOfVectorLength());
+            toFlush.append(bitwise_cast<char*>(object->butterfly()) + Butterfly::offsetOfPublicLength());
         }
     }
 
-    if (!ptr)
+    if (!toFlush.size())
         return JSValue::encode(jsBoolean(false));
 
-    clflush(ptr);
+    for (void* ptr : toFlush)
+        clflush(ptr);
     return JSValue::encode(jsBoolean(true));
 #else
     UNUSED_PARAM(exec);
@@ -1698,6 +1694,22 @@ static EncodedJSValue JSC_HOST_CALL functionCreateCustomTestGetterSetter(ExecSta
     return JSValue::encode(JSTestCustomGetterSetter::create(vm, globalObject, JSTestCustomGetterSetter::createStructure(vm, globalObject)));
 }
 
+static EncodedJSValue JSC_HOST_CALL functionDeltaBetweenButterflies(ExecState* exec)
+{
+    VM& vm = exec->vm();
+    JSObject* a = jsDynamicCast<JSObject*>(vm, exec->argument(0));
+    JSObject* b = jsDynamicCast<JSObject*>(vm, exec->argument(1));
+    if (!a || !b)
+        return JSValue::encode(jsNumber(PNaN));
+
+    ptrdiff_t delta = bitwise_cast<char*>(a->butterfly()) - bitwise_cast<char*>(b->butterfly());
+    if (delta < 0)
+        return JSValue::encode(jsNumber(PNaN));
+    if (delta > std::numeric_limits<int32_t>::max())
+        return JSValue::encode(jsNumber(PNaN));
+    return JSValue::encode(jsNumber(static_cast<int32_t>(delta)));
+}
+
 void JSDollarVM::finishCreation(VM& vm)
 {
     Base::finishCreation(vm);
@@ -1779,6 +1791,8 @@ void JSDollarVM::finishCreation(VM& vm)
     addFunction(vm, "getGetterSetter", functionGetGetterSetter, 2);
     addFunction(vm, "loadGetterFromGetterSetter", functionLoadGetterFromGetterSetter, 1);
     addFunction(vm, "createCustomTestGetterSetter", functionCreateCustomTestGetterSetter, 1);
+
+    addFunction(vm, "deltaBetweenButterflies", functionDeltaBetweenButterflies, 2);
 }
 
 void JSDollarVM::addFunction(VM& vm, JSGlobalObject* globalObject, const char* name, NativeFunction function, unsigned arguments)