Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2183)

Side by Side Diff: src/objects.cc

Issue 2632373002: [runtime] Add DescriptorArray::GeneralizeAllFields(). (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/objects.h" 5 #include "src/objects.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <iomanip> 8 #include <iomanip>
9 #include <memory> 9 #include <memory>
10 #include <sstream> 10 #include <sstream>
(...skipping 3874 matching lines...) Expand 10 before | Expand all | Expand 10 after
3885 3885
3886 int Map::NumberOfFields() { 3886 int Map::NumberOfFields() {
3887 DescriptorArray* descriptors = instance_descriptors(); 3887 DescriptorArray* descriptors = instance_descriptors();
3888 int result = 0; 3888 int result = 0;
3889 for (int i = 0; i < NumberOfOwnDescriptors(); i++) { 3889 for (int i = 0; i < NumberOfOwnDescriptors(); i++) {
3890 if (descriptors->GetDetails(i).location() == kField) result++; 3890 if (descriptors->GetDetails(i).location() == kField) result++;
3891 } 3891 }
3892 return result; 3892 return result;
3893 } 3893 }
3894 3894
3895 Handle<Map> Map::CopyGeneralizeAllRepresentations( 3895 void DescriptorArray::GeneralizeAllFields() {
3896 Handle<Map> map, ElementsKind elements_kind, int modify_index, 3896 int length = number_of_descriptors();
3897 StoreMode store_mode, PropertyKind kind, PropertyAttributes attributes, 3897 for (int i = 0; i < length; i++) {
3898 const char* reason) { 3898 PropertyDetails details = GetDetails(i);
3899 details = details.CopyWithRepresentation(Representation::Tagged());
3900 if (details.location() == kField) {
3901 DCHECK_EQ(kData, details.kind());
3902 SetValue(i, FieldType::Any());
3903 }
3904 set(ToDetailsIndex(i), details.AsSmi());
3905 }
3906 }
3907
3908 Handle<Map> Map::CopyGeneralizeAllFields(Handle<Map> map,
3909 ElementsKind elements_kind,
3910 int modify_index, StoreMode store_mode,
3911 PropertyKind kind,
3912 PropertyAttributes attributes,
3913 const char* reason) {
3899 Isolate* isolate = map->GetIsolate(); 3914 Isolate* isolate = map->GetIsolate();
3900 Handle<DescriptorArray> old_descriptors(map->instance_descriptors(), isolate); 3915 Handle<DescriptorArray> old_descriptors(map->instance_descriptors(), isolate);
3901 int number_of_own_descriptors = map->NumberOfOwnDescriptors(); 3916 int number_of_own_descriptors = map->NumberOfOwnDescriptors();
3902 Handle<DescriptorArray> descriptors = 3917 Handle<DescriptorArray> descriptors =
3903 DescriptorArray::CopyUpTo(old_descriptors, number_of_own_descriptors); 3918 DescriptorArray::CopyUpTo(old_descriptors, number_of_own_descriptors);
3904 3919 descriptors->GeneralizeAllFields();
3905 for (int i = 0; i < number_of_own_descriptors; i++) {
3906 descriptors->SetRepresentation(i, Representation::Tagged());
3907 if (descriptors->GetDetails(i).location() == kField) {
3908 DCHECK_EQ(kData, descriptors->GetDetails(i).kind());
3909 descriptors->SetValue(i, FieldType::Any());
3910 }
3911 }
3912 3920
3913 Handle<LayoutDescriptor> new_layout_descriptor( 3921 Handle<LayoutDescriptor> new_layout_descriptor(
3914 LayoutDescriptor::FastPointerLayout(), isolate); 3922 LayoutDescriptor::FastPointerLayout(), isolate);
3915 Handle<Map> new_map = CopyReplaceDescriptors( 3923 Handle<Map> new_map = CopyReplaceDescriptors(
3916 map, descriptors, new_layout_descriptor, OMIT_TRANSITION, 3924 map, descriptors, new_layout_descriptor, OMIT_TRANSITION,
3917 MaybeHandle<Name>(), reason, SPECIAL_TRANSITION); 3925 MaybeHandle<Name>(), reason, SPECIAL_TRANSITION);
3918 3926
3919 // Unless the instance is being migrated, ensure that modify_index is a field. 3927 // Unless the instance is being migrated, ensure that modify_index is a field.
3920 if (modify_index >= 0) { 3928 if (modify_index >= 0) {
3921 PropertyDetails details = descriptors->GetDetails(modify_index); 3929 PropertyDetails details = descriptors->GetDetails(modify_index);
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
4162 } 4170 }
4163 4171
4164 // TODO(ishell): remove. 4172 // TODO(ishell): remove.
4165 // static 4173 // static
4166 Handle<Map> Map::ReconfigureElementsKind(Handle<Map> map, 4174 Handle<Map> Map::ReconfigureElementsKind(Handle<Map> map,
4167 ElementsKind new_elements_kind) { 4175 ElementsKind new_elements_kind) {
4168 MapUpdater mu(map->GetIsolate(), map); 4176 MapUpdater mu(map->GetIsolate(), map);
4169 return mu.ReconfigureElementsKind(new_elements_kind); 4177 return mu.ReconfigureElementsKind(new_elements_kind);
4170 } 4178 }
4171 4179
4172 // Generalize the representation of all DATA descriptors. 4180 // Generalize all fields and update the transition tree.
4173 Handle<Map> Map::GeneralizeAllFieldRepresentations( 4181 Handle<Map> Map::GeneralizeAllFields(Handle<Map> map) {
4174 Handle<Map> map) {
4175 Isolate* isolate = map->GetIsolate(); 4182 Isolate* isolate = map->GetIsolate();
4176 Handle<FieldType> any_type = FieldType::Any(isolate); 4183 Handle<FieldType> any_type = FieldType::Any(isolate);
4177 4184
4178 Handle<DescriptorArray> descriptors(map->instance_descriptors()); 4185 Handle<DescriptorArray> descriptors(map->instance_descriptors());
4179 for (int i = 0; i < map->NumberOfOwnDescriptors(); ++i) { 4186 for (int i = 0; i < map->NumberOfOwnDescriptors(); ++i) {
4180 PropertyDetails details = descriptors->GetDetails(i); 4187 PropertyDetails details = descriptors->GetDetails(i);
4181 if (details.location() == kField) { 4188 if (details.location() == kField) {
4182 DCHECK_EQ(kData, details.kind()); 4189 DCHECK_EQ(kData, details.kind());
4183 MapUpdater mu(isolate, map); 4190 MapUpdater mu(isolate, map);
4184 map = mu.ReconfigureToDataField(i, details.attributes(), 4191 map = mu.ReconfigureToDataField(i, details.attributes(),
(...skipping 4651 matching lines...) Expand 10 before | Expand all | Expand 10 after
8836 8843
8837 if (!map->is_prototype_map()) { 8844 if (!map->is_prototype_map()) {
8838 if (flag == INSERT_TRANSITION && 8845 if (flag == INSERT_TRANSITION &&
8839 TransitionArray::CanHaveMoreTransitions(map)) { 8846 TransitionArray::CanHaveMoreTransitions(map)) {
8840 result->InitializeDescriptors(*descriptors, *layout_descriptor); 8847 result->InitializeDescriptors(*descriptors, *layout_descriptor);
8841 8848
8842 Handle<Name> name; 8849 Handle<Name> name;
8843 CHECK(maybe_name.ToHandle(&name)); 8850 CHECK(maybe_name.ToHandle(&name));
8844 ConnectTransition(map, result, name, simple_flag); 8851 ConnectTransition(map, result, name, simple_flag);
8845 } else { 8852 } else {
8846 int length = descriptors->number_of_descriptors(); 8853 descriptors->GeneralizeAllFields();
8847 for (int i = 0; i < length; i++) {
8848 descriptors->SetRepresentation(i, Representation::Tagged());
8849 if (descriptors->GetDetails(i).location() == kField) {
8850 DCHECK_EQ(kData, descriptors->GetDetails(i).kind());
8851 descriptors->SetValue(i, FieldType::Any());
8852 }
8853 }
8854 result->InitializeDescriptors(*descriptors, 8854 result->InitializeDescriptors(*descriptors,
8855 LayoutDescriptor::FastPointerLayout()); 8855 LayoutDescriptor::FastPointerLayout());
8856 } 8856 }
8857 } else { 8857 } else {
8858 result->InitializeDescriptors(*descriptors, *layout_descriptor); 8858 result->InitializeDescriptors(*descriptors, *layout_descriptor);
8859 } 8859 }
8860 #if TRACE_MAPS 8860 #if TRACE_MAPS
8861 if (FLAG_trace_maps && 8861 if (FLAG_trace_maps &&
8862 // Mirror conditions above that did not call ConnectTransition(). 8862 // Mirror conditions above that did not call ConnectTransition().
8863 (map->is_prototype_map() || 8863 (map->is_prototype_map() ||
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
9251 9251
9252 Handle<Map> Map::ReconfigureExistingProperty(Handle<Map> map, int descriptor, 9252 Handle<Map> Map::ReconfigureExistingProperty(Handle<Map> map, int descriptor,
9253 PropertyKind kind, 9253 PropertyKind kind,
9254 PropertyAttributes attributes) { 9254 PropertyAttributes attributes) {
9255 // Dictionaries have to be reconfigured in-place. 9255 // Dictionaries have to be reconfigured in-place.
9256 DCHECK(!map->is_dictionary_map()); 9256 DCHECK(!map->is_dictionary_map());
9257 9257
9258 if (!map->GetBackPointer()->IsMap()) { 9258 if (!map->GetBackPointer()->IsMap()) {
9259 // There is no benefit from reconstructing transition tree for maps without 9259 // There is no benefit from reconstructing transition tree for maps without
9260 // back pointers. 9260 // back pointers.
9261 return CopyGeneralizeAllRepresentations( 9261 return CopyGeneralizeAllFields(map, map->elements_kind(), descriptor,
9262 map, map->elements_kind(), descriptor, FORCE_FIELD, kind, attributes, 9262 FORCE_FIELD, kind, attributes,
9263 "GenAll_AttributesMismatchProtoMap"); 9263 "GenAll_AttributesMismatchProtoMap");
9264 } 9264 }
9265 9265
9266 if (FLAG_trace_generalization) { 9266 if (FLAG_trace_generalization) {
9267 map->PrintReconfiguration(stdout, descriptor, kind, attributes); 9267 map->PrintReconfiguration(stdout, descriptor, kind, attributes);
9268 } 9268 }
9269 9269
9270 Isolate* isolate = map->GetIsolate(); 9270 Isolate* isolate = map->GetIsolate();
9271 9271
9272 MapUpdater mu(isolate, map); 9272 MapUpdater mu(isolate, map);
9273 DCHECK_EQ(kData, kind); // Only kData case is supported so far. 9273 DCHECK_EQ(kData, kind); // Only kData case is supported so far.
(...skipping 10627 matching lines...) Expand 10 before | Expand all | Expand 10 after
19901 // depend on this. 19901 // depend on this.
19902 return DICTIONARY_ELEMENTS; 19902 return DICTIONARY_ELEMENTS;
19903 } 19903 }
19904 DCHECK_LE(kind, LAST_ELEMENTS_KIND); 19904 DCHECK_LE(kind, LAST_ELEMENTS_KIND);
19905 return kind; 19905 return kind;
19906 } 19906 }
19907 } 19907 }
19908 19908
19909 } // namespace internal 19909 } // namespace internal
19910 } // namespace v8 19910 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698