Chromium Code Reviews| Index: src/layout-descriptor.cc |
| diff --git a/src/layout-descriptor.cc b/src/layout-descriptor.cc |
| index 121836c173f9a70a73acc35633f646dfbb76539e..4bb48c0585249eade387436c487357b4a1c8f838 100644 |
| --- a/src/layout-descriptor.cc |
| +++ b/src/layout-descriptor.cc |
| @@ -19,55 +19,22 @@ Handle<LayoutDescriptor> LayoutDescriptor::New( |
| Isolate* isolate = descriptors->GetIsolate(); |
| if (!FLAG_unbox_double_fields) return handle(FastPointerLayout(), isolate); |
| - int inobject_properties = map->inobject_properties(); |
| - if (inobject_properties == 0) return handle(FastPointerLayout(), isolate); |
| + int layout_descriptor_length = |
| + CalculateCapacity(*map, *descriptors, num_descriptors); |
| - DCHECK(num_descriptors <= descriptors->number_of_descriptors()); |
| - |
| - int layout_descriptor_length; |
| - const int kMaxWordsPerField = kDoubleSize / kPointerSize; |
| - |
| - if (num_descriptors <= kSmiValueSize / kMaxWordsPerField) { |
| - // Even in the "worst" case (all fields are doubles) it would fit into |
| - // a Smi, so no need to calculate length. |
| - layout_descriptor_length = kSmiValueSize; |
| - |
| - } else { |
| - layout_descriptor_length = 0; |
| - |
| - for (int i = 0; i < num_descriptors; i++) { |
| - PropertyDetails details = descriptors->GetDetails(i); |
| - if (!InobjectUnboxedField(inobject_properties, details)) continue; |
| - int field_index = details.field_index(); |
| - int field_width_in_words = details.field_width_in_words(); |
| - layout_descriptor_length = |
| - Max(layout_descriptor_length, field_index + field_width_in_words); |
| - } |
| - |
| - if (layout_descriptor_length == 0) { |
| - // No double fields were found, use fast pointer layout. |
| - return handle(FastPointerLayout(), isolate); |
| - } |
| + if (layout_descriptor_length == 0) { |
| + // No double fields were found, use fast pointer layout. |
| + return handle(FastPointerLayout(), isolate); |
| } |
| - layout_descriptor_length = Min(layout_descriptor_length, inobject_properties); |
| // Initially, layout descriptor corresponds to an object with all fields |
| // tagged. |
| Handle<LayoutDescriptor> layout_descriptor_handle = |
| LayoutDescriptor::New(isolate, layout_descriptor_length); |
| - DisallowHeapAllocation no_allocation; |
| - LayoutDescriptor* layout_descriptor = *layout_descriptor_handle; |
| - |
| - for (int i = 0; i < num_descriptors; i++) { |
| - PropertyDetails details = descriptors->GetDetails(i); |
| - if (!InobjectUnboxedField(inobject_properties, details)) continue; |
| - int field_index = details.field_index(); |
| - layout_descriptor = layout_descriptor->SetRawData(field_index); |
| - if (details.field_width_in_words() > 1) { |
| - layout_descriptor = layout_descriptor->SetRawData(field_index + 1); |
| - } |
| - } |
| + LayoutDescriptor* layout_descriptor = Initialize( |
| + *layout_descriptor_handle, *map, *descriptors, num_descriptors); |
| + |
| return handle(layout_descriptor, isolate); |
| } |
| @@ -258,13 +225,44 @@ bool LayoutDescriptorHelper::IsTagged( |
| } |
| -bool LayoutDescriptor::IsConsistentWithMap(Map* map) { |
| +LayoutDescriptor* LayoutDescriptor::Trim(Heap* heap, Map* map, |
| + DescriptorArray* descriptors, |
| + int num_descriptors) { |
| + DisallowHeapAllocation no_allocation; |
| + // Fast mode descriptors are never shared and therefore always fully |
| + // correspond to their map. |
| + if (!IsSlowLayout()) return this; |
| + |
| + int layout_descriptor_length = |
| + CalculateCapacity(map, descriptors, num_descriptors); |
| + // It must not become fast-mode descriptor here, because otherwise it has to |
| + // be fast pointer layout descriptor already but it's is slow mode now. |
| + DCHECK_LT(kSmiValueSize, layout_descriptor_length); |
| + |
| + // Trim, clean and reinitialize this slow-mode layout descriptor. |
| + int array_length = GetSlowModeBackingStoreLength(layout_descriptor_length); |
| + int current_length = length(); |
| + if (current_length != array_length) { |
| + DCHECK_LT(array_length, current_length); |
| + int delta = current_length - array_length; |
| + heap->RightTrimFixedArray<Heap::FROM_GC>(this, delta); |
|
Toon Verwaest
2015/03/30 16:10:21
I hope DataSize() is updated here? Otherwise you'l
Igor Sheludko
2015/03/30 16:33:27
Yes, sure! It's length() * elements_size, essentia
|
| + } |
| + memset(DataPtr(), 0, DataSize()); |
| + LayoutDescriptor* layout_descriptor = |
| + Initialize(this, map, descriptors, num_descriptors); |
| + DCHECK_EQ(this, layout_descriptor); |
| + return layout_descriptor; |
| +} |
| + |
| + |
| +bool LayoutDescriptor::IsConsistentWithMap(Map* map, bool check_tail) { |
| if (FLAG_unbox_double_fields) { |
| DescriptorArray* descriptors = map->instance_descriptors(); |
| int nof_descriptors = map->NumberOfOwnDescriptors(); |
| + int last_field_index = 0; |
| for (int i = 0; i < nof_descriptors; i++) { |
| PropertyDetails details = descriptors->GetDetails(i); |
| - if (details.type() != DATA) continue; |
| + if (details.location() != kField) continue; |
| FieldIndex field_index = FieldIndex::ForDescriptor(map, i); |
| bool tagged_expected = |
| !field_index.is_inobject() || !details.representation().IsDouble(); |
| @@ -273,6 +271,15 @@ bool LayoutDescriptor::IsConsistentWithMap(Map* map) { |
| DCHECK_EQ(tagged_expected, tagged_actual); |
| if (tagged_actual != tagged_expected) return false; |
| } |
| + last_field_index = |
| + Max(last_field_index, |
| + details.field_index() + details.field_width_in_words()); |
| + } |
| + if (check_tail) { |
| + int n = capacity(); |
| + for (int i = last_field_index; i < n; i++) { |
| + DCHECK(IsTagged(i)); |
| + } |
| } |
| } |
| return true; |