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

Side by Side Diff: test/mjsunit/elements-transition-hoisting.js

Issue 9141016: Improve GVN handling of ElementTransitions. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: review feedback Created 8 years, 10 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/hydrogen.cc ('K') | « src/objects.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 --smi-only-arrays
29
30 // Ensure that ElementsKind transitions in various situations are hoisted (or
31 // not hoisted) correctly, don't change the semantics programs and don't trigger
32 // deopt through hoisting in important situations.
33
34 support_smi_only_arrays = %HasFastSmiOnlyElements(new Array(1,2,3,4,5,6));
35
36 if (support_smi_only_arrays) {
37 print("Tests include smi-only arrays.");
38 } else {
39 print("Tests do NOT include smi-only arrays.");
40 }
41
42 if (support_smi_only_arrays) {
43 // Make sure that multiple stores to an object array get hoisted in a way that
44 // doesn't generate a deopt in simple cases.
45 function testDoubleConversion4(a) {
46 var object = new Object();
47 a[0] = 0;
48 do {
49 // In non CS code, the array should have FAST_SMI_ONLY_ELEMENTS at this
50 // point, but when the code gets optimized, the double transition should
fschneider 2012/02/01 10:54:14 s/double//
danno 2012/02/01 16:53:15 Done.
51 // get hoisted out and the array should be of type FAST_OBJECT
52 assertTrue(((2 != %GetOptimizationStatus(testDoubleConversion4) &&
53 %HasFastElements(a)) || %HasFastSmiOnlyElements(a)));
54 a[0] = object;
55 result = a[0] == object;
56 } while (false);
fschneider 2012/02/01 10:54:14 do { } while(false) may be optimized away by the c
danno 2012/02/01 16:53:15 Done.
57 // Check outside of loop to prevent call in loop
fschneider 2012/02/01 10:54:14 This comment does not make sense: there is already
danno 2012/02/01 16:53:15 Done.
58 assertTrue(result);
59 }
60
61 testDoubleConversion4(new Array(5));
62 %OptimizeFunctionOnNextCall(testDoubleConversion4);
63 testDoubleConversion4(new Array(5));
64 testDoubleConversion4(new Array(5));
65 assertTrue(2 != %GetOptimizationStatus(testDoubleConversion4));
66
67 // Make sure that non-element related map checks still get hoisted in a way
68 // that doesn't generate a deopt in simple cases.
69 function testExactMapHoisting(a) {
70 var object = new Object();
71 a.foo = 0;
72 a[0] = 0;
73 a[1] = 1;
74 do {
75 // In non CS code, the array should have FAST_SMI_ONLY_ELEMENTS at this
76 // point, but when the code gets optimized, the double transition should
fschneider 2012/02/01 10:54:14 s/double//
danno 2012/02/01 16:53:15 Done.
77 // get hoisted out and the array should be of type FAST_OBJECT
78 assertTrue(((2 != %GetOptimizationStatus(testExactMapHoisting) &&
79 %HasFastElements(a)) || %HasFastSmiOnlyElements(a)));
80 a.foo = object; // This map check should be hoistable
81 a[1] = object;
82 result = a.foo == object && a[1] == object;
83 } while (false);
84 // Check outside of loop to prevent call in loop
85 assertTrue(result);
86 }
87
88 testExactMapHoisting(new Array(5));
89 %OptimizeFunctionOnNextCall(testExactMapHoisting);
90 testExactMapHoisting(new Array(5));
91 testExactMapHoisting(new Array(5));
92 assertTrue(2 != %GetOptimizationStatus(testExactMapHoisting));
93
94 // Make sure that non-element related map checks still get hoisted if all
95 // known element transitions have been done by the time the map check is done.
96 // Make sure it's done in a way that doesn't deopt later.
97 function testExactMapHoisting2(a) {
98 var object = new Object();
99 a.foo = 0;
100 a[0] = 0;
101 a[1] = 1;
102 do {
103 // In non CS code, the array should have FAST_SMI_ONLY_ELEMENTS at this
104 // point, but when the code gets optimized, the double transition should
105 // get hoisted out and the array should be of type FAST_DOUBLE_ELEMENTS
106 assertTrue(((2 != %GetOptimizationStatus(testExactMapHoisting2) &&
107 %HasFastDoubleElements(a)) || %HasFastSmiOnlyElements(a)));
108 a[1] = 2.5;
109 a.foo = object; // This map check should be hoistable
fschneider 2012/02/01 10:54:14 There are calls inside the loop, so this map check
danno 2012/02/01 16:53:15 Done.
110 result = a.foo == object && a[1] == 2.5;
111 } while (false);
112 // Check outside of loop to prevent call in loop
113 assertTrue(result);
114 }
115
116 testExactMapHoisting2(new Array(5));
117 %OptimizeFunctionOnNextCall(testExactMapHoisting2);
118 testExactMapHoisting2(new Array(5));
119 testExactMapHoisting2(new Array(5));
120 assertTrue(2 != %GetOptimizationStatus(testExactMapHoisting2));
121
122 // Make sure that non-element related map checks still get hoisted if all
123 // known element transitions have been done by the time the map check is done.
124 // Make sure it's done in a way that doesn't deopt later.
125 function testExactMapHoisting3(a) {
126 var object = new Object();
127 a.foo = 0;
128 a[0] = 0;
129 a[1] = 1;
130 do {
131 // In non CS code, the array should have FAST_SMI_ONLY_ELEMENTS at this
132 // point, but when the code gets optimized, the double transition should
133 // get hoisted out and the array should be of type FAST_DOUBLE_ELEMENTS
134 assertTrue(((2 != %GetOptimizationStatus(testExactMapHoisting3) &&
135 %HasFastDoubleElements(a)) || %HasFastSmiOnlyElements(a)));
136 a[1] = 2.5;
137 a.foo = object; // This map check should NOT be hoistable because it
138 // includes a check for the FAST_ELEMENTS map as well as the
139 // FAST_DOUBLE_ELEMENTS map.
140 result = a.foo == object && a[1] == 2.5;
141 } while (false);
142 // Check outside of loop to prevent call in loop
143 assertTrue(result);
144 }
145
146 var add_transition = new Array(5);
147 add_transition.foo = 0;
148 add_transition[0] = new Object(); // For FAST_ELEMENT transition to be created
149 testExactMapHoisting3(new Array(5));
150 %OptimizeFunctionOnNextCall(testExactMapHoisting3);
151 testExactMapHoisting3(new Array(5));
152 testExactMapHoisting3(new Array(5));
153 assertTrue(2 != %GetOptimizationStatus(testExactMapHoisting3));
154
155 function testDominatingTransitionHoisting1(a) {
156 var object = new Object();
157 a.foo = 0;
158 a[0] = 0;
159 do {
160 // Transitions shouldn't be hoisted that are not guaranteed to dominate
161 // all blocks after them with higher id numbers.
162 assertTrue(%HasFastSmiOnlyElements(a));
163 if (new Date() != true) {
164 a[1] = 2.5;
165 }
166 // The following FAST_DOUBLE_ELEMENTS -> FAST_ELEMENT transition can't be
167 // hoisted because of the FAST_SMI_ONLY_ELEMENTS -> FAST_DOUBLE_ELEMENTS
168 // transition in the if immediately above.
169 assertTrue(%HasFastDoubleElements(a));
170 a[0] = object;
171 result = a[0] == object && a[1] == 2.5;
172 } while (false);
173 // Check outside of loop to prevent call in loop
174 assertTrue(result);
175 }
176
177 testDominatingTransitionHoisting1(new Array(5));
178 %OptimizeFunctionOnNextCall(testDominatingTransitionHoisting1);
179 testDominatingTransitionHoisting1(new Array(5));
180 testDominatingTransitionHoisting1(new Array(5));
181 assertTrue(2 != %GetOptimizationStatus(testDominatingTransitionHoisting1));
182 }
OLDNEW
« src/hydrogen.cc ('K') | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698