OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 --smi-only-arrays --expose-gc --nostress-opt | 28 // Flags: --allow-natives-syntax --smi-only-arrays --expose-gc --nostress-opt --
typed-array-max_size_in-heap=2048 |
29 | 29 |
30 // Test element kind of objects. | 30 // Test element kind of objects. |
31 // Since --smi-only-arrays affects builtins, its default setting at compile | 31 // Since --smi-only-arrays affects builtins, its default setting at compile |
32 // time sticks if built with snapshot. If --smi-only-arrays is deactivated | 32 // time sticks if built with snapshot. If --smi-only-arrays is deactivated |
33 // by default, only a no-snapshot build actually has smi-only arrays enabled | 33 // by default, only a no-snapshot build actually has smi-only arrays enabled |
34 // in this test case. Depending on whether smi-only arrays are actually | 34 // in this test case. Depending on whether smi-only arrays are actually |
35 // enabled, this test takes the appropriate code path to check smi-only arrays. | 35 // enabled, this test takes the appropriate code path to check smi-only arrays. |
36 | 36 |
37 support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8)); | 37 support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8)); |
38 | 38 |
39 if (support_smi_only_arrays) { | 39 if (support_smi_only_arrays) { |
40 print("Tests include smi-only arrays."); | 40 print("Tests include smi-only arrays."); |
41 } else { | 41 } else { |
42 print("Tests do NOT include smi-only arrays."); | 42 print("Tests do NOT include smi-only arrays."); |
43 } | 43 } |
44 | 44 |
45 var elements_kind = { | 45 var elements_kind = { |
46 fast_smi_only : 'fast smi only elements', | 46 fast_smi_only : 'fast smi only elements', |
47 fast : 'fast elements', | 47 fast : 'fast elements', |
48 fast_double : 'fast double elements', | 48 fast_double : 'fast double elements', |
49 dictionary : 'dictionary elements', | 49 dictionary : 'dictionary elements', |
50 external_byte : 'external byte elements', | 50 external_int32 : 'external int8 elements', |
51 external_unsigned_byte : 'external unsigned byte elements', | 51 external_uint8 : 'external uint8 elements', |
52 external_short : 'external short elements', | 52 external_int16 : 'external int16 elements', |
53 external_unsigned_short : 'external unsigned short elements', | 53 external_uint16 : 'external uint16 elements', |
54 external_int : 'external int elements', | 54 external_int32 : 'external int32 elements', |
55 external_unsigned_int : 'external unsigned int elements', | 55 external_uint32 : 'external uint32 elements', |
56 external_float : 'external float elements', | 56 external_float32 : 'external float32 elements', |
57 external_double : 'external double elements', | 57 external_float64 : 'external float64 elements', |
58 external_pixel : 'external pixel elements' | 58 external_uint8_clamped : 'external uint8_clamped elements', |
| 59 fixed_int32 : 'fixed int8 elements', |
| 60 fixed_uint8 : 'fixed uint8 elements', |
| 61 fixed_int16 : 'fixed int16 elements', |
| 62 fixed_uint16 : 'fixed uint16 elements', |
| 63 fixed_int32 : 'fixed int32 elements', |
| 64 fixed_uint32 : 'fixed uint32 elements', |
| 65 fixed_float32 : 'fixed float32 elements', |
| 66 fixed_float64 : 'fixed float64 elements', |
| 67 fixed_uint8_clamped : 'fixed uint8_clamped elements' |
59 } | 68 } |
60 | 69 |
61 function getKind(obj) { | 70 function getKind(obj) { |
62 if (%HasFastSmiElements(obj)) return elements_kind.fast_smi_only; | 71 if (%HasFastSmiElements(obj)) return elements_kind.fast_smi_only; |
63 if (%HasFastObjectElements(obj)) return elements_kind.fast; | 72 if (%HasFastObjectElements(obj)) return elements_kind.fast; |
64 if (%HasFastDoubleElements(obj)) return elements_kind.fast_double; | 73 if (%HasFastDoubleElements(obj)) return elements_kind.fast_double; |
65 if (%HasDictionaryElements(obj)) return elements_kind.dictionary; | 74 if (%HasDictionaryElements(obj)) return elements_kind.dictionary; |
| 75 |
66 // Every external kind is also an external array. | 76 // Every external kind is also an external array. |
67 assertTrue(%HasExternalArrayElements(obj)); | |
68 if (%HasExternalInt8Elements(obj)) { | 77 if (%HasExternalInt8Elements(obj)) { |
69 return elements_kind.external_byte; | 78 return elements_kind.external_int8; |
70 } | 79 } |
71 if (%HasExternalUint8Elements(obj)) { | 80 if (%HasExternalUint8Elements(obj)) { |
72 return elements_kind.external_unsigned_byte; | 81 return elements_kind.external_uint8; |
73 } | 82 } |
74 if (%HasExternalInt16Elements(obj)) { | 83 if (%HasExternalInt16Elements(obj)) { |
75 return elements_kind.external_short; | 84 return elements_kind.external_int16; |
76 } | 85 } |
77 if (%HasExternalUint16Elements(obj)) { | 86 if (%HasExternalUint16Elements(obj)) { |
78 return elements_kind.external_unsigned_short; | 87 return elements_kind.external_uint16; |
79 } | 88 } |
80 if (%HasExternalInt32Elements(obj)) { | 89 if (%HasExternalInt32Elements(obj)) { |
81 return elements_kind.external_int; | 90 return elements_kind.external_int32; |
82 } | 91 } |
83 if (%HasExternalUint32Elements(obj)) { | 92 if (%HasExternalUint32Elements(obj)) { |
84 return elements_kind.external_unsigned_int; | 93 return elements_kind.external_uint32; |
85 } | 94 } |
86 if (%HasExternalFloat32Elements(obj)) { | 95 if (%HasExternalFloat32Elements(obj)) { |
87 return elements_kind.external_float; | 96 return elements_kind.external_float32; |
88 } | 97 } |
89 if (%HasExternalFloat64Elements(obj)) { | 98 if (%HasExternalFloat64Elements(obj)) { |
90 return elements_kind.external_double; | 99 return elements_kind.external_float64; |
91 } | 100 } |
92 if (%HasExternalUint8ClampedElements(obj)) { | 101 if (%HasExternalUint8ClampedElements(obj)) { |
93 return elements_kind.external_pixel; | 102 return elements_kind.external_uint8_clamped; |
| 103 } |
| 104 if (%HasFixedInt8Elements(obj)) { |
| 105 return elements_kind.fixed_int8; |
| 106 } |
| 107 if (%HasFixedUint8Elements(obj)) { |
| 108 return elements_kind.fixed_uint8; |
| 109 } |
| 110 if (%HasFixedInt16Elements(obj)) { |
| 111 return elements_kind.fixed_int16; |
| 112 } |
| 113 if (%HasFixedUint16Elements(obj)) { |
| 114 return elements_kind.fixed_uint16; |
| 115 } |
| 116 if (%HasFixedInt32Elements(obj)) { |
| 117 return elements_kind.fixed_int32; |
| 118 } |
| 119 if (%HasFixedUint32Elements(obj)) { |
| 120 return elements_kind.fixed_uint32; |
| 121 } |
| 122 if (%HasFixedFloat32Elements(obj)) { |
| 123 return elements_kind.fixed_float32; |
| 124 } |
| 125 if (%HasFixedFloat64Elements(obj)) { |
| 126 return elements_kind.fixed_float64; |
| 127 } |
| 128 if (%HasFixedUint8ClampedElements(obj)) { |
| 129 return elements_kind.fixed_uint8_clamped; |
94 } | 130 } |
95 } | 131 } |
96 | 132 |
97 function assertKind(expected, obj, name_opt) { | 133 function assertKind(expected, obj, name_opt) { |
98 if (!support_smi_only_arrays && | 134 if (!support_smi_only_arrays && |
99 expected == elements_kind.fast_smi_only) { | 135 expected == elements_kind.fast_smi_only) { |
100 expected = elements_kind.fast; | 136 expected = elements_kind.fast; |
101 } | 137 } |
102 assertEquals(expected, getKind(obj), name_opt); | 138 assertEquals(expected, getKind(obj), name_opt); |
103 } | 139 } |
(...skipping 25 matching lines...) Expand all Loading... |
129 you[i] = val; | 165 you[i] = val; |
130 } | 166 } |
131 assertKind(elements_kind.fast, you); | 167 assertKind(elements_kind.fast, you); |
132 | 168 |
133 assertKind(elements_kind.dictionary, new Array(0xDECAF)); | 169 assertKind(elements_kind.dictionary, new Array(0xDECAF)); |
134 | 170 |
135 var fast_double_array = new Array(0xDECAF); | 171 var fast_double_array = new Array(0xDECAF); |
136 for (var i = 0; i < 0xDECAF; i++) fast_double_array[i] = i / 2; | 172 for (var i = 0; i < 0xDECAF; i++) fast_double_array[i] = i / 2; |
137 assertKind(elements_kind.fast_double, fast_double_array); | 173 assertKind(elements_kind.fast_double, fast_double_array); |
138 | 174 |
139 assertKind(elements_kind.external_byte, new Int8Array(9001)); | 175 assertKind(elements_kind.fixed_int8, new Int8Array(007)); |
140 assertKind(elements_kind.external_unsigned_byte, new Uint8Array(007)); | 176 assertKind(elements_kind.fixed_uint8, new Uint8Array(007)); |
141 assertKind(elements_kind.external_short, new Int16Array(666)); | 177 assertKind(elements_kind.fixed_int16, new Int16Array(666)); |
142 assertKind(elements_kind.external_unsigned_short, new Uint16Array(42)); | 178 assertKind(elements_kind.fixed_uint16, new Uint16Array(42)); |
143 assertKind(elements_kind.external_int, new Int32Array(0xF)); | 179 assertKind(elements_kind.fixed_int32, new Int32Array(0xF)); |
144 assertKind(elements_kind.external_unsigned_int, new Uint32Array(23)); | 180 assertKind(elements_kind.fixed_uint32, new Uint32Array(23)); |
145 assertKind(elements_kind.external_float, new Float32Array(7)); | 181 assertKind(elements_kind.fixed_float32, new Float32Array(7)); |
146 assertKind(elements_kind.external_double, new Float64Array(0)); | 182 assertKind(elements_kind.fixed_float64, new Float64Array(0)); |
147 assertKind(elements_kind.external_pixel, new Uint8ClampedArray(512)); | 183 assertKind(elements_kind.fixed_uint8_clamped, new Uint8ClampedArray(512)); |
| 184 |
| 185 var ab = new ArrayBuffer(128); |
| 186 assertKind(elements_kind.external_int8, new Int8Array(ab)); |
| 187 assertKind(elements_kind.external_uint8, new Uint8Array(ab)); |
| 188 assertKind(elements_kind.external_int16, new Int16Array(ab)); |
| 189 assertKind(elements_kind.external_uint16, new Uint16Array(ab)); |
| 190 assertKind(elements_kind.external_int32, new Int32Array(ab)); |
| 191 assertKind(elements_kind.external_uint32, new Uint32Array(ab)); |
| 192 assertKind(elements_kind.external_float32, new Float32Array(ab)); |
| 193 assertKind(elements_kind.external_float64, new Float64Array(ab)); |
| 194 assertKind(elements_kind.external_uint8_clamped, new Uint8ClampedArray(ab)); |
148 | 195 |
149 // Crankshaft support for smi-only array elements. | 196 // Crankshaft support for smi-only array elements. |
150 function monomorphic(array) { | 197 function monomorphic(array) { |
151 assertKind(elements_kind.fast_smi_only, array); | 198 assertKind(elements_kind.fast_smi_only, array); |
152 for (var i = 0; i < 3; i++) { | 199 for (var i = 0; i < 3; i++) { |
153 array[i] = i + 10; | 200 array[i] = i + 10; |
154 } | 201 } |
155 assertKind(elements_kind.fast_smi_only, array); | 202 assertKind(elements_kind.fast_smi_only, array); |
156 for (var i = 0; i < 3; i++) { | 203 for (var i = 0; i < 3; i++) { |
157 var a = array[i]; | 204 var a = array[i]; |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 var a = ["foo", "bar"]; | 410 var a = ["foo", "bar"]; |
364 assertKind(elements_kind.fast, a); | 411 assertKind(elements_kind.fast, a); |
365 var b = a.splice(0, 1); | 412 var b = a.splice(0, 1); |
366 assertKind(elements_kind.fast, b); | 413 assertKind(elements_kind.fast, b); |
367 var c = a.slice(0, 1); | 414 var c = a.slice(0, 1); |
368 assertKind(elements_kind.fast, c); | 415 assertKind(elements_kind.fast, c); |
369 } | 416 } |
370 | 417 |
371 // Throw away type information in the ICs for next stress run. | 418 // Throw away type information in the ICs for next stress run. |
372 gc(); | 419 gc(); |
OLD | NEW |