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

Side by Side Diff: src/scopes.cc

Issue 6646017: Rebuild scope chain from serialized scope info before parsing lazily. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 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 | « src/scopes.h ('k') | 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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 141
142 142
143 Scope::Scope(Scope* inner_scope, SerializedScopeInfo* scope_info) 143 Scope::Scope(Scope* inner_scope, SerializedScopeInfo* scope_info)
144 : inner_scopes_(4), 144 : inner_scopes_(4),
145 variables_(), 145 variables_(),
146 temps_(4), 146 temps_(4),
147 params_(4), 147 params_(4),
148 unresolved_(16), 148 unresolved_(16),
149 decls_(4) { 149 decls_(4) {
150 ASSERT(scope_info != NULL); 150 ASSERT(scope_info != NULL);
151 SetDefaults(FUNCTION_SCOPE, inner_scope->outer_scope(), scope_info); 151 SetDefaults(FUNCTION_SCOPE, NULL, scope_info);
152 ASSERT(resolved()); 152 ASSERT(resolved());
153 InsertAfterScope(inner_scope);
154 if (scope_info->HasHeapAllocatedLocals()) { 153 if (scope_info->HasHeapAllocatedLocals()) {
155 num_heap_slots_ = scope_info_->NumberOfContextSlots(); 154 num_heap_slots_ = scope_info_->NumberOfContextSlots();
156 } 155 }
157 156
157 AddInnerScope(inner_scope);
158
158 // This scope's arguments shadow (if present) is context-allocated if an inner 159 // This scope's arguments shadow (if present) is context-allocated if an inner
159 // scope accesses this one's parameters. Allocate the arguments_shadow_ 160 // scope accesses this one's parameters. Allocate the arguments_shadow_
160 // variable if necessary. 161 // variable if necessary.
161 Variable::Mode mode; 162 Variable::Mode mode;
162 int arguments_shadow_index = 163 int arguments_shadow_index =
163 scope_info_->ContextSlotIndex(Heap::arguments_shadow_symbol(), &mode); 164 scope_info_->ContextSlotIndex(Heap::arguments_shadow_symbol(), &mode);
164 if (arguments_shadow_index >= 0) { 165 if (arguments_shadow_index >= 0) {
165 ASSERT(mode == Variable::INTERNAL); 166 ASSERT(mode == Variable::INTERNAL);
166 arguments_shadow_ = new Variable(this, 167 arguments_shadow_ = new Variable(this,
167 Factory::arguments_shadow_symbol(), 168 Factory::arguments_shadow_symbol(),
168 Variable::INTERNAL, 169 Variable::INTERNAL,
169 true, 170 true,
170 Variable::ARGUMENTS); 171 Variable::ARGUMENTS);
171 arguments_shadow_->set_rewrite( 172 arguments_shadow_->set_rewrite(
172 new Slot(arguments_shadow_, Slot::CONTEXT, arguments_shadow_index)); 173 new Slot(arguments_shadow_, Slot::CONTEXT, arguments_shadow_index));
173 arguments_shadow_->set_is_used(true); 174 arguments_shadow_->set_is_used(true);
174 } 175 }
175 } 176 }
176 177
177 178
179 Scope* Scope::DeserializeScopeChain(CompilationInfo* info,
180 Scope* global_scope) {
181 ASSERT(!info->closure().is_null());
182 // If we have a serialized scope info, reuse it.
183 Scope* innermost_scope = NULL;
184 Scope* scope = NULL;
185
186 SerializedScopeInfo* scope_info = info->closure()->shared()->scope_info();
187 if (scope_info != SerializedScopeInfo::Empty()) {
188 JSFunction* current = *info->closure();
189 do {
190 current = current->context()->closure();
191 SerializedScopeInfo* scope_info = current->shared()->scope_info();
192 if (scope_info != SerializedScopeInfo::Empty()) {
193 scope = new Scope(scope, scope_info);
194 if (innermost_scope == NULL) innermost_scope = scope;
195 } else {
196 ASSERT(current->context()->IsGlobalContext());
197 }
198 } while (!current->context()->IsGlobalContext());
199 }
200
201 global_scope->AddInnerScope(scope);
202 if (innermost_scope == NULL) innermost_scope = global_scope;
203
204 return innermost_scope;
205 }
206
178 207
179 bool Scope::Analyze(CompilationInfo* info) { 208 bool Scope::Analyze(CompilationInfo* info) {
180 ASSERT(info->function() != NULL); 209 ASSERT(info->function() != NULL);
181 Scope* top = info->function()->scope(); 210 Scope* top = info->function()->scope();
182 211
183 // If we have a serialized scope info, reuse it.
184 if (!info->closure().is_null()) {
185 SerializedScopeInfo* scope_info = info->closure()->shared()->scope_info();
186 if (scope_info != SerializedScopeInfo::Empty()) {
187 Scope* scope = top;
188 JSFunction* current = *info->closure();
189 do {
190 current = current->context()->closure();
191 SerializedScopeInfo* scope_info = current->shared()->scope_info();
192 if (scope_info != SerializedScopeInfo::Empty()) {
193 scope = new Scope(scope, scope_info);
194 } else {
195 ASSERT(current->context()->IsGlobalContext());
196 }
197 } while (!current->context()->IsGlobalContext());
198 }
199 }
200
201 while (top->outer_scope() != NULL) top = top->outer_scope(); 212 while (top->outer_scope() != NULL) top = top->outer_scope();
202 top->AllocateVariables(info->calling_context()); 213 top->AllocateVariables(info->calling_context());
203 214
204 #ifdef DEBUG 215 #ifdef DEBUG
205 if (Bootstrapper::IsActive() 216 if (Bootstrapper::IsActive()
206 ? FLAG_print_builtin_scopes 217 ? FLAG_print_builtin_scopes
207 : FLAG_print_scopes) { 218 : FLAG_print_scopes) {
208 info->function()->scope()->Print(); 219 info->function()->scope()->Print();
209 } 220 }
210 #endif 221 #endif
(...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && 1077 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS &&
1067 !must_have_local_context) { 1078 !must_have_local_context) {
1068 num_heap_slots_ = 0; 1079 num_heap_slots_ = 0;
1069 } 1080 }
1070 1081
1071 // Allocation done. 1082 // Allocation done.
1072 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); 1083 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS);
1073 } 1084 }
1074 1085
1075 } } // namespace v8::internal 1086 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/scopes.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698