isCacheableArrayLength should return true for undecided arrays
authorkeith_miller@apple.com <keith_miller@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 May 2018 20:47:57 +0000 (20:47 +0000)
committerkeith_miller@apple.com <keith_miller@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 May 2018 20:47:57 +0000 (20:47 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185309

Reviewed by Michael Saboff.

JSTests:

* stress/get-array-length-undecided.js: Added.
(test):

Source/JavaScriptCore:

Undecided arrays have butterflies so there is no reason why we
should not be able to cache their length.

* bytecode/InlineAccess.cpp:
(JSC::InlineAccess::isCacheableArrayLength):

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

JSTests/ChangeLog
JSTests/stress/get-array-length-undecided.js [new file with mode: 0644]
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/bytecode/InlineAccess.cpp

index e616a3b..3cc1a48 100644 (file)
@@ -1,3 +1,13 @@
+2018-05-04  Keith Miller  <keith_miller@apple.com>
+
+        isCacheableArrayLength should return true for undecided arrays
+        https://bugs.webkit.org/show_bug.cgi?id=185309
+
+        Reviewed by Michael Saboff.
+
+        * stress/get-array-length-undecided.js: Added.
+        (test):
+
 2018-05-04  Dominik Infuehr  <dinfuehr@igalia.com>
 
         Disable tests on systems with limited memory
diff --git a/JSTests/stress/get-array-length-undecided.js b/JSTests/stress/get-array-length-undecided.js
new file mode 100644 (file)
index 0000000..2ea3943
--- /dev/null
@@ -0,0 +1,10 @@
+function test(array) {
+    return array.length;
+}
+noInline(test);
+
+let array = new Array(10);
+for (let i = 0; i < 10000; i++) {
+    if (test(array) !== 10)
+        throw new Error("bad result");
+}
index 2dbcc93..e61aafe 100644 (file)
@@ -1,3 +1,16 @@
+2018-05-04  Keith Miller  <keith_miller@apple.com>
+
+        isCacheableArrayLength should return true for undecided arrays
+        https://bugs.webkit.org/show_bug.cgi?id=185309
+
+        Reviewed by Michael Saboff.
+
+        Undecided arrays have butterflies so there is no reason why we
+        should not be able to cache their length.
+
+        * bytecode/InlineAccess.cpp:
+        (JSC::InlineAccess::isCacheableArrayLength):
+
 2018-05-03  Yusuke Suzuki  <utatane.tea@gmail.com>
 
         Remove std::random_shuffle
index d3dcfe0..9130b1e 100644 (file)
@@ -249,9 +249,7 @@ bool InlineAccess::isCacheableArrayLength(StructureStubInfo& stubInfo, JSArray*
     if (!hasFreeRegister(stubInfo))
         return false;
 
-    return array->indexingType() == ArrayWithInt32
-        || array->indexingType() == ArrayWithDouble
-        || array->indexingType() == ArrayWithContiguous;
+    return !hasAnyArrayStorage(array->indexingType()) && array->indexingType() != ArrayClass;
 }
 
 bool InlineAccess::generateArrayLength(StructureStubInfo& stubInfo, JSArray* array)