From ea89d6bd29bc4a02312ba65a15f5634c02ce1bf0 Mon Sep 17 00:00:00 2001 From: "mstarzinger@chromium.org" Date: Tue, 5 Nov 2013 12:32:03 +0000 Subject: [PATCH] Handlify Heap::AllocateInitialMap method. R=rossberg@chromium.org BUG=v8:2877 Review URL: https://codereview.chromium.org/32003006 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17482 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/factory.cc | 6 ------ src/factory.h | 2 -- src/heap.cc | 42 ------------------------------------------ src/heap.h | 3 --- src/objects.cc | 39 ++++++++++++++++++++++++++++++++++++--- 5 files changed, 36 insertions(+), 56 deletions(-) diff --git a/src/factory.cc b/src/factory.cc index 7886627..400132e 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -583,12 +583,6 @@ Handle Factory::NewFunctionPrototype(Handle function) { } -Handle Factory::NewInitialMap(Handle function) { - CALL_HEAP_FUNCTION( - isolate(), isolate()->heap()->AllocateInitialMap(*function), Map); -} - - Handle Factory::CopyWithPreallocatedFieldDescriptors(Handle src) { CALL_HEAP_FUNCTION( isolate(), src->CopyWithPreallocatedFieldDescriptors(), Map); diff --git a/src/factory.h b/src/factory.h index 2e02ed1..d7761b9 100644 --- a/src/factory.h +++ b/src/factory.h @@ -263,8 +263,6 @@ class Factory { Handle NewFunctionPrototype(Handle function); - Handle NewInitialMap(Handle function); - Handle CopyWithPreallocatedFieldDescriptors(Handle map); // Copy the map adding more inobject properties if possible without diff --git a/src/heap.cc b/src/heap.cc index 7f5d323..ecd959d 100644 --- a/src/heap.cc +++ b/src/heap.cc @@ -4492,48 +4492,6 @@ MaybeObject* Heap::AllocateArgumentsObject(Object* callee, int length) { } -MaybeObject* Heap::AllocateInitialMap(JSFunction* fun) { - ASSERT(!fun->has_initial_map()); - - // First create a new map with the size and number of in-object properties - // suggested by the function. - InstanceType instance_type; - int instance_size; - int in_object_properties; - if (fun->shared()->is_generator()) { - instance_type = JS_GENERATOR_OBJECT_TYPE; - instance_size = JSGeneratorObject::kSize; - in_object_properties = 0; - } else { - instance_type = JS_OBJECT_TYPE; - instance_size = fun->shared()->CalculateInstanceSize(); - in_object_properties = fun->shared()->CalculateInObjectProperties(); - } - Map* map; - MaybeObject* maybe_map = AllocateMap(instance_type, instance_size); - if (!maybe_map->To(&map)) return maybe_map; - - // Fetch or allocate prototype. - Object* prototype; - if (fun->has_instance_prototype()) { - prototype = fun->instance_prototype(); - } else { - MaybeObject* maybe_prototype = AllocateFunctionPrototype(fun); - if (!maybe_prototype->To(&prototype)) return maybe_prototype; - } - map->set_inobject_properties(in_object_properties); - map->set_unused_property_fields(in_object_properties); - map->set_prototype(prototype); - ASSERT(map->has_fast_object_elements()); - - if (!fun->shared()->is_generator()) { - fun->shared()->StartInobjectSlackTracking(map); - } - - return map; -} - - void Heap::InitializeJSObjectFromMap(JSObject* obj, FixedArray* properties, Map* map) { diff --git a/src/heap.h b/src/heap.h index a18525c..fc0a215 100644 --- a/src/heap.h +++ b/src/heap.h @@ -744,9 +744,6 @@ class Heap { MUST_USE_RESULT MaybeObject* AllocatePartialMap(InstanceType instance_type, int instance_size); - // Allocate a map for the specified function - MUST_USE_RESULT MaybeObject* AllocateInitialMap(JSFunction* fun); - // Allocates an empty code cache. MUST_USE_RESULT MaybeObject* AllocateCodeCache(); diff --git a/src/objects.cc b/src/objects.cc index cc73995..8bb603a 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -9899,9 +9899,42 @@ void JSFunction::RemovePrototype() { void JSFunction::EnsureHasInitialMap(Handle function) { if (function->has_initial_map()) return; Isolate* isolate = function->GetIsolate(); - Handle initial_map = isolate->factory()->NewInitialMap(function); - function->set_initial_map(*initial_map); - initial_map->set_constructor(*function); + + // First create a new map with the size and number of in-object properties + // suggested by the function. + InstanceType instance_type; + int instance_size; + int in_object_properties; + if (function->shared()->is_generator()) { + instance_type = JS_GENERATOR_OBJECT_TYPE; + instance_size = JSGeneratorObject::kSize; + in_object_properties = 0; + } else { + instance_type = JS_OBJECT_TYPE; + instance_size = function->shared()->CalculateInstanceSize(); + in_object_properties = function->shared()->CalculateInObjectProperties(); + } + Handle map = isolate->factory()->NewMap(instance_type, instance_size); + + // Fetch or allocate prototype. + Handle prototype; + if (function->has_instance_prototype()) { + prototype = handle(function->instance_prototype(), isolate); + } else { + prototype = isolate->factory()->NewFunctionPrototype(function); + } + map->set_inobject_properties(in_object_properties); + map->set_unused_property_fields(in_object_properties); + map->set_prototype(*prototype); + ASSERT(map->has_fast_object_elements()); + + if (!function->shared()->is_generator()) { + function->shared()->StartInobjectSlackTracking(*map); + } + + // Finally link initial map and constructor function. + function->set_initial_map(*map); + map->set_constructor(*function); } -- 2.7.4