Commit e2cc4baa authored by verwaest@chromium.org's avatar verwaest@chromium.org

Use the initial map of the Object function for empty object literals

BUG=
R=jkummerow@chromium.org

Review URL: https://codereview.chromium.org/586673002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24088 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 5d0b12db
...@@ -483,12 +483,14 @@ Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) { ...@@ -483,12 +483,14 @@ Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) {
{ // --- O b j e c t --- { // --- O b j e c t ---
Handle<JSFunction> object_fun = factory->NewFunction(object_name); Handle<JSFunction> object_fun = factory->NewFunction(object_name);
int unused = JSObject::kInitialGlobalObjectUnusedPropertiesCount;
int instance_size = JSObject::kHeaderSize + kPointerSize * unused;
Handle<Map> object_function_map = Handle<Map> object_function_map =
factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); factory->NewMap(JS_OBJECT_TYPE, instance_size);
object_function_map->set_inobject_properties(unused);
JSFunction::SetInitialMap(object_fun, object_function_map, JSFunction::SetInitialMap(object_fun, object_function_map,
isolate->factory()->null_value()); isolate->factory()->null_value());
object_function_map->set_unused_property_fields( object_function_map->set_unused_property_fields(unused);
JSObject::kInitialGlobalObjectUnusedPropertiesCount);
native_context()->set_object_function(*object_fun); native_context()->set_object_function(*object_fun);
...@@ -1153,11 +1155,8 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> global_object, ...@@ -1153,11 +1155,8 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> global_object,
{ // Set up the iterator result object { // Set up the iterator result object
STATIC_ASSERT(JSGeneratorObject::kResultPropertyCount == 2); STATIC_ASSERT(JSGeneratorObject::kResultPropertyCount == 2);
Handle<JSFunction> object_function(native_context()->object_function()); Handle<JSFunction> object_function(native_context()->object_function());
DCHECK(object_function->initial_map()->inobject_properties() == 0);
Handle<Map> iterator_result_map = Handle<Map> iterator_result_map =
Map::Create(object_function, JSGeneratorObject::kResultPropertyCount); Map::Create(object_function, JSGeneratorObject::kResultPropertyCount);
DCHECK(iterator_result_map->inobject_properties() ==
JSGeneratorObject::kResultPropertyCount);
Map::EnsureDescriptorSlack(iterator_result_map, Map::EnsureDescriptorSlack(iterator_result_map,
JSGeneratorObject::kResultPropertyCount); JSGeneratorObject::kResultPropertyCount);
...@@ -1171,7 +1170,12 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> global_object, ...@@ -1171,7 +1170,12 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> global_object,
NONE, Representation::Tagged()); NONE, Representation::Tagged());
iterator_result_map->AppendDescriptor(&done_descr); iterator_result_map->AppendDescriptor(&done_descr);
iterator_result_map->set_instance_size(JSGeneratorObject::kResultSize);
iterator_result_map->set_unused_property_fields(0); iterator_result_map->set_unused_property_fields(0);
iterator_result_map->set_inobject_properties(
JSGeneratorObject::kResultPropertyCount);
iterator_result_map->set_pre_allocated_property_fields(
JSGeneratorObject::kResultPropertyCount);
DCHECK_EQ(JSGeneratorObject::kResultSize, DCHECK_EQ(JSGeneratorObject::kResultSize,
iterator_result_map->instance_size()); iterator_result_map->instance_size());
native_context()->set_iterator_result_map(*iterator_result_map); native_context()->set_iterator_result_map(*iterator_result_map);
......
...@@ -2328,9 +2328,12 @@ Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context, ...@@ -2328,9 +2328,12 @@ Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context,
Handle<MapCache>(MapCache::cast(context->map_cache())); Handle<MapCache>(MapCache::cast(context->map_cache()));
Handle<Object> result = Handle<Object>(cache->Lookup(*keys), isolate()); Handle<Object> result = Handle<Object>(cache->Lookup(*keys), isolate());
if (result->IsMap()) return Handle<Map>::cast(result); if (result->IsMap()) return Handle<Map>::cast(result);
// Create a new map and add it to the cache. int length = keys->length();
Handle<Map> map = Map::Create( // Create a new map and add it to the cache. Reuse the initial map of the
handle(context->object_function()), keys->length()); // Object function if the literal has no predeclared properties.
Handle<Map> map =
length == 0 ? handle(context->object_function()->initial_map())
: Map::Create(handle(context->object_function()), length);
AddToMapCache(context, keys, map); AddToMapCache(context, keys, map);
return map; return map;
} }
......
...@@ -11001,7 +11001,8 @@ HInstruction* HOptimizedGraphBuilder::BuildFastLiteral( ...@@ -11001,7 +11001,8 @@ HInstruction* HOptimizedGraphBuilder::BuildFastLiteral(
} }
// Copy in-object properties. // Copy in-object properties.
if (boilerplate_object->map()->NumberOfFields() != 0) { if (boilerplate_object->map()->NumberOfFields() != 0 ||
boilerplate_object->map()->unused_property_fields() > 0) {
BuildEmitInObjectProperties(boilerplate_object, object, site_context, BuildEmitInObjectProperties(boilerplate_object, object, site_context,
pretenure_flag); pretenure_flag);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment