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

Side by Side Diff: test/mjsunit/element-kind.js

Issue 8139027: Version 3.6.5 (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: '' Created 9 years, 2 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/mjsunit/const-redecl.js ('k') | test/mjsunit/global-const-var-conflicts.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // Flags: --allow-natives-syntax 28 // Flags: --allow-natives-syntax --smi-only-arrays
29 // Test element kind of objects 29 // Test element kind of objects.
30 // Since --smi-only-arrays affects builtins, its default setting at compile
31 // time sticks if built with snapshot. If --smi-only-arrays is deactivated
32 // by default, only a no-snapshot build actually has smi-only arrays enabled
33 // in this test case. Depending on whether smi-only arrays are actually
34 // enabled, this test takes the appropriate code path to check smi-only arrays.
35
36
37 support_smi_only_arrays = %HasFastSmiOnlyElements([]);
38
39 if (support_smi_only_arrays) {
40 print("Tests include smi-only arrays.");
41 } else {
42 print("Tests do NOT include smi-only arrays.");
43 }
30 44
31 var element_kind = { 45 var element_kind = {
46 fast_smi_only_elements : 0,
32 fast_elements : 1, 47 fast_elements : 1,
33 fast_double_elements : 2, 48 fast_double_elements : 2,
34 dictionary_elements : 3, 49 dictionary_elements : 3,
35 external_byte_elements : 4, 50 external_byte_elements : 4,
36 external_unsigned_byte_elements : 5, 51 external_unsigned_byte_elements : 5,
37 external_short_elements : 6, 52 external_short_elements : 6,
38 external_unsigned_short_elements : 7, 53 external_unsigned_short_elements : 7,
39 external_int_elements : 8, 54 external_int_elements : 8,
40 external_unsigned_int_elements : 9, 55 external_unsigned_int_elements : 9,
41 external_float_elements : 10, 56 external_float_elements : 10,
42 external_double_elements : 11, 57 external_double_elements : 11,
43 external_pixel_elements : 12 58 external_pixel_elements : 12
44 } 59 }
45 60
46 // We expect an object to only be of one element kind. 61 // We expect an object to only be of one element kind.
47 function assertKind(expected, obj){ 62 function assertKind(expected, obj) {
48 assertEquals(expected == element_kind.fast_elements, 63 if (support_smi_only_arrays) {
49 %HasFastElements(obj)); 64 assertEquals(expected == element_kind.fast_smi_only_elements,
65 %HasFastSmiOnlyElements(obj));
66 assertEquals(expected == element_kind.fast_elements,
67 %HasFastElements(obj));
68 } else {
69 assertEquals(expected == element_kind.fast_elements ||
70 expected == element_kind.fast_smi_only_elements,
71 %HasFastElements(obj));
72 }
50 assertEquals(expected == element_kind.fast_double_elements, 73 assertEquals(expected == element_kind.fast_double_elements,
51 %HasFastDoubleElements(obj)); 74 %HasFastDoubleElements(obj));
52 assertEquals(expected == element_kind.dictionary_elements, 75 assertEquals(expected == element_kind.dictionary_elements,
53 %HasDictionaryElements(obj)); 76 %HasDictionaryElements(obj));
54 assertEquals(expected == element_kind.external_byte_elements, 77 assertEquals(expected == element_kind.external_byte_elements,
55 %HasExternalByteElements(obj)); 78 %HasExternalByteElements(obj));
56 assertEquals(expected == element_kind.external_unsigned_byte_elements, 79 assertEquals(expected == element_kind.external_unsigned_byte_elements,
57 %HasExternalUnsignedByteElements(obj)); 80 %HasExternalUnsignedByteElements(obj));
58 assertEquals(expected == element_kind.external_short_elements, 81 assertEquals(expected == element_kind.external_short_elements,
59 %HasExternalShortElements(obj)); 82 %HasExternalShortElements(obj));
(...skipping 13 matching lines...) Expand all
73 assertEquals(expected >= element_kind.external_byte_elements, 96 assertEquals(expected >= element_kind.external_byte_elements,
74 %HasExternalArrayElements(obj)); 97 %HasExternalArrayElements(obj));
75 } 98 }
76 99
77 var me = {}; 100 var me = {};
78 assertKind(element_kind.fast_elements, me); 101 assertKind(element_kind.fast_elements, me);
79 me.dance = 0xD15C0; 102 me.dance = 0xD15C0;
80 me.drink = 0xC0C0A; 103 me.drink = 0xC0C0A;
81 assertKind(element_kind.fast_elements, me); 104 assertKind(element_kind.fast_elements, me);
82 105
106 var too = [1,2,3];
107 assertKind(element_kind.fast_smi_only_elements, too);
108 too.dance = 0xD15C0;
109 too.drink = 0xC0C0A;
110 assertKind(element_kind.fast_smi_only_elements, too);
111
112 // Make sure the element kind transitions from smionly when a non-smi is stored.
83 var you = new Array(); 113 var you = new Array();
84 for(i = 0; i < 1337; i++) { 114 assertKind(element_kind.fast_smi_only_elements, you);
85 you[i] = i; 115 for (var i = 0; i < 1337; i++) {
116 var val = i;
117 if (i == 1336) {
118 assertKind(element_kind.fast_smi_only_elements, you);
119 val = new Object();
120 }
121 you[i] = val;
86 } 122 }
87 assertKind(element_kind.fast_elements, you); 123 assertKind(element_kind.fast_elements, you);
88 124
89 assertKind(element_kind.dictionary_elements, new Array(0xC0C0A)); 125 assertKind(element_kind.dictionary_elements, new Array(0xDECAF));
90 126
91 // fast_double_elements not yet available 127 var fast_double_array = new Array(0xDECAF);
92 128 for (var i = 0; i < 0xDECAF; i++) fast_double_array[i] = i / 2;
129 assertKind(element_kind.fast_double_elements, fast_double_array);
93 130
94 assertKind(element_kind.external_byte_elements, new Int8Array(9001)); 131 assertKind(element_kind.external_byte_elements, new Int8Array(9001));
95 assertKind(element_kind.external_unsigned_byte_elements, new Uint8Array(007)); 132 assertKind(element_kind.external_unsigned_byte_elements, new Uint8Array(007));
96 assertKind(element_kind.external_short_elements, new Int16Array(666)); 133 assertKind(element_kind.external_short_elements, new Int16Array(666));
97 assertKind(element_kind.external_unsigned_short_elements, new Uint16Array(42)); 134 assertKind(element_kind.external_unsigned_short_elements, new Uint16Array(42));
98 assertKind(element_kind.external_int_elements, new Int32Array(0xF)); 135 assertKind(element_kind.external_int_elements, new Int32Array(0xF));
99 assertKind(element_kind.external_unsigned_int_elements, new Uint32Array(23)); 136 assertKind(element_kind.external_unsigned_int_elements, new Uint32Array(23));
100 assertKind(element_kind.external_float_elements, new Float32Array(7)); 137 assertKind(element_kind.external_float_elements, new Float32Array(7));
101 assertKind(element_kind.external_double_elements, new Float64Array(0)); 138 assertKind(element_kind.external_double_elements, new Float64Array(0));
102 assertKind(element_kind.external_pixel_elements, new PixelArray(512)); 139 assertKind(element_kind.external_pixel_elements, new PixelArray(512));
140
141 // Crankshaft support for smi-only array elements.
142 function monomorphic(array) {
143 for (var i = 0; i < 3; i++) {
144 array[i] = i + 10;
145 }
146 assertKind(element_kind.fast_smi_only_elements, array);
147 for (var i = 0; i < 3; i++) {
148 var a = array[i];
149 assertEquals(i + 10, a);
150 }
151 }
152 var smi_only = [1, 2, 3];
153 for (var i = 0; i < 3; i++) monomorphic(smi_only);
154 %OptimizeFunctionOnNextCall(monomorphic);
155 monomorphic(smi_only);
156 function polymorphic(array, expected_kind) {
157 array[1] = 42;
158 assertKind(expected_kind, array);
159 var a = array[1];
160 assertEquals(42, a);
161 }
162 var smis = [1, 2, 3];
163 var strings = ["one", "two", "three"];
164 var doubles = [0, 0, 0]; doubles[0] = 1.5; doubles[1] = 2.5; doubles[2] = 3.5;
165 assertKind(support_smi_only_arrays
166 ? element_kind.fast_double_elements
167 : element_kind.fast_elements,
168 doubles);
169 for (var i = 0; i < 3; i++) {
170 polymorphic(smis, element_kind.fast_smi_only_elements);
171 polymorphic(strings, element_kind.fast_elements);
172 polymorphic(doubles, support_smi_only_arrays
173 ? element_kind.fast_double_elements
174 : element_kind.fast_elements);
175 }
176 %OptimizeFunctionOnNextCall(polymorphic);
177 polymorphic(smis, element_kind.fast_smi_only_elements);
178 polymorphic(strings, element_kind.fast_elements);
179 polymorphic(doubles, support_smi_only_arrays
180 ? element_kind.fast_double_elements
181 : element_kind.fast_elements);
182
183 // Crankshaft support for smi-only elements in dynamic array literals.
184 function get(foo) { return foo; } // Used to generate dynamic values.
185
186 //function crankshaft_test(expected_kind) {
187 function crankshaft_test() {
188 var a = [get(1), get(2), get(3)];
189 assertKind(element_kind.fast_smi_only_elements, a);
190 var b = [get(1), get(2), get("three")];
191 assertKind(element_kind.fast_elements, b);
192 var c = [get(1), get(2), get(3.5)];
193 // The full code generator doesn't support conversion to fast_double_elements
194 // yet. Crankshaft does, but only with --smi-only-arrays support.
195 if ((%GetOptimizationStatus(crankshaft_test) & 1) &&
196 support_smi_only_arrays) {
197 assertKind(element_kind.fast_double_elements, c);
198 } else {
199 assertKind(element_kind.fast_elements, c);
200 }
201 }
202 for (var i = 0; i < 3; i++) {
203 crankshaft_test();
204 }
205 %OptimizeFunctionOnNextCall(crankshaft_test);
206 crankshaft_test();
OLDNEW
« no previous file with comments | « test/mjsunit/const-redecl.js ('k') | test/mjsunit/global-const-var-conflicts.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698