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

Side by Side Diff: test/mjsunit/compiler/count-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/assignment-deopt.js ('k') | test/mjsunit/compiler/deopt-args.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 inc1(x) { x++; o.x = x; } 34 function inc1(x) { x++; o.x = x; }
33 inc1(max_smi); 35 inc1(max_smi);
34 assertEquals(max_smi + 1, o.x); 36 assertEquals(max_smi + 1, o.x);
35 37
36 inc1(1.1); 38 inc1(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 inc2(p) { p.x++ } 43 function inc2(p) { p.x++ }
42 44
43 o.x = "42"; 45 o.x = "42";
44 inc2(o); 46 inc2(o);
45 assertEquals(43, o.x); 47 assertEquals(43, 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 inc2(o); 52 inc2(o);
53 if (i == 4) {
54 %OptimizeFunctionOnNextCall(inc2);
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 inc3(a, b) { a[b]++; } 61 function inc3(a, b) { a[b]++; }
57 62
58 o = ["42"]; 63 o = ["42"];
59 inc3(o, 0); 64 inc3(o, 0);
60 assertEquals(43, o[0]); 65 assertEquals(43, 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 inc3(o, 0); 70 inc3(o, 0);
71 if (i == 4) {
72 %OptimizeFunctionOnNextCall(inc3);
73 }
66 } 74 }
67 assertEquals(max_smi + 10000, o[0]); 75 assertEquals(max_smi + 10, o[0]);
68 76
69 inc3(o,"0"); 77 inc3(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 inc3(o, 0); 84 inc3(o, 0);
77 } 85 }
78 inc3(o,1); 86 %OptimizeFunctionOnNextCall(inc3);
87 inc3(o, 0);
88 inc3(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 inc4(x,y) { return (x++) + y; } 91 function inc4(x,y) { return (x++) + y; }
82 for (var i = 0; i < 100000; ++i) assertEquals(3, inc4(2, 1)); 92 for (var i = 0; i < 5; ++i) assertEquals(3, inc4(2, 1));
93 %OptimizeFunctionOnNextCall(inc4);
94 inc4(2, 1);
83 assertEquals(3.1, inc4(2, 1.1)); 95 assertEquals(3.1, inc4(2, 1.1));
84 96
85 function inc5(x,y) { return (++x) + y; } 97 function inc5(x,y) { return (++x) + y; }
86 for (var i = 0; i < 100000; ++i) assertEquals(4, inc5(2, 1)); 98 for (var i = 0; i < 5; ++i) assertEquals(4, inc5(2, 1));
99 %OptimizeFunctionOnNextCall(inc5);
100 assertEquals(4, inc5(2, 1));
87 assertEquals(4.1, inc5(2, 1.1)); 101 assertEquals(4.1, inc5(2, 1.1));
88 assertEquals(4.1, inc5(2.1, 1)); 102 assertEquals(4.1, inc5(2.1, 1));
89 103
90 function inc6(o,y) { return (o.x++) + y; } 104 function inc6(o,y) { return (o.x++) + y; }
91 o = {x:0}; 105 o = {x:0};
92 for (var i = 0; i < 10000; ++i) { 106 for (var i = 0; i < 5; ++i) {
93 o.x = 42; 107 o.x = 42;
94 assertEquals(43, inc6(o, 1)); 108 assertEquals(43, inc6(o, 1));
95 } 109 }
110 %OptimizeFunctionOnNextCall(inc6);
111 o.x = 42;
112 assertEquals(43, inc6(o, 1));
96 o.x = 42; 113 o.x = 42;
97 assertEquals(43.1, inc6(o, 1.1)); 114 assertEquals(43.1, inc6(o, 1.1));
98 o.x = 42.1; 115 o.x = 42.1;
99 assertEquals(43.1, inc6(o, 1)); 116 assertEquals(43.1, inc6(o, 1));
100 117
101 function inc7(o,y) { return (++o.x) + y; } 118 function inc7(o,y) { return (++o.x) + y; }
102 o = {x:0}; 119 o = {x:0};
103 for (var i = 0; i < 10000; ++i) { 120 for (var i = 0; i < 5; ++i) {
104 o.x = 42; 121 o.x = 42;
105 assertEquals(44, inc7(o, 1)); 122 assertEquals(44, inc7(o, 1));
106 } 123 }
124 %OptimizeFunctionOnNextCall(inc7);
125 o.x = 42;
126 assertEquals(44, inc7(o, 1));
107 o.x = 42; 127 o.x = 42;
108 assertEquals(44.1, inc7(o, 1.1)); 128 assertEquals(44.1, inc7(o, 1.1));
109 o.x = 42.1; 129 o.x = 42.1;
110 assertEquals(44.1, inc7(o, 1)); 130 assertEquals(44.1, inc7(o, 1));
111 131
112 function inc8(o,y) { return (o[0]++) + y; } 132 function inc8(o,y) { return (o[0]++) + y; }
113 var q = [0]; 133 var q = [0];
114 for (var i = 0; i < 100000; ++i) { 134 for (var i = 0; i < 5; ++i) {
115 q[0] = 42; 135 q[0] = 42;
116 assertEquals(43, inc8(q, 1)); 136 assertEquals(43, inc8(q, 1));
117 } 137 }
138 %OptimizeFunctionOnNextCall(inc8);
139 q[0] = 42;
140 assertEquals(43, inc8(q, 1));
118 q[0] = 42; 141 q[0] = 42;
119 assertEquals(43.1, inc8(q, 1.1)); 142 assertEquals(43.1, inc8(q, 1.1));
120 q[0] = 42.1; 143 q[0] = 42.1;
121 assertEquals(43.1, inc8(q, 1)); 144 assertEquals(43.1, inc8(q, 1));
122 145
123 function inc9(o,y) { return (++o[0]) + y; } 146 function inc9(o,y) { return (++o[0]) + y; }
124 q = [0]; 147 q = [0];
125 for (var i = 0; i < 100000; ++i) { 148 for (var i = 0; i < 5; ++i) {
126 q[0] = 42; 149 q[0] = 42;
127 assertEquals(44, inc9(q, 1)); 150 assertEquals(44, inc9(q, 1));
128 } 151 }
152 %OptimizeFunctionOnNextCall(inc9);
153 q[0] = 42;
154 assertEquals(44, inc9(q, 1));
129 q[0] = 42; 155 q[0] = 42;
130 assertEquals(44.1, inc9(q, 1.1)); 156 assertEquals(44.1, inc9(q, 1.1));
131 q[0] = 42.1; 157 q[0] = 42.1;
132 assertEquals(44.1, inc9(q, 1)); 158 assertEquals(44.1, inc9(q, 1));
133 159
134 // Test deopt because of a failed map check. 160 // Test deopt because of a failed map check.
135 function inc10(p) { return p.x++ } 161 function inc10(p) { return p.x++ }
136 var g1 = {x:0}; 162 var g1 = {x:0};
137 var g2 = {y:0, x:42} 163 var g2 = {y:0, x:42}
138 for (var i = 0; i < 10000; ++i) { 164 for (var i = 0; i < 5; ++i) {
139 g1.x = 42; 165 g1.x = 42;
140 assertEquals(42, inc10(g1)); 166 assertEquals(42, inc10(g1));
141 assertEquals(43, g1.x); 167 assertEquals(43, g1.x);
142 } 168 }
169 %OptimizeFunctionOnNextCall(inc10);
170 g1.x = 42;
171 assertEquals(42, inc10(g1));
172 assertEquals(43, g1.x);
143 assertEquals(42, inc10(g2)); 173 assertEquals(42, inc10(g2));
144 assertEquals(43, g2.x); 174 assertEquals(43, g2.x);
145 175
146 // Test deoptimization with postfix operation in a value context. 176 // Test deoptimization with postfix operation in a value context.
147 function inc11(a) { return a[this.x++]; } 177 function inc11(a) { return a[this.x++]; }
148 var g3 = {x:null, f:inc11}; 178 var g3 = {x:null, f:inc11};
149 var g4 = [42]; 179 var g4 = [42];
150 assertEquals(42, g3.f(g4)); 180 assertEquals(42, g3.f(g4));
OLDNEW
« no previous file with comments | « test/mjsunit/compiler/assignment-deopt.js ('k') | test/mjsunit/compiler/deopt-args.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698