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

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

Issue 1796893002: [Interpreter] Pops the context to the correct level on return. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Added a test for try-finally with return in test-interpreter. 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 | test/cctest/interpreter/bytecode_expectations/BasicLoops.golden » ('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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 65
66 ContextScope* previous = this; 66 ContextScope* previous = this;
67 for (int i = depth; i > 0; --i) { 67 for (int i = depth; i > 0; --i) {
68 previous = previous->outer_; 68 previous = previous->outer_;
69 } 69 }
70 return previous; 70 return previous;
71 } 71 }
72 72
73 Scope* scope() const { return scope_; } 73 Scope* scope() const { return scope_; }
74 Register reg() const { return register_; } 74 Register reg() const { return register_; }
75 bool ShouldPopContext() { return should_pop_context_; }
75 76
76 private: 77 private:
77 const BytecodeArrayBuilder* builder() const { return generator_->builder(); } 78 const BytecodeArrayBuilder* builder() const { return generator_->builder(); }
78 79
79 void set_register(Register reg) { register_ = reg; } 80 void set_register(Register reg) { register_ = reg; }
80 81
81 BytecodeGenerator* generator_; 82 BytecodeGenerator* generator_;
82 Scope* scope_; 83 Scope* scope_;
83 ContextScope* outer_; 84 ContextScope* outer_;
84 Register register_; 85 Register register_;
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 private: 357 private:
357 TryFinallyBuilder* try_finally_builder_; 358 TryFinallyBuilder* try_finally_builder_;
358 DeferredCommands* commands_; 359 DeferredCommands* commands_;
359 }; 360 };
360 361
361 362
362 void BytecodeGenerator::ControlScope::PerformCommand(Command command, 363 void BytecodeGenerator::ControlScope::PerformCommand(Command command,
363 Statement* statement) { 364 Statement* statement) {
364 ControlScope* current = this; 365 ControlScope* current = this;
365 ContextScope* context = generator()->execution_context(); 366 ContextScope* context = generator()->execution_context();
367 // Do not pop if it is the outermost context.
368 if (context != current->context() && context->ShouldPopContext()) {
mythria 2016/03/15 09:49:11 I am still not very sure about the check for conte
369 generator()->builder()->PopContext(current->context()->reg());
370 }
366 do { 371 do {
367 if (current->context() != context) {
368 // Pop context to the expected depth for break and continue. For return
369 // and throw it is not required to pop. Debugger expects that the
370 // context is not popped on return. So do not pop on return.
371 // TODO(rmcilroy): Only emit a single context pop.
372 if (command == CMD_BREAK || command == CMD_CONTINUE) {
373 generator()->builder()->PopContext(current->context()->reg());
374 }
375 context = current->context();
376 }
377 if (current->Execute(command, statement)) { 372 if (current->Execute(command, statement)) {
378 return; 373 return;
379 } 374 }
380 current = current->outer(); 375 current = current->outer();
376 if (current->context() != context) {
377 // Pop context to the expected depth.
378 // TODO(rmcilroy): Only emit a single context pop.
379 generator()->builder()->PopContext(current->context()->reg());
380 }
381 } while (current != nullptr); 381 } while (current != nullptr);
382 UNREACHABLE(); 382 UNREACHABLE();
383 } 383 }
384 384
385 385
386 class BytecodeGenerator::RegisterAllocationScope { 386 class BytecodeGenerator::RegisterAllocationScope {
387 public: 387 public:
388 explicit RegisterAllocationScope(BytecodeGenerator* generator) 388 explicit RegisterAllocationScope(BytecodeGenerator* generator)
389 : generator_(generator), 389 : generator_(generator),
390 outer_(generator->register_allocator()), 390 outer_(generator->register_allocator()),
(...skipping 2766 matching lines...) Expand 10 before | Expand all | Expand 10 after
3157 } 3157 }
3158 3158
3159 3159
3160 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { 3160 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const {
3161 return info()->feedback_vector()->GetIndex(slot); 3161 return info()->feedback_vector()->GetIndex(slot);
3162 } 3162 }
3163 3163
3164 } // namespace interpreter 3164 } // namespace interpreter
3165 } // namespace internal 3165 } // namespace internal
3166 } // namespace v8 3166 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/cctest/interpreter/bytecode_expectations/BasicLoops.golden » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698