OLD | NEW |
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 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 function assertKind(expected, obj, name_opt) { | 75 function assertKind(expected, obj, name_opt) { |
76 if (!support_smi_only_arrays && | 76 if (!support_smi_only_arrays && |
77 expected == elements_kind.fast_smi_only) { | 77 expected == elements_kind.fast_smi_only) { |
78 expected = elements_kind.fast; | 78 expected = elements_kind.fast; |
79 } | 79 } |
80 assertEquals(expected, getKind(obj), name_opt); | 80 assertEquals(expected, getKind(obj), name_opt); |
81 } | 81 } |
82 | 82 |
83 if (support_smi_only_arrays) { | 83 if (support_smi_only_arrays) { |
84 | 84 |
85 // Test: If a call site goes megamorphic, it loses the ability to | 85 // Test: If a call site goes megamorphic, it retains the ability to |
86 // use allocation site feedback. | 86 // use allocation site feedback. |
87 (function() { | 87 (function() { |
88 function bar(t, len) { | 88 function bar(t, len) { |
89 return new t(len); | 89 return new t(len); |
90 } | 90 } |
91 | 91 |
92 a = bar(Array, 10); | 92 a = bar(Array, 10); |
93 a[0] = 3.5; | 93 a[0] = 3.5; |
94 b = bar(Array, 1); | 94 b = bar(Array, 1); |
95 assertKind(elements_kind.fast_double, b); | 95 assertKind(elements_kind.fast_double, b); |
96 c = bar(Object, 3); | 96 c = bar(Object, 3); |
97 b = bar(Array, 10); | 97 b = bar(Array, 10); |
98 assertKind(elements_kind.fast_smi_only, b); | 98 assertKind(elements_kind.fast_double, b); |
99 b[0] = 3.5; | |
100 c = bar(Array, 10); | |
101 assertKind(elements_kind.fast_smi_only, c); | |
102 })(); | 99 })(); |
103 | 100 |
104 | 101 |
105 // Test: ensure that crankshafted array constructor sites are deopted | 102 // Test: ensure that crankshafted array constructor sites are deopted |
106 // if another function is used. | 103 // if another function is used. |
107 (function() { | 104 (function() { |
108 function bar0(t) { | 105 function bar0(t) { |
109 return new t(); | 106 return new t(); |
110 } | 107 } |
111 a = bar0(Array); | 108 a = bar0(Array); |
112 a[0] = 3.5; | 109 a[0] = 3.5; |
113 b = bar0(Array); | 110 b = bar0(Array); |
114 assertKind(elements_kind.fast_double, b); | 111 assertKind(elements_kind.fast_double, b); |
115 %OptimizeFunctionOnNextCall(bar0); | 112 %OptimizeFunctionOnNextCall(bar0); |
116 b = bar0(Array); | 113 b = bar0(Array); |
117 assertKind(elements_kind.fast_double, b); | 114 assertKind(elements_kind.fast_double, b); |
118 assertOptimized(bar0); | 115 assertOptimized(bar0); |
119 // bar0 should deopt | 116 // bar0 should deopt |
120 b = bar0(Object); | 117 b = bar0(Object); |
121 assertUnoptimized(bar0) | 118 assertUnoptimized(bar0) |
122 // When it's re-optimized, we should call through the full stub | 119 // When it's re-optimized, we should call through the full stub |
123 bar0(Array); | 120 bar0(Array); |
124 %OptimizeFunctionOnNextCall(bar0); | 121 %OptimizeFunctionOnNextCall(bar0); |
125 b = bar0(Array); | 122 b = bar0(Array); |
126 // We also lost our ability to record kind feedback, as the site | 123 // This only makes sense to test if we allow crankshafting |
127 // is megamorphic now. | 124 if (4 != %GetOptimizationStatus(bar0)) { |
128 assertKind(elements_kind.fast_smi_only, b); | 125 // We also lost our ability to record kind feedback, as the site |
129 assertOptimized(bar0); | 126 // is megamorphic now. |
130 b[0] = 3.5; | 127 assertKind(elements_kind.fast_smi_only, b); |
131 c = bar0(Array); | 128 assertOptimized(bar0); |
132 assertKind(elements_kind.fast_smi_only, c); | 129 b[0] = 3.5; |
| 130 c = bar0(Array); |
| 131 assertKind(elements_kind.fast_smi_only, c); |
| 132 } |
133 })(); | 133 })(); |
134 | 134 |
135 | 135 |
136 // Test: Ensure that inlined array calls in crankshaft learn from deopts | 136 // Test: Ensure that inlined array calls in crankshaft learn from deopts |
137 // based on the move to a dictionary for the array. | 137 // based on the move to a dictionary for the array. |
138 (function() { | 138 (function() { |
139 function bar(len) { | 139 function bar(len) { |
140 return new Array(len); | 140 return new Array(len); |
141 } | 141 } |
142 a = bar(10); | 142 a = bar(10); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 // Try again | 243 // Try again |
244 %OptimizeFunctionOnNextCall(bar); | 244 %OptimizeFunctionOnNextCall(bar); |
245 a = bar(100); | 245 a = bar(100); |
246 assertOptimized(bar); | 246 assertOptimized(bar); |
247 assertTrue(isHoley(a)); | 247 assertTrue(isHoley(a)); |
248 a = bar(0); | 248 a = bar(0); |
249 assertOptimized(bar); | 249 assertOptimized(bar); |
250 assertTrue(isHoley(a)); | 250 assertTrue(isHoley(a)); |
251 })(); | 251 })(); |
252 } | 252 } |
OLD | NEW |