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

Side by Side Diff: test/mjsunit/track-fields.js

Issue 14850006: Use mutable heapnumbers to store doubles in fields. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Ported to ARM and x64 Created 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-heap-profiler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 var of1 = {a:0}; 111 var of1 = {a:0};
112 of1.field = {}; 112 of1.field = {};
113 var of2 = {b:0}; 113 var of2 = {b:0};
114 of2.field = 10; 114 of2.field = 10;
115 115
116 poly_load(of1, false); 116 poly_load(of1, false);
117 poly_load(of1, false); 117 poly_load(of1, false);
118 poly_load(of2, true); 118 poly_load(of2, true);
119 %OptimizeFunctionOnNextCall(poly_load); 119 %OptimizeFunctionOnNextCall(poly_load);
120 assertEquals("[object Object]10", poly_load(of1, true)); 120 assertEquals("[object Object]10", poly_load(of1, true));
121
122 // Ensure small object literals with doubles do not share double storage.
123 function object_literal() { return {"a":1.5}; }
124 var o8 = object_literal();
125 var o9 = object_literal();
126 o8.a = 4.6
127 assertEquals(1.5, o9.a);
128
129 // Ensure double storage is not leaked in the case of polymorphic loads.
130 function load_poly(o) {
131 return o.a;
132 }
133
134 var o10 = { "a": 1.6 };
135 var o11 = { "b": 1, "a": 1.7 };
136 load_poly(o10);
137 load_poly(o10);
138 load_poly(o11);
139 %OptimizeFunctionOnNextCall(load_poly);
140 var val = load_poly(o10);
141 o10.a = 19.5;
142 assertFalse(o10.a == val);
143
144 // Ensure polymorphic loads only go monomorphic when the representations are
145 // compatible.
146
147 // Check polymorphic load from double + object fields.
148 function load_mono(o) {
149 return o.a1;
150 }
151
152 var object = {"x": 1};
153 var o10 = { "a1": 1.6 };
154 var o11 = { "a1": object, "b": 1 };
155 load_mono(o10);
156 load_mono(o10);
157 load_mono(o11);
158 %OptimizeFunctionOnNextCall(load_mono);
159 assertEquals(object, load_mono(o11));
160
161 // Check polymorphic load from smi + object fields.
162 function load_mono2(o) {
163 return o.a2;
164 }
165
166 var o12 = { "a2": 5 };
167 var o13 = { "a2": object, "b": 1 };
168 load_mono2(o12);
169 load_mono2(o12);
170 load_mono2(o13);
171 %OptimizeFunctionOnNextCall(load_mono2);
172 assertEquals(object, load_mono2(o13));
173
174 // Check polymorphic load from double + double fields.
175 function load_mono3(o) {
176 return o.a3;
177 }
178
179 var o14 = { "a3": 1.6 };
180 var o15 = { "a3": 1.8, "b": 1 };
181 load_mono3(o14);
182 load_mono3(o14);
183 load_mono3(o15);
184 %OptimizeFunctionOnNextCall(load_mono3);
185 assertEquals(1.6, load_mono3(o14));
186 assertEquals(1.8, load_mono3(o15));
187
188 // Check that JSON parsing respects existing representations.
189 var o16 = JSON.parse('{"a":1.5}');
190 var o17 = JSON.parse('{"a":100}');
191 assertTrue(%HaveSameMap(o16, o17));
192 var o17_a = o17.a;
193 assertEquals(100, o17_a);
194 o17.a = 200;
195 assertEquals(100, o17_a);
196 assertEquals(200, o17.a);
197
198 // Ensure normalizing results in ignored representations.
199 var o18 = {};
200 o18.field1 = 100;
201 o18.field2 = 1;
202 o18.to_delete = 100;
203
204 var o19 = {};
205 o19.field1 = 100;
206 o19.field2 = 1.6;
207 o19.to_delete = 100;
208
209 assertFalse(%HaveSameMap(o18, o19));
210
211 delete o18.to_delete;
212 delete o19.to_delete;
213
214 assertTrue(%HaveSameMap(o18, o19));
215 assertEquals(1, o18.field2);
216 assertEquals(1.6, o19.field2);
217
218 // Test megamorphic keyed stub behaviour in combination with representations.
219 var some_object20 = {"a":1};
220 var o20 = {};
221 o20.smi = 1;
222 o20.dbl = 1.5;
223 o20.obj = some_object20;
224
225 function keyed_load(o, k) {
226 return o[k];
227 }
228
229 function keyed_store(o, k, v) {
230 return o[k] = v;
231 }
232
233 var smi20 = keyed_load(o20, "smi");
234 var dbl20 = keyed_load(o20, "dbl");
235 var obj20 = keyed_load(o20, "obj");
236 keyed_load(o20, "smi");
237 keyed_load(o20, "dbl");
238 keyed_load(o20, "obj");
239 keyed_load(o20, "smi");
240 keyed_load(o20, "dbl");
241 keyed_load(o20, "obj");
242
243 assertEquals(1, smi20);
244 assertEquals(1.5, dbl20);
245 assertEquals(some_object20, obj20);
246
247 keyed_store(o20, "smi", 100);
248 keyed_store(o20, "dbl", 100);
249 keyed_store(o20, "obj", 100);
250 keyed_store(o20, "smi", 100);
251 keyed_store(o20, "dbl", 100);
252 keyed_store(o20, "obj", 100);
253 keyed_store(o20, "smi", 100);
254 keyed_store(o20, "dbl", 100);
255 keyed_store(o20, "obj", 100);
256
257 assertEquals(1, smi20);
258 assertEquals(1.5, dbl20);
259 assertEquals(some_object20, obj20);
260
261 assertEquals(100, o20.smi);
262 assertEquals(100, o20.dbl);
263 assertEquals(100, o20.dbl);
OLDNEW
« no previous file with comments | « test/cctest/test-heap-profiler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698