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

Side by Side Diff: test/mjsunit/allocation-site-info.js

Issue 11818021: Allocation Info Tracking, continued. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebase Created 7 years, 10 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
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 28 // Flags: --allow-natives-syntax --smi-only-arrays --expose-gc
29 // Flags: --track-allocation-sites 29 // Flags: --track-allocation-sites --nooptimize-constructed-arrays
30
31 // TODO(mvstanton): remove --nooptimize-constructed-arrays and enable
32 // the constructed array code below when the feature is turned on
33 // by default.
30 34
31 // Test element kind of objects. 35 // Test element kind of objects.
32 // Since --smi-only-arrays affects builtins, its default setting at compile 36 // Since --smi-only-arrays affects builtins, its default setting at compile
33 // time sticks if built with snapshot. If --smi-only-arrays is deactivated 37 // time sticks if built with snapshot. If --smi-only-arrays is deactivated
34 // by default, only a no-snapshot build actually has smi-only arrays enabled 38 // by default, only a no-snapshot build actually has smi-only arrays enabled
35 // in this test case. Depending on whether smi-only arrays are actually 39 // in this test case. Depending on whether smi-only arrays are actually
36 // enabled, this test takes the appropriate code path to check smi-only arrays. 40 // enabled, this test takes the appropriate code path to check smi-only arrays.
37 41
38 support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8)); 42 support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8));
43 optimize_constructed_arrays = false;
39 44
40 if (support_smi_only_arrays) { 45 if (support_smi_only_arrays) {
41 print("Tests include smi-only arrays."); 46 print("Tests include smi-only arrays.");
42 } else { 47 } else {
43 print("Tests do NOT include smi-only arrays."); 48 print("Tests do NOT include smi-only arrays.");
44 } 49 }
45 50
51 if (optimize_constructed_arrays) {
52 print("Tests include constructed array optimizations.");
53 } else {
54 print("Tests do NOT include constructed array optimizations.");
55 }
56
46 var elements_kind = { 57 var elements_kind = {
47 fast_smi_only : 'fast smi only elements', 58 fast_smi_only : 'fast smi only elements',
48 fast : 'fast elements', 59 fast : 'fast elements',
49 fast_double : 'fast double elements', 60 fast_double : 'fast double elements',
50 dictionary : 'dictionary elements', 61 dictionary : 'dictionary elements',
51 external_byte : 'external byte elements', 62 external_byte : 'external byte elements',
52 external_unsigned_byte : 'external unsigned byte elements', 63 external_unsigned_byte : 'external unsigned byte elements',
53 external_short : 'external short elements', 64 external_short : 'external short elements',
54 external_unsigned_short : 'external unsigned short elements', 65 external_unsigned_short : 'external unsigned short elements',
55 external_int : 'external int elements', 66 external_int : 'external int elements',
56 external_unsigned_int : 'external unsigned int elements', 67 external_unsigned_int : 'external unsigned int elements',
57 external_float : 'external float elements', 68 external_float : 'external float elements',
58 external_double : 'external double elements', 69 external_double : 'external double elements',
59 external_pixel : 'external pixel elements' 70 external_pixel : 'external pixel elements'
60 } 71 }
61 72
62 function getKind(obj) { 73 function getKind(obj) {
63 if (%HasFastSmiElements(obj)) return elements_kind.fast_smi_only; 74 if (%HasFastSmiElements(obj)) return elements_kind.fast_smi_only;
64 if (%HasFastObjectElements(obj)) return elements_kind.fast; 75 if (%HasFastObjectElements(obj)) return elements_kind.fast;
65 if (%HasFastDoubleElements(obj)) return elements_kind.fast_double; 76 if (%HasFastDoubleElements(obj)) return elements_kind.fast_double;
66 if (%HasDictionaryElements(obj)) return elements_kind.dictionary; 77 if (%HasDictionaryElements(obj)) return elements_kind.dictionary;
67 } 78 }
68 79
80 function isHoley(obj) {
81 if (%HasFastHoleyElements(obj)) return true;
82 return false;
83 }
84
69 function assertKind(expected, obj, name_opt) { 85 function assertKind(expected, obj, name_opt) {
70 if (!support_smi_only_arrays && 86 if (!support_smi_only_arrays &&
71 expected == elements_kind.fast_smi_only) { 87 expected == elements_kind.fast_smi_only) {
72 expected = elements_kind.fast; 88 expected = elements_kind.fast;
73 } 89 }
74 assertEquals(expected, getKind(obj), name_opt); 90 assertEquals(expected, getKind(obj), name_opt);
75 } 91 }
76 92
93 function assertHoley(obj, name_opt) {
94 assertEquals(true, isHoley(obj), name_opt);
95 }
96
97 function assertNotHoley(obj, name_opt) {
98 assertEquals(false, isHoley(obj), name_opt);
99 }
100
77 if (support_smi_only_arrays) { 101 if (support_smi_only_arrays) {
102
103 obj = [];
104 assertNotHoley(obj);
105 assertKind(elements_kind.fast_smi_only, obj);
106
107 obj = [1, 2, 3];
108 assertNotHoley(obj);
109 assertKind(elements_kind.fast_smi_only, obj);
110
111 obj = new Array();
112 assertNotHoley(obj);
113 assertKind(elements_kind.fast_smi_only, obj);
114
115 obj = new Array(0);
116 assertNotHoley(obj);
117 assertKind(elements_kind.fast_smi_only, obj);
118
119 obj = new Array(2);
120 assertHoley(obj);
121 assertKind(elements_kind.fast_smi_only, obj);
122
123 obj = new Array(1,2,3);
124 assertNotHoley(obj);
125 assertKind(elements_kind.fast_smi_only, obj);
126
127 obj = new Array(1, "hi", 2, undefined);
128 assertNotHoley(obj);
129 assertKind(elements_kind.fast, obj);
130
78 function fastliteralcase(literal, value) { 131 function fastliteralcase(literal, value) {
79 // var literal = [1, 2, 3];
80 literal[0] = value; 132 literal[0] = value;
81 return literal; 133 return literal;
82 } 134 }
83 135
84 function get_standard_literal() { 136 function get_standard_literal() {
85 var literal = [1, 2, 3]; 137 var literal = [1, 2, 3];
86 return literal; 138 return literal;
87 } 139 }
88 140
89 // Case: [1,2,3] as allocation site 141 // Case: [1,2,3] as allocation site
90 obj = fastliteralcase(get_standard_literal(), 1); 142 obj = fastliteralcase(get_standard_literal(), 1);
91 assertKind(elements_kind.fast_smi_only, obj); 143 assertKind(elements_kind.fast_smi_only, obj);
92 obj = fastliteralcase(get_standard_literal(), 1.5); 144 obj = fastliteralcase(get_standard_literal(), 1.5);
93 assertKind(elements_kind.fast_double, obj); 145 assertKind(elements_kind.fast_double, obj);
94 obj = fastliteralcase(get_standard_literal(), 2); 146 obj = fastliteralcase(get_standard_literal(), 2);
95 assertKind(elements_kind.fast_double, obj); 147 assertKind(elements_kind.fast_double, obj);
96 148
97 obj = fastliteralcase([5, 3, 2], 1.5); 149 obj = fastliteralcase([5, 3, 2], 1.5);
98 assertKind(elements_kind.fast_double, obj); 150 assertKind(elements_kind.fast_double, obj);
99 obj = fastliteralcase([3, 6, 2], 1.5); 151 obj = fastliteralcase([3, 6, 2], 1.5);
100 assertKind(elements_kind.fast_double, obj); 152 assertKind(elements_kind.fast_double, obj);
101 obj = fastliteralcase([2, 6, 3], 2); 153 obj = fastliteralcase([2, 6, 3], 2);
102 assertKind(elements_kind.fast_smi_only, obj); 154 assertKind(elements_kind.fast_smi_only, obj);
103 155
104 // Verify that we will not pretransition the double->fast path. 156 // Verify that we will not pretransition the double->fast path.
105 obj = fastliteralcase(get_standard_literal(), "elliot"); 157 obj = fastliteralcase(get_standard_literal(), "elliot");
106 assertKind(elements_kind.fast, obj); 158 assertKind(elements_kind.fast, obj);
107
108 // This fails until we turn off optimistic transitions to the 159 // This fails until we turn off optimistic transitions to the
109 // most general elements kind seen on keyed stores. It's a goal 160 // most general elements kind seen on keyed stores. It's a goal
110 // to turn it off, but for now we need it. 161 // to turn it off, but for now we need it.
111 // obj = fastliteralcase(3); 162 // obj = fastliteralcase(3);
112 // assertKind(elements_kind.fast_double, obj); 163 // assertKind(elements_kind.fast_double, obj);
113 164
114 function fastliteralcase_smifast(value) { 165 function fastliteralcase_smifast(value) {
115 var literal = [1, 2, 3, 4]; 166 var literal = [1, 2, 3, 4];
116 literal[0] = value; 167 literal[0] = value;
117 return literal; 168 return literal;
118 } 169 }
119 170
120 obj = fastliteralcase_smifast(1); 171 obj = fastliteralcase_smifast(1);
121 assertKind(elements_kind.fast_smi_only, obj); 172 assertKind(elements_kind.fast_smi_only, obj);
122 obj = fastliteralcase_smifast("carter"); 173 obj = fastliteralcase_smifast("carter");
123 assertKind(elements_kind.fast, obj); 174 assertKind(elements_kind.fast, obj);
124 obj = fastliteralcase_smifast(2); 175 obj = fastliteralcase_smifast(2);
125 assertKind(elements_kind.fast, obj); 176 assertKind(elements_kind.fast, obj);
177
178 if (optimize_constructed_arrays) {
179 function newarraycase_smidouble(value) {
180 var a = new Array();
181 a[0] = value;
182 return a;
183 }
184
185 // Case: new Array() as allocation site, smi->double
186 obj = newarraycase_smidouble(1);
187 assertKind(elements_kind.fast_smi_only, obj);
188 obj = newarraycase_smidouble(1.5);
189 assertKind(elements_kind.fast_double, obj);
190 obj = newarraycase_smidouble(2);
191 assertKind(elements_kind.fast_double, obj);
192
193 function newarraycase_smiobj(value) {
194 var a = new Array();
195 a[0] = value;
196 return a;
197 }
198
199 // Case: new Array() as allocation site, smi->fast
200 obj = newarraycase_smiobj(1);
201 assertKind(elements_kind.fast_smi_only, obj);
202 obj = newarraycase_smiobj("gloria");
203 assertKind(elements_kind.fast, obj);
204 obj = newarraycase_smiobj(2);
205 assertKind(elements_kind.fast, obj);
206
207 function newarraycase_length_smidouble(value) {
208 var a = new Array(3);
209 a[0] = value;
210 return a;
211 }
212
213 // Case: new Array(length) as allocation site
214 obj = newarraycase_length_smidouble(1);
215 assertKind(elements_kind.fast_smi_only, obj);
216 obj = newarraycase_length_smidouble(1.5);
217 assertKind(elements_kind.fast_double, obj);
218 obj = newarraycase_length_smidouble(2);
219 assertKind(elements_kind.fast_double, obj);
220
221 // Try to continue the transition to fast object, but
222 // we will not pretransition from double->fast, because
223 // it may hurt performance ("poisoning").
224 obj = newarraycase_length_smidouble("coates");
225 assertKind(elements_kind.fast, obj);
226 obj = newarraycase_length_smidouble(2.5);
227 // However, because of optimistic transitions, we will
228 // transition to the most general kind of elements kind found,
229 // therefore I can't count on this assert yet.
230 // assertKind(elements_kind.fast_double, obj);
231
232 function newarraycase_length_smiobj(value) {
233 var a = new Array(3);
234 a[0] = value;
235 return a;
236 }
237
238 // Case: new Array(<length>) as allocation site, smi->fast
239 obj = newarraycase_length_smiobj(1);
240 assertKind(elements_kind.fast_smi_only, obj);
241 obj = newarraycase_length_smiobj("gloria");
242 assertKind(elements_kind.fast, obj);
243 obj = newarraycase_length_smiobj(2);
244 assertKind(elements_kind.fast, obj);
245
246 function newarraycase_list_smidouble(value) {
247 var a = new Array(1, 2, 3);
248 a[0] = value;
249 return a;
250 }
251
252 obj = newarraycase_list_smidouble(1);
253 assertKind(elements_kind.fast_smi_only, obj);
254 obj = newarraycase_list_smidouble(1.5);
255 assertKind(elements_kind.fast_double, obj);
256 obj = newarraycase_list_smidouble(2);
257 assertKind(elements_kind.fast_double, obj);
258
259 function newarraycase_list_smiobj(value) {
260 var a = new Array(4, 5, 6);
261 a[0] = value;
262 return a;
263 }
264
265 obj = newarraycase_list_smiobj(1);
266 assertKind(elements_kind.fast_smi_only, obj);
267 obj = newarraycase_list_smiobj("coates");
268 assertKind(elements_kind.fast, obj);
269 obj = newarraycase_list_smiobj(2);
270 assertKind(elements_kind.fast, obj);
271 }
126 } 272 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698