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

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

Issue 1690973002: [interpreter] Correctly thread through catch prediction. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 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 | « src/interpreter/bytecode-generator.h ('k') | src/interpreter/control-flow-builders.h » ('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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 LoopBuilder* loop_builder_; 294 LoopBuilder* loop_builder_;
295 }; 295 };
296 296
297 297
298 // Scoped class for enabling 'throw' in try-catch constructs. 298 // Scoped class for enabling 'throw' in try-catch constructs.
299 class BytecodeGenerator::ControlScopeForTryCatch final 299 class BytecodeGenerator::ControlScopeForTryCatch final
300 : public BytecodeGenerator::ControlScope { 300 : public BytecodeGenerator::ControlScope {
301 public: 301 public:
302 ControlScopeForTryCatch(BytecodeGenerator* generator, 302 ControlScopeForTryCatch(BytecodeGenerator* generator,
303 TryCatchBuilder* try_catch_builder) 303 TryCatchBuilder* try_catch_builder)
304 : ControlScope(generator) {} 304 : ControlScope(generator) {
305 generator->try_catch_nesting_level_++;
306 }
307 virtual ~ControlScopeForTryCatch() {
308 generator()->try_catch_nesting_level_--;
309 }
305 310
306 protected: 311 protected:
307 bool Execute(Command command, Statement* statement) override { 312 bool Execute(Command command, Statement* statement) override {
308 switch (command) { 313 switch (command) {
309 case CMD_BREAK: 314 case CMD_BREAK:
310 case CMD_CONTINUE: 315 case CMD_CONTINUE:
311 case CMD_RETURN: 316 case CMD_RETURN:
312 break; 317 break;
313 case CMD_RETHROW: 318 case CMD_RETHROW:
314 generator()->builder()->ReThrow(); 319 generator()->builder()->ReThrow();
315 return true; 320 return true;
316 } 321 }
317 return false; 322 return false;
318 } 323 }
319 }; 324 };
320 325
321 326
322 // Scoped class for enabling control flow through try-finally constructs. 327 // Scoped class for enabling control flow through try-finally constructs.
323 class BytecodeGenerator::ControlScopeForTryFinally final 328 class BytecodeGenerator::ControlScopeForTryFinally final
324 : public BytecodeGenerator::ControlScope { 329 : public BytecodeGenerator::ControlScope {
325 public: 330 public:
326 ControlScopeForTryFinally(BytecodeGenerator* generator, 331 ControlScopeForTryFinally(BytecodeGenerator* generator,
327 TryFinallyBuilder* try_finally_builder, 332 TryFinallyBuilder* try_finally_builder,
328 DeferredCommands* commands) 333 DeferredCommands* commands)
329 : ControlScope(generator), 334 : ControlScope(generator),
330 try_finally_builder_(try_finally_builder), 335 try_finally_builder_(try_finally_builder),
331 commands_(commands) {} 336 commands_(commands) {
337 generator->try_finally_nesting_level_++;
338 }
339 virtual ~ControlScopeForTryFinally() {
340 generator()->try_finally_nesting_level_--;
341 }
332 342
333 protected: 343 protected:
334 bool Execute(Command command, Statement* statement) override { 344 bool Execute(Command command, Statement* statement) override {
335 switch (command) { 345 switch (command) {
336 case CMD_BREAK: 346 case CMD_BREAK:
337 case CMD_CONTINUE: 347 case CMD_CONTINUE:
338 case CMD_RETURN: 348 case CMD_RETURN:
339 case CMD_RETHROW: 349 case CMD_RETHROW:
340 commands_->RecordCommand(command, statement); 350 commands_->RecordCommand(command, statement);
341 try_finally_builder_->LeaveTry(); 351 try_finally_builder_->LeaveTry();
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 BytecodeGenerator::BytecodeGenerator(Isolate* isolate, Zone* zone) 546 BytecodeGenerator::BytecodeGenerator(Isolate* isolate, Zone* zone)
537 : isolate_(isolate), 547 : isolate_(isolate),
538 zone_(zone), 548 zone_(zone),
539 builder_(nullptr), 549 builder_(nullptr),
540 info_(nullptr), 550 info_(nullptr),
541 scope_(nullptr), 551 scope_(nullptr),
542 globals_(0, zone), 552 globals_(0, zone),
543 execution_control_(nullptr), 553 execution_control_(nullptr),
544 execution_context_(nullptr), 554 execution_context_(nullptr),
545 execution_result_(nullptr), 555 execution_result_(nullptr),
546 register_allocator_(nullptr) { 556 register_allocator_(nullptr),
557 try_catch_nesting_level_(0),
558 try_finally_nesting_level_(0) {
547 InitializeAstVisitor(isolate); 559 InitializeAstVisitor(isolate);
548 } 560 }
549 561
550 562
551 Handle<BytecodeArray> BytecodeGenerator::MakeBytecode(CompilationInfo* info) { 563 Handle<BytecodeArray> BytecodeGenerator::MakeBytecode(CompilationInfo* info) {
552 set_info(info); 564 set_info(info);
553 set_scope(info->scope()); 565 set_scope(info->scope());
554 566
555 // Initialize bytecode array builder. 567 // Initialize bytecode array builder.
556 set_builder(new (zone()) BytecodeArrayBuilder( 568 set_builder(new (zone()) BytecodeArrayBuilder(
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 // Load the catch context into the accumulator. 1155 // Load the catch context into the accumulator.
1144 builder()->LoadAccumulatorWithRegister(context); 1156 builder()->LoadAccumulatorWithRegister(context);
1145 1157
1146 // Evaluate the catch-block. 1158 // Evaluate the catch-block.
1147 VisitInScope(stmt->catch_block(), stmt->scope()); 1159 VisitInScope(stmt->catch_block(), stmt->scope());
1148 try_control_builder.EndCatch(); 1160 try_control_builder.EndCatch();
1149 } 1161 }
1150 1162
1151 1163
1152 void BytecodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) { 1164 void BytecodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) {
1153 TryFinallyBuilder try_control_builder(builder()); 1165 TryFinallyBuilder try_control_builder(builder(), IsInsideTryCatch());
1154 Register no_reg; 1166 Register no_reg;
1155 1167
1156 // We keep a record of all paths that enter the finally-block to be able to 1168 // We keep a record of all paths that enter the finally-block to be able to
1157 // dispatch to the correct continuation point after the statements in the 1169 // dispatch to the correct continuation point after the statements in the
1158 // finally-block have been evaluated. 1170 // finally-block have been evaluated.
1159 // 1171 //
1160 // The try-finally construct can enter the finally-block in three ways: 1172 // The try-finally construct can enter the finally-block in three ways:
1161 // 1. By exiting the try-block normally, falling through at the end. 1173 // 1. By exiting the try-block normally, falling through at the end.
1162 // 2. By exiting the try-block with a function-local control flow transfer 1174 // 2. By exiting the try-block with a function-local control flow transfer
1163 // (i.e. through break/continue/return statements). 1175 // (i.e. through break/continue/return statements).
(...skipping 1707 matching lines...) Expand 10 before | Expand all | Expand 10 after
2871 } 2883 }
2872 2884
2873 2885
2874 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { 2886 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const {
2875 return info()->feedback_vector()->GetIndex(slot); 2887 return info()->feedback_vector()->GetIndex(slot);
2876 } 2888 }
2877 2889
2878 } // namespace interpreter 2890 } // namespace interpreter
2879 } // namespace internal 2891 } // namespace internal
2880 } // namespace v8 2892 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/bytecode-generator.h ('k') | src/interpreter/control-flow-builders.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698