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

Side by Side Diff: src/runtime.cc

Issue 7860045: Stack allocating block scoped variables. Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased on tip of tree. Created 9 years 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/parser.cc ('k') | src/scopeinfo.cc » ('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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 11141 matching lines...) Expand 10 before | Expand all | Expand 10 after
11152 SetProperty(catch_scope, name, thrown_object, NONE, kNonStrictMode), 11152 SetProperty(catch_scope, name, thrown_object, NONE, kNonStrictMode),
11153 Handle<JSObject>()); 11153 Handle<JSObject>());
11154 return catch_scope; 11154 return catch_scope;
11155 } 11155 }
11156 11156
11157 11157
11158 // Create a plain JSObject which materializes the block scope for the specified 11158 // Create a plain JSObject which materializes the block scope for the specified
11159 // block context. 11159 // block context.
11160 static Handle<JSObject> MaterializeBlockScope( 11160 static Handle<JSObject> MaterializeBlockScope(
11161 Isolate* isolate, 11161 Isolate* isolate,
11162 Handle<Context> context) { 11162 Handle<Context> context,
11163 ASSERT(context->IsBlockContext()); 11163 Handle<ScopeInfo> scope_info,
11164 Handle<ScopeInfo> scope_info(ScopeInfo::cast(context->extension())); 11164 JavaScriptFrame* frame,
11165 int inlined_frame_index) {
11166 FrameInspector frame_inspector(frame, inlined_frame_index, isolate);
11165 11167
11166 // Allocate and initialize a JSObject with all the arguments, stack locals 11168 // Allocate and initialize a JSObject with all the arguments, stack locals
11167 // heap locals and extension properties of the debugged function. 11169 // heap locals and extension properties of the debugged function.
11168 Handle<JSObject> block_scope = 11170 Handle<JSObject> block_scope =
11169 isolate->factory()->NewJSObject(isolate->object_function()); 11171 isolate->factory()->NewJSObject(isolate->object_function());
11170 11172
11173 // Second fill all stack locals.
11174 int stack_slots_depth = scope_info->StackSlotsDepth();
11175 for (int i = 0; i < scope_info->StackLocalCount(); ++i) {
11176 int index = i + stack_slots_depth;
11177 RETURN_IF_EMPTY_HANDLE_VALUE(
11178 isolate,
11179 SetProperty(block_scope,
11180 Handle<String>(scope_info->StackLocalName(i)),
11181 Handle<Object>(frame_inspector.GetExpression(index)),
11182 NONE,
11183 kNonStrictMode),
11184 Handle<JSObject>());
11185 }
11186
11171 // Fill all context locals. 11187 // Fill all context locals.
11172 if (!CopyContextLocalsToScopeObject( 11188 if (scope_info->HasContext()) {
11173 isolate, scope_info, context, block_scope)) { 11189 ASSERT(context->IsBlockContext());
11174 return Handle<JSObject>(); 11190 ASSERT(context->extension() == *scope_info);
11191 if (!CopyContextLocalsToScopeObject(
11192 isolate, scope_info, context, block_scope)) {
11193 return Handle<JSObject>();
11194 }
11175 } 11195 }
11176 11196
11177 return block_scope; 11197 return block_scope;
11178 } 11198 }
11179 11199
11180 11200
11181 // Iterate over the actual scopes visible from a stack frame. The iteration 11201 // Iterate over the actual scopes visible from a stack frame. The iteration
11182 // proceeds from the innermost visible nested scope outwards. All scopes are 11202 // proceeds from the innermost visible nested scope outwards. All scopes are
11183 // backed by an actual context except the local scope, which is inserted 11203 // backed by an actual context except the local function scope and local block
11184 // "artificially" in the context chain. 11204 // scopes, which is inserted "artificially" in the context chain.
11185 class ScopeIterator { 11205 class ScopeIterator {
11186 public: 11206 public:
11187 enum ScopeType { 11207 enum ScopeType {
11188 ScopeTypeGlobal = 0, 11208 ScopeTypeGlobal = 0,
11189 ScopeTypeLocal, 11209 ScopeTypeLocal,
11190 ScopeTypeWith, 11210 ScopeTypeWith,
11191 ScopeTypeClosure, 11211 ScopeTypeClosure,
11192 ScopeTypeCatch, 11212 ScopeTypeCatch,
11193 ScopeTypeBlock 11213 ScopeTypeBlock
11194 }; 11214 };
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
11248 if (scope_info->Type() != FUNCTION_SCOPE) { 11268 if (scope_info->Type() != FUNCTION_SCOPE) {
11249 // Global or eval code. 11269 // Global or eval code.
11250 CompilationInfo info(script); 11270 CompilationInfo info(script);
11251 if (scope_info->Type() == GLOBAL_SCOPE) { 11271 if (scope_info->Type() == GLOBAL_SCOPE) {
11252 info.MarkAsGlobal(); 11272 info.MarkAsGlobal();
11253 } else { 11273 } else {
11254 ASSERT(scope_info->Type() == EVAL_SCOPE); 11274 ASSERT(scope_info->Type() == EVAL_SCOPE);
11255 info.MarkAsEval(); 11275 info.MarkAsEval();
11256 info.SetCallingContext(Handle<Context>(function_->context())); 11276 info.SetCallingContext(Handle<Context>(function_->context()));
11257 } 11277 }
11258 if (ParserApi::Parse(&info, kNoParsingFlags) && Scope::Analyze(&info)) { 11278 if (ParserApi::Parse(&info, kNoParsingFlags) &&
11279 Compiler::MakeCode(&info)) {
11259 scope = info.function()->scope(); 11280 scope = info.function()->scope();
11260 } 11281 }
11261 } else { 11282 } else {
11262 // Function code 11283 // Function code
11263 CompilationInfo info(shared_info); 11284 CompilationInfo info(shared_info);
11264 if (ParserApi::Parse(&info, kNoParsingFlags) && Scope::Analyze(&info)) { 11285 if (ParserApi::Parse(&info, kNoParsingFlags) &&
11286 Compiler::MakeCode(&info)) {
11265 scope = info.function()->scope(); 11287 scope = info.function()->scope();
11266 } 11288 }
11267 } 11289 }
11268 11290
11269 // Retrieve the scope chain for the current position. 11291 // Retrieve the scope chain for the current position.
11270 if (scope != NULL) { 11292 if (scope != NULL) {
11271 int source_position = shared_info->code()->SourcePosition(frame_->pc()); 11293 int source_position = shared_info->code()->SourcePosition(frame_->pc());
11272 scope->GetNestedScopeChain(&nested_scope_chain_, source_position); 11294 scope->GetNestedScopeChain(&nested_scope_chain_, source_position);
11273 } else { 11295 } else {
11274 // A failed reparse indicates that the preparser has diverged from the 11296 // A failed reparse indicates that the preparser has diverged from the
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
11358 return MaterializeLocalScope(isolate_, frame_, inlined_frame_index_); 11380 return MaterializeLocalScope(isolate_, frame_, inlined_frame_index_);
11359 case ScopeIterator::ScopeTypeWith: 11381 case ScopeIterator::ScopeTypeWith:
11360 // Return the with object. 11382 // Return the with object.
11361 return Handle<JSObject>(JSObject::cast(CurrentContext()->extension())); 11383 return Handle<JSObject>(JSObject::cast(CurrentContext()->extension()));
11362 case ScopeIterator::ScopeTypeCatch: 11384 case ScopeIterator::ScopeTypeCatch:
11363 return MaterializeCatchScope(isolate_, CurrentContext()); 11385 return MaterializeCatchScope(isolate_, CurrentContext());
11364 case ScopeIterator::ScopeTypeClosure: 11386 case ScopeIterator::ScopeTypeClosure:
11365 // Materialize the content of the closure scope into a JSObject. 11387 // Materialize the content of the closure scope into a JSObject.
11366 return MaterializeClosure(isolate_, CurrentContext()); 11388 return MaterializeClosure(isolate_, CurrentContext());
11367 case ScopeIterator::ScopeTypeBlock: 11389 case ScopeIterator::ScopeTypeBlock:
11368 return MaterializeBlockScope(isolate_, CurrentContext()); 11390 return MaterializeBlockScope(isolate_,
11391 CurrentContext(),
11392 CurrentScopeInfo(),
11393 frame_,
11394 inlined_frame_index_);
11369 } 11395 }
11370 UNREACHABLE(); 11396 UNREACHABLE();
11371 return Handle<JSObject>(); 11397 return Handle<JSObject>();
11372 } 11398 }
11373 11399
11374 Handle<ScopeInfo> CurrentScopeInfo() { 11400 Handle<ScopeInfo> CurrentScopeInfo() {
11375 if (!nested_scope_chain_.is_empty()) { 11401 if (!nested_scope_chain_.is_empty()) {
11376 return nested_scope_chain_.last(); 11402 return nested_scope_chain_.last();
11377 } else if (context_->IsBlockContext()) { 11403 } else if (context_->IsBlockContext()) {
11378 return Handle<ScopeInfo>(ScopeInfo::cast(context_->extension())); 11404 return Handle<ScopeInfo>(ScopeInfo::cast(context_->extension()));
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
11946 if (scope_info->Type() == CATCH_SCOPE) { 11972 if (scope_info->Type() == CATCH_SCOPE) {
11947 Handle<String> name(String::cast(current->extension())); 11973 Handle<String> name(String::cast(current->extension()));
11948 Handle<Object> thrown_object(current->get(Context::THROWN_OBJECT_INDEX)); 11974 Handle<Object> thrown_object(current->get(Context::THROWN_OBJECT_INDEX));
11949 context = 11975 context =
11950 isolate->factory()->NewCatchContext(function, 11976 isolate->factory()->NewCatchContext(function,
11951 context, 11977 context,
11952 name, 11978 name,
11953 thrown_object); 11979 thrown_object);
11954 } else if (scope_info->Type() == BLOCK_SCOPE) { 11980 } else if (scope_info->Type() == BLOCK_SCOPE) {
11955 // Materialize the contents of the block scope into a JSObject. 11981 // Materialize the contents of the block scope into a JSObject.
11956 Handle<JSObject> block_scope_object = 11982 Handle<JSObject> block_scope_object = MaterializeBlockScope(
11957 MaterializeBlockScope(isolate, current); 11983 isolate, current, scope_info, frame, inlined_frame_index);
11958 if (block_scope_object.is_null()) { 11984 if (block_scope_object.is_null()) {
11959 return Handle<Context>::null(); 11985 return Handle<Context>::null();
11960 } 11986 }
11961 // Allocate a new function context for the debug evaluation and set the 11987 // Allocate a new function context for the debug evaluation and set the
11962 // extension object. 11988 // extension object.
11963 Handle<Context> new_context = 11989 Handle<Context> new_context =
11964 isolate->factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS, 11990 isolate->factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS,
11965 function); 11991 function);
11966 new_context->set_extension(*block_scope_object); 11992 new_context->set_extension(*block_scope_object);
11967 new_context->set_previous(*context); 11993 new_context->set_previous(*context);
(...skipping 1594 matching lines...) Expand 10 before | Expand all | Expand 10 after
13562 } else { 13588 } else {
13563 // Handle last resort GC and make sure to allow future allocations 13589 // Handle last resort GC and make sure to allow future allocations
13564 // to grow the heap without causing GCs (if possible). 13590 // to grow the heap without causing GCs (if possible).
13565 isolate->counters()->gc_last_resort_from_js()->Increment(); 13591 isolate->counters()->gc_last_resort_from_js()->Increment();
13566 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); 13592 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
13567 } 13593 }
13568 } 13594 }
13569 13595
13570 13596
13571 } } // namespace v8::internal 13597 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | src/scopeinfo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698