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

Side by Side Diff: src/fast-codegen.cc

Issue 435020: Fast-compiler: Add stack limit checks to back edges of while, do-while and for. (Closed)
Patch Set: Created 11 years 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
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 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
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 298
299 299
300 void FastCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { 300 void FastCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) {
301 UNREACHABLE(); 301 UNREACHABLE();
302 } 302 }
303 303
304 304
305 void FastCodeGenerator::VisitDoWhileStatement(DoWhileStatement* stmt) { 305 void FastCodeGenerator::VisitDoWhileStatement(DoWhileStatement* stmt) {
306 Comment cmnt(masm_, "[ DoWhileStatement"); 306 Comment cmnt(masm_, "[ DoWhileStatement");
307 increment_loop_depth(); 307 increment_loop_depth();
308 Label body, exit; 308 Label body, exit, stack_limit_hit, stack_check_success;
309 309
310 // Emit the test at the bottom of the loop.
311 __ bind(&body); 310 __ bind(&body);
312 Visit(stmt->body()); 311 Visit(stmt->body());
313 312
313 // Check stack before looping.
314 __ StackLimitCheck(&stack_limit_hit);
315 __ bind(&stack_check_success);
316
314 // We are not in an expression context because we have been compiling 317 // We are not in an expression context because we have been compiling
315 // statements. Set up a test expression context for the condition. 318 // statements. Set up a test expression context for the condition.
316 ASSERT_EQ(NULL, true_label_); 319 ASSERT_EQ(NULL, true_label_);
317 ASSERT_EQ(NULL, false_label_); 320 ASSERT_EQ(NULL, false_label_);
318 true_label_ = &body; 321 true_label_ = &body;
319 false_label_ = &exit; 322 false_label_ = &exit;
320 ASSERT(stmt->cond()->context() == Expression::kTest); 323 ASSERT(stmt->cond()->context() == Expression::kTest);
321 Visit(stmt->cond()); 324 Visit(stmt->cond());
322 true_label_ = NULL; 325 true_label_ = NULL;
323 false_label_ = NULL; 326 false_label_ = NULL;
324 327
328 __ bind(&stack_limit_hit);
329 StackCheckStub stack_stub;
330 __ CallStub(&stack_stub);
331 __ jmp(&stack_check_success);
332
325 __ bind(&exit); 333 __ bind(&exit);
326 334
327 decrement_loop_depth(); 335 decrement_loop_depth();
328 } 336 }
329 337
330 338
331 void FastCodeGenerator::VisitWhileStatement(WhileStatement* stmt) { 339 void FastCodeGenerator::VisitWhileStatement(WhileStatement* stmt) {
332 Comment cmnt(masm_, "[ WhileStatement"); 340 Comment cmnt(masm_, "[ WhileStatement");
333 increment_loop_depth(); 341 increment_loop_depth();
334 Label test, body, exit; 342 Label test, body, exit, stack_limit_hit, stack_check_success;
335 343
336 // Emit the test at the bottom of the loop. 344 // Emit the test at the bottom of the loop.
337 __ jmp(&test); 345 __ jmp(&test);
338 346
339 __ bind(&body); 347 __ bind(&body);
340 Visit(stmt->body()); 348 Visit(stmt->body());
341 349
342 __ bind(&test); 350 __ bind(&test);
351 // Check stack before looping.
352 __ StackLimitCheck(&stack_limit_hit);
353 __ bind(&stack_check_success);
354
343 // We are not in an expression context because we have been compiling 355 // We are not in an expression context because we have been compiling
344 // statements. Set up a test expression context for the condition. 356 // statements. Set up a test expression context for the condition.
345 ASSERT_EQ(NULL, true_label_); 357 ASSERT_EQ(NULL, true_label_);
346 ASSERT_EQ(NULL, false_label_); 358 ASSERT_EQ(NULL, false_label_);
347 true_label_ = &body; 359 true_label_ = &body;
348 false_label_ = &exit; 360 false_label_ = &exit;
349 ASSERT(stmt->cond()->context() == Expression::kTest); 361 ASSERT(stmt->cond()->context() == Expression::kTest);
350 Visit(stmt->cond()); 362 Visit(stmt->cond());
351 true_label_ = NULL; 363 true_label_ = NULL;
352 false_label_ = NULL; 364 false_label_ = NULL;
353 365
366 __ bind(&stack_limit_hit);
367 StackCheckStub stack_stub;
368 __ CallStub(&stack_stub);
369 __ jmp(&stack_check_success);
370
354 __ bind(&exit); 371 __ bind(&exit);
355 372
356 decrement_loop_depth(); 373 decrement_loop_depth();
357 } 374 }
358 375
359 376
360 void FastCodeGenerator::VisitForStatement(ForStatement* stmt) { 377 void FastCodeGenerator::VisitForStatement(ForStatement* stmt) {
361 Comment cmnt(masm_, "[ ForStatement"); 378 Comment cmnt(masm_, "[ ForStatement");
362 Label test, body, exit; 379 Label test, body, exit, stack_limit_hit, stack_check_success;
363 if (stmt->init() != NULL) Visit(stmt->init()); 380 if (stmt->init() != NULL) Visit(stmt->init());
364 381
365 increment_loop_depth(); 382 increment_loop_depth();
366 // Emit the test at the bottom of the loop (even if empty). 383 // Emit the test at the bottom of the loop (even if empty).
367 __ jmp(&test); 384 __ jmp(&test);
368 __ bind(&body); 385 __ bind(&body);
369 Visit(stmt->body()); 386 Visit(stmt->body());
387
388 // Check stack before looping.
389 __ StackLimitCheck(&stack_limit_hit);
390 __ bind(&stack_check_success);
391
370 if (stmt->next() != NULL) Visit(stmt->next()); 392 if (stmt->next() != NULL) Visit(stmt->next());
371 393
372 __ bind(&test); 394 __ bind(&test);
395
373 if (stmt->cond() == NULL) { 396 if (stmt->cond() == NULL) {
374 // For an empty test jump to the top of the loop. 397 // For an empty test jump to the top of the loop.
375 __ jmp(&body); 398 __ jmp(&body);
376 } else { 399 } else {
377 // We are not in an expression context because we have been compiling 400 // We are not in an expression context because we have been compiling
378 // statements. Set up a test expression context for the condition. 401 // statements. Set up a test expression context for the condition.
379 ASSERT_EQ(NULL, true_label_); 402 ASSERT_EQ(NULL, true_label_);
380 ASSERT_EQ(NULL, false_label_); 403 ASSERT_EQ(NULL, false_label_);
404
381 true_label_ = &body; 405 true_label_ = &body;
382 false_label_ = &exit; 406 false_label_ = &exit;
383 ASSERT(stmt->cond()->context() == Expression::kTest); 407 ASSERT(stmt->cond()->context() == Expression::kTest);
384 Visit(stmt->cond()); 408 Visit(stmt->cond());
385 true_label_ = NULL; 409 true_label_ = NULL;
386 false_label_ = NULL; 410 false_label_ = NULL;
387 } 411 }
388 412
413 __ bind(&stack_limit_hit);
414 StackCheckStub stack_stub;
415 __ CallStub(&stack_stub);
416 __ jmp(&stack_check_success);
417
389 __ bind(&exit); 418 __ bind(&exit);
390 decrement_loop_depth(); 419 decrement_loop_depth();
391 } 420 }
392 421
393 422
394 void FastCodeGenerator::VisitForInStatement(ForInStatement* stmt) { 423 void FastCodeGenerator::VisitForInStatement(ForInStatement* stmt) {
395 UNREACHABLE(); 424 UNREACHABLE();
396 } 425 }
397 426
398 427
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 550
522 void FastCodeGenerator::VisitThisFunction(ThisFunction* expr) { 551 void FastCodeGenerator::VisitThisFunction(ThisFunction* expr) {
523 UNREACHABLE(); 552 UNREACHABLE();
524 } 553 }
525 554
526 555
527 #undef __ 556 #undef __
528 557
529 558
530 } } // namespace v8::internal 559 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698