From db233217043ac3c9f3b467caab3daea241be8e51 Mon Sep 17 00:00:00 2001 From: "kaznacheev@chromium.org" Date: Wed, 14 Jul 2010 11:18:09 +0000 Subject: [PATCH] Create a separate class to encapsulate ScopeInfo serialization. The static ScopeInfo members moved into this class. The new class is named ScopeInfoObject which I am not proud of, better ideas are very welcome. Also got rid of the sentinels in the serialized scope info which saves 3 words per function and is not slower. Review URL: http://codereview.chromium.org/2908009 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5067 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/accessors.cc | 4 +- src/compiler.cc | 10 +- src/contexts.cc | 22 +-- src/factory.cc | 2 +- src/factory.h | 2 +- src/frames.cc | 4 +- src/globals.h | 1 + src/heap.cc | 2 +- src/objects-inl.h | 14 +- src/objects.h | 2 +- src/parser.cc | 6 +- src/profile-generator.cc | 7 +- src/runtime.cc | 53 +++-- src/scopeinfo.cc | 407 ++++++++++++++++++--------------------- src/scopeinfo.h | 119 ++++++------ 15 files changed, 320 insertions(+), 335 deletions(-) diff --git a/src/accessors.cc b/src/accessors.cc index 9fbfe56dae..ed0bbd7a1c 100644 --- a/src/accessors.cc +++ b/src/accessors.cc @@ -549,8 +549,8 @@ Object* Accessors::FunctionGetArguments(Object* object, void*) { if (frame->function() != *function) continue; // If there is an arguments variable in the stack, we return that. - int index = ScopeInfo<>::StackSlotIndex(function->shared()->scope_info(), - Heap::arguments_symbol()); + int index = function->shared()->scope_info()-> + StackSlotIndex(Heap::arguments_symbol()); if (index >= 0) { Handle arguments = Handle(frame->GetExpression(index)); if (!arguments->IsTheHole()) return *arguments; diff --git a/src/compiler.cc b/src/compiler.cc index ec6b5ffb4a..0d1fe9952b 100755 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -160,7 +160,7 @@ Handle MakeCodeForLiveEdit(CompilationInfo* info) { Handle code = MakeCode(context, info); if (!info->shared_info().is_null()) { info->shared_info()->set_scope_info( - *ScopeInfo<>::CreateHeapObject(info->scope())); + *SerializedScopeInfo::Create(info->scope())); } return code; } @@ -262,7 +262,7 @@ static Handle MakeFunctionInfo(bool is_global, lit->name(), lit->materialized_literal_count(), code, - ScopeInfo<>::CreateHeapObject(info.scope())); + SerializedScopeInfo::Create(info.scope())); ASSERT_EQ(RelocInfo::kNoPosition, lit->function_token_position()); Compiler::SetFunctionInfo(result, lit, true, script); @@ -450,7 +450,7 @@ bool Compiler::CompileLazy(CompilationInfo* info) { // Update the shared function info with the compiled code and the scope info. shared->set_code(*code); - shared->set_scope_info(*ScopeInfo<>::CreateHeapObject(info->scope())); + shared->set_scope_info(*SerializedScopeInfo::Create(info->scope())); // Set the expected number of properties for instances. SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); @@ -485,7 +485,7 @@ Handle Compiler::BuildFunctionInfo(FunctionLiteral* literal, bool allow_lazy = literal->AllowsLazyCompilation() && !LiveEditFunctionTracker::IsActive(); - Handle scope_info(ScopeInfo<>::EmptyHeapObject()); + Handle scope_info(SerializedScopeInfo::Empty()); // Generate code Handle code; @@ -568,7 +568,7 @@ Handle Compiler::BuildFunctionInfo(FunctionLiteral* literal, literal->start_position(), script, code); - scope_info = ScopeInfo<>::CreateHeapObject(info.scope()); + scope_info = SerializedScopeInfo::Create(info.scope()); } // Create a shared function info object. diff --git a/src/contexts.cc b/src/contexts.cc index 1eab24c28e..723354fc84 100644 --- a/src/contexts.cc +++ b/src/contexts.cc @@ -120,9 +120,10 @@ Handle Context::Lookup(Handle name, ContextLookupFlags flags, // we have context-local slots // check non-parameter locals in context - Handle scope_info(context->closure()->shared()->scope_info()); + Handle scope_info( + context->closure()->shared()->scope_info()); Variable::Mode mode; - int index = ScopeInfo<>::ContextSlotIndex(*scope_info, *name, &mode); + int index = scope_info->ContextSlotIndex(*name, &mode); ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS); if (index >= 0) { // slot found @@ -150,13 +151,11 @@ Handle Context::Lookup(Handle name, ContextLookupFlags flags, } // check parameter locals in context - int param_index = ScopeInfo<>::ParameterIndex(*scope_info, *name); + int param_index = scope_info->ParameterIndex(*name); if (param_index >= 0) { // slot found. int index = - ScopeInfo<>::ContextSlotIndex(*scope_info, - Heap::arguments_shadow_symbol(), - NULL); + scope_info->ContextSlotIndex(Heap::arguments_shadow_symbol(), NULL); ASSERT(index >= 0); // arguments must exist and be in the heap context Handle arguments(JSObject::cast(context->get(index))); ASSERT(arguments->HasLocalProperty(Heap::length_symbol())); @@ -170,7 +169,7 @@ Handle Context::Lookup(Handle name, ContextLookupFlags flags, // check intermediate context (holding only the function name variable) if (follow_context_chain) { - int index = ScopeInfo<>::FunctionContextSlotIndex(*scope_info, *name); + int index = scope_info->FunctionContextSlotIndex(*name); if (index >= 0) { // slot found if (FLAG_trace_contexts) { @@ -216,18 +215,19 @@ bool Context::GlobalIfNotShadowedByEval(Handle name) { ASSERT(context->is_function_context()); // Check non-parameter locals. - Handle scope_info(context->closure()->shared()->scope_info()); + Handle scope_info( + context->closure()->shared()->scope_info()); Variable::Mode mode; - int index = ScopeInfo<>::ContextSlotIndex(*scope_info, *name, &mode); + int index = scope_info->ContextSlotIndex(*name, &mode); ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS); if (index >= 0) return false; // Check parameter locals. - int param_index = ScopeInfo<>::ParameterIndex(*scope_info, *name); + int param_index = scope_info->ParameterIndex(*name); if (param_index >= 0) return false; // Check context only holding the function name variable. - index = ScopeInfo<>::FunctionContextSlotIndex(*scope_info, *name); + index = scope_info->FunctionContextSlotIndex(*name); if (index >= 0) return false; context = Context::cast(context->closure()->context()); } diff --git a/src/factory.cc b/src/factory.cc index 18be639f39..d65338385e 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -684,7 +684,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 0576d74a6e..22511121cb 100644 --- a/src/factory.h +++ b/src/factory.h @@ -351,7 +351,7 @@ class Factory : public AllStatic { Handle name, int number_of_literals, Handle code, - Handle scope_info); + Handle scope_info); static Handle NewSharedFunctionInfo(Handle name); static Handle DictionaryAtNumberPut( diff --git a/src/frames.cc b/src/frames.cc index 8b601b67b7..bdd5100ed8 100644 --- a/src/frames.cc +++ b/src/frames.cc @@ -532,11 +532,11 @@ void JavaScriptFrame::Print(StringStream* accumulator, if (IsConstructor()) accumulator->Add("new "); accumulator->PrintFunction(function, receiver, &code); - Handle scope_info(ScopeInfo<>::EmptyHeapObject()); + Handle scope_info(SerializedScopeInfo::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