From 7385fef2cabb2bf7df57236b7a6673b443a19b3b Mon Sep 17 00:00:00 2001 From: "keuchel@chromium.org" Date: Thu, 3 Nov 2011 10:36:55 +0000 Subject: [PATCH] Cleanup ScopeInfo and SerializedScopeInfo. Both classes have been merged into a single ScopeInfo class that implements the functionality from both. This CL does not adapt the broken gdb-jit interface. Review URL: http://codereview.chromium.org/8352039 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9868 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/accessors.cc | 5 +- src/compiler.cc | 14 +- src/contexts.cc | 17 +- src/factory.cc | 10 +- src/factory.h | 6 +- src/frames.cc | 31 +-- src/full-codegen.cc | 5 +- src/gdb-jit.cc | 6 +- src/heap.cc | 21 +- src/heap.h | 6 +- src/hydrogen.cc | 6 +- src/liveedit.cc | 2 +- src/objects-inl.h | 12 +- src/objects.h | 162 +++++++++-- src/parser.cc | 2 +- src/profile-generator.cc | 31 ++- src/runtime.cc | 158 +++++------ src/scopeinfo.cc | 706 ++++++++++++++++++----------------------------- src/scopeinfo.h | 61 ---- src/scopes.cc | 75 ++--- src/scopes.h | 17 +- src/serialize.h | 2 +- src/v8globals.h | 3 +- 23 files changed, 613 insertions(+), 745 deletions(-) diff --git a/src/accessors.cc b/src/accessors.cc index 02998f9..fac8ed9 100644 --- a/src/accessors.cc +++ b/src/accessors.cc @@ -621,8 +621,9 @@ MaybeObject* Accessors::FunctionGetArguments(Object* object, void*) { if (!frame->is_optimized()) { // If there is an arguments variable in the stack, we return that. - Handle info(function->shared()->scope_info()); - int index = info->StackSlotIndex(isolate->heap()->arguments_symbol()); + Handle scope_info(function->shared()->scope_info()); + int index = scope_info->StackSlotIndex( + isolate->heap()->arguments_symbol()); if (index >= 0) { Handle arguments(frame->GetExpression(index), isolate); if (!arguments->IsArgumentsMarker()) return *arguments; diff --git a/src/compiler.cc b/src/compiler.cc index 88db467..4a5f399 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -326,8 +326,7 @@ bool Compiler::MakeCodeForLiveEdit(CompilationInfo* info) { // the compilation info is set if compilation succeeded. bool succeeded = MakeCode(info); if (!info->shared_info().is_null()) { - Handle scope_info = - SerializedScopeInfo::Create(info->scope()); + Handle scope_info = ScopeInfo::Create(info->scope()); info->shared_info()->set_scope_info(*scope_info); } return succeeded; @@ -395,7 +394,7 @@ static Handle MakeFunctionInfo(CompilationInfo* info) { lit->name(), lit->materialized_literal_count(), info->code(), - SerializedScopeInfo::Create(info->scope())); + ScopeInfo::Create(info->scope())); ASSERT_EQ(RelocInfo::kNoPosition, lit->function_token_position()); Compiler::SetFunctionInfo(result, lit, true, script); @@ -623,7 +622,7 @@ bool Compiler::CompileLazy(CompilationInfo* info) { RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); if (info->IsOptimizing()) { - ASSERT(shared->scope_info() != SerializedScopeInfo::Empty()); + ASSERT(shared->scope_info() != ScopeInfo::Empty()); function->ReplaceCode(*code); } else { // Update the shared function info with the compiled code and the @@ -631,8 +630,7 @@ bool Compiler::CompileLazy(CompilationInfo* info) { // info initialization is important since set_scope_info might // trigger a GC, causing the ASSERT below to be invalid if the code // was flushed. By settting the code object last we avoid this. - Handle scope_info = - SerializedScopeInfo::Create(info->scope()); + Handle scope_info = ScopeInfo::Create(info->scope()); shared->set_scope_info(*scope_info); shared->set_code(*code); if (!function.is_null()) { @@ -695,7 +693,7 @@ Handle Compiler::BuildFunctionInfo(FunctionLiteral* literal, bool allow_lazy = literal->AllowsLazyCompilation() && !LiveEditFunctionTracker::IsActive(info.isolate()); - Handle scope_info(SerializedScopeInfo::Empty()); + Handle scope_info(ScopeInfo::Empty()); // Generate code if (FLAG_lazy && allow_lazy) { @@ -704,7 +702,7 @@ Handle Compiler::BuildFunctionInfo(FunctionLiteral* literal, } else if ((V8::UseCrankshaft() && MakeCrankshaftCode(&info)) || (!V8::UseCrankshaft() && FullCodeGenerator::MakeCode(&info))) { ASSERT(!info.code().is_null()); - scope_info = SerializedScopeInfo::Create(info.scope()); + scope_info = ScopeInfo::Create(info.scope()); } else { return Handle::null(); } diff --git a/src/contexts.cc b/src/contexts.cc index b25ffac..0e7ef5f 100644 --- a/src/contexts.cc +++ b/src/contexts.cc @@ -137,13 +137,13 @@ Handle Context::Lookup(Handle name, if (context->IsFunctionContext() || context->IsBlockContext()) { // Use serialized scope information of functions and blocks to search // for the context index. - Handle scope_info; + Handle scope_info; if (context->IsFunctionContext()) { - scope_info = Handle( + scope_info = Handle( context->closure()->shared()->scope_info(), isolate); } else { - scope_info = Handle( - SerializedScopeInfo::cast(context->extension()), isolate); + scope_info = Handle( + ScopeInfo::cast(context->extension()), isolate); } VariableMode mode; int slot_index = scope_info->ContextSlotIndex(*name, &mode); @@ -250,8 +250,7 @@ bool Context::GlobalIfNotShadowedByEval(Handle name) { ASSERT(context->IsFunctionContext()); // Check non-parameter locals. - Handle scope_info( - context->closure()->shared()->scope_info()); + Handle scope_info(context->closure()->shared()->scope_info()); VariableMode mode; int index = scope_info->ContextSlotIndex(*name, &mode); ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS); @@ -262,7 +261,7 @@ bool Context::GlobalIfNotShadowedByEval(Handle name) { if (param_index >= 0) return false; // Check context only holding the function name variable. - index = scope_info->FunctionContextSlotIndex(*name, NULL); + index = scope_info->FunctionContextSlotIndex(*name, &mode); if (index >= 0) return false; context = context->previous(); } @@ -279,9 +278,7 @@ void Context::ComputeEvalScopeInfo(bool* outer_scope_calls_non_strict_eval) { Context* context = this; while (!context->IsGlobalContext()) { if (context->IsFunctionContext()) { - Handle scope_info( - context->closure()->shared()->scope_info()); - if (scope_info->CallsEval() && !scope_info->IsStrictMode()) { + if (context->closure()->shared()->scope_info()->CallsNonStrictEval()) { // No need to go further since the answers will not change from // here. *outer_scope_calls_non_strict_eval = true; diff --git a/src/factory.cc b/src/factory.cc index 15f640e..88684a4 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -303,7 +303,7 @@ Handle Factory::NewWithContext(Handle function, Handle Factory::NewBlockContext( Handle function, Handle previous, - Handle scope_info) { + Handle scope_info) { CALL_HEAP_FUNCTION( isolate(), isolate()->heap()->AllocateBlockContext(*function, @@ -766,11 +766,11 @@ Handle Factory::NewFunctionWithoutPrototype(Handle name, } -Handle Factory::NewSerializedScopeInfo(int length) { +Handle Factory::NewScopeInfo(int length) { CALL_HEAP_FUNCTION( isolate(), - isolate()->heap()->AllocateSerializedScopeInfo(length), - SerializedScopeInfo); + isolate()->heap()->AllocateScopeInfo(length), + ScopeInfo); } @@ -985,7 +985,7 @@ Handle Factory::NewSharedFunctionInfo( Handle name, int number_of_literals, Handle code, - Handle scope_info) { + Handle scope_info) { Handle shared = NewSharedFunctionInfo(name); shared->set_code(*code); shared->set_scope_info(*scope_info); diff --git a/src/factory.h b/src/factory.h index 2073ce3..158db5b 100644 --- a/src/factory.h +++ b/src/factory.h @@ -172,7 +172,7 @@ class Factory { // Create a 'block' context. Handle NewBlockContext(Handle function, Handle previous, - Handle scope_info); + Handle scope_info); // Return the Symbol matching the passed in string. Handle SymbolFromString(Handle value); @@ -291,7 +291,7 @@ class Factory { Handle context, PretenureFlag pretenure = TENURED); - Handle NewSerializedScopeInfo(int length); + Handle NewScopeInfo(int length); Handle NewCode(const CodeDesc& desc, Code::Flags flags, @@ -409,7 +409,7 @@ class Factory { Handle name, int number_of_literals, Handle code, - Handle scope_info); + Handle scope_info); Handle NewSharedFunctionInfo(Handle name); Handle NewJSMessageObject( diff --git a/src/frames.cc b/src/frames.cc index 7c4c573..9fd0042 100644 --- a/src/frames.cc +++ b/src/frames.cc @@ -1002,11 +1002,15 @@ void JavaScriptFrame::Print(StringStream* accumulator, if (IsConstructor()) accumulator->Add("new "); accumulator->PrintFunction(function, receiver, &code); - Handle scope_info(SerializedScopeInfo::Empty()); + // Get scope information for nicer output, if possible. If code is NULL, or + // doesn't contain scope info, scope_info will return 0 for the number of + // parameters, stack local variables, context local variables, stack slots, + // or context slots. + Handle scope_info(ScopeInfo::Empty()); if (function->IsJSFunction()) { Handle shared(JSFunction::cast(function)->shared()); - scope_info = Handle(shared->scope_info()); + scope_info = Handle(shared->scope_info()); Object* script_obj = shared->script(); if (script_obj->IsScript()) { Handle