From 10714e29fa1ea1cefd6f9e17ffa7f40981488ceb Mon Sep 17 00:00:00 2001 From: "verwaest@chromium.org" Date: Wed, 16 Apr 2014 11:11:21 +0000 Subject: [PATCH] Introduce an abstraction to write to a field. BUG= R=ishell@chromium.org Review URL: https://codereview.chromium.org/236063016 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20792 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/objects.cc | 74 ++++++++++++++++++-------------------------------- src/objects.h | 5 ++++ 2 files changed, 32 insertions(+), 47 deletions(-) diff --git a/src/objects.cc b/src/objects.cc index 7094de13f1..a603bac852 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -1907,22 +1907,7 @@ void JSObject::AddFastProperty(Handle object, return; } - JSObject::MigrateToMap(object, new_map); - - PropertyDetails details = new_map->GetLastDescriptorDetails(); - if (details.type() != FIELD) return; - - Representation representation = details.representation(); - int index = details.field_index(); - - if (representation.IsDouble()) { - // Nothing more to be done. - if (value->IsUninitialized()) return; - HeapNumber* box = HeapNumber::cast(object->RawFastPropertyAt(index)); - box->set_value(value->Number()); - } else { - object->FastPropertyAtPut(index, *value); - } + JSObject::MigrateToNewProperty(object, new_map, value); } @@ -3954,31 +3939,42 @@ MaybeHandle JSObject::SetPropertyUsingTransition( field_representation, field_type, FORCE_FIELD); } - JSObject::MigrateToMap(object, transition_map); + JSObject::MigrateToNewProperty(object, transition_map, value); + return value; +} - // Reload. - descriptors = handle(transition_map->instance_descriptors()); - details = descriptors->GetDetails(descriptor); - if (details.type() != FIELD) return value; +void JSObject::MigrateToNewProperty(Handle object, + Handle map, + Handle value) { + JSObject::MigrateToMap(object, map); + if (map->GetLastDescriptorDetails().type() != FIELD) return; + object->WriteToField(map->LastAdded(), *value); +} - int field_index = descriptors->GetFieldIndex(descriptor); + +void JSObject::WriteToField(int descriptor, Object* value) { + DisallowHeapAllocation no_gc; + + DescriptorArray* desc = map()->instance_descriptors(); + PropertyDetails details = desc->GetDetails(descriptor); + + ASSERT(details.type() == FIELD); + + int field_index = desc->GetFieldIndex(descriptor); if (details.representation().IsDouble()) { // Nothing more to be done. - if (value->IsUninitialized()) return value; - HeapNumber* box = HeapNumber::cast(object->RawFastPropertyAt(field_index)); + if (value->IsUninitialized()) return; + HeapNumber* box = HeapNumber::cast(RawFastPropertyAt(field_index)); box->set_value(value->Number()); } else { - object->FastPropertyAtPut(field_index, *value); + FastPropertyAtPut(field_index, value); } - - return value; } static void SetPropertyToField(LookupResult* lookup, Handle value) { - Representation representation = lookup->representation(); if (lookup->type() == CONSTANT || !lookup->CanHoldValue(value)) { Representation field_representation = value->OptimalRepresentation(); Handle field_type = value->OptimalType( @@ -3987,20 +3983,8 @@ static void SetPropertyToField(LookupResult* lookup, lookup->GetDescriptorIndex(), field_representation, field_type, FORCE_FIELD); - DescriptorArray* desc = lookup->holder()->map()->instance_descriptors(); - int descriptor = lookup->GetDescriptorIndex(); - representation = desc->GetDetails(descriptor).representation(); } - - if (representation.IsDouble()) { - HeapNumber* storage = HeapNumber::cast(lookup->holder()->RawFastPropertyAt( - lookup->GetFieldIndex().field_index())); - storage->set_value(value->Number()); - return; - } - - lookup->holder()->FastPropertyAtPut( - lookup->GetFieldIndex().field_index(), *value); + lookup->holder()->WriteToField(lookup->GetDescriptorIndex(), *value); } @@ -4030,9 +4014,7 @@ static void ConvertAndSetLocalProperty(LookupResult* lookup, JSObject::MigrateToMap(object, new_map); } - DescriptorArray* descriptors = object->map()->instance_descriptors(); - int index = descriptors->GetDetails(descriptor_index).field_index(); - object->FastPropertyAtPut(index, *value); + object->WriteToField(descriptor_index, *value); } @@ -5227,9 +5209,7 @@ Handle JSObject::SetHiddenPropertiesHashTable(Handle object, int sorted_index = descriptors->GetSortedKeyIndex(0); if (descriptors->GetKey(sorted_index) == isolate->heap()->hidden_string() && sorted_index < object->map()->NumberOfOwnDescriptors()) { - ASSERT(descriptors->GetType(sorted_index) == FIELD); - object->FastPropertyAtPut(descriptors->GetFieldIndex(sorted_index), - *value); + object->WriteToField(sorted_index, *value); return object; } } diff --git a/src/objects.h b/src/objects.h index 985472bc9c..31ee16c66d 100644 --- a/src/objects.h +++ b/src/objects.h @@ -2610,6 +2610,7 @@ class JSObject: public JSReceiver { int index); inline Object* RawFastPropertyAt(int index); inline void FastPropertyAtPut(int index, Object* value); + void WriteToField(int descriptor, Object* value); // Access to in object properties. inline int GetInObjectPropertyOffset(int index); @@ -2900,6 +2901,10 @@ class JSObject: public JSReceiver { ValueType value_type, TransitionFlag flag); + static void MigrateToNewProperty(Handle object, + Handle transition, + Handle value); + // Add a property to a slow-case object. static void AddSlowProperty(Handle object, Handle name,