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 14152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14163 | 14163 |
14164 // Force instantiation of template instances class. | 14164 // Force instantiation of template instances class. |
14165 // Please note this list is compiler dependent. | 14165 // Please note this list is compiler dependent. |
14166 | 14166 |
14167 template class HashTable<StringTableShape, HashTableKey*>; | 14167 template class HashTable<StringTableShape, HashTableKey*>; |
14168 | 14168 |
14169 template class HashTable<CompilationCacheShape, HashTableKey*>; | 14169 template class HashTable<CompilationCacheShape, HashTableKey*>; |
14170 | 14170 |
14171 template class HashTable<MapCacheShape, HashTableKey*>; | 14171 template class HashTable<MapCacheShape, HashTableKey*>; |
14172 | 14172 |
14173 template class HashTable<ObjectHashTableShape<1>, Object*>; | 14173 template class HashTable<ObjectHashTableShape, Object*>; |
14174 | |
14175 template class HashTable<ObjectHashTableShape<2>, Object*>; | |
14176 | 14174 |
14177 template class HashTable<WeakHashTableShape<2>, Object*>; | 14175 template class HashTable<WeakHashTableShape<2>, Object*>; |
14178 | 14176 |
14179 template class Dictionary<NameDictionaryShape, Name*>; | 14177 template class Dictionary<NameDictionaryShape, Name*>; |
14180 | 14178 |
14181 template class Dictionary<SeededNumberDictionaryShape, uint32_t>; | 14179 template class Dictionary<SeededNumberDictionaryShape, uint32_t>; |
14182 | 14180 |
14183 template class Dictionary<UnseededNumberDictionaryShape, uint32_t>; | 14181 template class Dictionary<UnseededNumberDictionaryShape, uint32_t>; |
14184 | 14182 |
14185 template MaybeObject* Dictionary<SeededNumberDictionaryShape, uint32_t>:: | 14183 template MaybeObject* Dictionary<SeededNumberDictionaryShape, uint32_t>:: |
(...skipping 1516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15702 obj->set_properties(fields); | 15700 obj->set_properties(fields); |
15703 ASSERT(obj->IsJSObject()); | 15701 ASSERT(obj->IsJSObject()); |
15704 | 15702 |
15705 // Check that it really works. | 15703 // Check that it really works. |
15706 ASSERT(obj->HasFastProperties()); | 15704 ASSERT(obj->HasFastProperties()); |
15707 | 15705 |
15708 return obj; | 15706 return obj; |
15709 } | 15707 } |
15710 | 15708 |
15711 | 15709 |
15712 Handle<ObjectHashSet> ObjectHashSet::EnsureCapacity( | |
15713 Handle<ObjectHashSet> table, | |
15714 int n, | |
15715 Handle<Object> key, | |
15716 PretenureFlag pretenure) { | |
15717 Handle<HashTable<ObjectHashTableShape<1>, Object*> > table_base = table; | |
15718 CALL_HEAP_FUNCTION(table_base->GetIsolate(), | |
15719 table_base->EnsureCapacity(n, *key, pretenure), | |
15720 ObjectHashSet); | |
15721 } | |
15722 | |
15723 | |
15724 Handle<ObjectHashSet> ObjectHashSet::Shrink(Handle<ObjectHashSet> table, | |
15725 Handle<Object> key) { | |
15726 Handle<HashTable<ObjectHashTableShape<1>, Object*> > table_base = table; | |
15727 CALL_HEAP_FUNCTION(table_base->GetIsolate(), | |
15728 table_base->Shrink(*key), | |
15729 ObjectHashSet); | |
15730 } | |
15731 | |
15732 | |
15733 bool ObjectHashSet::Contains(Object* key) { | |
15734 ASSERT(IsKey(key)); | |
15735 | |
15736 // If the object does not have an identity hash, it was never used as a key. | |
15737 Object* hash = key->GetHash(); | |
15738 if (hash->IsUndefined()) return false; | |
15739 | |
15740 return (FindEntry(key) != kNotFound); | |
15741 } | |
15742 | |
15743 | |
15744 Handle<ObjectHashSet> ObjectHashSet::Add(Handle<ObjectHashSet> table, | |
15745 Handle<Object> key) { | |
15746 ASSERT(table->IsKey(*key)); | |
15747 | |
15748 // Make sure the key object has an identity hash code. | |
15749 Handle<Object> object_hash = Object::GetOrCreateHash(key, | |
15750 table->GetIsolate()); | |
15751 | |
15752 int entry = table->FindEntry(*key); | |
15753 | |
15754 // Check whether key is already present. | |
15755 if (entry != kNotFound) return table; | |
15756 | |
15757 // Check whether the hash set should be extended and add entry. | |
15758 Handle<ObjectHashSet> new_table = | |
15759 ObjectHashSet::EnsureCapacity(table, 1, key); | |
15760 entry = new_table->FindInsertionEntry(Smi::cast(*object_hash)->value()); | |
15761 new_table->set(EntryToIndex(entry), *key); | |
15762 new_table->ElementAdded(); | |
15763 return new_table; | |
15764 } | |
15765 | |
15766 | |
15767 Handle<ObjectHashSet> ObjectHashSet::Remove(Handle<ObjectHashSet> table, | |
15768 Handle<Object> key) { | |
15769 ASSERT(table->IsKey(*key)); | |
15770 | |
15771 // If the object does not have an identity hash, it was never used as a key. | |
15772 if (key->GetHash()->IsUndefined()) return table; | |
15773 | |
15774 int entry = table->FindEntry(*key); | |
15775 | |
15776 // Check whether key is actually present. | |
15777 if (entry == kNotFound) return table; | |
15778 | |
15779 // Remove entry and try to shrink this hash set. | |
15780 table->set_the_hole(EntryToIndex(entry)); | |
15781 table->ElementRemoved(); | |
15782 | |
15783 return ObjectHashSet::Shrink(table, key); | |
15784 } | |
15785 | |
15786 | |
15787 Handle<ObjectHashTable> ObjectHashTable::EnsureCapacity( | 15710 Handle<ObjectHashTable> ObjectHashTable::EnsureCapacity( |
15788 Handle<ObjectHashTable> table, | 15711 Handle<ObjectHashTable> table, |
15789 int n, | 15712 int n, |
15790 Handle<Object> key, | 15713 Handle<Object> key, |
15791 PretenureFlag pretenure) { | 15714 PretenureFlag pretenure) { |
15792 Handle<HashTable<ObjectHashTableShape<2>, Object*> > table_base = table; | 15715 Handle<HashTable<ObjectHashTableShape, Object*> > table_base = table; |
15793 CALL_HEAP_FUNCTION(table_base->GetIsolate(), | 15716 CALL_HEAP_FUNCTION(table_base->GetIsolate(), |
15794 table_base->EnsureCapacity(n, *key, pretenure), | 15717 table_base->EnsureCapacity(n, *key, pretenure), |
15795 ObjectHashTable); | 15718 ObjectHashTable); |
15796 } | 15719 } |
15797 | 15720 |
15798 | 15721 |
15799 Handle<ObjectHashTable> ObjectHashTable::Shrink( | 15722 Handle<ObjectHashTable> ObjectHashTable::Shrink( |
15800 Handle<ObjectHashTable> table, Handle<Object> key) { | 15723 Handle<ObjectHashTable> table, Handle<Object> key) { |
15801 Handle<HashTable<ObjectHashTableShape<2>, Object*> > table_base = table; | 15724 Handle<HashTable<ObjectHashTableShape, Object*> > table_base = table; |
15802 CALL_HEAP_FUNCTION(table_base->GetIsolate(), | 15725 CALL_HEAP_FUNCTION(table_base->GetIsolate(), |
15803 table_base->Shrink(*key), | 15726 table_base->Shrink(*key), |
15804 ObjectHashTable); | 15727 ObjectHashTable); |
15805 } | 15728 } |
15806 | 15729 |
15807 | 15730 |
15808 Object* ObjectHashTable::Lookup(Object* key) { | 15731 Object* ObjectHashTable::Lookup(Object* key) { |
15809 ASSERT(IsKey(key)); | 15732 ASSERT(IsKey(key)); |
15810 | 15733 |
15811 // If the object does not have an identity hash, it was never used as a key. | 15734 // If the object does not have an identity hash, it was never used as a key. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15909 // to divide and multiple by 2 (kLoadFactor) to derive capacity | 15832 // to divide and multiple by 2 (kLoadFactor) to derive capacity |
15910 // from number of buckets. If we decide to change kLoadFactor | 15833 // from number of buckets. If we decide to change kLoadFactor |
15911 // to something other than 2, capacity should be stored as another | 15834 // to something other than 2, capacity should be stored as another |
15912 // field of this object. | 15835 // field of this object. |
15913 const int kMinCapacity = 4; | 15836 const int kMinCapacity = 4; |
15914 capacity = RoundUpToPowerOf2(Max(kMinCapacity, capacity)); | 15837 capacity = RoundUpToPowerOf2(Max(kMinCapacity, capacity)); |
15915 if (capacity > kMaxCapacity) { | 15838 if (capacity > kMaxCapacity) { |
15916 v8::internal::Heap::FatalProcessOutOfMemory("invalid table size", true); | 15839 v8::internal::Heap::FatalProcessOutOfMemory("invalid table size", true); |
15917 } | 15840 } |
15918 int num_buckets = capacity / kLoadFactor; | 15841 int num_buckets = capacity / kLoadFactor; |
15919 Handle<Derived> table = | 15842 Handle<FixedArray> backing_store = isolate->factory()->NewFixedArray( |
15920 Handle<Derived>::cast( | 15843 kHashTableStartIndex + num_buckets + (capacity * kEntrySize), pretenure); |
15921 isolate->factory()->NewFixedArray( | 15844 backing_store->set_map_no_write_barrier( |
15922 kHashTableStartIndex + num_buckets + (capacity * kEntrySize), | 15845 isolate->heap()->ordered_hash_table_map()); |
15923 pretenure)); | 15846 Handle<Derived> table = Handle<Derived>::cast(backing_store); |
15924 for (int i = 0; i < num_buckets; ++i) { | 15847 for (int i = 0; i < num_buckets; ++i) { |
15925 table->set(kHashTableStartIndex + i, Smi::FromInt(kNotFound)); | 15848 table->set(kHashTableStartIndex + i, Smi::FromInt(kNotFound)); |
15926 } | 15849 } |
15927 table->SetNumberOfBuckets(num_buckets); | 15850 table->SetNumberOfBuckets(num_buckets); |
15928 table->SetNumberOfElements(0); | 15851 table->SetNumberOfElements(0); |
15929 table->SetNumberOfDeletedElements(0); | 15852 table->SetNumberOfDeletedElements(0); |
15930 return table; | 15853 return table; |
15931 } | 15854 } |
15932 | 15855 |
15933 | 15856 |
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16677 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16600 #define ERROR_MESSAGES_TEXTS(C, T) T, |
16678 static const char* error_messages_[] = { | 16601 static const char* error_messages_[] = { |
16679 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16602 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
16680 }; | 16603 }; |
16681 #undef ERROR_MESSAGES_TEXTS | 16604 #undef ERROR_MESSAGES_TEXTS |
16682 return error_messages_[reason]; | 16605 return error_messages_[reason]; |
16683 } | 16606 } |
16684 | 16607 |
16685 | 16608 |
16686 } } // namespace v8::internal | 16609 } } // namespace v8::internal |
OLD | NEW |