Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1577)

Unified Diff: test/mjsunit/polymorph-arrays.js

Issue 6894003: Better support for 'polymorphic' JS and external arrays (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: review feedback and merge Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/x64/stub-cache-x64.cc ('K') | « src/x64/stub-cache-x64.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/polymorph-arrays.js
diff --git a/test/mjsunit/polymorph-arrays.js b/test/mjsunit/polymorph-arrays.js
new file mode 100644
index 0000000000000000000000000000000000000000..f878a7819d88d6ec6c05329502631454066fc8ac
--- /dev/null
+++ b/test/mjsunit/polymorph-arrays.js
@@ -0,0 +1,123 @@
+// Copyright 2011 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Flags: --allow-natives-syntax
+
+function init_array(a) {
+ for (var i = 0; i < 10; ++i ){
+ a[i] = i;
+ }
+}
+
+function f1(a, i) {
+ a[i+4] = a[a+5];
+ return (a[i] + a[i+1]);
+}
+
+// Check smi checks and monomorphic ICs for object arrays.
+var object_array = new Object();
+init_array(object_array);
+assertEquals(3, f1(object_array, 1));
+assertEquals(NaN, f1(1, 1));
+assertEquals(NaN, f1(object_array, new Object()));
+assertEquals(0, f1(new PixelArray(10), 1));
+
+function f2(a, i) {
+ a[i+4] = a[a+5];
+ return (a[i] + a[i+1]);
+}
+
+// Check smi checks and monomorphic ICs for JS arrays.
+var js_array = new Array();
+init_array(js_array);
+assertEquals(3, f2(js_array, 1));
+assertEquals(NaN, f2(1, 1));
+assertEquals(NaN, f2(js_array, new Object()));
+assertEquals(0, f2(new PixelArray(10), 1));
+
+function f3(a, i) {
+ a[i+4] = a[a+5];
+ return (a[i] + a[i+1]);
+}
+
+// Check smi checks and monomorphic ICs for simple external arrays.
+var int_array = new Int32Array(10);
+init_array(int_array);
+assertEquals(3, f3(int_array, 1));
+assertEquals(NaN, f3(1, 1));
+assertEquals(NaN, f3(int_array, new Object()));
+assertEquals(0, f4(new PixelArray(10), 1));
+
+function f4(a, i) {
+ a[i+4] = a[a+5];
+ return (a[i] + a[i+1]);
+}
+
+// Check smi checks for simple megamorphic array ICs.
+var int_array_2 = new Int8Array(10);
+var js_array_2 = new Array();
+var object_array_2 = new Object();
+init_array(int_array_2);
+init_array(js_array_2);
+init_array(object_array_2);
+assertEquals(3, f4(int_array_2, 1));
+assertEquals(3, f4(js_array_2, 1));
+assertEquals(3, f4(object_array_2, 1));
+assertEquals(NaN, f4(1, 1));
+assertEquals(NaN, f4(int_array, new Object()));
+assertEquals(0, f4(new PixelArray(10), 1));
+
+function f5(a, i) {
+ a[i+4] = a[a+5];
+ return (a[i] + a[i+1]);
+}
+
+// Check megamorphic array ICs that exceed the maximum allowed polymorphism
+var int8_array_3 = new Int8Array(10);
+var uint8_array_3 = new Uint8Array(10);
+var int16_array_3 = new Int16Array(10);
+var uint16_array_3 = new Uint16Array(10);
+var int32_array_3 = new Int32Array(10);
+var uint32_array_3 = new Uint32Array(10);
+var js_array_3 = new Array();
+var object_array_3 = new Object();
+init_array(int8_array_3);
+init_array(uint8_array_3);
+init_array(int16_array_3);
+init_array(uint16_array_3);
+init_array(int32_array_3);
+init_array(uint32_array_3);
+init_array(js_array_3);
+init_array(object_array_3);
+assertEquals(3, f5(int8_array_3, 1));
+assertEquals(3, f5(uint8_array_3, 1));
+assertEquals(3, f5(int16_array_3, 1));
+assertEquals(3, f5(uint16_array_3, 1));
+assertEquals(3, f5(int32_array_3, 1));
+assertEquals(3, f5(uint32_array_3, 1));
+assertEquals(3, f5(js_array_3, 1));
+assertEquals(3, f5(object_array_3, 1));
« src/x64/stub-cache-x64.cc ('K') | « src/x64/stub-cache-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698