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

Side by Side Diff: src/objects.cc

Issue 409603002: Reduce usage of StoreMode. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « src/objects.h ('k') | src/runtime.cc » ('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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/allocation-site-scopes.h" 8 #include "src/allocation-site-scopes.h"
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/arguments.h" 10 #include "src/arguments.h"
(...skipping 1851 matching lines...) Expand 10 before | Expand all | Expand 10 after
1862 value = cell; 1862 value = cell;
1863 } 1863 }
1864 PropertyDetails details = PropertyDetails(attributes, NORMAL, 0); 1864 PropertyDetails details = PropertyDetails(attributes, NORMAL, 0);
1865 Handle<NameDictionary> result = 1865 Handle<NameDictionary> result =
1866 NameDictionary::Add(dict, name, value, details); 1866 NameDictionary::Add(dict, name, value, details);
1867 if (*dict != *result) object->set_properties(*result); 1867 if (*dict != *result) object->set_properties(*result);
1868 } 1868 }
1869 1869
1870 1870
1871 MaybeHandle<Object> JSObject::AddPropertyInternal( 1871 MaybeHandle<Object> JSObject::AddPropertyInternal(
1872 Handle<JSObject> object, 1872 Handle<JSObject> object, Handle<Name> name, Handle<Object> value,
1873 Handle<Name> name, 1873 PropertyAttributes attributes, StoreMode mode,
Igor Sheludko 2014/07/21 12:17:31 The |mode| parameter is not used. Lets remove it a
1874 Handle<Object> value,
1875 PropertyAttributes attributes,
1876 StrictMode strict_mode,
1877 JSReceiver::StoreFromKeyed store_mode, 1874 JSReceiver::StoreFromKeyed store_mode,
1878 ExtensibilityCheck extensibility_check, 1875 ExtensibilityCheck extensibility_check, TransitionFlag transition_flag) {
1879 StoreMode mode,
1880 TransitionFlag transition_flag) {
1881 ASSERT(!object->IsJSGlobalProxy()); 1876 ASSERT(!object->IsJSGlobalProxy());
1882 Isolate* isolate = object->GetIsolate(); 1877 Isolate* isolate = object->GetIsolate();
1883 1878
1884 if (!name->IsUniqueName()) { 1879 if (!name->IsUniqueName()) {
1885 name = isolate->factory()->InternalizeString( 1880 name = isolate->factory()->InternalizeString(
1886 Handle<String>::cast(name)); 1881 Handle<String>::cast(name));
1887 } 1882 }
1888 1883
1889 if (extensibility_check == PERFORM_EXTENSIBILITY_CHECK && 1884 if (extensibility_check == PERFORM_EXTENSIBILITY_CHECK &&
1890 !object->map()->is_extensible()) { 1885 !object->map()->is_extensible()) {
1891 if (strict_mode == SLOPPY) { 1886 Handle<Object> args[1] = {name};
1892 return value; 1887 Handle<Object> error = isolate->factory()->NewTypeError(
1893 } else { 1888 "object_not_extensible", HandleVector(args, ARRAY_SIZE(args)));
1894 Handle<Object> args[1] = { name }; 1889 return isolate->Throw<Object>(error);
1895 Handle<Object> error = isolate->factory()->NewTypeError(
1896 "object_not_extensible", HandleVector(args, ARRAY_SIZE(args)));
1897 return isolate->Throw<Object>(error);
1898 }
1899 } 1890 }
1900 1891
1901 if (object->HasFastProperties()) { 1892 if (object->HasFastProperties()) {
1902 AddFastProperty(object, name, value, attributes, store_mode, 1893 AddFastProperty(object, name, value, attributes, store_mode,
1903 transition_flag); 1894 transition_flag);
1904 } 1895 }
1905 1896
1906 if (!object->HasFastProperties()) { 1897 if (!object->HasFastProperties()) {
1907 AddSlowProperty(object, name, value, attributes); 1898 AddSlowProperty(object, name, value, attributes);
1908 } 1899 }
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
2252 2243
2253 // We are storing the new map using release store after creating a filler for 2244 // We are storing the new map using release store after creating a filler for
2254 // the left-over space to avoid races with the sweeper thread. 2245 // the left-over space to avoid races with the sweeper thread.
2255 object->synchronized_set_map(*new_map); 2246 object->synchronized_set_map(*new_map);
2256 } 2247 }
2257 2248
2258 2249
2259 void JSObject::GeneralizeFieldRepresentation(Handle<JSObject> object, 2250 void JSObject::GeneralizeFieldRepresentation(Handle<JSObject> object,
2260 int modify_index, 2251 int modify_index,
2261 Representation new_representation, 2252 Representation new_representation,
2262 Handle<HeapType> new_field_type, 2253 Handle<HeapType> new_field_type) {
2263 StoreMode store_mode) {
2264 Handle<Map> new_map = Map::GeneralizeRepresentation( 2254 Handle<Map> new_map = Map::GeneralizeRepresentation(
2265 handle(object->map()), modify_index, new_representation, 2255 handle(object->map()), modify_index, new_representation, new_field_type,
2266 new_field_type, store_mode); 2256 FORCE_FIELD);
2267 MigrateToMap(object, new_map); 2257 MigrateToMap(object, new_map);
2268 } 2258 }
2269 2259
2270 2260
2271 int Map::NumberOfFields() { 2261 int Map::NumberOfFields() {
2272 DescriptorArray* descriptors = instance_descriptors(); 2262 DescriptorArray* descriptors = instance_descriptors();
2273 int result = 0; 2263 int result = 0;
2274 for (int i = 0; i < NumberOfOwnDescriptors(); i++) { 2264 for (int i = 0; i < NumberOfOwnDescriptors(); i++) {
2275 if (descriptors->GetDetails(i).type() == FIELD) result++; 2265 if (descriptors->GetDetails(i).type() == FIELD) result++;
2276 } 2266 }
(...skipping 1708 matching lines...) Expand 10 before | Expand all | Expand 10 after
3985 int descriptor = transition_map->LastAdded(); 3975 int descriptor = transition_map->LastAdded();
3986 3976
3987 Handle<DescriptorArray> descriptors(transition_map->instance_descriptors()); 3977 Handle<DescriptorArray> descriptors(transition_map->instance_descriptors());
3988 PropertyDetails details = descriptors->GetDetails(descriptor); 3978 PropertyDetails details = descriptors->GetDetails(descriptor);
3989 3979
3990 if (details.type() == CALLBACKS || attributes != details.attributes()) { 3980 if (details.type() == CALLBACKS || attributes != details.attributes()) {
3991 // AddPropertyInternal will either normalize the object, or create a new 3981 // AddPropertyInternal will either normalize the object, or create a new
3992 // fast copy of the map. If we get a fast copy of the map, all field 3982 // fast copy of the map. If we get a fast copy of the map, all field
3993 // representations will be tagged since the transition is omitted. 3983 // representations will be tagged since the transition is omitted.
3994 return JSObject::AddPropertyInternal( 3984 return JSObject::AddPropertyInternal(
3995 object, name, value, attributes, SLOPPY, 3985 object, name, value, attributes, FORCE_FIELD,
3996 JSReceiver::CERTAINLY_NOT_STORE_FROM_KEYED, 3986 JSReceiver::CERTAINLY_NOT_STORE_FROM_KEYED,
3997 JSReceiver::OMIT_EXTENSIBILITY_CHECK, FORCE_FIELD, OMIT_TRANSITION); 3987 JSReceiver::OMIT_EXTENSIBILITY_CHECK, OMIT_TRANSITION);
3998 } 3988 }
3999 3989
4000 // Keep the target CONSTANT if the same value is stored. 3990 // Keep the target CONSTANT if the same value is stored.
4001 // TODO(verwaest): Also support keeping the placeholder 3991 // TODO(verwaest): Also support keeping the placeholder
4002 // (value->IsUninitialized) as constant. 3992 // (value->IsUninitialized) as constant.
4003 if (!lookup->CanHoldValue(value)) { 3993 if (!lookup->CanHoldValue(value)) {
4004 Representation field_representation = value->OptimalRepresentation(); 3994 Representation field_representation = value->OptimalRepresentation();
4005 Handle<HeapType> field_type = value->OptimalType( 3995 Handle<HeapType> field_type = value->OptimalType(
4006 lookup->isolate(), field_representation); 3996 lookup->isolate(), field_representation);
4007 transition_map = Map::GeneralizeRepresentation( 3997 transition_map = Map::GeneralizeRepresentation(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
4044 } 4034 }
4045 4035
4046 4036
4047 void JSObject::SetPropertyToField(LookupResult* lookup, Handle<Object> value) { 4037 void JSObject::SetPropertyToField(LookupResult* lookup, Handle<Object> value) {
4048 if (lookup->type() == CONSTANT || !lookup->CanHoldValue(value)) { 4038 if (lookup->type() == CONSTANT || !lookup->CanHoldValue(value)) {
4049 Representation field_representation = value->OptimalRepresentation(); 4039 Representation field_representation = value->OptimalRepresentation();
4050 Handle<HeapType> field_type = value->OptimalType( 4040 Handle<HeapType> field_type = value->OptimalType(
4051 lookup->isolate(), field_representation); 4041 lookup->isolate(), field_representation);
4052 JSObject::GeneralizeFieldRepresentation(handle(lookup->holder()), 4042 JSObject::GeneralizeFieldRepresentation(handle(lookup->holder()),
4053 lookup->GetDescriptorIndex(), 4043 lookup->GetDescriptorIndex(),
4054 field_representation, field_type, 4044 field_representation, field_type);
4055 FORCE_FIELD);
4056 } 4045 }
4057 lookup->holder()->WriteToField(lookup->GetDescriptorIndex(), *value); 4046 lookup->holder()->WriteToField(lookup->GetDescriptorIndex(), *value);
4058 } 4047 }
4059 4048
4060 4049
4061 void JSObject::ConvertAndSetOwnProperty(LookupResult* lookup, 4050 void JSObject::ConvertAndSetOwnProperty(LookupResult* lookup,
4062 Handle<Name> name, 4051 Handle<Name> name,
4063 Handle<Object> value, 4052 Handle<Object> value,
4064 PropertyAttributes attributes) { 4053 PropertyAttributes attributes) {
4065 Handle<JSObject> object(lookup->holder()); 4054 Handle<JSObject> object(lookup->holder());
4066 if (object->map()->TooManyFastProperties(Object::MAY_BE_STORE_FROM_KEYED)) { 4055 if (object->map()->TooManyFastProperties(Object::MAY_BE_STORE_FROM_KEYED)) {
4067 JSObject::NormalizeProperties(object, CLEAR_INOBJECT_PROPERTIES, 0); 4056 JSObject::NormalizeProperties(object, CLEAR_INOBJECT_PROPERTIES, 0);
4068 } 4057 }
4069 4058
4070 if (!object->HasFastProperties()) { 4059 if (!object->HasFastProperties()) {
4071 ReplaceSlowProperty(object, name, value, attributes); 4060 ReplaceSlowProperty(object, name, value, attributes);
4072 return; 4061 return;
4073 } 4062 }
4074 4063
4075 int descriptor_index = lookup->GetDescriptorIndex(); 4064 int descriptor_index = lookup->GetDescriptorIndex();
4076 if (lookup->GetAttributes() == attributes) { 4065 if (lookup->GetAttributes() == attributes) {
4077 JSObject::GeneralizeFieldRepresentation( 4066 JSObject::GeneralizeFieldRepresentation(object, descriptor_index,
4078 object, descriptor_index, Representation::Tagged(), 4067 Representation::Tagged(),
4079 HeapType::Any(lookup->isolate()), FORCE_FIELD); 4068 HeapType::Any(lookup->isolate()));
4080 } else { 4069 } else {
4081 Handle<Map> old_map(object->map()); 4070 Handle<Map> old_map(object->map());
4082 Handle<Map> new_map = Map::CopyGeneralizeAllRepresentations(old_map, 4071 Handle<Map> new_map = Map::CopyGeneralizeAllRepresentations(old_map,
4083 descriptor_index, FORCE_FIELD, attributes, "attributes mismatch"); 4072 descriptor_index, FORCE_FIELD, attributes, "attributes mismatch");
4084 JSObject::MigrateToMap(object, new_map); 4073 JSObject::MigrateToMap(object, new_map);
4085 } 4074 }
4086 4075
4087 object->WriteToField(descriptor_index, *value); 4076 object->WriteToField(descriptor_index, *value);
4088 } 4077 }
4089 4078
4090 4079
4091 void JSObject::SetPropertyToFieldWithAttributes(LookupResult* lookup, 4080 void JSObject::SetPropertyToFieldWithAttributes(LookupResult* lookup,
4092 Handle<Name> name, 4081 Handle<Name> name,
4093 Handle<Object> value, 4082 Handle<Object> value,
4094 PropertyAttributes attributes) { 4083 PropertyAttributes attributes) {
4095 if (lookup->GetAttributes() == attributes) { 4084 if (lookup->GetAttributes() == attributes) {
4096 if (value->IsUninitialized()) return; 4085 if (value->IsUninitialized()) return;
4097 SetPropertyToField(lookup, value); 4086 SetPropertyToField(lookup, value);
4098 } else { 4087 } else {
4099 ConvertAndSetOwnProperty(lookup, name, value, attributes); 4088 ConvertAndSetOwnProperty(lookup, name, value, attributes);
4100 } 4089 }
4101 } 4090 }
4102 4091
4103 4092
4104 void JSObject::AddProperty( 4093 void JSObject::AddProperty(Handle<JSObject> object, Handle<Name> name,
4105 Handle<JSObject> object, 4094 Handle<Object> value,
4106 Handle<Name> name, 4095 PropertyAttributes attributes) {
4107 Handle<Object> value,
4108 PropertyAttributes attributes,
4109 StoreMode store_mode) {
4110 #ifdef DEBUG 4096 #ifdef DEBUG
4111 uint32_t index; 4097 uint32_t index;
4112 ASSERT(!object->IsJSProxy()); 4098 ASSERT(!object->IsJSProxy());
4113 ASSERT(!name->AsArrayIndex(&index)); 4099 ASSERT(!name->AsArrayIndex(&index));
4114 LookupIterator it(object, name, LookupIterator::CHECK_OWN_REAL); 4100 LookupIterator it(object, name, LookupIterator::CHECK_OWN_REAL);
4115 GetPropertyAttributes(&it); 4101 GetPropertyAttributes(&it);
4116 ASSERT(!it.IsFound()); 4102 ASSERT(!it.IsFound());
4117 ASSERT(object->map()->is_extensible()); 4103 ASSERT(object->map()->is_extensible());
4118 #endif 4104 #endif
4119 SetOwnPropertyIgnoreAttributes(object, name, value, attributes, store_mode, 4105 SetOwnPropertyIgnoreAttributes(object, name, value, attributes,
4120 OMIT_EXTENSIBILITY_CHECK).Check(); 4106 OMIT_EXTENSIBILITY_CHECK).Check();
4121 } 4107 }
4122 4108
4123 4109
4124 // Reconfigures a property to a data property with attributes, even if it is not 4110 // Reconfigures a property to a data property with attributes, even if it is not
4125 // reconfigurable. 4111 // reconfigurable.
4126 MaybeHandle<Object> JSObject::SetOwnPropertyIgnoreAttributes( 4112 MaybeHandle<Object> JSObject::SetOwnPropertyIgnoreAttributes(
4127 Handle<JSObject> object, 4113 Handle<JSObject> object,
4128 Handle<Name> name, 4114 Handle<Name> name,
4129 Handle<Object> value, 4115 Handle<Object> value,
4130 PropertyAttributes attributes, 4116 PropertyAttributes attributes,
4131 StoreMode mode,
4132 ExtensibilityCheck extensibility_check, 4117 ExtensibilityCheck extensibility_check,
4133 StoreFromKeyed store_from_keyed, 4118 StoreFromKeyed store_from_keyed,
4134 ExecutableAccessorInfoHandling handling) { 4119 ExecutableAccessorInfoHandling handling) {
4135 ASSERT(!value->IsTheHole()); 4120 ASSERT(!value->IsTheHole());
4136 Isolate* isolate = object->GetIsolate(); 4121 Isolate* isolate = object->GetIsolate();
4137 4122
4138 // Make sure that the top context does not change when doing callbacks or 4123 // Make sure that the top context does not change when doing callbacks or
4139 // interceptor calls. 4124 // interceptor calls.
4140 AssertNoContextChange ncc(isolate); 4125 AssertNoContextChange ncc(isolate);
4141 4126
(...skipping 10 matching lines...) Expand all
4152 return SetPropertyWithFailedAccessCheck(&it, value, SLOPPY); 4137 return SetPropertyWithFailedAccessCheck(&it, value, SLOPPY);
4153 } 4138 }
4154 } 4139 }
4155 4140
4156 if (object->IsJSGlobalProxy()) { 4141 if (object->IsJSGlobalProxy()) {
4157 PrototypeIterator iter(isolate, object); 4142 PrototypeIterator iter(isolate, object);
4158 if (iter.IsAtEnd()) return value; 4143 if (iter.IsAtEnd()) return value;
4159 ASSERT(PrototypeIterator::GetCurrent(iter)->IsJSGlobalObject()); 4144 ASSERT(PrototypeIterator::GetCurrent(iter)->IsJSGlobalObject());
4160 return SetOwnPropertyIgnoreAttributes( 4145 return SetOwnPropertyIgnoreAttributes(
4161 Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)), name, 4146 Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)), name,
4162 value, attributes, mode, extensibility_check); 4147 value, attributes, extensibility_check);
4163 } 4148 }
4164 4149
4165 if (lookup.IsInterceptor() || 4150 if (lookup.IsInterceptor() ||
4166 (lookup.IsDescriptorOrDictionary() && lookup.type() == CALLBACKS)) { 4151 (lookup.IsDescriptorOrDictionary() && lookup.type() == CALLBACKS)) {
4167 object->LookupOwnRealNamedProperty(name, &lookup); 4152 object->LookupOwnRealNamedProperty(name, &lookup);
4168 } 4153 }
4169 4154
4170 // Check for accessor in prototype chain removed here in clone. 4155 // Check for accessor in prototype chain removed here in clone.
4171 if (!lookup.IsFound()) { 4156 if (!lookup.IsFound()) {
4172 object->map()->LookupTransition(*object, *name, &lookup); 4157 object->map()->LookupTransition(*object, *name, &lookup);
4173 TransitionFlag flag = lookup.IsFound() 4158 TransitionFlag flag = lookup.IsFound()
4174 ? OMIT_TRANSITION : INSERT_TRANSITION; 4159 ? OMIT_TRANSITION : INSERT_TRANSITION;
4175 // Neither properties nor transitions found. 4160 // Neither properties nor transitions found.
4176 return AddPropertyInternal(object, name, value, attributes, SLOPPY, 4161 return AddPropertyInternal(object, name, value, attributes,
4177 store_from_keyed, extensibility_check, mode, 4162 ALLOW_AS_CONSTANT, store_from_keyed,
4178 flag); 4163 extensibility_check, flag);
4179 } 4164 }
4180 4165
4181 Handle<Object> old_value = isolate->factory()->the_hole_value(); 4166 Handle<Object> old_value = isolate->factory()->the_hole_value();
4182 PropertyAttributes old_attributes = ABSENT; 4167 PropertyAttributes old_attributes = ABSENT;
4183 bool is_observed = object->map()->is_observed() && 4168 bool is_observed = object->map()->is_observed() &&
4184 *name != isolate->heap()->hidden_string(); 4169 *name != isolate->heap()->hidden_string();
4185 if (is_observed && lookup.IsProperty()) { 4170 if (is_observed && lookup.IsProperty()) {
4186 if (lookup.IsDataProperty()) { 4171 if (lookup.IsDataProperty()) {
4187 old_value = Object::GetPropertyOrElement(object, name).ToHandleChecked(); 4172 old_value = Object::GetPropertyOrElement(object, name).ToHandleChecked();
4188 } 4173 }
(...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after
5134 int sorted_index = descriptors->GetSortedKeyIndex(0); 5119 int sorted_index = descriptors->GetSortedKeyIndex(0);
5135 if (descriptors->GetKey(sorted_index) == isolate->heap()->hidden_string() 5120 if (descriptors->GetKey(sorted_index) == isolate->heap()->hidden_string()
5136 && sorted_index < object->map()->NumberOfOwnDescriptors()) { 5121 && sorted_index < object->map()->NumberOfOwnDescriptors()) {
5137 object->WriteToField(sorted_index, *value); 5122 object->WriteToField(sorted_index, *value);
5138 return object; 5123 return object;
5139 } 5124 }
5140 } 5125 }
5141 } 5126 }
5142 5127
5143 SetOwnPropertyIgnoreAttributes(object, isolate->factory()->hidden_string(), 5128 SetOwnPropertyIgnoreAttributes(object, isolate->factory()->hidden_string(),
5144 value, DONT_ENUM, ALLOW_AS_CONSTANT, 5129 value, DONT_ENUM,
5145 OMIT_EXTENSIBILITY_CHECK).Assert(); 5130 OMIT_EXTENSIBILITY_CHECK).Assert();
5146 return object; 5131 return object;
5147 } 5132 }
5148 5133
5149 5134
5150 Handle<Object> JSObject::DeletePropertyPostInterceptor(Handle<JSObject> object, 5135 Handle<Object> JSObject::DeletePropertyPostInterceptor(Handle<JSObject> object,
5151 Handle<Name> name, 5136 Handle<Name> name,
5152 DeleteMode mode) { 5137 DeleteMode mode) {
5153 // Check own property, ignore interceptor. 5138 // Check own property, ignore interceptor.
5154 Isolate* isolate = object->GetIsolate(); 5139 Isolate* isolate = object->GetIsolate();
(...skipping 11800 matching lines...) Expand 10 before | Expand all | Expand 10 after
16955 #define ERROR_MESSAGES_TEXTS(C, T) T, 16940 #define ERROR_MESSAGES_TEXTS(C, T) T,
16956 static const char* error_messages_[] = { 16941 static const char* error_messages_[] = {
16957 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 16942 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
16958 }; 16943 };
16959 #undef ERROR_MESSAGES_TEXTS 16944 #undef ERROR_MESSAGES_TEXTS
16960 return error_messages_[reason]; 16945 return error_messages_[reason];
16961 } 16946 }
16962 16947
16963 16948
16964 } } // namespace v8::internal 16949 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698