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

Side by Side Diff: test/cctest/compiler/test-run-inlining.cc

Issue 573703002: Add handling for deopt and argument adaptor frames. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Minor improvements. Created 6 years, 3 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
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "test/cctest/compiler/function-tester.h" 7 #include "test/cctest/compiler/function-tester.h"
8 8
9 #if V8_TURBOFAN_TARGET 9 #if V8_TURBOFAN_TARGET
10 10
11 using namespace v8::internal; 11 using namespace v8::internal;
12 using namespace v8::internal::compiler; 12 using namespace v8::internal::compiler;
13 13
14 // TODO(sigurds) At the moment we do not write optimization frames when 14 // Helper to determine inline count via JavaScriptFrame::GetInlineCount.
15 // inlining, thus the reported stack depth changes depending on inlining. 15 // Note that a count of 1 indicates that no inlining has occured.
16 // AssertStackDepth checks the stack depth actually changes as a simple way 16 static void AssertInlineCount(const v8::FunctionCallbackInfo<v8::Value>& args) {
17 // to ensure that inlining actually occurs. 17 StackTraceFrameIterator it(CcTest::i_isolate());
18 // Once inlining creates optimization frames, all these unit tests need to 18 int frames_seen = 0;
19 // check that the optimization frame is there. 19 JavaScriptFrame* topmost = it.frame();
20 20 while (!it.done()) {
21 21 JavaScriptFrame* frame = it.frame();
22 static void AssertStackDepth(const v8::FunctionCallbackInfo<v8::Value>& args) { 22 PrintF("%d %s, inline count: %d\n", frames_seen,
23 v8::HandleScope scope(args.GetIsolate()); 23 frame->function()->shared()->DebugName()->ToCString().get(),
24 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( 24 frame->GetInlineCount());
25 args.GetIsolate(), 10, v8::StackTrace::kDetailed); 25 frames_seen++;
26 CHECK_EQ(args[0]->ToInt32()->Value(), stackTrace->GetFrameCount()); 26 it.Advance();
27 }
28 CHECK_EQ(args[0]->ToInt32()->Value(), topmost->GetInlineCount());
27 } 29 }
28 30
29 31
30 static void InstallAssertStackDepthHelper(v8::Isolate* isolate) { 32 static void InstallAssertInlineCountHelper(v8::Isolate* isolate) {
31 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 33 v8::Local<v8::Context> context = isolate->GetCurrentContext();
32 v8::Local<v8::FunctionTemplate> t = 34 v8::Local<v8::FunctionTemplate> t =
33 v8::FunctionTemplate::New(isolate, AssertStackDepth); 35 v8::FunctionTemplate::New(isolate, AssertInlineCount);
34 context->Global()->Set(v8_str("AssertStackDepth"), t->GetFunction()); 36 context->Global()->Set(v8_str("AssertInlineCount"), t->GetFunction());
35 } 37 }
36 38
37 39
38 TEST(SimpleInlining) { 40 TEST(SimpleInlining) {
41 FLAG_turbo_deoptimization = true;
39 FunctionTester T( 42 FunctionTester T(
40 "(function(){" 43 "(function(){"
41 "function foo(s) { AssertStackDepth(1); return s; };" 44 "function foo(s) { AssertInlineCount(2); return s; };"
42 "function bar(s, t) { return foo(s); };" 45 "function bar(s, t) { return foo(s); };"
43 "return bar;})();", 46 "return bar;})();",
44 CompilationInfo::kInliningEnabled | 47 CompilationInfo::kInliningEnabled |
45 CompilationInfo::kContextSpecializing | 48 CompilationInfo::kContextSpecializing |
46 CompilationInfo::kTypingEnabled); 49 CompilationInfo::kTypingEnabled);
47 50
48 InstallAssertStackDepthHelper(CcTest::isolate()); 51 InstallAssertInlineCountHelper(CcTest::isolate());
52 T.CheckCall(T.Val(1), T.Val(1), T.Val(2));
53 }
54
55
56 TEST(SimpleInliningDeopt) {
57 FLAG_turbo_deoptimization = true;
58 FunctionTester T(
59 "(function(){"
60 "function foo(s) { %DeoptimizeFunction(bar); return "
61 "s; };"
62 "function bar(s, t) { return foo(s); };"
63 "return bar;})();",
64 CompilationInfo::kInliningEnabled |
65 CompilationInfo::kContextSpecializing |
66 CompilationInfo::kTypingEnabled);
67
68 InstallAssertInlineCountHelper(CcTest::isolate());
49 T.CheckCall(T.Val(1), T.Val(1), T.Val(2)); 69 T.CheckCall(T.Val(1), T.Val(1), T.Val(2));
50 } 70 }
51 71
52 72
53 TEST(SimpleInliningContext) { 73 TEST(SimpleInliningContext) {
74 FLAG_turbo_deoptimization = true;
54 FunctionTester T( 75 FunctionTester T(
55 "(function () {" 76 "(function () {"
56 "function foo(s) { AssertStackDepth(1); var x = 12; return s + x; };" 77 "function foo(s) { AssertInlineCount(2); var x = 12; return s + x; };"
57 "function bar(s, t) { return foo(s); };" 78 "function bar(s, t) { return foo(s); };"
58 "return bar;" 79 "return bar;"
59 "})();", 80 "})();",
60 CompilationInfo::kInliningEnabled | 81 CompilationInfo::kInliningEnabled |
61 CompilationInfo::kContextSpecializing | 82 CompilationInfo::kContextSpecializing |
62 CompilationInfo::kTypingEnabled); 83 CompilationInfo::kTypingEnabled);
63 84
64 InstallAssertStackDepthHelper(CcTest::isolate()); 85 InstallAssertInlineCountHelper(CcTest::isolate());
86 T.CheckCall(T.Val(13), T.Val(1), T.Val(2));
87 }
88
89
90 TEST(SimpleInliningContextDeopt) {
91 FLAG_turbo_deoptimization = true;
92 FunctionTester T(
93 "(function () {"
94 "function foo(s) { AssertInlineCount(2); %DeoptimizeFunction(bar); var x "
95 "= 12;"
Jarin 2014/09/15 13:37:52 This is a funky line break. Could you make it a bi
sigurds 2014/09/16 08:39:03 Done.
96 " return s + x; };"
97 "function bar(s, t) { return foo(s); };"
98 "return bar;"
99 "})();",
100 CompilationInfo::kInliningEnabled |
101 CompilationInfo::kContextSpecializing |
102 CompilationInfo::kTypingEnabled);
103
104 InstallAssertInlineCountHelper(CcTest::isolate());
65 T.CheckCall(T.Val(13), T.Val(1), T.Val(2)); 105 T.CheckCall(T.Val(13), T.Val(1), T.Val(2));
66 } 106 }
67 107
68 108
69 TEST(CaptureContext) { 109 TEST(CaptureContext) {
110 FLAG_turbo_deoptimization = true;
70 FunctionTester T( 111 FunctionTester T(
71 "var f = (function () {" 112 "var f = (function () {"
72 "var x = 42;" 113 "var x = 42;"
73 "function bar(s) { return x + s; };" 114 "function bar(s) { return x + s; };"
74 "return (function (s) { return bar(s); });" 115 "return (function (s) { return bar(s); });"
75 "})();" 116 "})();"
76 "(function (s) { return f(s)})", 117 "(function (s) { return f(s)})",
77 CompilationInfo::kInliningEnabled | 118 CompilationInfo::kInliningEnabled |
78 CompilationInfo::kContextSpecializing | 119 CompilationInfo::kContextSpecializing |
79 CompilationInfo::kTypingEnabled); 120 CompilationInfo::kTypingEnabled);
80 121
81 InstallAssertStackDepthHelper(CcTest::isolate()); 122 InstallAssertInlineCountHelper(CcTest::isolate());
82 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined()); 123 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined());
83 } 124 }
84 125
85 126
86 // TODO(sigurds) For now we do not inline any native functions. If we do at 127 // TODO(sigurds) For now we do not inline any native functions. If we do at
87 // some point, change this test. 128 // some point, change this test.
88 TEST(DontInlineEval) { 129 TEST(DontInlineEval) {
130 FLAG_turbo_deoptimization = true;
89 FunctionTester T( 131 FunctionTester T(
90 "var x = 42;" 132 "var x = 42;"
91 "(function () {" 133 "(function () {"
92 "function bar(s, t) { return eval(\"AssertStackDepth(2); x\") };" 134 "function bar(s, t) { return eval(\"AssertInlineCount(1); x\") };"
93 "return bar;" 135 "return bar;"
94 "})();", 136 "})();",
95 CompilationInfo::kInliningEnabled | 137 CompilationInfo::kInliningEnabled |
96 CompilationInfo::kContextSpecializing | 138 CompilationInfo::kContextSpecializing |
97 CompilationInfo::kTypingEnabled); 139 CompilationInfo::kTypingEnabled);
98 140
99 InstallAssertStackDepthHelper(CcTest::isolate()); 141 InstallAssertInlineCountHelper(CcTest::isolate());
100 T.CheckCall(T.Val(42), T.Val("x"), T.undefined()); 142 T.CheckCall(T.Val(42), T.Val("x"), T.undefined());
101 } 143 }
102 144
103 145
104 TEST(InlineOmitArguments) { 146 TEST(InlineOmitArguments) {
147 FLAG_turbo_deoptimization = true;
105 FunctionTester T( 148 FunctionTester T(
106 "(function () {" 149 "(function () {"
107 "var x = 42;" 150 "var x = 42;"
108 "function bar(s, t, u, v) { AssertStackDepth(1); return x + s; };" 151 "function bar(s, t, u, v) { AssertInlineCount(2); return x + s; };"
109 "return (function (s,t) { return bar(s); });" 152 "return (function (s,t) { return bar(s); });"
110 "})();", 153 "})();",
111 CompilationInfo::kInliningEnabled | 154 CompilationInfo::kInliningEnabled |
112 CompilationInfo::kContextSpecializing | 155 CompilationInfo::kContextSpecializing |
113 CompilationInfo::kTypingEnabled); 156 CompilationInfo::kTypingEnabled);
114 157
115 InstallAssertStackDepthHelper(CcTest::isolate()); 158 InstallAssertInlineCountHelper(CcTest::isolate());
116 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined()); 159 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined());
117 } 160 }
118 161
119 162
163 TEST(InlineOmitArgumentsDeopt) {
164 FLAG_turbo_deoptimization = true;
165 FunctionTester T(
166 "(function () {"
167 "function foo(s,t,u,v) { AssertInlineCount(2); %DeoptimizeFunction(bar); "
168 "return baz(); };"
169 "function bar() { return foo(11); };"
170 "function baz() { return foo.arguments.length == 1 && "
171 " foo.arguments[0] == 11 ; }"
172 "return bar;"
173 "})();",
174 CompilationInfo::kInliningEnabled |
175 CompilationInfo::kContextSpecializing |
176 CompilationInfo::kTypingEnabled);
177
178 InstallAssertInlineCountHelper(CcTest::isolate());
179 T.CheckCall(T.true_value(), T.Val(12), T.Val(14));
180 }
181
182
120 TEST(InlineSurplusArguments) { 183 TEST(InlineSurplusArguments) {
184 FLAG_turbo_deoptimization = true;
121 FunctionTester T( 185 FunctionTester T(
122 "(function () {" 186 "(function () {"
123 "var x = 42;" 187 "var x = 42;"
124 "function foo(s) { AssertStackDepth(1); return x + s; };" 188 "function foo(s) { AssertInlineCount(2); return x + s; };"
125 "function bar(s,t) { return foo(s,t,13); };" 189 "function bar(s,t) { return foo(s,t,13); };"
126 "return bar;" 190 "return bar;"
127 "})();", 191 "})();",
128 CompilationInfo::kInliningEnabled | 192 CompilationInfo::kInliningEnabled |
129 CompilationInfo::kContextSpecializing | 193 CompilationInfo::kContextSpecializing |
130 CompilationInfo::kTypingEnabled); 194 CompilationInfo::kTypingEnabled);
131 195
132 InstallAssertStackDepthHelper(CcTest::isolate()); 196 InstallAssertInlineCountHelper(CcTest::isolate());
133 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined()); 197 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined());
134 } 198 }
135 199
136 200
201 TEST(InlineSurplusArgumentsDeopt) {
202 FLAG_turbo_deoptimization = true;
203 FunctionTester T(
204 "(function () {"
205 "function foo(s) { AssertInlineCount(2); %DeoptimizeFunction(bar); "
206 "return baz(); };"
207 "function bar() { return foo(13, 14, 15); };"
208 "function baz() { return foo.arguments.length == 3 && "
209 " foo.arguments[0] == 13 && "
210 " foo.arguments[1] == 14 && "
211 " foo.arguments[2] == 15; }"
212 "return bar;"
213 "})();",
214 CompilationInfo::kInliningEnabled |
215 CompilationInfo::kContextSpecializing |
216 CompilationInfo::kTypingEnabled);
217
218 InstallAssertInlineCountHelper(CcTest::isolate());
219 T.CheckCall(T.true_value(), T.Val(12), T.Val(14));
220 }
221
222
137 TEST(InlineTwice) { 223 TEST(InlineTwice) {
224 FLAG_turbo_deoptimization = true;
138 FunctionTester T( 225 FunctionTester T(
139 "(function () {" 226 "(function () {"
140 "var x = 42;" 227 "var x = 42;"
141 "function bar(s) { AssertStackDepth(1); return x + s; };" 228 "function bar(s) { AssertInlineCount(2); return x + s; };"
142 "return (function (s,t) { return bar(s) + bar(t); });" 229 "return (function (s,t) { return bar(s) + bar(t); });"
143 "})();", 230 "})();",
144 CompilationInfo::kInliningEnabled | 231 CompilationInfo::kInliningEnabled |
145 CompilationInfo::kContextSpecializing | 232 CompilationInfo::kContextSpecializing |
146 CompilationInfo::kTypingEnabled); 233 CompilationInfo::kTypingEnabled);
147 234
148 InstallAssertStackDepthHelper(CcTest::isolate()); 235 InstallAssertInlineCountHelper(CcTest::isolate());
149 T.CheckCall(T.Val(2 * 42 + 12 + 4), T.Val(12), T.Val(4)); 236 T.CheckCall(T.Val(2 * 42 + 12 + 4), T.Val(12), T.Val(4));
150 } 237 }
151 238
152 239
153 TEST(InlineTwiceDependent) { 240 TEST(InlineTwiceDependent) {
241 FLAG_turbo_deoptimization = true;
154 FunctionTester T( 242 FunctionTester T(
155 "(function () {" 243 "(function () {"
156 "var x = 42;" 244 "var x = 42;"
157 "function foo(s) { AssertStackDepth(1); return x + s; };" 245 "function foo(s) { AssertInlineCount(2); return x + s; };"
158 "function bar(s,t) { return foo(foo(s)); };" 246 "function bar(s,t) { return foo(foo(s)); };"
159 "return bar;" 247 "return bar;"
160 "})();", 248 "})();",
161 CompilationInfo::kInliningEnabled | 249 CompilationInfo::kInliningEnabled |
162 CompilationInfo::kContextSpecializing | 250 CompilationInfo::kContextSpecializing |
163 CompilationInfo::kTypingEnabled); 251 CompilationInfo::kTypingEnabled);
164 252
165 InstallAssertStackDepthHelper(CcTest::isolate()); 253 InstallAssertInlineCountHelper(CcTest::isolate());
166 T.CheckCall(T.Val(42 + 42 + 12), T.Val(12), T.Val(4)); 254 T.CheckCall(T.Val(42 + 42 + 12), T.Val(12), T.Val(4));
167 } 255 }
168 256
169 257
170 TEST(InlineTwiceDependentDiamond) { 258 TEST(InlineTwiceDependentDiamond) {
259 FLAG_turbo_deoptimization = true;
171 FunctionTester T( 260 FunctionTester T(
172 "(function () {" 261 "(function () {"
173 "var x = 41;" 262 "var x = 41;"
174 "function foo(s) { AssertStackDepth(1); if (s % 2 == 0) {" 263 "function foo(s) { AssertInlineCount(2); if (s % 2 == 0) {"
175 " return x - s } else { return x + s; } };" 264 " return x - s } else { return x + s; } };"
176 "function bar(s,t) { return foo(foo(s)); };" 265 "function bar(s,t) { return foo(foo(s)); };"
177 "return bar;" 266 "return bar;"
178 "})();", 267 "})();",
179 CompilationInfo::kInliningEnabled | 268 CompilationInfo::kInliningEnabled |
180 CompilationInfo::kContextSpecializing | 269 CompilationInfo::kContextSpecializing |
181 CompilationInfo::kTypingEnabled); 270 CompilationInfo::kTypingEnabled);
182 271
183 InstallAssertStackDepthHelper(CcTest::isolate()); 272 InstallAssertInlineCountHelper(CcTest::isolate());
184 T.CheckCall(T.Val(-11), T.Val(11), T.Val(4)); 273 T.CheckCall(T.Val(-11), T.Val(11), T.Val(4));
185 } 274 }
186 275
187 276
188 TEST(InlineTwiceDependentDiamondDifferent) { 277 TEST(InlineTwiceDependentDiamondDifferent) {
278 FLAG_turbo_deoptimization = true;
189 FunctionTester T( 279 FunctionTester T(
190 "(function () {" 280 "(function () {"
191 "var x = 41;" 281 "var x = 41;"
192 "function foo(s,t) { AssertStackDepth(1); if (s % 2 == 0) {" 282 "function foo(s,t) { AssertInlineCount(2); if (s % 2 == 0) {"
193 " return x - s * t } else { return x + s * t; } };" 283 " return x - s * t } else { return x + s * t; } };"
194 "function bar(s,t) { return foo(foo(s, 3), 5); };" 284 "function bar(s,t) { return foo(foo(s, 3), 5); };"
195 "return bar;" 285 "return bar;"
196 "})();", 286 "})();",
197 CompilationInfo::kInliningEnabled | 287 CompilationInfo::kInliningEnabled |
198 CompilationInfo::kContextSpecializing | 288 CompilationInfo::kContextSpecializing |
199 CompilationInfo::kTypingEnabled); 289 CompilationInfo::kTypingEnabled);
200 290
201 InstallAssertStackDepthHelper(CcTest::isolate()); 291 InstallAssertInlineCountHelper(CcTest::isolate());
202 T.CheckCall(T.Val(-329), T.Val(11), T.Val(4)); 292 T.CheckCall(T.Val(-329), T.Val(11), T.Val(4));
203 } 293 }
204 294
205 295
206 TEST(InlineLoop) { 296 TEST(InlineLoop) {
297 FLAG_turbo_deoptimization = true;
207 FunctionTester T( 298 FunctionTester T(
208 "(function () {" 299 "(function () {"
209 "var x = 41;" 300 "var x = 41;"
210 "function foo(s) { AssertStackDepth(1); while (s > 0) {" 301 "function foo(s) { AssertInlineCount(2); while (s > 0) {"
211 " s = s - 1; }; return s; };" 302 " s = s - 1; }; return s; };"
212 "function bar(s,t) { return foo(foo(s)); };" 303 "function bar(s,t) { return foo(foo(s)); };"
213 "return bar;" 304 "return bar;"
214 "})();", 305 "})();",
215 CompilationInfo::kInliningEnabled | 306 CompilationInfo::kInliningEnabled |
216 CompilationInfo::kContextSpecializing | 307 CompilationInfo::kContextSpecializing |
217 CompilationInfo::kTypingEnabled); 308 CompilationInfo::kTypingEnabled);
218 309
219 InstallAssertStackDepthHelper(CcTest::isolate()); 310 InstallAssertInlineCountHelper(CcTest::isolate());
220 T.CheckCall(T.Val(0.0), T.Val(11), T.Val(4)); 311 T.CheckCall(T.Val(0.0), T.Val(11), T.Val(4));
221 } 312 }
222 313
223 314
224 TEST(InlineStrictIntoNonStrict) { 315 TEST(InlineStrictIntoNonStrict) {
316 FLAG_turbo_deoptimization = true;
225 FunctionTester T( 317 FunctionTester T(
226 "(function () {" 318 "(function () {"
227 "var x = Object.create({}, { y: { value:42, writable:false } });" 319 "var x = Object.create({}, { y: { value:42, writable:false } });"
228 "function foo(s) { 'use strict';" 320 "function foo(s) { 'use strict';"
229 " x.y = 9; };" 321 " x.y = 9; };"
230 "function bar(s,t) { return foo(s); };" 322 "function bar(s,t) { return foo(s); };"
231 "return bar;" 323 "return bar;"
232 "})();", 324 "})();",
233 CompilationInfo::kInliningEnabled | 325 CompilationInfo::kInliningEnabled |
234 CompilationInfo::kContextSpecializing | 326 CompilationInfo::kContextSpecializing |
235 CompilationInfo::kTypingEnabled); 327 CompilationInfo::kTypingEnabled);
236 328
237 InstallAssertStackDepthHelper(CcTest::isolate()); 329 InstallAssertInlineCountHelper(CcTest::isolate());
238 T.CheckThrows(T.undefined(), T.undefined()); 330 T.CheckThrows(T.undefined(), T.undefined());
239 } 331 }
240 332
241 333
242 TEST(InlineNonStrictIntoStrict) { 334 TEST(InlineNonStrictIntoStrict) {
335 FLAG_turbo_deoptimization = true;
243 FunctionTester T( 336 FunctionTester T(
244 "(function () {" 337 "(function () {"
245 "var x = Object.create({}, { y: { value:42, writable:false } });" 338 "var x = Object.create({}, { y: { value:42, writable:false } });"
246 "function foo(s) { x.y = 9; return x.y; };" 339 "function foo(s) { x.y = 9; return x.y; };"
247 "function bar(s,t) { \'use strict\'; return foo(s); };" 340 "function bar(s,t) { \'use strict\'; return foo(s); };"
248 "return bar;" 341 "return bar;"
249 "})();", 342 "})();",
250 CompilationInfo::kInliningEnabled | 343 CompilationInfo::kInliningEnabled |
251 CompilationInfo::kContextSpecializing | 344 CompilationInfo::kContextSpecializing |
252 CompilationInfo::kTypingEnabled); 345 CompilationInfo::kTypingEnabled);
253 346
254 InstallAssertStackDepthHelper(CcTest::isolate()); 347 InstallAssertInlineCountHelper(CcTest::isolate());
255 T.CheckCall(T.Val(42), T.undefined(), T.undefined()); 348 T.CheckCall(T.Val(42), T.undefined(), T.undefined());
256 } 349 }
257 350
258 351
259 #endif // V8_TURBOFAN_TARGET 352 #endif // V8_TURBOFAN_TARGET
OLDNEW
« src/frames.cc ('K') | « test/cctest/compiler/test-js-typed-lowering.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698