OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 1707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1718 } | 1718 } |
1719 } | 1719 } |
1720 int offset = kHeaderSize + old_length * kDoubleSize; | 1720 int offset = kHeaderSize + old_length * kDoubleSize; |
1721 for (int current = from->length(); current < length(); ++current) { | 1721 for (int current = from->length(); current < length(); ++current) { |
1722 WRITE_DOUBLE_FIELD(this, offset, hole_nan_as_double()); | 1722 WRITE_DOUBLE_FIELD(this, offset, hole_nan_as_double()); |
1723 offset += kDoubleSize; | 1723 offset += kDoubleSize; |
1724 } | 1724 } |
1725 } | 1725 } |
1726 | 1726 |
1727 | 1727 |
1728 void FixedDoubleArray::Initialize(NumberDictionary* from) { | 1728 void FixedDoubleArray::Initialize(SeededNumberDictionary* from) { |
1729 int offset = kHeaderSize; | 1729 int offset = kHeaderSize; |
1730 for (int current = 0; current < length(); ++current) { | 1730 for (int current = 0; current < length(); ++current) { |
1731 WRITE_DOUBLE_FIELD(this, offset, hole_nan_as_double()); | 1731 WRITE_DOUBLE_FIELD(this, offset, hole_nan_as_double()); |
1732 offset += kDoubleSize; | 1732 offset += kDoubleSize; |
1733 } | 1733 } |
1734 for (int i = 0; i < from->Capacity(); i++) { | 1734 for (int i = 0; i < from->Capacity(); i++) { |
1735 Object* key = from->KeyAt(i); | 1735 Object* key = from->KeyAt(i); |
1736 if (key->IsNumber()) { | 1736 if (key->IsNumber()) { |
1737 uint32_t entry = static_cast<uint32_t>(key->Number()); | 1737 uint32_t entry = static_cast<uint32_t>(key->Number()); |
1738 set(entry, from->ValueAt(i)->Number()); | 1738 set(entry, from->ValueAt(i)->Number()); |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2050 template<typename Shape, typename Key> | 2050 template<typename Shape, typename Key> |
2051 int HashTable<Shape, Key>::FindEntry(Key key) { | 2051 int HashTable<Shape, Key>::FindEntry(Key key) { |
2052 return FindEntry(GetIsolate(), key); | 2052 return FindEntry(GetIsolate(), key); |
2053 } | 2053 } |
2054 | 2054 |
2055 | 2055 |
2056 // Find entry for key otherwise return kNotFound. | 2056 // Find entry for key otherwise return kNotFound. |
2057 template<typename Shape, typename Key> | 2057 template<typename Shape, typename Key> |
2058 int HashTable<Shape, Key>::FindEntry(Isolate* isolate, Key key) { | 2058 int HashTable<Shape, Key>::FindEntry(Isolate* isolate, Key key) { |
2059 uint32_t capacity = Capacity(); | 2059 uint32_t capacity = Capacity(); |
2060 uint32_t entry = FirstProbe(Shape::Hash(key), capacity); | 2060 uint32_t entry = FirstProbe(HashTable<Shape, Key>::Hash(key), capacity); |
2061 uint32_t count = 1; | 2061 uint32_t count = 1; |
2062 // EnsureCapacity will guarantee the hash table is never full. | 2062 // EnsureCapacity will guarantee the hash table is never full. |
2063 while (true) { | 2063 while (true) { |
2064 Object* element = KeyAt(entry); | 2064 Object* element = KeyAt(entry); |
2065 // Empty entry. | 2065 // Empty entry. |
2066 if (element == isolate->heap()->raw_unchecked_undefined_value()) break; | 2066 if (element == isolate->heap()->raw_unchecked_undefined_value()) break; |
2067 if (element != isolate->heap()->raw_unchecked_the_hole_value() && | 2067 if (element != isolate->heap()->raw_unchecked_the_hole_value() && |
2068 Shape::IsMatch(key, element)) return entry; | 2068 Shape::IsMatch(key, element)) return entry; |
2069 entry = NextProbe(entry, count++, capacity); | 2069 entry = NextProbe(entry, count++, capacity); |
2070 } | 2070 } |
2071 return kNotFound; | 2071 return kNotFound; |
2072 } | 2072 } |
2073 | 2073 |
2074 | 2074 |
2075 bool NumberDictionary::requires_slow_elements() { | 2075 bool SeededNumberDictionary::requires_slow_elements() { |
2076 Object* max_index_object = get(kMaxNumberKeyIndex); | 2076 Object* max_index_object = get(kMaxNumberKeyIndex); |
2077 if (!max_index_object->IsSmi()) return false; | 2077 if (!max_index_object->IsSmi()) return false; |
2078 return 0 != | 2078 return 0 != |
2079 (Smi::cast(max_index_object)->value() & kRequiresSlowElementsMask); | 2079 (Smi::cast(max_index_object)->value() & kRequiresSlowElementsMask); |
2080 } | 2080 } |
2081 | 2081 |
2082 uint32_t NumberDictionary::max_number_key() { | 2082 uint32_t SeededNumberDictionary::max_number_key() { |
2083 ASSERT(!requires_slow_elements()); | 2083 ASSERT(!requires_slow_elements()); |
2084 Object* max_index_object = get(kMaxNumberKeyIndex); | 2084 Object* max_index_object = get(kMaxNumberKeyIndex); |
2085 if (!max_index_object->IsSmi()) return 0; | 2085 if (!max_index_object->IsSmi()) return 0; |
2086 uint32_t value = static_cast<uint32_t>(Smi::cast(max_index_object)->value()); | 2086 uint32_t value = static_cast<uint32_t>(Smi::cast(max_index_object)->value()); |
2087 return value >> kRequiresSlowElementsTagSize; | 2087 return value >> kRequiresSlowElementsTagSize; |
2088 } | 2088 } |
2089 | 2089 |
2090 void NumberDictionary::set_requires_slow_elements() { | 2090 void SeededNumberDictionary::set_requires_slow_elements() { |
2091 set(kMaxNumberKeyIndex, Smi::FromInt(kRequiresSlowElementsMask)); | 2091 set(kMaxNumberKeyIndex, Smi::FromInt(kRequiresSlowElementsMask)); |
2092 } | 2092 } |
2093 | 2093 |
2094 | 2094 |
2095 // ------------------------------------ | 2095 // ------------------------------------ |
2096 // Cast operations | 2096 // Cast operations |
2097 | 2097 |
2098 | 2098 |
2099 CAST_ACCESSOR(FixedArray) | 2099 CAST_ACCESSOR(FixedArray) |
2100 CAST_ACCESSOR(FixedDoubleArray) | 2100 CAST_ACCESSOR(FixedDoubleArray) |
(...skipping 1278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3379 ACCESSORS(GlobalObject, global_receiver, JSObject, kGlobalReceiverOffset) | 3379 ACCESSORS(GlobalObject, global_receiver, JSObject, kGlobalReceiverOffset) |
3380 | 3380 |
3381 ACCESSORS(JSGlobalProxy, context, Object, kContextOffset) | 3381 ACCESSORS(JSGlobalProxy, context, Object, kContextOffset) |
3382 | 3382 |
3383 ACCESSORS(AccessorInfo, getter, Object, kGetterOffset) | 3383 ACCESSORS(AccessorInfo, getter, Object, kGetterOffset) |
3384 ACCESSORS(AccessorInfo, setter, Object, kSetterOffset) | 3384 ACCESSORS(AccessorInfo, setter, Object, kSetterOffset) |
3385 ACCESSORS(AccessorInfo, data, Object, kDataOffset) | 3385 ACCESSORS(AccessorInfo, data, Object, kDataOffset) |
3386 ACCESSORS(AccessorInfo, name, Object, kNameOffset) | 3386 ACCESSORS(AccessorInfo, name, Object, kNameOffset) |
3387 ACCESSORS(AccessorInfo, flag, Smi, kFlagOffset) | 3387 ACCESSORS(AccessorInfo, flag, Smi, kFlagOffset) |
3388 | 3388 |
| 3389 ACCESSORS(AccessorPair, getter, Object, kGetterOffset) |
| 3390 ACCESSORS(AccessorPair, setter, Object, kSetterOffset) |
| 3391 |
3389 ACCESSORS(AccessCheckInfo, named_callback, Object, kNamedCallbackOffset) | 3392 ACCESSORS(AccessCheckInfo, named_callback, Object, kNamedCallbackOffset) |
3390 ACCESSORS(AccessCheckInfo, indexed_callback, Object, kIndexedCallbackOffset) | 3393 ACCESSORS(AccessCheckInfo, indexed_callback, Object, kIndexedCallbackOffset) |
3391 ACCESSORS(AccessCheckInfo, data, Object, kDataOffset) | 3394 ACCESSORS(AccessCheckInfo, data, Object, kDataOffset) |
3392 | 3395 |
3393 ACCESSORS(InterceptorInfo, getter, Object, kGetterOffset) | 3396 ACCESSORS(InterceptorInfo, getter, Object, kGetterOffset) |
3394 ACCESSORS(InterceptorInfo, setter, Object, kSetterOffset) | 3397 ACCESSORS(InterceptorInfo, setter, Object, kSetterOffset) |
3395 ACCESSORS(InterceptorInfo, query, Object, kQueryOffset) | 3398 ACCESSORS(InterceptorInfo, query, Object, kQueryOffset) |
3396 ACCESSORS(InterceptorInfo, deleter, Object, kDeleterOffset) | 3399 ACCESSORS(InterceptorInfo, deleter, Object, kDeleterOffset) |
3397 ACCESSORS(InterceptorInfo, enumerator, Object, kEnumeratorOffset) | 3400 ACCESSORS(InterceptorInfo, enumerator, Object, kEnumeratorOffset) |
3398 ACCESSORS(InterceptorInfo, data, Object, kDataOffset) | 3401 ACCESSORS(InterceptorInfo, data, Object, kDataOffset) |
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4289 return writable_elems; | 4292 return writable_elems; |
4290 } | 4293 } |
4291 | 4294 |
4292 | 4295 |
4293 StringDictionary* JSObject::property_dictionary() { | 4296 StringDictionary* JSObject::property_dictionary() { |
4294 ASSERT(!HasFastProperties()); | 4297 ASSERT(!HasFastProperties()); |
4295 return StringDictionary::cast(properties()); | 4298 return StringDictionary::cast(properties()); |
4296 } | 4299 } |
4297 | 4300 |
4298 | 4301 |
4299 NumberDictionary* JSObject::element_dictionary() { | 4302 SeededNumberDictionary* JSObject::element_dictionary() { |
4300 ASSERT(HasDictionaryElements()); | 4303 ASSERT(HasDictionaryElements()); |
4301 return NumberDictionary::cast(elements()); | 4304 return SeededNumberDictionary::cast(elements()); |
4302 } | 4305 } |
4303 | 4306 |
4304 | 4307 |
4305 bool String::IsHashFieldComputed(uint32_t field) { | 4308 bool String::IsHashFieldComputed(uint32_t field) { |
4306 return (field & kHashNotComputedMask) == 0; | 4309 return (field & kHashNotComputedMask) == 0; |
4307 } | 4310 } |
4308 | 4311 |
4309 | 4312 |
4310 bool String::HasHashCode() { | 4313 bool String::HasHashCode() { |
4311 return IsHashFieldComputed(hash_field()); | 4314 return IsHashFieldComputed(hash_field()); |
4312 } | 4315 } |
4313 | 4316 |
4314 | 4317 |
4315 uint32_t String::Hash() { | 4318 uint32_t String::Hash() { |
4316 // Fast case: has hash code already been computed? | 4319 // Fast case: has hash code already been computed? |
4317 uint32_t field = hash_field(); | 4320 uint32_t field = hash_field(); |
4318 if (IsHashFieldComputed(field)) return field >> kHashShift; | 4321 if (IsHashFieldComputed(field)) return field >> kHashShift; |
4319 // Slow case: compute hash code and set it. | 4322 // Slow case: compute hash code and set it. |
4320 return ComputeAndSetHash(); | 4323 return ComputeAndSetHash(); |
4321 } | 4324 } |
4322 | 4325 |
4323 | 4326 |
4324 StringHasher::StringHasher(int length, uint32_t seed) | 4327 StringHasher::StringHasher(int length, uint32_t seed) |
4325 : length_(length), | 4328 : length_(length), |
4326 raw_running_hash_(seed), | 4329 raw_running_hash_(seed), |
4327 array_index_(0), | 4330 array_index_(0), |
4328 is_array_index_(0 < length_ && length_ <= String::kMaxArrayIndexSize), | 4331 is_array_index_(0 < length_ && length_ <= String::kMaxArrayIndexSize), |
4329 is_first_char_(true), | 4332 is_first_char_(true), |
4330 is_valid_(true) { | 4333 is_valid_(true) { |
4331 ASSERT(FLAG_randomize_string_hashes || raw_running_hash_ == 0); | 4334 ASSERT(FLAG_randomize_hashes || raw_running_hash_ == 0); |
4332 } | 4335 } |
4333 | 4336 |
4334 | 4337 |
4335 bool StringHasher::has_trivial_hash() { | 4338 bool StringHasher::has_trivial_hash() { |
4336 return length_ > String::kMaxHashCalcLength; | 4339 return length_ > String::kMaxHashCalcLength; |
4337 } | 4340 } |
4338 | 4341 |
4339 | 4342 |
4340 void StringHasher::AddCharacter(uc32 c) { | 4343 void StringHasher::AddCharacter(uc32 c) { |
4341 // Use the Jenkins one-at-a-time hash function to update the hash | 4344 // Use the Jenkins one-at-a-time hash function to update the hash |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4528 FixedArray::set(index+2, details.AsSmi()); | 4531 FixedArray::set(index+2, details.AsSmi()); |
4529 } | 4532 } |
4530 | 4533 |
4531 | 4534 |
4532 bool NumberDictionaryShape::IsMatch(uint32_t key, Object* other) { | 4535 bool NumberDictionaryShape::IsMatch(uint32_t key, Object* other) { |
4533 ASSERT(other->IsNumber()); | 4536 ASSERT(other->IsNumber()); |
4534 return key == static_cast<uint32_t>(other->Number()); | 4537 return key == static_cast<uint32_t>(other->Number()); |
4535 } | 4538 } |
4536 | 4539 |
4537 | 4540 |
4538 uint32_t NumberDictionaryShape::Hash(uint32_t key) { | 4541 uint32_t UnseededNumberDictionaryShape::Hash(uint32_t key) { |
4539 return ComputeIntegerHash(key); | 4542 return ComputeIntegerHash(key, 0); |
4540 } | 4543 } |
4541 | 4544 |
4542 | 4545 |
4543 uint32_t NumberDictionaryShape::HashForObject(uint32_t key, Object* other) { | 4546 uint32_t UnseededNumberDictionaryShape::HashForObject(uint32_t key, |
| 4547 Object* other) { |
4544 ASSERT(other->IsNumber()); | 4548 ASSERT(other->IsNumber()); |
4545 return ComputeIntegerHash(static_cast<uint32_t>(other->Number())); | 4549 return ComputeIntegerHash(static_cast<uint32_t>(other->Number()), 0); |
4546 } | 4550 } |
4547 | 4551 |
| 4552 uint32_t SeededNumberDictionaryShape::SeededHash(uint32_t key, uint32_t seed) { |
| 4553 return ComputeIntegerHash(key, seed); |
| 4554 } |
| 4555 |
| 4556 uint32_t SeededNumberDictionaryShape::SeededHashForObject(uint32_t key, |
| 4557 uint32_t seed, |
| 4558 Object* other) { |
| 4559 ASSERT(other->IsNumber()); |
| 4560 return ComputeIntegerHash(static_cast<uint32_t>(other->Number()), seed); |
| 4561 } |
4548 | 4562 |
4549 MaybeObject* NumberDictionaryShape::AsObject(uint32_t key) { | 4563 MaybeObject* NumberDictionaryShape::AsObject(uint32_t key) { |
4550 return Isolate::Current()->heap()->NumberFromUint32(key); | 4564 return Isolate::Current()->heap()->NumberFromUint32(key); |
4551 } | 4565 } |
4552 | 4566 |
4553 | 4567 |
4554 bool StringDictionaryShape::IsMatch(String* key, Object* other) { | 4568 bool StringDictionaryShape::IsMatch(String* key, Object* other) { |
4555 // We know that all entries in a hash table had their hash keys created. | 4569 // We know that all entries in a hash table had their hash keys created. |
4556 // Use that knowledge to have fast failure. | 4570 // Use that knowledge to have fast failure. |
4557 if (key->Hash() != String::cast(other)->Hash()) return false; | 4571 if (key->Hash() != String::cast(other)->Hash()) return false; |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4769 #undef WRITE_INT_FIELD | 4783 #undef WRITE_INT_FIELD |
4770 #undef READ_SHORT_FIELD | 4784 #undef READ_SHORT_FIELD |
4771 #undef WRITE_SHORT_FIELD | 4785 #undef WRITE_SHORT_FIELD |
4772 #undef READ_BYTE_FIELD | 4786 #undef READ_BYTE_FIELD |
4773 #undef WRITE_BYTE_FIELD | 4787 #undef WRITE_BYTE_FIELD |
4774 | 4788 |
4775 | 4789 |
4776 } } // namespace v8::internal | 4790 } } // namespace v8::internal |
4777 | 4791 |
4778 #endif // V8_OBJECTS_INL_H_ | 4792 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |