OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 1319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1330 return function; | 1330 return function; |
1331 } | 1331 } |
1332 | 1332 |
1333 // Add a CONSTANT_TRANSITION descriptor to the old map, | 1333 // Add a CONSTANT_TRANSITION descriptor to the old map, |
1334 // so future assignments to this property on other objects | 1334 // so future assignments to this property on other objects |
1335 // of the same type will create a normal field, not a constant function. | 1335 // of the same type will create a normal field, not a constant function. |
1336 // Don't do this for special properties, with non-trival attributes. | 1336 // Don't do this for special properties, with non-trival attributes. |
1337 if (attributes != NONE) { | 1337 if (attributes != NONE) { |
1338 return function; | 1338 return function; |
1339 } | 1339 } |
1340 ConstTransitionDescriptor mark(name); | 1340 ConstTransitionDescriptor mark(name, Map::cast(new_map)); |
1341 new_descriptors = | 1341 new_descriptors = |
1342 old_map->instance_descriptors()->CopyInsert(&mark, KEEP_TRANSITIONS); | 1342 old_map->instance_descriptors()->CopyInsert(&mark, KEEP_TRANSITIONS); |
1343 if (new_descriptors->IsFailure()) { | 1343 if (new_descriptors->IsFailure()) { |
1344 return function; // We have accomplished the main goal, so return success. | 1344 return function; // We have accomplished the main goal, so return success. |
1345 } | 1345 } |
1346 old_map->set_instance_descriptors(DescriptorArray::cast(new_descriptors)); | 1346 old_map->set_instance_descriptors(DescriptorArray::cast(new_descriptors)); |
1347 | 1347 |
1348 return function; | 1348 return function; |
1349 } | 1349 } |
1350 | 1350 |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1688 return true; | 1688 return true; |
1689 } | 1689 } |
1690 } | 1690 } |
1691 } | 1691 } |
1692 return false; | 1692 return false; |
1693 } | 1693 } |
1694 | 1694 |
1695 | 1695 |
1696 void JSObject::LookupInDescriptor(String* name, LookupResult* result) { | 1696 void JSObject::LookupInDescriptor(String* name, LookupResult* result) { |
1697 DescriptorArray* descriptors = map()->instance_descriptors(); | 1697 DescriptorArray* descriptors = map()->instance_descriptors(); |
1698 int number = DescriptorLookupCache::Lookup(descriptors, name); | 1698 int number = descriptors->SearchWithCache(name); |
1699 if (number == DescriptorLookupCache::kAbsent) { | |
1700 number = descriptors->Search(name); | |
1701 DescriptorLookupCache::Update(descriptors, name, number); | |
1702 } | |
1703 if (number != DescriptorArray::kNotFound) { | 1699 if (number != DescriptorArray::kNotFound) { |
1704 result->DescriptorResult(this, descriptors->GetDetails(number), number); | 1700 result->DescriptorResult(this, descriptors->GetDetails(number), number); |
1705 } else { | 1701 } else { |
1706 result->NotFound(); | 1702 result->NotFound(); |
1707 } | 1703 } |
1708 } | 1704 } |
1709 | 1705 |
1710 | 1706 |
1711 void JSObject::LocalLookupRealNamedProperty(String* name, | 1707 void JSObject::LocalLookupRealNamedProperty(String* name, |
1712 LookupResult* result) { | 1708 LookupResult* result) { |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1889 // Preserve the attributes of this existing property. | 1885 // Preserve the attributes of this existing property. |
1890 attributes = result->GetAttributes(); | 1886 attributes = result->GetAttributes(); |
1891 return ConvertDescriptorToField(name, value, attributes); | 1887 return ConvertDescriptorToField(name, value, attributes); |
1892 case CALLBACKS: | 1888 case CALLBACKS: |
1893 return SetPropertyWithCallback(result->GetCallbackObject(), | 1889 return SetPropertyWithCallback(result->GetCallbackObject(), |
1894 name, | 1890 name, |
1895 value, | 1891 value, |
1896 result->holder()); | 1892 result->holder()); |
1897 case INTERCEPTOR: | 1893 case INTERCEPTOR: |
1898 return SetPropertyWithInterceptor(name, value, attributes); | 1894 return SetPropertyWithInterceptor(name, value, attributes); |
1899 case CONSTANT_TRANSITION: | 1895 case CONSTANT_TRANSITION: { |
1900 // Replace with a MAP_TRANSITION to a new map with a FIELD, even | 1896 // If the same constant function is being added we can simply |
1901 // if the value is a function. | 1897 // transition to the target map. |
| 1898 Map* target_map = result->GetTransitionMap(); |
| 1899 DescriptorArray* target_descriptors = target_map->instance_descriptors(); |
| 1900 int number = target_descriptors->SearchWithCache(name); |
| 1901 ASSERT(number != DescriptorArray::kNotFound); |
| 1902 ASSERT(target_descriptors->GetType(number) == CONSTANT_FUNCTION); |
| 1903 JSFunction* function = |
| 1904 JSFunction::cast(target_descriptors->GetValue(number)); |
| 1905 ASSERT(!Heap::InNewSpace(function)); |
| 1906 if (value == function) { |
| 1907 set_map(target_map); |
| 1908 return value; |
| 1909 } |
| 1910 // Otherwise, replace with a MAP_TRANSITION to a new map with a |
| 1911 // FIELD, even if the value is a constant function. |
1902 return ConvertDescriptorToFieldAndMapTransition(name, value, attributes); | 1912 return ConvertDescriptorToFieldAndMapTransition(name, value, attributes); |
| 1913 } |
1903 case NULL_DESCRIPTOR: | 1914 case NULL_DESCRIPTOR: |
1904 return ConvertDescriptorToFieldAndMapTransition(name, value, attributes); | 1915 return ConvertDescriptorToFieldAndMapTransition(name, value, attributes); |
1905 default: | 1916 default: |
1906 UNREACHABLE(); | 1917 UNREACHABLE(); |
1907 } | 1918 } |
1908 UNREACHABLE(); | 1919 UNREACHABLE(); |
1909 return value; | 1920 return value; |
1910 } | 1921 } |
1911 | 1922 |
1912 | 1923 |
(...skipping 3057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4970 int length = this->length(); | 4981 int length = this->length(); |
4971 for (int i = 0; i < length; i++) { | 4982 for (int i = 0; i < length; i++) { |
4972 fprintf(file, "%c", Get(i)); | 4983 fprintf(file, "%c", Get(i)); |
4973 } | 4984 } |
4974 } | 4985 } |
4975 | 4986 |
4976 | 4987 |
4977 void Map::CreateBackPointers() { | 4988 void Map::CreateBackPointers() { |
4978 DescriptorArray* descriptors = instance_descriptors(); | 4989 DescriptorArray* descriptors = instance_descriptors(); |
4979 for (int i = 0; i < descriptors->number_of_descriptors(); i++) { | 4990 for (int i = 0; i < descriptors->number_of_descriptors(); i++) { |
4980 if (descriptors->GetType(i) == MAP_TRANSITION) { | 4991 if (descriptors->GetType(i) == MAP_TRANSITION || |
| 4992 descriptors->GetType(i) == CONSTANT_TRANSITION) { |
4981 // Get target. | 4993 // Get target. |
4982 Map* target = Map::cast(descriptors->GetValue(i)); | 4994 Map* target = Map::cast(descriptors->GetValue(i)); |
4983 #ifdef DEBUG | 4995 #ifdef DEBUG |
4984 // Verify target. | 4996 // Verify target. |
4985 Object* source_prototype = prototype(); | 4997 Object* source_prototype = prototype(); |
4986 Object* target_prototype = target->prototype(); | 4998 Object* target_prototype = target->prototype(); |
4987 ASSERT(source_prototype->IsJSObject() || | 4999 ASSERT(source_prototype->IsJSObject() || |
4988 source_prototype->IsMap() || | 5000 source_prototype->IsMap() || |
4989 source_prototype->IsNull()); | 5001 source_prototype->IsNull()); |
4990 ASSERT(target_prototype->IsJSObject() || | 5002 ASSERT(target_prototype->IsJSObject() || |
(...skipping 20 matching lines...) Expand all Loading... |
5011 FixedArray* contents = reinterpret_cast<FixedArray*>( | 5023 FixedArray* contents = reinterpret_cast<FixedArray*>( |
5012 d->get(DescriptorArray::kContentArrayIndex)); | 5024 d->get(DescriptorArray::kContentArrayIndex)); |
5013 ASSERT(contents->length() >= 2); | 5025 ASSERT(contents->length() >= 2); |
5014 for (int i = 0; i < contents->length(); i += 2) { | 5026 for (int i = 0; i < contents->length(); i += 2) { |
5015 // If the pair (value, details) is a map transition, | 5027 // If the pair (value, details) is a map transition, |
5016 // check if the target is live. If not, null the descriptor. | 5028 // check if the target is live. If not, null the descriptor. |
5017 // Also drop the back pointer for that map transition, so that this | 5029 // Also drop the back pointer for that map transition, so that this |
5018 // map is not reached again by following a back pointer from a | 5030 // map is not reached again by following a back pointer from a |
5019 // non-live object. | 5031 // non-live object. |
5020 PropertyDetails details(Smi::cast(contents->get(i + 1))); | 5032 PropertyDetails details(Smi::cast(contents->get(i + 1))); |
5021 if (details.type() == MAP_TRANSITION) { | 5033 if (details.type() == MAP_TRANSITION || |
| 5034 details.type() == CONSTANT_TRANSITION) { |
5022 Map* target = reinterpret_cast<Map*>(contents->get(i)); | 5035 Map* target = reinterpret_cast<Map*>(contents->get(i)); |
5023 ASSERT(target->IsHeapObject()); | 5036 ASSERT(target->IsHeapObject()); |
5024 if (!target->IsMarked()) { | 5037 if (!target->IsMarked()) { |
5025 ASSERT(target->IsMap()); | 5038 ASSERT(target->IsMap()); |
5026 contents->set(i + 1, NullDescriptorDetails); | 5039 contents->set(i + 1, NullDescriptorDetails); |
5027 contents->set_null(i); | 5040 contents->set_null(i); |
5028 ASSERT(target->prototype() == this || | 5041 ASSERT(target->prototype() == this || |
5029 target->prototype() == real_prototype); | 5042 target->prototype() == real_prototype); |
5030 // Getter prototype() is read-only, set_prototype() has side effects. | 5043 // Getter prototype() is read-only, set_prototype() has side effects. |
5031 *RawField(target, Map::kPrototypeOffset) = real_prototype; | 5044 *RawField(target, Map::kPrototypeOffset) = real_prototype; |
(...skipping 3787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8819 if (break_point_objects()->IsUndefined()) return 0; | 8832 if (break_point_objects()->IsUndefined()) return 0; |
8820 // Single beak point. | 8833 // Single beak point. |
8821 if (!break_point_objects()->IsFixedArray()) return 1; | 8834 if (!break_point_objects()->IsFixedArray()) return 1; |
8822 // Multiple break points. | 8835 // Multiple break points. |
8823 return FixedArray::cast(break_point_objects())->length(); | 8836 return FixedArray::cast(break_point_objects())->length(); |
8824 } | 8837 } |
8825 #endif | 8838 #endif |
8826 | 8839 |
8827 | 8840 |
8828 } } // namespace v8::internal | 8841 } } // namespace v8::internal |
OLD | NEW |