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

Side by Side Diff: test/cctest/compiler/test-codegen-deopt.cc

Issue 522873002: Removal of the deoptimization block from Turbofan (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Change constant capitalization 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
« no previous file with comments | « src/x87/lithium-x87.cc ('k') | test/cctest/compiler/test-schedule.cc » ('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 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 #include "test/cctest/cctest.h" 6 #include "test/cctest/cctest.h"
7 7
8 #include "src/compiler/code-generator.h" 8 #include "src/compiler/code-generator.h"
9 #include "src/compiler/common-operator.h" 9 #include "src/compiler/common-operator.h"
10 #include "src/compiler/graph.h" 10 #include "src/compiler/graph.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 PrintableUnique<Object> undef_constant = 133 PrintableUnique<Object> undef_constant =
134 PrintableUnique<Object>::CreateUninitialized(zone(), undef_object); 134 PrintableUnique<Object>::CreateUninitialized(zone(), undef_object);
135 Node* undef_node = m.NewNode(common.HeapConstant(undef_constant)); 135 Node* undef_node = m.NewNode(common.HeapConstant(undef_constant));
136 136
137 Handle<JSFunction> deopt_function = 137 Handle<JSFunction> deopt_function =
138 NewFunction("function deopt() { %DeoptimizeFunction(foo); }; deopt"); 138 NewFunction("function deopt() { %DeoptimizeFunction(foo); }; deopt");
139 PrintableUnique<Object> deopt_fun_constant = 139 PrintableUnique<Object> deopt_fun_constant =
140 PrintableUnique<Object>::CreateUninitialized(zone(), deopt_function); 140 PrintableUnique<Object>::CreateUninitialized(zone(), deopt_function);
141 Node* deopt_fun_node = m.NewNode(common.HeapConstant(deopt_fun_constant)); 141 Node* deopt_fun_node = m.NewNode(common.HeapConstant(deopt_fun_constant));
142 142
143 MLabel deopt, cont;
144 Node* call = m.CallJS0(deopt_fun_node, undef_node, &cont, &deopt);
145
146 m.Bind(&cont);
147 m.NewNode(common.Continuation(), call);
148 m.Return(undef_node);
149
150 m.Bind(&deopt);
151 m.NewNode(common.LazyDeoptimization(), call);
152 143
153 bailout_id = GetCallBailoutId(); 144 bailout_id = GetCallBailoutId();
154 Node* parameters = m.NewNode(common.StateValues(1), undef_node); 145 Node* parameters = m.NewNode(common.StateValues(1), undef_node);
155 Node* locals = m.NewNode(common.StateValues(0)); 146 Node* locals = m.NewNode(common.StateValues(0));
156 Node* stack = m.NewNode(common.StateValues(0)); 147 Node* stack = m.NewNode(common.StateValues(0));
157 148
158 Node* state_node = 149 Node* state_node = m.NewNode(common.FrameState(bailout_id, kIgnoreOutput),
159 m.NewNode(common.FrameState(bailout_id), parameters, locals, stack); 150 parameters, locals, stack, undef_node);
160 m.Deoptimize(state_node); 151
152 m.CallJS0(deopt_fun_node, undef_node, state_node);
153
154 m.Return(undef_node);
161 155
162 // Schedule the graph: 156 // Schedule the graph:
163 Schedule* schedule = m.Export(); 157 Schedule* schedule = m.Export();
164 158
165 cont_block = cont.block();
166 deopt_block = deopt.block();
167
168 return schedule; 159 return schedule;
169 } 160 }
170 161
171 BailoutId GetCallBailoutId() { 162 BailoutId GetCallBailoutId() {
172 ZoneList<Statement*>* body = info.function()->body(); 163 ZoneList<Statement*>* body = info.function()->body();
173 for (int i = 0; i < body->length(); i++) { 164 for (int i = 0; i < body->length(); i++) {
174 if (body->at(i)->IsExpressionStatement() && 165 if (body->at(i)->IsExpressionStatement() &&
175 body->at(i)->AsExpressionStatement()->expression()->IsCall()) { 166 body->at(i)->AsExpressionStatement()->expression()->IsCall()) {
176 return body->at(i)->AsExpressionStatement()->expression()->id(); 167 return body->at(i)->AsExpressionStatement()->expression()->id();
177 } 168 }
178 } 169 }
179 CHECK(false); 170 CHECK(false);
180 return BailoutId(-1); 171 return BailoutId(-1);
181 } 172 }
182
183 BasicBlock* cont_block;
184 BasicBlock* deopt_block;
185 }; 173 };
186 174
187 175
188 TEST(TurboTrivialDeoptCodegen) { 176 TEST(TurboTrivialDeoptCodegen) {
189 HandleAndZoneScope scope; 177 HandleAndZoneScope scope;
190 InitializedHandleScope handles; 178 InitializedHandleScope handles;
191 179
192 FLAG_allow_natives_syntax = true; 180 FLAG_allow_natives_syntax = true;
193 FLAG_turbo_deoptimization = true; 181 FLAG_turbo_deoptimization = true;
194 182
195 TrivialDeoptCodegenTester t(&scope); 183 TrivialDeoptCodegenTester t(&scope);
196 t.GenerateCode(); 184 t.GenerateCode();
197 185
198 DeoptimizationInputData* data = 186 DeoptimizationInputData* data =
199 DeoptimizationInputData::cast(t.result_code->deoptimization_data()); 187 DeoptimizationInputData::cast(t.result_code->deoptimization_data());
200 188
201 Label* cont_label = t.code->GetLabel(t.cont_block); 189 // TODO(jarin) Find a way to test the safepoint.
202 Label* deopt_label = t.code->GetLabel(t.deopt_block);
203
204 // Check the safepoint - it should contain an entry for the call
205 // with the right deoptimization address.
206 SafepointEntry entry = t.result_code->GetSafepointEntry(
207 t.result_code->instruction_start() + cont_label->pos());
208 CHECK(entry.is_valid());
209 CHECK_EQ(deopt_label->pos(), entry.deoptimization_pc());
210 190
211 // Check that we deoptimize to the right AST id. 191 // Check that we deoptimize to the right AST id.
212 CHECK_EQ(1, data->DeoptCount()); 192 CHECK_EQ(1, data->DeoptCount());
213 CHECK_EQ(t.bailout_id.ToInt(), data->AstId(0).ToInt()); 193 CHECK_EQ(t.bailout_id.ToInt(), data->AstId(0).ToInt());
214 } 194 }
215 195
216 196
217 TEST(TurboTrivialDeoptCodegenAndRun) { 197 TEST(TurboTrivialDeoptCodegenAndRun) {
218 HandleAndZoneScope scope; 198 HandleAndZoneScope scope;
219 InitializedHandleScope handles; 199 InitializedHandleScope handles;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 Handle<Object> undef_object = 247 Handle<Object> undef_object =
268 Handle<Object>(isolate->heap()->undefined_value(), isolate); 248 Handle<Object>(isolate->heap()->undefined_value(), isolate);
269 PrintableUnique<Object> undef_constant = 249 PrintableUnique<Object> undef_constant =
270 PrintableUnique<Object>::CreateUninitialized(zone(), undef_object); 250 PrintableUnique<Object>::CreateUninitialized(zone(), undef_object);
271 Node* undef_node = m.NewNode(common.HeapConstant(undef_constant)); 251 Node* undef_node = m.NewNode(common.HeapConstant(undef_constant));
272 252
273 PrintableUnique<Object> this_fun_constant = 253 PrintableUnique<Object> this_fun_constant =
274 PrintableUnique<Object>::CreateUninitialized(zone(), function); 254 PrintableUnique<Object>::CreateUninitialized(zone(), function);
275 Node* this_fun_node = m.NewNode(common.HeapConstant(this_fun_constant)); 255 Node* this_fun_node = m.NewNode(common.HeapConstant(this_fun_constant));
276 256
277 MLabel deopt, cont;
278 Node* call = m.CallRuntime1(Runtime::kDeoptimizeFunction, this_fun_node,
279 &cont, &deopt);
280
281 m.Bind(&cont);
282 m.NewNode(common.Continuation(), call);
283 m.Return(undef_node);
284
285 m.Bind(&deopt);
286 m.NewNode(common.LazyDeoptimization(), call);
287
288 bailout_id = GetCallBailoutId(); 257 bailout_id = GetCallBailoutId();
289 Node* parameters = m.NewNode(common.StateValues(1), undef_node); 258 Node* parameters = m.NewNode(common.StateValues(1), undef_node);
290 Node* locals = m.NewNode(common.StateValues(0)); 259 Node* locals = m.NewNode(common.StateValues(0));
291 Node* stack = m.NewNode(common.StateValues(0)); 260 Node* stack = m.NewNode(common.StateValues(0));
292 261
293 Node* state_node = 262 Node* state_node = m.NewNode(common.FrameState(bailout_id, kIgnoreOutput),
294 m.NewNode(common.FrameState(bailout_id), parameters, locals, stack); 263 parameters, locals, stack, undef_node);
295 m.Deoptimize(state_node); 264
265 m.CallRuntime1(Runtime::kDeoptimizeFunction, this_fun_node, state_node);
266
267 m.Return(undef_node);
296 268
297 // Schedule the graph: 269 // Schedule the graph:
298 Schedule* schedule = m.Export(); 270 Schedule* schedule = m.Export();
299 271
300 cont_block = cont.block();
301 deopt_block = deopt.block();
302
303 return schedule; 272 return schedule;
304 } 273 }
305 274
306 BailoutId GetCallBailoutId() { 275 BailoutId GetCallBailoutId() {
307 ZoneList<Statement*>* body = info.function()->body(); 276 ZoneList<Statement*>* body = info.function()->body();
308 for (int i = 0; i < body->length(); i++) { 277 for (int i = 0; i < body->length(); i++) {
309 if (body->at(i)->IsExpressionStatement() && 278 if (body->at(i)->IsExpressionStatement() &&
310 body->at(i)->AsExpressionStatement()->expression()->IsCallRuntime()) { 279 body->at(i)->AsExpressionStatement()->expression()->IsCallRuntime()) {
311 return body->at(i)->AsExpressionStatement()->expression()->id(); 280 return body->at(i)->AsExpressionStatement()->expression()->id();
312 } 281 }
313 } 282 }
314 CHECK(false); 283 CHECK(false);
315 return BailoutId(-1); 284 return BailoutId(-1);
316 } 285 }
317
318 BasicBlock* cont_block;
319 BasicBlock* deopt_block;
320 }; 286 };
321 287
322 288
323 TEST(TurboTrivialRuntimeDeoptCodegenAndRun) { 289 TEST(TurboTrivialRuntimeDeoptCodegenAndRun) {
324 HandleAndZoneScope scope; 290 HandleAndZoneScope scope;
325 InitializedHandleScope handles; 291 InitializedHandleScope handles;
326 292
327 FLAG_allow_natives_syntax = true; 293 FLAG_allow_natives_syntax = true;
328 FLAG_turbo_deoptimization = true; 294 FLAG_turbo_deoptimization = true;
329 295
330 TrivialRuntimeDeoptCodegenTester t(&scope); 296 TrivialRuntimeDeoptCodegenTester t(&scope);
331 t.GenerateCode(); 297 t.GenerateCode();
332 298
333 t.function->ReplaceCode(*t.result_code); 299 t.function->ReplaceCode(*t.result_code);
334 t.info.context()->native_context()->AddOptimizedCode(*t.result_code); 300 t.info.context()->native_context()->AddOptimizedCode(*t.result_code);
335 301
336 Isolate* isolate = scope.main_isolate(); 302 Isolate* isolate = scope.main_isolate();
337 Handle<Object> result; 303 Handle<Object> result;
338 bool has_pending_exception = 304 bool has_pending_exception =
339 !Execution::Call(isolate, t.function, 305 !Execution::Call(isolate, t.function,
340 isolate->factory()->undefined_value(), 0, NULL, 306 isolate->factory()->undefined_value(), 0, NULL,
341 false).ToHandle(&result); 307 false).ToHandle(&result);
342 CHECK(!has_pending_exception); 308 CHECK(!has_pending_exception);
343 CHECK(result->SameValue(Smi::FromInt(42))); 309 CHECK(result->SameValue(Smi::FromInt(42)));
344 } 310 }
345 311
346 #endif 312 #endif
OLDNEW
« no previous file with comments | « src/x87/lithium-x87.cc ('k') | test/cctest/compiler/test-schedule.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698