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

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

Issue 208503007: Revert "This implements allocating small typed arrays in heap." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 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 | « src/typedarray.js ('k') | test/mjsunit/external-array.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 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 -- typed-array-max_size_in-heap=2048 28 // Flags: --allow-natives-syntax --smi-only-arrays --expose-gc --nostress-opt
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_int32 : 'external int8 elements', 50 external_byte : 'external byte elements',
51 external_uint8 : 'external uint8 elements', 51 external_unsigned_byte : 'external unsigned byte elements',
52 external_int16 : 'external int16 elements', 52 external_short : 'external short elements',
53 external_uint16 : 'external uint16 elements', 53 external_unsigned_short : 'external unsigned short elements',
54 external_int32 : 'external int32 elements', 54 external_int : 'external int elements',
55 external_uint32 : 'external uint32 elements', 55 external_unsigned_int : 'external unsigned int elements',
56 external_float32 : 'external float32 elements', 56 external_float : 'external float elements',
57 external_float64 : 'external float64 elements', 57 external_double : 'external double elements',
58 external_uint8_clamped : 'external uint8_clamped elements', 58 external_pixel : 'external pixel 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'
68 } 59 }
69 60
70 function getKind(obj) { 61 function getKind(obj) {
71 if (%HasFastSmiElements(obj)) return elements_kind.fast_smi_only; 62 if (%HasFastSmiElements(obj)) return elements_kind.fast_smi_only;
72 if (%HasFastObjectElements(obj)) return elements_kind.fast; 63 if (%HasFastObjectElements(obj)) return elements_kind.fast;
73 if (%HasFastDoubleElements(obj)) return elements_kind.fast_double; 64 if (%HasFastDoubleElements(obj)) return elements_kind.fast_double;
74 if (%HasDictionaryElements(obj)) return elements_kind.dictionary; 65 if (%HasDictionaryElements(obj)) return elements_kind.dictionary;
75
76 // Every external kind is also an external array. 66 // Every external kind is also an external array.
67 assertTrue(%HasExternalArrayElements(obj));
77 if (%HasExternalInt8Elements(obj)) { 68 if (%HasExternalInt8Elements(obj)) {
78 return elements_kind.external_int8; 69 return elements_kind.external_byte;
79 } 70 }
80 if (%HasExternalUint8Elements(obj)) { 71 if (%HasExternalUint8Elements(obj)) {
81 return elements_kind.external_uint8; 72 return elements_kind.external_unsigned_byte;
82 } 73 }
83 if (%HasExternalInt16Elements(obj)) { 74 if (%HasExternalInt16Elements(obj)) {
84 return elements_kind.external_int16; 75 return elements_kind.external_short;
85 } 76 }
86 if (%HasExternalUint16Elements(obj)) { 77 if (%HasExternalUint16Elements(obj)) {
87 return elements_kind.external_uint16; 78 return elements_kind.external_unsigned_short;
88 } 79 }
89 if (%HasExternalInt32Elements(obj)) { 80 if (%HasExternalInt32Elements(obj)) {
90 return elements_kind.external_int32; 81 return elements_kind.external_int;
91 } 82 }
92 if (%HasExternalUint32Elements(obj)) { 83 if (%HasExternalUint32Elements(obj)) {
93 return elements_kind.external_uint32; 84 return elements_kind.external_unsigned_int;
94 } 85 }
95 if (%HasExternalFloat32Elements(obj)) { 86 if (%HasExternalFloat32Elements(obj)) {
96 return elements_kind.external_float32; 87 return elements_kind.external_float;
97 } 88 }
98 if (%HasExternalFloat64Elements(obj)) { 89 if (%HasExternalFloat64Elements(obj)) {
99 return elements_kind.external_float64; 90 return elements_kind.external_double;
100 } 91 }
101 if (%HasExternalUint8ClampedElements(obj)) { 92 if (%HasExternalUint8ClampedElements(obj)) {
102 return elements_kind.external_uint8_clamped; 93 return elements_kind.external_pixel;
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;
130 } 94 }
131 } 95 }
132 96
133 function assertKind(expected, obj, name_opt) { 97 function assertKind(expected, obj, name_opt) {
134 if (!support_smi_only_arrays && 98 if (!support_smi_only_arrays &&
135 expected == elements_kind.fast_smi_only) { 99 expected == elements_kind.fast_smi_only) {
136 expected = elements_kind.fast; 100 expected = elements_kind.fast;
137 } 101 }
138 assertEquals(expected, getKind(obj), name_opt); 102 assertEquals(expected, getKind(obj), name_opt);
139 } 103 }
(...skipping 25 matching lines...) Expand all
165 you[i] = val; 129 you[i] = val;
166 } 130 }
167 assertKind(elements_kind.fast, you); 131 assertKind(elements_kind.fast, you);
168 132
169 assertKind(elements_kind.dictionary, new Array(0xDECAF)); 133 assertKind(elements_kind.dictionary, new Array(0xDECAF));
170 134
171 var fast_double_array = new Array(0xDECAF); 135 var fast_double_array = new Array(0xDECAF);
172 for (var i = 0; i < 0xDECAF; i++) fast_double_array[i] = i / 2; 136 for (var i = 0; i < 0xDECAF; i++) fast_double_array[i] = i / 2;
173 assertKind(elements_kind.fast_double, fast_double_array); 137 assertKind(elements_kind.fast_double, fast_double_array);
174 138
175 assertKind(elements_kind.fixed_int8, new Int8Array(007)); 139 assertKind(elements_kind.external_byte, new Int8Array(9001));
176 assertKind(elements_kind.fixed_uint8, new Uint8Array(007)); 140 assertKind(elements_kind.external_unsigned_byte, new Uint8Array(007));
177 assertKind(elements_kind.fixed_int16, new Int16Array(666)); 141 assertKind(elements_kind.external_short, new Int16Array(666));
178 assertKind(elements_kind.fixed_uint16, new Uint16Array(42)); 142 assertKind(elements_kind.external_unsigned_short, new Uint16Array(42));
179 assertKind(elements_kind.fixed_int32, new Int32Array(0xF)); 143 assertKind(elements_kind.external_int, new Int32Array(0xF));
180 assertKind(elements_kind.fixed_uint32, new Uint32Array(23)); 144 assertKind(elements_kind.external_unsigned_int, new Uint32Array(23));
181 assertKind(elements_kind.fixed_float32, new Float32Array(7)); 145 assertKind(elements_kind.external_float, new Float32Array(7));
182 assertKind(elements_kind.fixed_float64, new Float64Array(0)); 146 assertKind(elements_kind.external_double, new Float64Array(0));
183 assertKind(elements_kind.fixed_uint8_clamped, new Uint8ClampedArray(512)); 147 assertKind(elements_kind.external_pixel, 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));
195 148
196 // Crankshaft support for smi-only array elements. 149 // Crankshaft support for smi-only array elements.
197 function monomorphic(array) { 150 function monomorphic(array) {
198 assertKind(elements_kind.fast_smi_only, array); 151 assertKind(elements_kind.fast_smi_only, array);
199 for (var i = 0; i < 3; i++) { 152 for (var i = 0; i < 3; i++) {
200 array[i] = i + 10; 153 array[i] = i + 10;
201 } 154 }
202 assertKind(elements_kind.fast_smi_only, array); 155 assertKind(elements_kind.fast_smi_only, array);
203 for (var i = 0; i < 3; i++) { 156 for (var i = 0; i < 3; i++) {
204 var a = array[i]; 157 var a = array[i];
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 var a = ["foo", "bar"]; 363 var a = ["foo", "bar"];
411 assertKind(elements_kind.fast, a); 364 assertKind(elements_kind.fast, a);
412 var b = a.splice(0, 1); 365 var b = a.splice(0, 1);
413 assertKind(elements_kind.fast, b); 366 assertKind(elements_kind.fast, b);
414 var c = a.slice(0, 1); 367 var c = a.slice(0, 1);
415 assertKind(elements_kind.fast, c); 368 assertKind(elements_kind.fast, c);
416 } 369 }
417 370
418 // Throw away type information in the ICs for next stress run. 371 // Throw away type information in the ICs for next stress run.
419 gc(); 372 gc();
OLDNEW
« no previous file with comments | « src/typedarray.js ('k') | test/mjsunit/external-array.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698