OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 2038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2049 | 2049 |
2050 MaybeObject* JSObject::ConvertTransitionToMapTransition( | 2050 MaybeObject* JSObject::ConvertTransitionToMapTransition( |
2051 int transition_index, | 2051 int transition_index, |
2052 Name* name, | 2052 Name* name, |
2053 Object* new_value, | 2053 Object* new_value, |
2054 PropertyAttributes attributes) { | 2054 PropertyAttributes attributes) { |
2055 Map* old_map = map(); | 2055 Map* old_map = map(); |
2056 Map* old_target = old_map->GetTransition(transition_index); | 2056 Map* old_target = old_map->GetTransition(transition_index); |
2057 Object* result; | 2057 Object* result; |
2058 | 2058 |
2059 MaybeObject* maybe_result = | 2059 MaybeObject* maybe_result = ConvertDescriptorToField( |
2060 ConvertDescriptorToField(name, new_value, attributes); | 2060 name, new_value, attributes, OMIT_TRANSITION_KEEP_REPRESENTATIONS); |
2061 if (!maybe_result->To(&result)) return maybe_result; | 2061 if (!maybe_result->To(&result)) return maybe_result; |
2062 | 2062 |
2063 if (!HasFastProperties()) return result; | 2063 if (!HasFastProperties()) return result; |
2064 | 2064 |
2065 // This method should only be used to convert existing transitions. | 2065 // This method should only be used to convert existing transitions. |
2066 Map* new_map = map(); | 2066 Map* new_map = map(); |
2067 | 2067 |
2068 // TODO(verwaest): From here on we lose existing map transitions, causing | 2068 // TODO(verwaest): From here on we lose existing map transitions, causing |
2069 // invalid back pointers. This will change once we can store multiple | 2069 // invalid back pointers. This will change once we can store multiple |
2070 // transitions with the same key. | 2070 // transitions with the same key. |
(...skipping 20 matching lines...) Expand all Loading... |
2091 old_target->DeprecateTransitionTree(); | 2091 old_target->DeprecateTransitionTree(); |
2092 | 2092 |
2093 old_map->SetTransition(transition_index, new_map); | 2093 old_map->SetTransition(transition_index, new_map); |
2094 new_map->SetBackPointer(old_map); | 2094 new_map->SetBackPointer(old_map); |
2095 return result; | 2095 return result; |
2096 } | 2096 } |
2097 | 2097 |
2098 | 2098 |
2099 MaybeObject* JSObject::ConvertDescriptorToField(Name* name, | 2099 MaybeObject* JSObject::ConvertDescriptorToField(Name* name, |
2100 Object* new_value, | 2100 Object* new_value, |
2101 PropertyAttributes attributes) { | 2101 PropertyAttributes attributes, |
| 2102 TransitionFlag flag) { |
2102 if (map()->unused_property_fields() == 0 && | 2103 if (map()->unused_property_fields() == 0 && |
2103 TooManyFastProperties(properties()->length(), MAY_BE_STORE_FROM_KEYED)) { | 2104 TooManyFastProperties(properties()->length(), MAY_BE_STORE_FROM_KEYED)) { |
2104 Object* obj; | 2105 Object* obj; |
2105 MaybeObject* maybe_obj = NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0); | 2106 MaybeObject* maybe_obj = NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0); |
2106 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 2107 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
2107 return ReplaceSlowProperty(name, new_value, attributes); | 2108 return ReplaceSlowProperty(name, new_value, attributes); |
2108 } | 2109 } |
2109 | 2110 |
2110 Representation representation = IsJSContextExtensionObject() | 2111 Representation representation = IsJSContextExtensionObject() |
2111 ? Representation::Tagged() : new_value->OptimalRepresentation(); | 2112 ? Representation::Tagged() : new_value->OptimalRepresentation(); |
2112 int index = map()->NextFreePropertyIndex(); | 2113 int index = map()->NextFreePropertyIndex(); |
2113 FieldDescriptor new_field(name, index, attributes, representation); | 2114 FieldDescriptor new_field(name, index, attributes, representation); |
2114 | 2115 |
2115 // Make a new map for the object. | 2116 // Make a new map for the object. |
2116 Map* new_map; | 2117 Map* new_map; |
2117 MaybeObject* maybe_new_map = map()->CopyInsertDescriptor(&new_field, | 2118 MaybeObject* maybe_new_map = map()->CopyInsertDescriptor(&new_field, flag); |
2118 OMIT_TRANSITION); | |
2119 if (!maybe_new_map->To(&new_map)) return maybe_new_map; | 2119 if (!maybe_new_map->To(&new_map)) return maybe_new_map; |
2120 | 2120 |
2121 // Make new properties array if necessary. | 2121 // Make new properties array if necessary. |
2122 FixedArray* new_properties = NULL; | 2122 FixedArray* new_properties = NULL; |
2123 int new_unused_property_fields = map()->unused_property_fields() - 1; | 2123 int new_unused_property_fields = map()->unused_property_fields() - 1; |
2124 if (map()->unused_property_fields() == 0) { | 2124 if (map()->unused_property_fields() == 0) { |
2125 new_unused_property_fields = kFieldsAdded - 1; | 2125 new_unused_property_fields = kFieldsAdded - 1; |
2126 MaybeObject* maybe_new_properties = | 2126 MaybeObject* maybe_new_properties = |
2127 properties()->CopySize(properties()->length() + kFieldsAdded); | 2127 properties()->CopySize(properties()->length() + kFieldsAdded); |
2128 if (!maybe_new_properties->To(&new_properties)) return maybe_new_properties; | 2128 if (!maybe_new_properties->To(&new_properties)) return maybe_new_properties; |
(...skipping 4253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6382 SimpleTransitionFlag simple_flag = | 6382 SimpleTransitionFlag simple_flag = |
6383 (descriptor_index == descriptors->number_of_descriptors() - 1) | 6383 (descriptor_index == descriptors->number_of_descriptors() - 1) |
6384 ? SIMPLE_TRANSITION | 6384 ? SIMPLE_TRANSITION |
6385 : FULL_TRANSITION; | 6385 : FULL_TRANSITION; |
6386 ASSERT(name == descriptors->GetKey(descriptor_index)); | 6386 ASSERT(name == descriptors->GetKey(descriptor_index)); |
6387 MaybeObject* maybe_transitions = AddTransition(name, result, simple_flag); | 6387 MaybeObject* maybe_transitions = AddTransition(name, result, simple_flag); |
6388 if (!maybe_transitions->To(&transitions)) return maybe_transitions; | 6388 if (!maybe_transitions->To(&transitions)) return maybe_transitions; |
6389 | 6389 |
6390 set_transitions(transitions); | 6390 set_transitions(transitions); |
6391 result->SetBackPointer(this); | 6391 result->SetBackPointer(this); |
6392 } else { | 6392 } else if (flag != OMIT_TRANSITION_KEEP_REPRESENTATIONS) { |
6393 descriptors->InitializeRepresentations(Representation::Tagged()); | 6393 descriptors->InitializeRepresentations(Representation::Tagged()); |
6394 } | 6394 } |
6395 | 6395 |
6396 return result; | 6396 return result; |
6397 } | 6397 } |
6398 | 6398 |
6399 | 6399 |
| 6400 // Since this method is used to rewrite an existing transition tree, it can |
| 6401 // always insert transitions without checking. |
6400 MaybeObject* Map::CopyInstallDescriptors(int new_descriptor, | 6402 MaybeObject* Map::CopyInstallDescriptors(int new_descriptor, |
6401 DescriptorArray* descriptors) { | 6403 DescriptorArray* descriptors) { |
6402 ASSERT(descriptors->IsSortedNoDuplicates()); | 6404 ASSERT(descriptors->IsSortedNoDuplicates()); |
6403 | 6405 |
6404 Map* result; | 6406 Map* result; |
6405 MaybeObject* maybe_result = CopyDropDescriptors(); | 6407 MaybeObject* maybe_result = CopyDropDescriptors(); |
6406 if (!maybe_result->To(&result)) return maybe_result; | 6408 if (!maybe_result->To(&result)) return maybe_result; |
6407 | 6409 |
6408 result->InitializeDescriptors(descriptors); | 6410 result->InitializeDescriptors(descriptors); |
6409 result->SetNumberOfOwnDescriptors(new_descriptor + 1); | 6411 result->SetNumberOfOwnDescriptors(new_descriptor + 1); |
6410 | 6412 |
6411 int unused_property_fields = this->unused_property_fields(); | 6413 int unused_property_fields = this->unused_property_fields(); |
6412 if (descriptors->GetDetails(new_descriptor).type() == FIELD) { | 6414 if (descriptors->GetDetails(new_descriptor).type() == FIELD) { |
6413 unused_property_fields = this->unused_property_fields() - 1; | 6415 unused_property_fields = this->unused_property_fields() - 1; |
6414 if (unused_property_fields < 0) { | 6416 if (unused_property_fields < 0) { |
6415 unused_property_fields += JSObject::kFieldsAdded; | 6417 unused_property_fields += JSObject::kFieldsAdded; |
6416 } | 6418 } |
6417 } | 6419 } |
6418 | 6420 |
6419 result->set_unused_property_fields(unused_property_fields); | 6421 result->set_unused_property_fields(unused_property_fields); |
6420 result->set_owns_descriptors(false); | 6422 result->set_owns_descriptors(false); |
6421 | 6423 |
6422 if (CanHaveMoreTransitions()) { | 6424 Name* name = descriptors->GetKey(new_descriptor); |
6423 Name* name = descriptors->GetKey(new_descriptor); | 6425 TransitionArray* transitions; |
6424 TransitionArray* transitions; | 6426 MaybeObject* maybe_transitions = |
6425 MaybeObject* maybe_transitions = | 6427 AddTransition(name, result, SIMPLE_TRANSITION); |
6426 AddTransition(name, result, SIMPLE_TRANSITION); | 6428 if (!maybe_transitions->To(&transitions)) return maybe_transitions; |
6427 if (!maybe_transitions->To(&transitions)) return maybe_transitions; | |
6428 | 6429 |
6429 set_transitions(transitions); | 6430 set_transitions(transitions); |
6430 result->SetBackPointer(this); | 6431 result->SetBackPointer(this); |
6431 } else { | |
6432 descriptors->InitializeRepresentations(Representation::Tagged()); | |
6433 } | |
6434 | 6432 |
6435 return result; | 6433 return result; |
6436 } | 6434 } |
6437 | 6435 |
6438 | 6436 |
6439 MaybeObject* Map::CopyAsElementsKind(ElementsKind kind, TransitionFlag flag) { | 6437 MaybeObject* Map::CopyAsElementsKind(ElementsKind kind, TransitionFlag flag) { |
6440 if (flag == INSERT_TRANSITION) { | 6438 if (flag == INSERT_TRANSITION) { |
6441 ASSERT(!HasElementsTransition() || | 6439 ASSERT(!HasElementsTransition() || |
6442 ((elements_transition_map()->elements_kind() == DICTIONARY_ELEMENTS || | 6440 ((elements_transition_map()->elements_kind() == DICTIONARY_ELEMENTS || |
6443 IsExternalArrayElementsKind( | 6441 IsExternalArrayElementsKind( |
(...skipping 9017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15461 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); | 15459 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); |
15462 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); | 15460 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); |
15463 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); | 15461 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); |
15464 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); | 15462 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); |
15465 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); | 15463 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); |
15466 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); | 15464 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); |
15467 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); | 15465 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); |
15468 } | 15466 } |
15469 | 15467 |
15470 } } // namespace v8::internal | 15468 } } // namespace v8::internal |
OLD | NEW |