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

Side by Side Diff: src/interpreter/bytecode-generator.cc

Issue 1721983005: [Interpreter] Handles stack overflow in interpreter. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fixed comments. Created 4 years, 9 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
« no previous file with comments | « no previous file | src/interpreter/interpreter.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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/interpreter/bytecode-generator.h" 5 #include "src/interpreter/bytecode-generator.h"
6 6
7 #include "src/ast/scopes.h" 7 #include "src/ast/scopes.h"
8 #include "src/compiler.h" 8 #include "src/compiler.h"
9 #include "src/interpreter/bytecode-register-allocator.h" 9 #include "src/interpreter/bytecode-register-allocator.h"
10 #include "src/interpreter/control-flow-builders.h" 10 #include "src/interpreter/control-flow-builders.h"
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 : generator_(generator), 443 : generator_(generator),
444 kind_(kind), 444 kind_(kind),
445 outer_(generator->execution_result()), 445 outer_(generator->execution_result()),
446 allocator_(generator), 446 allocator_(generator),
447 result_identified_(false) { 447 result_identified_(false) {
448 generator_->set_execution_result(this); 448 generator_->set_execution_result(this);
449 } 449 }
450 450
451 virtual ~ExpressionResultScope() { 451 virtual ~ExpressionResultScope() {
452 generator_->set_execution_result(outer_); 452 generator_->set_execution_result(outer_);
453 DCHECK(result_identified()); 453 DCHECK(result_identified() || generator_->HasStackOverflow());
454 } 454 }
455 455
456 bool IsEffect() const { return kind_ == Expression::kEffect; } 456 bool IsEffect() const { return kind_ == Expression::kEffect; }
457 bool IsValue() const { return kind_ == Expression::kValue; } 457 bool IsValue() const { return kind_ == Expression::kValue; }
458 458
459 virtual void SetResultInAccumulator() = 0; 459 virtual void SetResultInAccumulator() = 0;
460 virtual void SetResultInRegister(Register reg) = 0; 460 virtual void SetResultInRegister(Register reg) = 0;
461 461
462 protected: 462 protected:
463 ExpressionResultScope* outer() const { return outer_; } 463 ExpressionResultScope* outer() const { return outer_; }
464 BytecodeArrayBuilder* builder() const { return generator_->builder(); } 464 BytecodeArrayBuilder* builder() const { return generator_->builder(); }
465 BytecodeGenerator* generator() const { return generator_; }
465 const RegisterAllocationScope* allocator() const { return &allocator_; } 466 const RegisterAllocationScope* allocator() const { return &allocator_; }
466 467
467 void set_result_identified() { 468 void set_result_identified() {
468 DCHECK(!result_identified()); 469 DCHECK(!result_identified());
469 result_identified_ = true; 470 result_identified_ = true;
470 } 471 }
471 472
472 bool result_identified() const { return result_identified_; } 473 bool result_identified() const { return result_identified_; }
473 474
474 private: 475 private:
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 } 530 }
530 531
531 virtual void SetResultInRegister(Register reg) { 532 virtual void SetResultInRegister(Register reg) {
532 DCHECK(builder()->RegisterIsParameterOrLocal(reg) || 533 DCHECK(builder()->RegisterIsParameterOrLocal(reg) ||
533 (builder()->TemporaryRegisterIsLive(reg) && 534 (builder()->TemporaryRegisterIsLive(reg) &&
534 !allocator()->RegisterIsAllocatedInThisScope(reg))); 535 !allocator()->RegisterIsAllocatedInThisScope(reg)));
535 result_register_ = reg; 536 result_register_ = reg;
536 set_result_identified(); 537 set_result_identified();
537 } 538 }
538 539
539 Register ResultRegister() const { return result_register_; } 540 Register ResultRegister() {
541 if (generator()->HasStackOverflow() && !result_identified()) {
542 SetResultInAccumulator();
543 }
544 return result_register_;
545 }
540 546
541 private: 547 private:
542 Register result_register_; 548 Register result_register_;
543 }; 549 };
544 550
545 BytecodeGenerator::BytecodeGenerator(Isolate* isolate, Zone* zone) 551 BytecodeGenerator::BytecodeGenerator(Isolate* isolate, Zone* zone)
546 : isolate_(isolate), 552 : isolate_(isolate),
547 zone_(zone), 553 zone_(zone),
548 builder_(nullptr), 554 builder_(nullptr),
549 info_(nullptr), 555 info_(nullptr),
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
1260 void BytecodeGenerator::VisitDebuggerStatement(DebuggerStatement* stmt) { 1266 void BytecodeGenerator::VisitDebuggerStatement(DebuggerStatement* stmt) {
1261 builder()->SetStatementPosition(stmt); 1267 builder()->SetStatementPosition(stmt);
1262 builder()->Debugger(); 1268 builder()->Debugger();
1263 } 1269 }
1264 1270
1265 1271
1266 void BytecodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) { 1272 void BytecodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) {
1267 // Find or build a shared function info. 1273 // Find or build a shared function info.
1268 Handle<SharedFunctionInfo> shared_info = 1274 Handle<SharedFunctionInfo> shared_info =
1269 Compiler::GetSharedFunctionInfo(expr, info()->script(), info()); 1275 Compiler::GetSharedFunctionInfo(expr, info()->script(), info());
1270 CHECK(!shared_info.is_null()); // TODO(rmcilroy): Set stack overflow? 1276 if (shared_info.is_null()) {
1277 return SetStackOverflow();
1278 }
1271 builder()->CreateClosure(shared_info, 1279 builder()->CreateClosure(shared_info,
1272 expr->pretenure() ? TENURED : NOT_TENURED); 1280 expr->pretenure() ? TENURED : NOT_TENURED);
1273 execution_result()->SetResultInAccumulator(); 1281 execution_result()->SetResultInAccumulator();
1274 } 1282 }
1275 1283
1276 1284
1277 void BytecodeGenerator::VisitClassLiteral(ClassLiteral* expr) { 1285 void BytecodeGenerator::VisitClassLiteral(ClassLiteral* expr) {
1278 if (expr->scope()->ContextLocalCount() > 0) { 1286 if (expr->scope()->ContextLocalCount() > 0) {
1279 VisitNewLocalBlockContext(expr->scope()); 1287 VisitNewLocalBlockContext(expr->scope());
1280 ContextScope scope(this, expr->scope()); 1288 ContextScope scope(this, expr->scope());
(...skipping 1852 matching lines...) Expand 10 before | Expand all | Expand 10 after
3133 } 3141 }
3134 3142
3135 3143
3136 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { 3144 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const {
3137 return info()->feedback_vector()->GetIndex(slot); 3145 return info()->feedback_vector()->GetIndex(slot);
3138 } 3146 }
3139 3147
3140 } // namespace interpreter 3148 } // namespace interpreter
3141 } // namespace internal 3149 } // namespace internal
3142 } // namespace v8 3150 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/interpreter/interpreter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698