Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1945 if (array->GetKey(low)->Equals(name)) return low; | 1945 if (array->GetKey(low)->Equals(name)) return low; |
| 1946 } | 1946 } |
| 1947 | 1947 |
| 1948 return T::kNotFound; | 1948 return T::kNotFound; |
| 1949 } | 1949 } |
| 1950 | 1950 |
| 1951 | 1951 |
| 1952 // Perform a linear search in this fixed array. len is the number of entry | 1952 // Perform a linear search in this fixed array. len is the number of entry |
| 1953 // indices that are valid. | 1953 // indices that are valid. |
| 1954 template<typename T> | 1954 template<typename T> |
| 1955 int LinearSearch(T* array, SearchMode mode, String* name, int len) { | 1955 int LinearSearch(T* array, String* name, int len) { |
| 1956 uint32_t hash = name->Hash(); | 1956 uint32_t hash = name->Hash(); |
| 1957 for (int number = 0; number < len; number++) { | 1957 for (int number = 0; number < len; number++) { |
| 1958 String* entry = array->GetKey(number); | 1958 String* entry = array->GetKey(number); |
| 1959 uint32_t current_hash = entry->Hash(); | 1959 uint32_t current_hash = entry->Hash(); |
| 1960 if (mode == EXPECT_SORTED && current_hash > hash) break; | 1960 if (current_hash > hash) break; |
| 1961 if (current_hash == hash && name->Equals(entry)) return number; | 1961 if (current_hash == hash && name->Equals(entry)) return number; |
| 1962 } | 1962 } |
| 1963 return T::kNotFound; | 1963 return T::kNotFound; |
| 1964 } | 1964 } |
| 1965 | 1965 |
| 1966 | 1966 |
| 1967 template<typename T> | 1967 template<typename T> |
| 1968 int Search(T* array, String* name) { | 1968 int Search(T* array, String* name) { |
| 1969 SLOW_ASSERT(array->IsSortedNoDuplicates()); | 1969 SLOW_ASSERT(array->IsSortedNoDuplicates()); |
| 1970 | 1970 |
| 1971 // Check for empty descriptor array. | 1971 // Check for empty descriptor array. |
| 1972 int nof = array->number_of_entries(); | 1972 int nof = array->number_of_entries(); |
| 1973 if (nof == 0) return T::kNotFound; | 1973 if (nof == 0) return T::kNotFound; |
| 1974 | 1974 |
| 1975 // Fast case: do linear search for small arrays. | 1975 // Fast case: do linear search for small arrays. |
| 1976 const int kMaxElementsForLinearSearch = 8; | 1976 const int kMaxElementsForLinearSearch = 8; |
| 1977 if (StringShape(name).IsSymbol() && nof < kMaxElementsForLinearSearch) { | 1977 if (StringShape(name).IsSymbol() && nof < kMaxElementsForLinearSearch) { |
| 1978 return LinearSearch(array, EXPECT_SORTED, name, nof); | 1978 return LinearSearch(array, name, nof); |
| 1979 } | 1979 } |
| 1980 | 1980 |
| 1981 // Slow case: perform binary search. | 1981 // Slow case: perform binary search. |
| 1982 return BinarySearch(array, name, 0, nof - 1); | 1982 return BinarySearch(array, name, 0, nof - 1); |
| 1983 } | 1983 } |
| 1984 | 1984 |
| 1985 | 1985 |
| 1986 int DescriptorArray::Search(String* name) { | 1986 int DescriptorArray::Search(String* name) { |
| 1987 return internal::Search(this, name); | 1987 return internal::Search(this, name); |
| 1988 } | 1988 } |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2108 ToDetailsIndex(descriptor_number), | 2108 ToDetailsIndex(descriptor_number), |
| 2109 desc->GetDetails().AsSmi()); | 2109 desc->GetDetails().AsSmi()); |
| 2110 } | 2110 } |
| 2111 | 2111 |
| 2112 | 2112 |
| 2113 void DescriptorArray::Append(Descriptor* desc, | 2113 void DescriptorArray::Append(Descriptor* desc, |
| 2114 const WhitenessWitness& witness) { | 2114 const WhitenessWitness& witness) { |
| 2115 int descriptor_number = NumberOfSetDescriptors(); | 2115 int descriptor_number = NumberOfSetDescriptors(); |
| 2116 int enumeration_index = descriptor_number + 1; | 2116 int enumeration_index = descriptor_number + 1; |
| 2117 desc->SetEnumerationIndex(enumeration_index); | 2117 desc->SetEnumerationIndex(enumeration_index); |
| 2118 | |
| 2119 uint32_t hash = desc->GetKey()->Hash(); | |
| 2120 | |
| 2121 for (; descriptor_number > 0; --descriptor_number) { | |
| 2122 String* key = GetKey(descriptor_number - 1); | |
| 2123 if (key->Hash() <= hash) break; | |
| 2124 Object* value = GetValue(descriptor_number - 1); | |
| 2125 PropertyDetails details = GetDetails(descriptor_number - 1); | |
| 2126 Descriptor desc(key, value, details); | |
|
Jakob Kummerow
2012/07/18 15:17:55
nit: I don't like shadowing variables. Can you pic
| |
| 2127 Set(descriptor_number, &desc, witness); | |
| 2128 } | |
| 2129 | |
| 2118 Set(descriptor_number, desc, witness); | 2130 Set(descriptor_number, desc, witness); |
| 2119 SetLastAdded(descriptor_number); | 2131 SetLastAdded(descriptor_number); |
| 2120 } | 2132 } |
| 2121 | 2133 |
| 2122 | 2134 |
| 2123 void DescriptorArray::NoIncrementalWriteBarrierSwapDescriptors( | 2135 void DescriptorArray::NoIncrementalWriteBarrierSwapDescriptors( |
| 2124 int first, int second) { | 2136 int first, int second) { |
| 2125 NoIncrementalWriteBarrierSwap(this, ToKeyIndex(first), ToKeyIndex(second)); | 2137 NoIncrementalWriteBarrierSwap(this, ToKeyIndex(first), ToKeyIndex(second)); |
| 2126 NoIncrementalWriteBarrierSwap(this, | 2138 NoIncrementalWriteBarrierSwap(this, |
| 2127 ToValueIndex(first), | 2139 ToValueIndex(first), |
| (...skipping 1354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3482 value->set_back_pointer_storage(object); | 3494 value->set_back_pointer_storage(object); |
| 3483 } | 3495 } |
| 3484 | 3496 |
| 3485 ASSERT(!is_shared()); | 3497 ASSERT(!is_shared()); |
| 3486 WRITE_FIELD(this, kInstanceDescriptorsOrBackPointerOffset, value); | 3498 WRITE_FIELD(this, kInstanceDescriptorsOrBackPointerOffset, value); |
| 3487 CONDITIONAL_WRITE_BARRIER( | 3499 CONDITIONAL_WRITE_BARRIER( |
| 3488 heap, this, kInstanceDescriptorsOrBackPointerOffset, value, mode); | 3500 heap, this, kInstanceDescriptorsOrBackPointerOffset, value, mode); |
| 3489 } | 3501 } |
| 3490 | 3502 |
| 3491 | 3503 |
| 3504 void Map::InitializeDescriptors(DescriptorArray* descriptors) { | |
| 3505 int len = descriptors->number_of_descriptors(); | |
| 3506 SLOW_ASSERT(descriptors->IsSortedNoDuplicates()); | |
| 3507 | |
| 3508 #ifdef DEBUG | |
| 3509 // Ensure that all enumeration indexes between 1 and length occur uniquely in | |
| 3510 // the descriptor array. | |
| 3511 for (int i = 1; i <= len; ++i) { | |
|
Jakob Kummerow
2012/07/18 15:17:55
Not sure if it's worth the effort, but we *could*
| |
| 3512 int j; | |
| 3513 for (j = 0; j < len; ++j) { | |
| 3514 if (descriptors->GetDetails(j).index() == i) break; | |
| 3515 } | |
| 3516 ASSERT(j != len); | |
| 3517 for (j++; j < len; ++j) { | |
| 3518 ASSERT(descriptors->GetDetails(j).index() != i); | |
| 3519 } | |
| 3520 } | |
| 3521 #endif | |
| 3522 | |
| 3523 for (int i = 0; i < len; ++i) { | |
| 3524 if (descriptors->GetDetails(i).index() == len) { | |
| 3525 descriptors->SetLastAdded(i); | |
| 3526 break; | |
| 3527 } | |
| 3528 } | |
| 3529 | |
| 3530 ASSERT(len == 0 || | |
| 3531 len == descriptors->GetDetails(descriptors->LastAdded()).index()); | |
| 3532 | |
| 3533 set_instance_descriptors(descriptors); | |
| 3534 } | |
| 3535 | |
| 3536 | |
| 3492 SMI_ACCESSORS(Map, bit_field3, kBitField3Offset) | 3537 SMI_ACCESSORS(Map, bit_field3, kBitField3Offset) |
| 3493 | 3538 |
| 3494 | 3539 |
| 3495 void Map::ClearDescriptorArray(Heap* heap, WriteBarrierMode mode) { | 3540 void Map::ClearDescriptorArray(Heap* heap, WriteBarrierMode mode) { |
| 3496 Object* back_pointer = GetBackPointer(); | 3541 Object* back_pointer = GetBackPointer(); |
| 3497 #ifdef DEBUG | 3542 #ifdef DEBUG |
| 3498 Object* object = READ_FIELD(this, kInstanceDescriptorsOrBackPointerOffset); | 3543 Object* object = READ_FIELD(this, kInstanceDescriptorsOrBackPointerOffset); |
| 3499 if (object->IsDescriptorArray()) { | 3544 if (object->IsDescriptorArray()) { |
| 3500 ZapTransitions(); | 3545 ZapTransitions(); |
| 3501 } else { | 3546 } else { |
| (...skipping 1821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5323 #undef WRITE_UINT32_FIELD | 5368 #undef WRITE_UINT32_FIELD |
| 5324 #undef READ_SHORT_FIELD | 5369 #undef READ_SHORT_FIELD |
| 5325 #undef WRITE_SHORT_FIELD | 5370 #undef WRITE_SHORT_FIELD |
| 5326 #undef READ_BYTE_FIELD | 5371 #undef READ_BYTE_FIELD |
| 5327 #undef WRITE_BYTE_FIELD | 5372 #undef WRITE_BYTE_FIELD |
| 5328 | 5373 |
| 5329 | 5374 |
| 5330 } } // namespace v8::internal | 5375 } } // namespace v8::internal |
| 5331 | 5376 |
| 5332 #endif // V8_OBJECTS_INL_H_ | 5377 #endif // V8_OBJECTS_INL_H_ |
| OLD | NEW |