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

Side by Side Diff: test/mjsunit/polymorph-arrays.js

Issue 7227010: Create and use shared stub for for DictionaryValue-based elements. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: remove unrelated changes Created 9 years, 5 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
« src/stub-cache.h ('K') | « src/x64/stub-cache-x64.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
(Empty)
1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
27
28 // Flags: --allow-natives-syntax
29 // Flags: --allow-natives-syntax --expose-gc
Jakob Kummerow 2011/07/07 13:55:38 AFAICS you're not calling GC anywhere, so the firs
danno 2011/07/08 11:00:24 Done.
30 function init_array(a) {
31 for (var i = 0; i < 10; ++i ){
32 a[i] = i;
33 }
34 }
35
36 function init_sparse_array(a) {
37 for (var i = 0; i < 10; ++i ){
38 a[i] = i;
39 }
40 a[5000000] = 256;
41 assertTrue(%HasDictionaryElements(a));
42 }
43
44 function testPolymorphicLoads() {
45 function make_polymorphic_load_function() {
46 function load(a, i) {
47 return a[i];
48 }
49
50 var object_array = new Object;
51 var sparse_object_array = new Object;
52 var js_array = new Array(10);
53 var sparse_js_array = new Array(5000001);
54
55 init_array(object_array);
56 init_array(js_array);
57 init_sparse_array(sparse_object_array);
58 init_sparse_array(sparse_js_array);
59
60 assertEquals(1, load(object_array, 1));
61 assertEquals(1, load(js_array, 1));
62 assertEquals(1, load(sparse_object_array, 1));
63 assertEquals(1, load(sparse_js_array, 1));
64
65 return load;
66 }
67
68 var object_array = new Object;
69 var sparse_object_array = new Object;
70 var js_array = new Array(10);
71 var sparse_js_array = new Array(5000001);
72
73 init_array(object_array);
74 init_array(js_array);
75 init_sparse_array(sparse_object_array);
76 init_sparse_array(sparse_js_array);
77
78 // load() should now use polymorphic element loads.
79 load = make_polymorphic_load_function();
80 assertEquals(1, load(object_array, 1));
Jakob Kummerow 2011/07/07 13:55:38 Since exactly this assertion is performed inside m
danno 2011/07/08 11:00:24 Done.
81 load = make_polymorphic_load_function();
82 assertEquals(1, load(js_array, 1));
83 load = make_polymorphic_load_function();
84 assertEquals(1, load(sparse_object_array, 1));
85 load = make_polymorphic_load_function();
86 assertEquals(1, load(sparse_js_array, 1));
87
88 load = make_polymorphic_load_function();
89 assertEquals(undefined, load(js_array, new Object()));
90 load = make_polymorphic_load_function();
91 assertEquals(undefined, load(object_array, new Object()));
92 load = make_polymorphic_load_function();
93 assertEquals(undefined, load(sparse_js_array, new Object()));
94 load = make_polymorphic_load_function();
95 assertEquals(undefined, load(sparse_object_array, new Object()));
96
97 // Try with crankshaft.
98 load = make_polymorphic_load_function();
99 %OptimizeFunctionOnNextCall(load);
100 assertEquals(1, load(object_array, 1));
101 assertEquals(1, load(js_array, 1));
102 assertEquals(1, load(sparse_object_array, 1));
103 assertEquals(1, load(sparse_js_array, 1));
104
105 load = make_polymorphic_load_function();
106 %OptimizeFunctionOnNextCall(load);
107 assertEquals(undefined, load(js_array, new Object()));
108 assertEquals(undefined, load(js_array, new Object()));
Jakob Kummerow 2011/07/07 13:55:38 Duplicate line.
danno 2011/07/08 11:00:24 Done.
109 load = make_polymorphic_load_function();
110 %OptimizeFunctionOnNextCall(load);
111 assertEquals(undefined, load(object_array, new Object()));
112 load = make_polymorphic_load_function();
113 %OptimizeFunctionOnNextCall(load);
114 assertEquals(undefined, load(sparse_js_array, new Object()));
115 load = make_polymorphic_load_function();
116 %OptimizeFunctionOnNextCall(load);
117 assertEquals(undefined, load(sparse_object_array, new Object()));
118 }
119
120 function testPolymorphicStores() {
121 function make_polymorphic_store_function() {
122 function store(a, i, val) {
123 a[i] = val;
124 }
125
126 var object_array = new Object;
127 var sparse_object_array = new Object;
128 var js_array = new Array(10);
129 var sparse_js_array = new Array(5000001);
130
131 init_array(object_array);
132 init_array(js_array);
133 init_sparse_array(sparse_object_array);
134 init_sparse_array(sparse_js_array);
135
136 store(object_array, 1, 256);
137 store(js_array, 1, 256);
138 store(sparse_object_array, 1, 256);
139 store(sparse_js_array, 1, 256);
140
141 return store;
142 }
143
144 var object_array = new Object;
145 var sparse_object_array = new Object;
146 var js_array = new Array(10);
147 var sparse_js_array = new Array(5000001);
148
149 init_array(object_array);
150 init_array(js_array);
151 init_sparse_array(sparse_object_array);
152 init_sparse_array(sparse_js_array);
153
154 store = make_polymorphic_store_function();
155 store(object_array, 2, 257);
156 store = make_polymorphic_store_function();
157 store(js_array, 2, 257);
158 store = make_polymorphic_store_function();
159 store(sparse_object_array, 2, 257);
160 store = make_polymorphic_store_function();
161 store(sparse_js_array, 2, 257);
162
163 assertEquals(257, object_array[2]);
164 assertEquals(257, js_array[2]);
165 assertEquals(257, sparse_js_array[2]);
166 assertEquals(257, sparse_object_array[2]);
167
168 // Now try Crankshaft optimized polymorphic stores
169 store = make_polymorphic_store_function();
170 %OptimizeFunctionOnNextCall(store);
171 store(object_array, 3, 258);
172 store = make_polymorphic_store_function();
173 %OptimizeFunctionOnNextCall(store);
174 store(js_array, 3, 258);
175 store = make_polymorphic_store_function();
176 %OptimizeFunctionOnNextCall(store);
177 store(sparse_object_array, 3, 258);
178 store = make_polymorphic_store_function();
179 %OptimizeFunctionOnNextCall(store);
180 store(sparse_js_array, 3, 258);
181
182 assertEquals(258, object_array[3]);
183 assertEquals(258, js_array[3]);
184 assertEquals(258, sparse_js_array[3]);
185 assertEquals(258, sparse_object_array[3]);
186 }
187
188 testPolymorphicLoads();
189 testPolymorphicStores();
OLDNEW
« src/stub-cache.h ('K') | « src/x64/stub-cache-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698