From 6f5d9f9af268ae8fab97c8aae6289bfac7a9f9e3 Mon Sep 17 00:00:00 2001 From: "verwaest@chromium.org" Date: Fri, 31 May 2013 19:11:09 +0000 Subject: [PATCH] Move field index into property details, freeing up the value slot of fields. BUG= R=jkummerow@chromium.org Review URL: https://chromiumcodereview.appspot.com/15941016 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14909 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/handles.cc | 2 +- src/json-stringifier.h | 2 +- src/objects-inl.h | 7 +++++-- src/objects.cc | 2 -- src/property-details.h | 19 +++++++++++++++---- src/property.h | 26 +++++++++++++------------- 6 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/handles.cc b/src/handles.cc index 7a8d5c9..8b3a2db 100644 --- a/src/handles.cc +++ b/src/handles.cc @@ -802,7 +802,7 @@ Handle GetEnumPropertyKeys(Handle object, if (details.type() != FIELD) { indices = Handle(); } else { - int field_index = Descriptor::IndexFromValue(descs->GetValue(i)); + int field_index = descs->GetFieldIndex(i); if (field_index >= map->inobject_properties()) { field_index = -(field_index - map->inobject_properties() + 1); } diff --git a/src/json-stringifier.h b/src/json-stringifier.h index f548a2e..e4a978d 100644 --- a/src/json-stringifier.h +++ b/src/json-stringifier.h @@ -640,7 +640,7 @@ BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSObject( if (!name->IsString()) continue; Handle key = Handle::cast(name); PropertyDetails details = map->instance_descriptors()->GetDetails(i); - if (details.IsDontEnum() || details.IsDeleted()) continue; + if (details.IsDontEnum()) continue; Handle property; if (details.type() == FIELD && *map == object->map()) { property = Handle( diff --git a/src/objects-inl.h b/src/objects-inl.h index d0958ee..3d64383 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -58,7 +58,10 @@ PropertyDetails::PropertyDetails(Smi* smi) { Smi* PropertyDetails::AsSmi() { - return Smi::FromInt(value_); + // Ensure the upper 2 bits have the same value by sign extending it. This is + // necessary to be able to use the 31st bit of the property details. + int value = value_ << 1; + return Smi::FromInt(value >> 1); } @@ -2327,7 +2330,7 @@ PropertyType DescriptorArray::GetType(int descriptor_number) { int DescriptorArray::GetFieldIndex(int descriptor_number) { - return Descriptor::IndexFromValue(GetValue(descriptor_number)); + return GetDetails(descriptor_number).field_index(); } diff --git a/src/objects.cc b/src/objects.cc index f45945b..c94a697 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -2500,8 +2500,6 @@ Map* Map::FindLastMatchMap(int verbatim, if (details.type() != next_details.type()) break; if (details.attributes() != next_details.attributes()) break; if (!details.representation().Equals(next_details.representation())) break; - ASSERT(!details.IsDeleted()); - ASSERT(!next_details.IsDeleted()); current = next; } diff --git a/src/property-details.h b/src/property-details.h index 3bb1f33..6d0f147 100644 --- a/src/property-details.h +++ b/src/property-details.h @@ -169,10 +169,12 @@ class PropertyDetails BASE_EMBEDDED { PropertyDetails(PropertyAttributes attributes, PropertyType type, - Representation representation) { + Representation representation, + int field_index = 0) { value_ = TypeField::encode(type) | AttributesField::encode(attributes) - | RepresentationField::encode(EncodeRepresentation(representation)); + | RepresentationField::encode(EncodeRepresentation(representation)) + | FieldIndexField::encode(field_index); } int pointer() { return DescriptorPointer::decode(value_); } @@ -214,6 +216,10 @@ class PropertyDetails BASE_EMBEDDED { return DecodeRepresentation(RepresentationField::decode(value_)); } + int field_index() { + return FieldIndexField::decode(value_); + } + inline PropertyDetails AsDeleted(); static bool IsValidIndex(int index) { @@ -229,10 +235,15 @@ class PropertyDetails BASE_EMBEDDED { // constants can be embedded in generated code. class TypeField: public BitField {}; class AttributesField: public BitField {}; + + // Bit fields for normalized objects. class DeletedField: public BitField {}; class DictionaryStorageField: public BitField {}; - class DescriptorPointer: public BitField {}; - class RepresentationField: public BitField {}; + + // Bit fields for fast objects. + class DescriptorPointer: public BitField {}; + class RepresentationField: public BitField {}; + class FieldIndexField: public BitField {}; static const int kInitialIndex = 1; diff --git a/src/property.h b/src/property.h index 606f111..124775f 100644 --- a/src/property.h +++ b/src/property.h @@ -44,10 +44,6 @@ namespace internal { class Descriptor BASE_EMBEDDED { public: - static int IndexFromValue(Object* value) { - return Smi::cast(value)->value(); - } - MUST_USE_RESULT MaybeObject* KeyToUniqueName() { if (!key_->IsUniqueName()) { MaybeObject* maybe_result = HEAP->InternalizeString(String::cast(key_)); @@ -89,10 +85,11 @@ class Descriptor BASE_EMBEDDED { Object* value, PropertyAttributes attributes, PropertyType type, - Representation representation) + Representation representation, + int field_index = 0) : key_(key), value_(value), - details_(attributes, type, representation) { } + details_(attributes, type, representation, field_index) { } friend class DescriptorArray; }; @@ -104,8 +101,8 @@ class FieldDescriptor: public Descriptor { int field_index, PropertyAttributes attributes, Representation representation) - : Descriptor(key, Smi::FromInt(field_index), attributes, - FIELD, representation) {} + : Descriptor(key, Smi::FromInt(0), attributes, + FIELD, representation, field_index) {} }; @@ -311,7 +308,6 @@ class LookupResult BASE_EMBEDDED { bool IsDontDelete() { return details_.IsDontDelete(); } bool IsDontEnum() { return details_.IsDontEnum(); } - bool IsDeleted() { return details_.IsDeleted(); } bool IsFound() { return lookup_type_ != NOT_FOUND; } bool IsTransition() { return lookup_type_ == TRANSITION_TYPE; } bool IsHandler() { return lookup_type_ == HANDLER_TYPE; } @@ -417,14 +413,12 @@ class LookupResult BASE_EMBEDDED { PropertyIndex GetFieldIndex() { ASSERT(lookup_type_ == DESCRIPTOR_TYPE); ASSERT(IsField()); - return PropertyIndex::NewFieldIndex( - Descriptor::IndexFromValue(GetValue())); + return PropertyIndex::NewFieldIndex(GetFieldIndexFromMap(holder()->map())); } int GetLocalFieldIndexFromMap(Map* map) { ASSERT(IsField()); - return Descriptor::IndexFromValue(GetValueFromMap(map)) - - map->inobject_properties(); + return GetFieldIndexFromMap(map) - map->inobject_properties(); } int GetDictionaryEntry() { @@ -466,6 +460,12 @@ class LookupResult BASE_EMBEDDED { return map->instance_descriptors()->GetValue(number_); } + int GetFieldIndexFromMap(Map* map) const { + ASSERT(lookup_type_ == DESCRIPTOR_TYPE); + ASSERT(number_ < map->NumberOfOwnDescriptors()); + return map->instance_descriptors()->GetFieldIndex(number_); + } + void Iterate(ObjectVisitor* visitor); private: -- 2.7.4