Chromium Code Reviews| Index: src/objects.cc |
| diff --git a/src/objects.cc b/src/objects.cc |
| index f66275a3ae46d1f802db1e313190d11a6b201698..2432dd2d87165f57e6dc77319240bbc20e613ab7 100644 |
| --- a/src/objects.cc |
| +++ b/src/objects.cc |
| @@ -4761,10 +4761,9 @@ void JSObject::TransformToFastProperties(Handle<JSObject> object, |
| int unused_property_fields) { |
| if (object->HasFastProperties()) return; |
| ASSERT(!object->IsGlobalObject()); |
| - CALL_HEAP_FUNCTION_VOID( |
| - object->GetIsolate(), |
| - object->property_dictionary()->TransformPropertiesToFastFor( |
| - *object, unused_property_fields)); |
| + Handle<NameDictionary> dictionary(object->property_dictionary()); |
| + NameDictionary::TransformPropertiesToFastFor( |
| + dictionary, object, unused_property_fields); |
| } |
| @@ -6830,23 +6829,17 @@ Handle<Map> Map::CopyNormalized(Handle<Map> map, |
| Handle<Map> Map::CopyDropDescriptors(Handle<Map> map) { |
| - CALL_HEAP_FUNCTION(map->GetIsolate(), map->CopyDropDescriptors(), Map); |
| -} |
| - |
| - |
| -MaybeObject* Map::CopyDropDescriptors() { |
| - Map* result; |
| - MaybeObject* maybe_result = RawCopy(instance_size()); |
| - if (!maybe_result->To(&result)) return maybe_result; |
| + Handle<Map> result = RawCopy(map, map->instance_size()); |
| // Please note instance_type and instance_size are set when allocated. |
| - result->set_inobject_properties(inobject_properties()); |
| - result->set_unused_property_fields(unused_property_fields()); |
| + result->set_inobject_properties(map->inobject_properties()); |
| + result->set_unused_property_fields(map->unused_property_fields()); |
| - result->set_pre_allocated_property_fields(pre_allocated_property_fields()); |
| + result->set_pre_allocated_property_fields( |
| + map->pre_allocated_property_fields()); |
| result->set_is_shared(false); |
| - result->ClearCodeCache(GetHeap()); |
| - NotifyLeafMapLayoutChange(); |
| + result->ClearCodeCache(map->GetHeap()); |
| + map->NotifyLeafMapLayoutChange(); |
| return result; |
| } |
| @@ -15591,30 +15584,33 @@ Object* Dictionary<Shape, Key>::SlowReverseLookup(Object* value) { |
| } |
| -MaybeObject* NameDictionary::TransformPropertiesToFastFor( |
| - JSObject* obj, int unused_property_fields) { |
| +void NameDictionary::TransformPropertiesToFastFor( |
| + Handle<NameDictionary> dictionary, |
| + Handle<JSObject> obj, |
| + int unused_property_fields) { |
| // Make sure we preserve dictionary representation if there are too many |
| // descriptors. |
| - int number_of_elements = NumberOfElements(); |
| - if (number_of_elements > kMaxNumberOfDescriptors) return obj; |
| + int number_of_elements = dictionary->NumberOfElements(); |
| + if (number_of_elements > kMaxNumberOfDescriptors) return; |
| - if (number_of_elements != NextEnumerationIndex()) { |
| - MaybeObject* maybe_result = GenerateNewEnumerationIndices(); |
| - if (maybe_result->IsFailure()) return maybe_result; |
| + if (number_of_elements != dictionary->NextEnumerationIndex()) { |
| + NameDictionary::DoGenerateNewEnumerationIndices(dictionary); |
| } |
| int instance_descriptor_length = 0; |
| int number_of_fields = 0; |
| - Heap* heap = GetHeap(); |
| + Isolate* isolate = dictionary->GetIsolate(); |
| + Factory* factory = isolate->factory(); |
| + Heap* heap = isolate->heap(); |
| // Compute the length of the instance descriptor. |
| - int capacity = Capacity(); |
| + int capacity = dictionary->Capacity(); |
| for (int i = 0; i < capacity; i++) { |
| - Object* k = KeyAt(i); |
| - if (IsKey(k)) { |
| - Object* value = ValueAt(i); |
| - PropertyType type = DetailsAt(i).type(); |
| + Object* k = dictionary->KeyAt(i); |
| + if (dictionary->IsKey(k)) { |
| + Object* value = dictionary->ValueAt(i); |
| + PropertyType type = dictionary->DetailsAt(i).type(); |
| ASSERT(type != FIELD); |
| instance_descriptor_length++; |
| if (type == NORMAL && !value->IsJSFunction()) { |
| @@ -15626,31 +15622,23 @@ MaybeObject* NameDictionary::TransformPropertiesToFastFor( |
| int inobject_props = obj->map()->inobject_properties(); |
| // Allocate new map. |
| - Map* new_map; |
| - MaybeObject* maybe_new_map = obj->map()->CopyDropDescriptors(); |
| - if (!maybe_new_map->To(&new_map)) return maybe_new_map; |
| + Handle<Map> new_map = Map::CopyDropDescriptors(handle(obj->map())); |
| new_map->set_dictionary_map(false); |
| if (instance_descriptor_length == 0) { |
| ASSERT_LE(unused_property_fields, inobject_props); |
|
Toon Verwaest
2014/04/11 10:37:59
DisallowHeapAllocation no_gc; while committing the
|
| // Transform the object. |
| new_map->set_unused_property_fields(inobject_props); |
| - obj->set_map(new_map); |
| + obj->set_map(*new_map); |
| obj->set_properties(heap->empty_fixed_array()); |
| // Check that it really works. |
| ASSERT(obj->HasFastProperties()); |
| - return obj; |
| + return; |
| } |
| // Allocate the instance descriptor. |
| - DescriptorArray* descriptors; |
| - MaybeObject* maybe_descriptors = |
| - DescriptorArray::Allocate(GetIsolate(), instance_descriptor_length); |
| - if (!maybe_descriptors->To(&descriptors)) { |
| - return maybe_descriptors; |
| - } |
| - |
| - DescriptorArray::WhitenessWitness witness(descriptors); |
| + Handle<DescriptorArray> descriptors = factory->NewDescriptorArray( |
| + instance_descriptor_length); |
| int number_of_allocated_fields = |
| number_of_fields + unused_property_fields - inobject_props; |
| @@ -15661,36 +15649,33 @@ MaybeObject* NameDictionary::TransformPropertiesToFastFor( |
| } |
| // Allocate the fixed array for the fields. |
| - FixedArray* fields; |
| - MaybeObject* maybe_fields = |
| - heap->AllocateFixedArray(number_of_allocated_fields); |
| - if (!maybe_fields->To(&fields)) return maybe_fields; |
| + Handle<FixedArray> fields = factory->NewFixedArray( |
| + number_of_allocated_fields); |
| // Fill in the instance descriptor and the fields. |
| int current_offset = 0; |
| for (int i = 0; i < capacity; i++) { |
| - Object* k = KeyAt(i); |
| - if (IsKey(k)) { |
| - Object* value = ValueAt(i); |
| - Name* key; |
| + Object* k = dictionary->KeyAt(i); |
| + if (dictionary->IsKey(k)) { |
| + Object* value = dictionary->ValueAt(i); |
| + Handle<Name> key; |
| if (k->IsSymbol()) { |
| - key = Symbol::cast(k); |
| + key = handle(Symbol::cast(k)); |
| } else { |
| // Ensure the key is a unique name before writing into the |
| // instance descriptor. |
| - MaybeObject* maybe_key = heap->InternalizeString(String::cast(k)); |
| - if (!maybe_key->To(&key)) return maybe_key; |
| + key = factory->InternalizeString(handle(String::cast(k))); |
| } |
| - PropertyDetails details = DetailsAt(i); |
| + PropertyDetails details = dictionary->DetailsAt(i); |
| int enumeration_index = details.dictionary_index(); |
| PropertyType type = details.type(); |
| if (value->IsJSFunction()) { |
| - ConstantDescriptor d(handle(key), |
| - handle(value, GetIsolate()), |
| + ConstantDescriptor d(key, |
| + handle(value, isolate), |
| details.attributes()); |
| - descriptors->Set(enumeration_index - 1, &d, witness); |
| + descriptors->Set(enumeration_index - 1, &d); |
| } else if (type == NORMAL) { |
| if (current_offset < inobject_props) { |
| obj->InObjectPropertyAtPut(current_offset, |
| @@ -15700,17 +15685,17 @@ MaybeObject* NameDictionary::TransformPropertiesToFastFor( |
| int offset = current_offset - inobject_props; |
| fields->set(offset, value); |
| } |
| - FieldDescriptor d(handle(key), |
| + FieldDescriptor d(key, |
| current_offset++, |
| details.attributes(), |
| // TODO(verwaest): value->OptimalRepresentation(); |
| Representation::Tagged()); |
| - descriptors->Set(enumeration_index - 1, &d, witness); |
| + descriptors->Set(enumeration_index - 1, &d); |
| } else if (type == CALLBACKS) { |
| - CallbacksDescriptor d(handle(key), |
| - handle(value, GetIsolate()), |
| + CallbacksDescriptor d(key, |
| + handle(value, isolate), |
| details.attributes()); |
| - descriptors->Set(enumeration_index - 1, &d, witness); |
| + descriptors->Set(enumeration_index - 1, &d); |
| } else { |
| UNREACHABLE(); |
| } |
| @@ -15720,19 +15705,17 @@ MaybeObject* NameDictionary::TransformPropertiesToFastFor( |
| descriptors->Sort(); |
|
Toon Verwaest
2014/04/11 10:37:59
DisallowHeapAllocation no_gc while committing stat
mvstanton
2014/04/11 11:25:20
Done.
|
| - new_map->InitializeDescriptors(descriptors); |
| + new_map->InitializeDescriptors(*descriptors); |
| new_map->set_unused_property_fields(unused_property_fields); |
| // Transform the object. |
| - obj->set_map(new_map); |
| + obj->set_map(*new_map); |
| - obj->set_properties(fields); |
| + obj->set_properties(*fields); |
| ASSERT(obj->IsJSObject()); |
| // Check that it really works. |
| ASSERT(obj->HasFastProperties()); |
| - |
| - return obj; |
| } |