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

Side by Side Diff: runtime/vm/scopes.cc

Issue 1308163006: Reduce the number of captured variables in async code, by only capturing local (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: address comments Created 5 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
« no previous file with comments | « runtime/vm/scopes.h ('k') | runtime/vm/symbols.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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/scopes.h" 5 #include "vm/scopes.h"
6 6
7 #include "vm/object.h" 7 #include "vm/object.h"
8 #include "vm/stack_frame.h" 8 #include "vm/stack_frame.h"
9 #include "vm/symbols.h" 9 #include "vm/symbols.h"
10 10
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 LocalScope* owner_scope = new LocalScope(NULL, 0, 0); 610 LocalScope* owner_scope = new LocalScope(NULL, 0, 0);
611 owner_scope->set_context_level(context_scope.ContextLevelAt(i)); 611 owner_scope->set_context_level(context_scope.ContextLevelAt(i));
612 owner_scope->AddVariable(variable); 612 owner_scope->AddVariable(variable);
613 outer_scope->AddVariable(variable); // As alias. 613 outer_scope->AddVariable(variable); // As alias.
614 ASSERT(variable->owner() == owner_scope); 614 ASSERT(variable->owner() == owner_scope);
615 } 615 }
616 return outer_scope; 616 return outer_scope;
617 } 617 }
618 618
619 619
620 void LocalScope::RecursivelyCaptureAllVariables() { 620 void LocalScope::CaptureLocalVariables(LocalScope* top_scope) {
621 for (intptr_t i = 0; i < num_variables(); i++) { 621 ASSERT(top_scope->function_level() == function_level());
622 if ((VariableAt(i)->name().raw() == Symbols::StackTraceVar().raw()) || 622 LocalScope* scope = this;
623 (VariableAt(i)->name().raw() == Symbols::ExceptionVar().raw()) || 623 while (scope != top_scope->parent()) {
624 (VariableAt(i)->name().raw() == Symbols::SavedTryContextVar().raw())) { 624 for (intptr_t i = 0; i < scope->num_variables(); i++) {
625 // Don't capture those variables because the VM expects them to be on the 625 LocalVariable* variable = scope->VariableAt(i);
626 // stack. 626 if ((variable->name().raw() == Symbols::StackTraceVar().raw()) ||
627 continue; 627 (variable->name().raw() == Symbols::ExceptionVar().raw()) ||
628 (variable->name().raw() == Symbols::SavedTryContextVar().raw())) {
629 // Don't capture those variables because the VM expects them to be on
630 // the stack.
631 continue;
632 }
633 scope->CaptureVariable(variable);
628 } 634 }
629 CaptureVariable(VariableAt(i)); 635 scope = scope->parent();
630 } 636 }
631 if (sibling() != NULL) { sibling()->RecursivelyCaptureAllVariables(); }
632 if (child() != NULL) { child()->RecursivelyCaptureAllVariables(); }
633 } 637 }
634 638
635 639
636 RawContextScope* LocalScope::CreateImplicitClosureScope(const Function& func) { 640 RawContextScope* LocalScope::CreateImplicitClosureScope(const Function& func) {
637 static const intptr_t kNumCapturedVars = 1; 641 static const intptr_t kNumCapturedVars = 1;
638 642
639 // Create a ContextScope with space for kNumCapturedVars descriptors. 643 // Create a ContextScope with space for kNumCapturedVars descriptors.
640 const ContextScope& context_scope = 644 const ContextScope& context_scope =
641 ContextScope::Handle(ContextScope::New(kNumCapturedVars, true)); 645 ContextScope::Handle(ContextScope::New(kNumCapturedVars, true));
642 646
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 return fixed_parameter_count - (index() - kParamEndSlotFromFp); 683 return fixed_parameter_count - (index() - kParamEndSlotFromFp);
680 } else { 684 } else {
681 // Shift negative indexes so that the lowest one is 0 (they are still 685 // Shift negative indexes so that the lowest one is 0 (they are still
682 // non-positive). 686 // non-positive).
683 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); 687 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp);
684 } 688 }
685 } 689 }
686 690
687 691
688 } // namespace dart 692 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/scopes.h ('k') | runtime/vm/symbols.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698