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

Side by Side Diff: test/mjsunit/compiler/assignment-deopt.js

Issue 6821009: Introduce runtime function %OptimizeFunctionOnNextCall to manually trigger optimization. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: address comments Created 9 years, 8 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
« no previous file with comments | « test/mjsunit/compiler/array-length.js ('k') | test/mjsunit/compiler/count-deopt.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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
29
28 // Test deopt with count operation on parameter. 30 // Test deopt with count operation on parameter.
29 var max_smi = 1073741823; 31 var max_smi = 1073741823;
30 var o = {x:0}; 32 var o = {x:0};
31 33
32 function assign1(x) { x += 1; o.x = x; } 34 function assign1(x) { x += 1; o.x = x; }
33 assign1(max_smi); 35 assign1(max_smi);
34 assertEquals(max_smi + 1, o.x); 36 assertEquals(max_smi + 1, o.x);
35 37
36 assign1(1.1); 38 assign1(1.1);
37 assertEquals(2.1, o.x); 39 assertEquals(2.1, o.x);
38 40
39 41
40 // Test deopt with count operation on named property. 42 // Test deopt with count operation on named property.
41 function assign2(p) { p.x += 1 } 43 function assign2(p) { p.x += 1 }
42 44
43 o.x = "42"; 45 o.x = "42";
44 assign2(o); 46 assign2(o);
45 assertEquals("421", o.x); 47 assertEquals("421", o.x);
46 48
47 var s = max_smi - 10000; 49 var s = max_smi - 10;
48 o.x = s; 50 o.x = s;
49 for(var i = 0; i < 20000; i++) { 51 for(var i = 0; i < 20; i++) {
50 assign2(o); 52 assign2(o);
53 if (i == 4) {
54 %OptimizeFunctionOnNextCall(assign2);
55 }
51 } 56 }
52 assertEquals(max_smi + 10000, o.x); 57 assertEquals(max_smi + 10, o.x);
53 58
54 59
55 // Test deopt with count operation on keyed property. 60 // Test deopt with count operation on keyed property.
56 function assign3(a, b) { a[b] += 1; } 61 function assign3(a, b) { a[b] += 1; }
57 62
58 o = ["42"]; 63 o = ["42"];
59 assign3(o, 0); 64 assign3(o, 0);
60 assertEquals("421", o[0]); 65 assertEquals("421", o[0]);
61 66
62 var s = max_smi - 10000; 67 var s = max_smi - 10;
63 o[0] = s; 68 o[0] = s;
64 for(var i = 0; i < 20000; i++) { 69 for(var i = 0; i < 20; i++) {
65 assign3(o, 0); 70 assign3(o, 0);
71 if (i == 4) {
72 %OptimizeFunctionOnNextCall(assign3);
73 }
66 } 74 }
67 assertEquals(max_smi + 10000, o[0]); 75 assertEquals(max_smi + 10, o[0]);
68 76
69 assign3(o,"0"); 77 assign3(o, "0");
70 78
71 assertEquals(max_smi + 10001, o[0]); 79 assertEquals(max_smi + 11, o[0]);
72 80
73 // Test bailout when accessing a non-existing array element. 81 // Test bailout when accessing a non-existing array element.
74 o[0] = 0; 82 o[0] = 0;
75 for(var i = 0; i < 10000; i++) { 83 for(var i = 0; i < 5; i++) {
76 assign3(o, 0); 84 assign3(o, 0);
77 } 85 }
78 assign3(o,1); 86 %OptimizeFunctionOnNextCall(assign3);
87 assign3(o, 0);
88 assign3(o, 1);
79 89
80 // Test bailout with count operation in a value context. 90 // Test bailout with count operation in a value context.
81 function assign5(x,y) { return (x += 1) + y; } 91 function assign5(x,y) { return (x += 1) + y; }
82 for (var i = 0; i < 10000; ++i) assertEquals(4, assign5(2, 1)); 92 for (var i = 0; i < 5; ++i) assertEquals(4, assign5(2, 1));
93 %OptimizeFunctionOnNextCall(assign5);
94 assertEquals(4, assign5(2, 1));
95
83 assertEquals(4.1, assign5(2, 1.1)); 96 assertEquals(4.1, assign5(2, 1.1));
84 assertEquals(4.1, assign5(2.1, 1)); 97 assertEquals(4.1, assign5(2.1, 1));
85 98
86 function assign7(o,y) { return (o.x += 1) + y; } 99 function assign7(o,y) { return (o.x += 1) + y; }
87 o = {x:0}; 100 o = {x:0};
88 for (var i = 0; i < 10000; ++i) { 101 for (var i = 0; i < 5; ++i) {
89 o.x = 42; 102 o.x = 42;
90 assertEquals(44, assign7(o, 1)); 103 assertEquals(44, assign7(o, 1));
91 } 104 }
105 %OptimizeFunctionOnNextCall(assign7);
106 o.x = 42;
107 assertEquals(44, assign7(o, 1));
108
92 o.x = 42; 109 o.x = 42;
93 assertEquals(44.1, assign7(o, 1.1)); 110 assertEquals(44.1, assign7(o, 1.1));
94 o.x = 42.1; 111 o.x = 42.1;
95 assertEquals(44.1, assign7(o, 1)); 112 assertEquals(44.1, assign7(o, 1));
96 113
97 function assign9(o,y) { return (o[0] += 1) + y; } 114 function assign9(o,y) { return (o[0] += 1) + y; }
98 q = [0]; 115 q = [0];
99 for (var i = 0; i < 10000; ++i) { 116 for (var i = 0; i < 5; ++i) {
100 q[0] = 42; 117 q[0] = 42;
101 assertEquals(44, assign9(q, 1)); 118 assertEquals(44, assign9(q, 1));
102 } 119 }
120 %OptimizeFunctionOnNextCall(assign9);
121 q[0] = 42;
122 assertEquals(44, assign9(q, 1));
123
103 q[0] = 42; 124 q[0] = 42;
104 assertEquals(44.1, assign9(q, 1.1)); 125 assertEquals(44.1, assign9(q, 1.1));
105 q[0] = 42.1; 126 q[0] = 42.1;
106 assertEquals(44.1, assign9(q, 1)); 127 assertEquals(44.1, assign9(q, 1));
107 128
108 // Test deopt because of a failed map check on the load. 129 // Test deopt because of a failed map check on the load.
109 function assign10(p) { return p.x += 1 } 130 function assign10(p) { return p.x += 1 }
110 var g1 = {x:0}; 131 var g1 = {x:0};
111 var g2 = {y:0, x:42}; 132 var g2 = {y:0, x:42};
112 for (var i = 0; i < 10000; ++i) { 133 for (var i = 0; i < 5; ++i) {
113 g1.x = 42; 134 g1.x = 42;
114 assertEquals(43, assign10(g1)); 135 assertEquals(43, assign10(g1));
115 assertEquals(43, g1.x); 136 assertEquals(43, g1.x);
116 } 137 }
138 %OptimizeFunctionOnNextCall(assign10);
139 g1.x = 42;
140 assertEquals(43, assign10(g1));
141 assertEquals(43, g1.x);
142
117 assertEquals(43, assign10(g2)); 143 assertEquals(43, assign10(g2));
118 assertEquals(43, g2.x); 144 assertEquals(43, g2.x);
119 145
120 // Test deopt because of a failed map check on the store. 146 // Test deopt because of a failed map check on the store.
121 // The binary operation changes the map as a side effect. 147 // The binary operation changes the map as a side effect.
122 o = {x:0}; 148 o = {x:0};
123 var g3 = { valueOf: function() { o.y = "bar"; return 42; }}; 149 var g3 = { valueOf: function() { o.y = "bar"; return 42; }};
124 function assign11(p) { return p.x += 1; } 150 function assign11(p) { return p.x += 1; }
125 151
126 for (var i = 0; i < 10000; i++) { 152 for (var i = 0; i < 5; i++) {
127 o.x = "a"; 153 o.x = "a";
128 assign11(o); 154 assign11(o);
129 } 155 }
156 %OptimizeFunctionOnNextCall(assign11);
157 o.x = "a";
158 assign11(o);
159
130 assertEquals("a11", assign11(o)); 160 assertEquals("a11", assign11(o));
131 o.x = g3; 161 o.x = g3;
132 assertEquals(43, assign11(o)); 162 assertEquals(43, assign11(o));
133 assertEquals("bar", o.y); 163 assertEquals("bar", o.y);
134 164
135 o = [0]; 165 o = [0];
136 var g4 = { valueOf: function() { o.y = "bar"; return 42; }}; 166 var g4 = { valueOf: function() { o.y = "bar"; return 42; }};
137 function assign12(p) { return p[0] += 1; } 167 function assign12(p) { return p[0] += 1; }
138 168
139 for (var i = 0; i < 1000000; i++) { 169 for (var i = 0; i < 5; i++) {
140 o[0] = "a"; 170 o[0] = "a";
141 assign12(o); 171 assign12(o);
142 } 172 }
173 %OptimizeFunctionOnNextCall(assign12);
174 o[0] = "a";
175 assign12(o);
176
143 assertEquals("a11", assign12(o)); 177 assertEquals("a11", assign12(o));
144 o[0] = g4; 178 o[0] = g4;
145 assertEquals(43, assign12(o)); 179 assertEquals(43, assign12(o));
146 assertEquals("bar", o.y); 180 assertEquals("bar", o.y);
OLDNEW
« no previous file with comments | « test/mjsunit/compiler/array-length.js ('k') | test/mjsunit/compiler/count-deopt.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698