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 1771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1782 } | 1782 } |
1783 } | 1783 } |
1784 int offset = kHeaderSize + old_length * kDoubleSize; | 1784 int offset = kHeaderSize + old_length * kDoubleSize; |
1785 for (int current = from->length(); current < length(); ++current) { | 1785 for (int current = from->length(); current < length(); ++current) { |
1786 WRITE_DOUBLE_FIELD(this, offset, hole_nan_as_double()); | 1786 WRITE_DOUBLE_FIELD(this, offset, hole_nan_as_double()); |
1787 offset += kDoubleSize; | 1787 offset += kDoubleSize; |
1788 } | 1788 } |
1789 } | 1789 } |
1790 | 1790 |
1791 | 1791 |
1792 void FixedDoubleArray::Initialize(NumberDictionary* from) { | 1792 void FixedDoubleArray::Initialize(SeededNumberDictionary* from) { |
1793 int offset = kHeaderSize; | 1793 int offset = kHeaderSize; |
1794 for (int current = 0; current < length(); ++current) { | 1794 for (int current = 0; current < length(); ++current) { |
1795 WRITE_DOUBLE_FIELD(this, offset, hole_nan_as_double()); | 1795 WRITE_DOUBLE_FIELD(this, offset, hole_nan_as_double()); |
1796 offset += kDoubleSize; | 1796 offset += kDoubleSize; |
1797 } | 1797 } |
1798 for (int i = 0; i < from->Capacity(); i++) { | 1798 for (int i = 0; i < from->Capacity(); i++) { |
1799 Object* key = from->KeyAt(i); | 1799 Object* key = from->KeyAt(i); |
1800 if (key->IsNumber()) { | 1800 if (key->IsNumber()) { |
1801 uint32_t entry = static_cast<uint32_t>(key->Number()); | 1801 uint32_t entry = static_cast<uint32_t>(key->Number()); |
1802 set(entry, from->ValueAt(i)->Number()); | 1802 set(entry, from->ValueAt(i)->Number()); |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2070 template<typename Shape, typename Key> | 2070 template<typename Shape, typename Key> |
2071 int HashTable<Shape, Key>::FindEntry(Key key) { | 2071 int HashTable<Shape, Key>::FindEntry(Key key) { |
2072 return FindEntry(GetIsolate(), key); | 2072 return FindEntry(GetIsolate(), key); |
2073 } | 2073 } |
2074 | 2074 |
2075 | 2075 |
2076 // Find entry for key otherwise return kNotFound. | 2076 // Find entry for key otherwise return kNotFound. |
2077 template<typename Shape, typename Key> | 2077 template<typename Shape, typename Key> |
2078 int HashTable<Shape, Key>::FindEntry(Isolate* isolate, Key key) { | 2078 int HashTable<Shape, Key>::FindEntry(Isolate* isolate, Key key) { |
2079 uint32_t capacity = Capacity(); | 2079 uint32_t capacity = Capacity(); |
2080 uint32_t entry = FirstProbe(Shape::Hash(key), capacity); | 2080 uint32_t entry = FirstProbe(HashTable<Shape, Key>::Hash(key), capacity); |
2081 uint32_t count = 1; | 2081 uint32_t count = 1; |
2082 // EnsureCapacity will guarantee the hash table is never full. | 2082 // EnsureCapacity will guarantee the hash table is never full. |
2083 while (true) { | 2083 while (true) { |
2084 Object* element = KeyAt(entry); | 2084 Object* element = KeyAt(entry); |
2085 // Empty entry. | 2085 // Empty entry. |
2086 if (element == isolate->heap()->raw_unchecked_undefined_value()) break; | 2086 if (element == isolate->heap()->raw_unchecked_undefined_value()) break; |
2087 if (element != isolate->heap()->raw_unchecked_null_value() && | 2087 if (element != isolate->heap()->raw_unchecked_null_value() && |
2088 Shape::IsMatch(key, element)) return entry; | 2088 Shape::IsMatch(key, element)) return entry; |
2089 entry = NextProbe(entry, count++, capacity); | 2089 entry = NextProbe(entry, count++, capacity); |
2090 } | 2090 } |
2091 return kNotFound; | 2091 return kNotFound; |
2092 } | 2092 } |
2093 | 2093 |
2094 | 2094 |
2095 bool NumberDictionary::requires_slow_elements() { | 2095 bool SeededNumberDictionary::requires_slow_elements() { |
2096 Object* max_index_object = get(kMaxNumberKeyIndex); | 2096 Object* max_index_object = get(kMaxNumberKeyIndex); |
2097 if (!max_index_object->IsSmi()) return false; | 2097 if (!max_index_object->IsSmi()) return false; |
2098 return 0 != | 2098 return 0 != |
2099 (Smi::cast(max_index_object)->value() & kRequiresSlowElementsMask); | 2099 (Smi::cast(max_index_object)->value() & kRequiresSlowElementsMask); |
2100 } | 2100 } |
2101 | 2101 |
2102 uint32_t NumberDictionary::max_number_key() { | 2102 uint32_t SeededNumberDictionary::max_number_key() { |
2103 ASSERT(!requires_slow_elements()); | 2103 ASSERT(!requires_slow_elements()); |
2104 Object* max_index_object = get(kMaxNumberKeyIndex); | 2104 Object* max_index_object = get(kMaxNumberKeyIndex); |
2105 if (!max_index_object->IsSmi()) return 0; | 2105 if (!max_index_object->IsSmi()) return 0; |
2106 uint32_t value = static_cast<uint32_t>(Smi::cast(max_index_object)->value()); | 2106 uint32_t value = static_cast<uint32_t>(Smi::cast(max_index_object)->value()); |
2107 return value >> kRequiresSlowElementsTagSize; | 2107 return value >> kRequiresSlowElementsTagSize; |
2108 } | 2108 } |
2109 | 2109 |
2110 void NumberDictionary::set_requires_slow_elements() { | 2110 void SeededNumberDictionary::set_requires_slow_elements() { |
2111 set(kMaxNumberKeyIndex, Smi::FromInt(kRequiresSlowElementsMask)); | 2111 set(kMaxNumberKeyIndex, Smi::FromInt(kRequiresSlowElementsMask)); |
2112 } | 2112 } |
2113 | 2113 |
2114 | 2114 |
2115 // ------------------------------------ | 2115 // ------------------------------------ |
2116 // Cast operations | 2116 // Cast operations |
2117 | 2117 |
2118 | 2118 |
2119 CAST_ACCESSOR(FixedArray) | 2119 CAST_ACCESSOR(FixedArray) |
2120 CAST_ACCESSOR(FixedDoubleArray) | 2120 CAST_ACCESSOR(FixedDoubleArray) |
(...skipping 2083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4204 return writable_elems; | 4204 return writable_elems; |
4205 } | 4205 } |
4206 | 4206 |
4207 | 4207 |
4208 StringDictionary* JSObject::property_dictionary() { | 4208 StringDictionary* JSObject::property_dictionary() { |
4209 ASSERT(!HasFastProperties()); | 4209 ASSERT(!HasFastProperties()); |
4210 return StringDictionary::cast(properties()); | 4210 return StringDictionary::cast(properties()); |
4211 } | 4211 } |
4212 | 4212 |
4213 | 4213 |
4214 NumberDictionary* JSObject::element_dictionary() { | 4214 SeededNumberDictionary* JSObject::element_dictionary() { |
4215 ASSERT(HasDictionaryElements()); | 4215 ASSERT(HasDictionaryElements()); |
4216 return NumberDictionary::cast(elements()); | 4216 return SeededNumberDictionary::cast(elements()); |
4217 } | 4217 } |
4218 | 4218 |
4219 | 4219 |
4220 bool String::IsHashFieldComputed(uint32_t field) { | 4220 bool String::IsHashFieldComputed(uint32_t field) { |
4221 return (field & kHashNotComputedMask) == 0; | 4221 return (field & kHashNotComputedMask) == 0; |
4222 } | 4222 } |
4223 | 4223 |
4224 | 4224 |
4225 bool String::HasHashCode() { | 4225 bool String::HasHashCode() { |
4226 return IsHashFieldComputed(hash_field()); | 4226 return IsHashFieldComputed(hash_field()); |
4227 } | 4227 } |
4228 | 4228 |
4229 | 4229 |
4230 uint32_t String::Hash() { | 4230 uint32_t String::Hash() { |
4231 // Fast case: has hash code already been computed? | 4231 // Fast case: has hash code already been computed? |
4232 uint32_t field = hash_field(); | 4232 uint32_t field = hash_field(); |
4233 if (IsHashFieldComputed(field)) return field >> kHashShift; | 4233 if (IsHashFieldComputed(field)) return field >> kHashShift; |
4234 // Slow case: compute hash code and set it. | 4234 // Slow case: compute hash code and set it. |
4235 return ComputeAndSetHash(); | 4235 return ComputeAndSetHash(); |
4236 } | 4236 } |
4237 | 4237 |
4238 | 4238 |
4239 StringHasher::StringHasher(int length, uint32_t seed) | 4239 StringHasher::StringHasher(int length, uint32_t seed) |
4240 : length_(length), | 4240 : length_(length), |
4241 raw_running_hash_(seed), | 4241 raw_running_hash_(seed), |
4242 array_index_(0), | 4242 array_index_(0), |
4243 is_array_index_(0 < length_ && length_ <= String::kMaxArrayIndexSize), | 4243 is_array_index_(0 < length_ && length_ <= String::kMaxArrayIndexSize), |
4244 is_first_char_(true), | 4244 is_first_char_(true), |
4245 is_valid_(true) { | 4245 is_valid_(true) { |
4246 ASSERT(FLAG_randomize_string_hashes || raw_running_hash_ == 0); | 4246 ASSERT(FLAG_randomize_hashes || raw_running_hash_ == 0); |
4247 } | 4247 } |
4248 | 4248 |
4249 | 4249 |
4250 bool StringHasher::has_trivial_hash() { | 4250 bool StringHasher::has_trivial_hash() { |
4251 return length_ > String::kMaxHashCalcLength; | 4251 return length_ > String::kMaxHashCalcLength; |
4252 } | 4252 } |
4253 | 4253 |
4254 | 4254 |
4255 void StringHasher::AddCharacter(uc32 c) { | 4255 void StringHasher::AddCharacter(uc32 c) { |
4256 // Use the Jenkins one-at-a-time hash function to update the hash | 4256 // Use the Jenkins one-at-a-time hash function to update the hash |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4469 FixedArray::fast_set(this, index+2, details.AsSmi()); | 4469 FixedArray::fast_set(this, index+2, details.AsSmi()); |
4470 } | 4470 } |
4471 | 4471 |
4472 | 4472 |
4473 bool NumberDictionaryShape::IsMatch(uint32_t key, Object* other) { | 4473 bool NumberDictionaryShape::IsMatch(uint32_t key, Object* other) { |
4474 ASSERT(other->IsNumber()); | 4474 ASSERT(other->IsNumber()); |
4475 return key == static_cast<uint32_t>(other->Number()); | 4475 return key == static_cast<uint32_t>(other->Number()); |
4476 } | 4476 } |
4477 | 4477 |
4478 | 4478 |
4479 uint32_t NumberDictionaryShape::Hash(uint32_t key) { | 4479 uint32_t UnseededNumberDictionaryShape::Hash(uint32_t key) { |
4480 return ComputeIntegerHash(key); | 4480 return ComputeIntegerHash(key, 0); |
4481 } | 4481 } |
4482 | 4482 |
4483 | 4483 |
4484 uint32_t NumberDictionaryShape::HashForObject(uint32_t key, Object* other) { | 4484 uint32_t UnseededNumberDictionaryShape::HashForObject(uint32_t key, |
| 4485 Object* other) { |
4485 ASSERT(other->IsNumber()); | 4486 ASSERT(other->IsNumber()); |
4486 return ComputeIntegerHash(static_cast<uint32_t>(other->Number())); | 4487 return ComputeIntegerHash(static_cast<uint32_t>(other->Number()), 0); |
4487 } | 4488 } |
4488 | 4489 |
| 4490 uint32_t SeededNumberDictionaryShape::SeededHash(uint32_t key, uint32_t seed) { |
| 4491 return ComputeIntegerHash(key, seed); |
| 4492 } |
| 4493 |
| 4494 uint32_t SeededNumberDictionaryShape::SeededHashForObject(uint32_t key, |
| 4495 uint32_t seed, |
| 4496 Object* other) { |
| 4497 ASSERT(other->IsNumber()); |
| 4498 return ComputeIntegerHash(static_cast<uint32_t>(other->Number()), seed); |
| 4499 } |
4489 | 4500 |
4490 MaybeObject* NumberDictionaryShape::AsObject(uint32_t key) { | 4501 MaybeObject* NumberDictionaryShape::AsObject(uint32_t key) { |
4491 return Isolate::Current()->heap()->NumberFromUint32(key); | 4502 return Isolate::Current()->heap()->NumberFromUint32(key); |
4492 } | 4503 } |
4493 | 4504 |
4494 | 4505 |
4495 bool StringDictionaryShape::IsMatch(String* key, Object* other) { | 4506 bool StringDictionaryShape::IsMatch(String* key, Object* other) { |
4496 // We know that all entries in a hash table had their hash keys created. | 4507 // We know that all entries in a hash table had their hash keys created. |
4497 // Use that knowledge to have fast failure. | 4508 // Use that knowledge to have fast failure. |
4498 if (key->Hash() != String::cast(other)->Hash()) return false; | 4509 if (key->Hash() != String::cast(other)->Hash()) return false; |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4689 #undef WRITE_INT_FIELD | 4700 #undef WRITE_INT_FIELD |
4690 #undef READ_SHORT_FIELD | 4701 #undef READ_SHORT_FIELD |
4691 #undef WRITE_SHORT_FIELD | 4702 #undef WRITE_SHORT_FIELD |
4692 #undef READ_BYTE_FIELD | 4703 #undef READ_BYTE_FIELD |
4693 #undef WRITE_BYTE_FIELD | 4704 #undef WRITE_BYTE_FIELD |
4694 | 4705 |
4695 | 4706 |
4696 } } // namespace v8::internal | 4707 } } // namespace v8::internal |
4697 | 4708 |
4698 #endif // V8_OBJECTS_INL_H_ | 4709 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |