OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 } | 45 } |
46 return r; | 46 return r; |
47 } | 47 } |
48 test_do_not_assert_on_non_int32(v,1); | 48 test_do_not_assert_on_non_int32(v,1); |
49 test_do_not_assert_on_non_int32(v,1); | 49 test_do_not_assert_on_non_int32(v,1); |
50 test_do_not_assert_on_non_int32(v,"a"); | 50 test_do_not_assert_on_non_int32(v,"a"); |
51 test_do_not_assert_on_non_int32(v,"a"); | 51 test_do_not_assert_on_non_int32(v,"a"); |
52 %OptimizeFunctionOnNextCall(test_do_not_assert_on_non_int32); | 52 %OptimizeFunctionOnNextCall(test_do_not_assert_on_non_int32); |
53 test_do_not_assert_on_non_int32(v,0); | 53 test_do_not_assert_on_non_int32(v,0); |
54 | 54 |
55 function test_base(base,cond) { | 55 function test_base(a, base, condition) { |
56 a[base + 1] = 1; | 56 a[base + 1] = 1; |
57 a[base + 4] = 2; | 57 a[base + 4] = 2; |
58 a[base + 3] = 3; | 58 a[base + 3] = 3; |
59 a[base + 2] = 4; | 59 a[base + 2] = 4; |
60 a[base + 4] = base + 4; | 60 a[base + 4] = base + 4; |
61 if (cond) { | 61 if (condition) { |
62 a[base + 1] = 1; | 62 a[base + 1] = 1; |
63 a[base + 2] = 2; | 63 a[base + 2] = 2; |
64 a[base + 2] = 3; | 64 a[base + 2] = 3; |
65 a[base + 2] = 4; | 65 a[base + 2] = 4; |
66 a[base + 4] = base + 4; | 66 a[base + 4] = base + 4; |
67 } else { | 67 } else { |
68 a[base + 6] = 1; | 68 a[base + 6] = 1; |
69 a[base + 4] = 2; | 69 a[base + 4] = 2; |
70 a[base + 3] = 3; | 70 a[base + 3] = 3; |
71 a[base + 2] = 4; | 71 a[base + 2] = 4; |
72 a[base + 4] = base - 4; | 72 a[base + 4] = base - 4; |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
76 function check_test_base(base,cond) { | 76 function check_test_base(a, base, condition) { |
77 if (cond) { | 77 if (condition) { |
78 assertEquals(1, a[base + 1]); | 78 assertEquals(1, a[base + 1]); |
79 assertEquals(4, a[base + 2]); | 79 assertEquals(4, a[base + 2]); |
80 assertEquals(base + 4, a[base + 4]); | 80 assertEquals(base + 4, a[base + 4]); |
81 } else { | 81 } else { |
82 assertEquals(1, a[base + 6]); | 82 assertEquals(1, a[base + 6]); |
83 assertEquals(3, a[base + 3]); | 83 assertEquals(3, a[base + 3]); |
84 assertEquals(4, a[base + 2]); | 84 assertEquals(4, a[base + 2]); |
85 assertEquals(base - 4, a[base + 4]); | 85 assertEquals(base - 4, a[base + 4]); |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
89 | 89 |
| 90 test_base(a, 1, true); |
| 91 test_base(a, 2, true); |
| 92 test_base(a, 1, false); |
| 93 test_base(a, 2, false); |
| 94 %OptimizeFunctionOnNextCall(test_base); |
| 95 test_base(a, 3, true); |
| 96 check_test_base(a, 3, true); |
| 97 test_base(a, 3, false); |
| 98 check_test_base(a, 3, false); |
| 99 |
| 100 // Test that we deopt on failed bounds checks. |
| 101 var dictionary_map_array = new Int32Array(128); |
| 102 test_base(dictionary_map_array, 5, true); |
| 103 test_base(dictionary_map_array, 6, true); |
| 104 test_base(dictionary_map_array, 5, false); |
| 105 test_base(dictionary_map_array, 6, false); |
| 106 %OptimizeFunctionOnNextCall(test_base); |
| 107 test_base(dictionary_map_array, -2, true); |
| 108 assertTrue(%GetOptimizationStatus(test_base) != 1); |
| 109 |
| 110 // Forget about the dictionary_map_array's map. |
| 111 %ClearFunctionTypeFeedback(test_base); |
| 112 |
| 113 test_base(a, 5, true); |
| 114 test_base(a, 6, true); |
| 115 test_base(a, 5, false); |
| 116 test_base(a, 6, false); |
| 117 %OptimizeFunctionOnNextCall(test_base); |
| 118 test_base(a, 2048, true); |
| 119 assertTrue(%GetOptimizationStatus(test_base) != 1); |
| 120 |
90 function test_minus(base,cond) { | 121 function test_minus(base,cond) { |
91 a[base - 1] = 1; | 122 a[base - 1] = 1; |
92 a[base - 2] = 2; | 123 a[base - 2] = 2; |
93 a[base + 4] = 3; | 124 a[base + 4] = 3; |
94 a[base] = 4; | 125 a[base] = 4; |
95 a[base + 4] = base + 4; | 126 a[base + 4] = base + 4; |
96 if (cond) { | 127 if (cond) { |
97 a[base - 4] = 1; | 128 a[base - 4] = 1; |
98 a[base + 5] = 2; | 129 a[base + 5] = 2; |
99 a[base + 3] = 3; | 130 a[base + 3] = 3; |
(...skipping 15 matching lines...) Expand all Loading... |
115 assertEquals(4, a[base + 2]); | 146 assertEquals(4, a[base + 2]); |
116 assertEquals(base + 4, a[base + 4]); | 147 assertEquals(base + 4, a[base + 4]); |
117 } else { | 148 } else { |
118 assertEquals(1, a[base + 6]); | 149 assertEquals(1, a[base + 6]); |
119 assertEquals(3, a[base + 3]); | 150 assertEquals(3, a[base + 3]); |
120 assertEquals(4, a[base + 2]); | 151 assertEquals(4, a[base + 2]); |
121 assertEquals(base - 4, a[base + 4]); | 152 assertEquals(base - 4, a[base + 4]); |
122 } | 153 } |
123 } | 154 } |
124 | 155 |
125 test_base(1,true); | |
126 test_base(2,true); | |
127 test_base(1,false); | |
128 test_base(2,false); | |
129 %OptimizeFunctionOnNextCall(test_base); | |
130 test_base(3,true); | |
131 check_test_base(3,true); | |
132 test_base(3,false); | |
133 check_test_base(3,false); | |
134 | |
135 test_minus(5,true); | 156 test_minus(5,true); |
136 test_minus(6,true); | 157 test_minus(6,true); |
137 %OptimizeFunctionOnNextCall(test_minus); | 158 %OptimizeFunctionOnNextCall(test_minus); |
138 test_minus(7,true); | 159 test_minus(7,true); |
139 check_test_minus(7,true); | 160 check_test_minus(7,true); |
140 test_minus(7,false); | 161 test_minus(7,false); |
141 check_test_minus(7,false); | 162 check_test_minus(7,false); |
142 | 163 |
143 // Optimization status: | 164 // Specific test on negative offsets. |
144 // YES: 1 | |
145 // NO: 2 | |
146 // ALWAYS: 3 | |
147 // NEVER: 4 | |
148 | |
149 // Test that we still deopt on failed bound checks | |
150 test_base(5,true); | |
151 test_base(6,true); | |
152 test_base(5,false); | |
153 test_base(6,false); | |
154 %OptimizeFunctionOnNextCall(test_base); | |
155 test_base(-2,true); | |
156 assertTrue(%GetOptimizationStatus(test_base) != 1); | |
157 | |
158 test_base(5,true); | |
159 test_base(6,true); | |
160 test_base(5,false); | |
161 test_base(6,false); | |
162 %OptimizeFunctionOnNextCall(test_base); | |
163 test_base(2048,true); | |
164 assertTrue(%GetOptimizationStatus(test_base) != 1); | |
165 | |
166 // Specific test on negative offsets | |
167 var short_a = new Array(100); | 165 var short_a = new Array(100); |
168 for (var i = 0; i < short_a.length; i++) short_a[i] = 0; | 166 for (var i = 0; i < short_a.length; i++) short_a[i] = 0; |
169 function short_test(a, i) { | 167 function short_test(a, i) { |
170 a[i + 9] = 0; | 168 a[i + 9] = 0; |
171 a[i - 10] = 0; | 169 a[i - 10] = 0; |
172 } | 170 } |
173 short_test(short_a, 50); | 171 short_test(short_a, 50); |
174 short_test(short_a, 50); | 172 short_test(short_a, 50); |
175 %OptimizeFunctionOnNextCall(short_test); | 173 %OptimizeFunctionOnNextCall(short_test); |
176 short_a.length = 10; | 174 short_a.length = 10; |
177 short_test(a, 0); | 175 short_test(short_a, 0); |
178 assertTrue(%GetOptimizationStatus(short_test) != 1); | 176 assertTrue(%GetOptimizationStatus(short_test) != 1); |
179 | 177 |
180 | 178 |
181 // A test for when we would modify a phi index. | 179 // A test for when we would modify a phi index. |
182 var data_phi = [0, 1, 2, 3, 4, 5, 6, 7, 8]; | 180 var data_phi = [0, 1, 2, 3, 4, 5, 6, 7, 8]; |
183 function test_phi(a, base, check) { | 181 function test_phi(a, base, check) { |
184 var index; | 182 var index; |
185 if (check) { | 183 if (check) { |
186 index = base + 1; | 184 index = base + 1; |
187 } else { | 185 } else { |
188 index = base + 2; | 186 index = base + 2; |
189 } | 187 } |
190 var result = a[index]; | 188 var result = a[index]; |
191 result += a[index + 1]; | 189 result += a[index + 1]; |
192 result += a[index - 1]; | 190 result += a[index - 1]; |
193 return result; | 191 return result; |
194 } | 192 } |
195 var result_phi = 0; | 193 var result_phi = 0; |
196 result_phi = test_phi(data_phi, 3, true); | 194 result_phi = test_phi(data_phi, 3, true); |
197 assertEquals(12, result_phi); | 195 assertEquals(12, result_phi); |
198 result_phi = test_phi(data_phi, 3, true); | 196 result_phi = test_phi(data_phi, 3, true); |
199 assertEquals(12, result_phi); | 197 assertEquals(12, result_phi); |
200 %OptimizeFunctionOnNextCall(test_phi); | 198 %OptimizeFunctionOnNextCall(test_phi); |
201 result_phi = test_phi(data_phi, 3, true); | 199 result_phi = test_phi(data_phi, 3, true); |
202 assertEquals(12, result_phi); | 200 assertEquals(12, result_phi); |
203 | 201 |
204 | 202 |
205 gc(); | 203 gc(); |
206 | |
OLD | NEW |