OLD | NEW |
---|---|
1 // Copyright 2012 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 |
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 --noalways-opt | 29 // Flags: --notrack_allocation_sites |
mvstanton
2013/06/26 13:21:43
In these new tests, why do you have to turn off tr
titzer
2013/06/26 17:53:59
It was turned off in the test from which I extract
| |
30 | |
31 // Limit the number of stress runs to reduce polymorphism it defeats some of the | |
32 // assumptions made about how elements transitions work because transition stubs | |
33 // end up going generic. | |
34 // Flags: --stress-runs=2 | |
30 | 35 |
31 // Test element kind of objects. | 36 // Test element kind of objects. |
32 // Since --smi-only-arrays affects builtins, its default setting at compile | 37 // Since --smi-only-arrays affects builtins, its default setting at compile |
33 // time sticks if built with snapshot. If --smi-only-arrays is deactivated | 38 // 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 | 39 // 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 | 40 // 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. | 41 // enabled, this test takes the appropriate code path to check smi-only arrays. |
37 | 42 |
38 // support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8)); | 43 support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8)); |
39 support_smi_only_arrays = true; | |
40 | 44 |
41 if (support_smi_only_arrays) { | 45 if (support_smi_only_arrays) { |
42 print("Tests include smi-only arrays."); | 46 print("Tests include smi-only arrays."); |
43 } else { | 47 } else { |
44 print("Tests do NOT include smi-only arrays."); | 48 print("Tests do NOT include smi-only arrays."); |
45 } | 49 } |
46 | 50 |
47 var elements_kind = { | 51 var elements_kind = { |
48 fast_smi_only : 'fast smi only elements', | 52 fast_smi_only : 'fast smi only elements', |
49 fast : 'fast elements', | 53 fast : 'fast elements', |
50 fast_double : 'fast double elements', | 54 fast_double : 'fast double elements', |
51 dictionary : 'dictionary elements', | 55 dictionary : 'dictionary elements', |
52 external_byte : 'external byte elements', | 56 external_byte : 'external byte elements', |
53 external_unsigned_byte : 'external unsigned byte elements', | 57 external_unsigned_byte : 'external unsigned byte elements', |
54 external_short : 'external short elements', | 58 external_short : 'external short elements', |
55 external_unsigned_short : 'external unsigned short elements', | 59 external_unsigned_short : 'external unsigned short elements', |
56 external_int : 'external int elements', | 60 external_int : 'external int elements', |
57 external_unsigned_int : 'external unsigned int elements', | 61 external_unsigned_int : 'external unsigned int elements', |
58 external_float : 'external float elements', | 62 external_float : 'external float elements', |
59 external_double : 'external double elements', | 63 external_double : 'external double elements', |
60 external_pixel : 'external pixel elements' | 64 external_pixel : 'external pixel elements' |
61 } | 65 } |
62 | 66 |
63 function getKind(obj) { | 67 function getKind(obj) { |
64 if (%HasFastSmiElements(obj)) return elements_kind.fast_smi_only; | 68 if (%HasFastSmiElements(obj)) return elements_kind.fast_smi_only; |
65 if (%HasFastObjectElements(obj)) return elements_kind.fast; | 69 if (%HasFastObjectElements(obj)) return elements_kind.fast; |
66 if (%HasFastDoubleElements(obj)) return elements_kind.fast_double; | 70 if (%HasFastDoubleElements(obj)) return elements_kind.fast_double; |
67 if (%HasDictionaryElements(obj)) return elements_kind.dictionary; | 71 if (%HasDictionaryElements(obj)) return elements_kind.dictionary; |
68 } | 72 // Every external kind is also an external array. |
69 | 73 assertTrue(%HasExternalArrayElements(obj)); |
70 function isHoley(obj) { | 74 if (%HasExternalByteElements(obj)) { |
71 if (%HasFastHoleyElements(obj)) return true; | 75 return elements_kind.external_byte; |
72 return false; | 76 } |
77 if (%HasExternalUnsignedByteElements(obj)) { | |
78 return elements_kind.external_unsigned_byte; | |
79 } | |
80 if (%HasExternalShortElements(obj)) { | |
81 return elements_kind.external_short; | |
82 } | |
83 if (%HasExternalUnsignedShortElements(obj)) { | |
84 return elements_kind.external_unsigned_short; | |
85 } | |
86 if (%HasExternalIntElements(obj)) { | |
87 return elements_kind.external_int; | |
88 } | |
89 if (%HasExternalUnsignedIntElements(obj)) { | |
90 return elements_kind.external_unsigned_int; | |
91 } | |
92 if (%HasExternalFloatElements(obj)) { | |
93 return elements_kind.external_float; | |
94 } | |
95 if (%HasExternalDoubleElements(obj)) { | |
96 return elements_kind.external_double; | |
97 } | |
98 if (%HasExternalPixelElements(obj)) { | |
99 return elements_kind.external_pixel; | |
100 } | |
73 } | 101 } |
74 | 102 |
75 function assertKind(expected, obj, name_opt) { | 103 function assertKind(expected, obj, name_opt) { |
76 if (!support_smi_only_arrays && | 104 if (!support_smi_only_arrays && |
77 expected == elements_kind.fast_smi_only) { | 105 expected == elements_kind.fast_smi_only) { |
78 expected = elements_kind.fast; | 106 expected = elements_kind.fast; |
79 } | 107 } |
80 assertEquals(expected, getKind(obj), name_opt); | 108 assertEquals(expected, getKind(obj), name_opt); |
81 } | 109 } |
82 | 110 |
83 if (support_smi_only_arrays) { | 111 function construct_smis() { |
84 function bar0(t) { | 112 try {} catch (e) {} // TODO(titzer): DisableOptimization |
85 return new t(); | 113 var a = [0, 0, 0]; |
86 } | 114 a[0] = 0; // Send the COW array map to the steak house. |
115 assertKind(elements_kind.fast_smi_only, a); | |
116 return a; | |
117 } | |
87 | 118 |
88 a = bar0(Array); | 119 function construct_doubles() { |
89 a[0] = 3.5; | 120 try {} catch (e) {} // TODO(titzer): DisableOptimization |
90 b = bar0(Array); | 121 var a = construct_smis(); |
91 assertKind(elements_kind.fast_double, b); | 122 a[0] = 1.5; |
92 %OptimizeFunctionOnNextCall(bar0); | 123 assertKind(elements_kind.fast_double, a); |
93 b = bar0(Array); | 124 return a; |
94 assertKind(elements_kind.fast_double, b); | |
95 assertTrue(2 != %GetOptimizationStatus(bar0)); | |
96 // bar0 should deopt | |
97 b = bar0(Object); | |
98 assertTrue(1 != %GetOptimizationStatus(bar0)); | |
99 } | 125 } |
126 | |
127 function convert_mixed(array, value, kind) { | |
128 try {} catch (e) {} // TODO(titzer): DisableOptimization | |
129 array[1] = value; | |
130 assertKind(kind, array); | |
131 assertEquals(value, array[1]); | |
132 } | |
133 | |
134 function test1() { | |
135 if (!support_smi_only_arrays) return; | |
136 | |
137 // Test transition chain SMI->DOUBLE->FAST (crankshafted function will | |
138 // transition to FAST directly). | |
139 var smis = construct_smis(); | |
140 convert_mixed(smis, 1.5, elements_kind.fast_double); | |
141 | |
142 var doubles = construct_doubles(); | |
143 convert_mixed(doubles, "three", elements_kind.fast); | |
144 | |
145 convert_mixed(construct_smis(), "three", elements_kind.fast); | |
146 convert_mixed(construct_doubles(), "three", elements_kind.fast); | |
147 | |
148 smis = construct_smis(); | |
149 doubles = construct_doubles(); | |
150 convert_mixed(smis, 1, elements_kind.fast); | |
151 convert_mixed(doubles, 1, elements_kind.fast); | |
152 assertTrue(%HaveSameMap(smis, doubles)); | |
153 } | |
154 | |
155 test1(); | |
156 gc(); // clear IC state | |
157 test1(); | |
158 gc(); // clear IC state | |
159 %OptimizeFunctionOnNextCall(test1); | |
160 test1(); | |
161 gc(); // clear IC state | |
OLD | NEW |