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

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

Issue 1028473002: Add a flag controlling context sharing. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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
11 namespace dart { 11 namespace dart {
12 12
13 DEFINE_FLAG(bool, share_enclosing_context, true,
14 "Allocate captured variables in the existing context of an "
15 "enclosing scope (up to innermost loop) and spare the allocation "
16 "of a local context.");
17
13 int SourceLabel::FunctionLevel() const { 18 int SourceLabel::FunctionLevel() const {
14 ASSERT(owner() != NULL); 19 ASSERT(owner() != NULL);
15 return owner()->function_level(); 20 return owner()->function_level();
16 } 21 }
17 22
18 23
19 LocalScope::LocalScope(LocalScope* parent, int function_level, int loop_level) 24 LocalScope::LocalScope(LocalScope* parent, int function_level, int loop_level)
20 : parent_(parent), 25 : parent_(parent),
21 child_(NULL), 26 child_(NULL),
22 sibling_(NULL), 27 sibling_(NULL),
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 ASSERT(variable->is_captured()); 146 ASSERT(variable->is_captured());
142 ASSERT(variable->owner() == this); 147 ASSERT(variable->owner() == this);
143 // The context level in the owner scope of a captured variable indicates at 148 // The context level in the owner scope of a captured variable indicates at
144 // code generation time how far to walk up the context chain in order to 149 // code generation time how far to walk up the context chain in order to
145 // access the variable from the current context level. 150 // access the variable from the current context level.
146 if ((*context_owner) == NULL) { 151 if ((*context_owner) == NULL) {
147 ASSERT(num_context_variables_ == 0); 152 ASSERT(num_context_variables_ == 0);
148 // This scope becomes the current context owner. 153 // This scope becomes the current context owner.
149 set_context_level(1); 154 set_context_level(1);
150 *context_owner = this; 155 *context_owner = this;
156 } else if (!FLAG_share_enclosing_context && ((*context_owner) != this)) {
157 // The captured variable is in a child scope of the context owner and we do
158 // not share contexts.
159 // This scope will allocate and chain a new context.
160 ASSERT(num_context_variables_ == 0);
161 // This scope becomes the current context owner.
162 set_context_level((*context_owner)->context_level() + 1);
163 *context_owner = this;
151 } else if ((*context_owner)->loop_level() < loop_level()) { 164 } else if ((*context_owner)->loop_level() < loop_level()) {
165 ASSERT(FLAG_share_enclosing_context);
152 // The captured variable is at a deeper loop level than the current context. 166 // The captured variable is at a deeper loop level than the current context.
153 // This scope will allocate and chain a new context. 167 // This scope will allocate and chain a new context.
154 ASSERT(num_context_variables_ == 0); 168 ASSERT(num_context_variables_ == 0);
155 // This scope becomes the current context owner. 169 // This scope becomes the current context owner.
156 set_context_level((*context_owner)->context_level() + 1); 170 set_context_level((*context_owner)->context_level() + 1);
157 *context_owner = this; 171 *context_owner = this;
158 } else { 172 } else {
159 // Allocate the captured variable in the current context. 173 // Allocate the captured variable in the current context.
160 if (!HasContextLevel()) { 174 if (!HasContextLevel()) {
161 ASSERT(variable->owner() != *context_owner); 175 ASSERT(variable->owner() != *context_owner);
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 return fixed_parameter_count - (index() - kParamEndSlotFromFp); 667 return fixed_parameter_count - (index() - kParamEndSlotFromFp);
654 } else { 668 } else {
655 // Shift negative indexes so that the lowest one is 0 (they are still 669 // Shift negative indexes so that the lowest one is 0 (they are still
656 // non-positive). 670 // non-positive).
657 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); 671 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp);
658 } 672 }
659 } 673 }
660 674
661 675
662 } // namespace dart 676 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698