Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/objects-inl.h

Issue 227423004: Reland "HashTable::Shrink() handlified and derived template parameter added to HashTable hierarchy." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: The fix Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 847 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 } 858 }
859 859
860 860
861 bool Object::IsDictionary() { 861 bool Object::IsDictionary() {
862 return IsHashTable() && 862 return IsHashTable() &&
863 this != HeapObject::cast(this)->GetHeap()->string_table(); 863 this != HeapObject::cast(this)->GetHeap()->string_table();
864 } 864 }
865 865
866 866
867 bool Object::IsStringTable() { 867 bool Object::IsStringTable() {
868 return IsHashTable() && 868 return IsHashTable();
869 this == HeapObject::cast(this)->GetHeap()->raw_unchecked_string_table();
870 } 869 }
871 870
872 871
873 bool Object::IsJSFunctionResultCache() { 872 bool Object::IsJSFunctionResultCache() {
874 if (!IsFixedArray()) return false; 873 if (!IsFixedArray()) return false;
875 FixedArray* self = FixedArray::cast(this); 874 FixedArray* self = FixedArray::cast(this);
876 int length = self->length(); 875 int length = self->length();
877 if (length < JSFunctionResultCache::kEntriesIndex) return false; 876 if (length < JSFunctionResultCache::kEntriesIndex) return false;
878 if ((length - JSFunctionResultCache::kEntriesIndex) 877 if ((length - JSFunctionResultCache::kEntriesIndex)
879 % JSFunctionResultCache::kEntrySize != 0) { 878 % JSFunctionResultCache::kEntrySize != 0) {
(...skipping 1995 matching lines...) Expand 10 before | Expand all | Expand 10 after
2875 ASSERT(!marking_->IsMarking() || 2874 ASSERT(!marking_->IsMarking() ||
2876 Marking::Color(array) == Marking::WHITE_OBJECT); 2875 Marking::Color(array) == Marking::WHITE_OBJECT);
2877 } 2876 }
2878 2877
2879 2878
2880 DescriptorArray::WhitenessWitness::~WhitenessWitness() { 2879 DescriptorArray::WhitenessWitness::~WhitenessWitness() {
2881 marking_->LeaveNoMarkingScope(); 2880 marking_->LeaveNoMarkingScope();
2882 } 2881 }
2883 2882
2884 2883
2885 template<typename Shape, typename Key> 2884 template<typename Derived, typename Shape, typename Key>
2886 int HashTable<Shape, Key>::ComputeCapacity(int at_least_space_for) { 2885 int HashTable<Derived, Shape, Key>::ComputeCapacity(int at_least_space_for) {
2887 const int kMinCapacity = 32; 2886 const int kMinCapacity = 32;
2888 int capacity = RoundUpToPowerOf2(at_least_space_for * 2); 2887 int capacity = RoundUpToPowerOf2(at_least_space_for * 2);
2889 if (capacity < kMinCapacity) { 2888 if (capacity < kMinCapacity) {
2890 capacity = kMinCapacity; // Guarantee min capacity. 2889 capacity = kMinCapacity; // Guarantee min capacity.
2891 } 2890 }
2892 return capacity; 2891 return capacity;
2893 } 2892 }
2894 2893
2895 2894
2896 template<typename Shape, typename Key> 2895 template<typename Derived, typename Shape, typename Key>
2897 int HashTable<Shape, Key>::FindEntry(Key key) { 2896 int HashTable<Derived, Shape, Key>::FindEntry(Key key) {
2898 return FindEntry(GetIsolate(), key); 2897 return FindEntry(GetIsolate(), key);
2899 } 2898 }
2900 2899
2901 2900
2902 // Find entry for key otherwise return kNotFound. 2901 // Find entry for key otherwise return kNotFound.
2903 template<typename Shape, typename Key> 2902 template<typename Derived, typename Shape, typename Key>
2904 int HashTable<Shape, Key>::FindEntry(Isolate* isolate, Key key) { 2903 int HashTable<Derived, Shape, Key>::FindEntry(Isolate* isolate, Key key) {
2905 uint32_t capacity = Capacity(); 2904 uint32_t capacity = Capacity();
2906 uint32_t entry = FirstProbe(HashTable<Shape, Key>::Hash(key), capacity); 2905 uint32_t entry = FirstProbe(HashTable::Hash(key), capacity);
2907 uint32_t count = 1; 2906 uint32_t count = 1;
2908 // EnsureCapacity will guarantee the hash table is never full. 2907 // EnsureCapacity will guarantee the hash table is never full.
2909 while (true) { 2908 while (true) {
2910 Object* element = KeyAt(entry); 2909 Object* element = KeyAt(entry);
2911 // Empty entry. Uses raw unchecked accessors because it is called by the 2910 // Empty entry. Uses raw unchecked accessors because it is called by the
2912 // string table during bootstrapping. 2911 // string table during bootstrapping.
2913 if (element == isolate->heap()->raw_unchecked_undefined_value()) break; 2912 if (element == isolate->heap()->raw_unchecked_undefined_value()) break;
2914 if (element != isolate->heap()->raw_unchecked_the_hole_value() && 2913 if (element != isolate->heap()->raw_unchecked_the_hole_value() &&
2915 Shape::IsMatch(key, element)) return entry; 2914 Shape::IsMatch(key, element)) return entry;
2916 entry = NextProbe(entry, count++, capacity); 2915 entry = NextProbe(entry, count++, capacity);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
3021 Traits::kInstanceType); 3020 Traits::kInstanceType);
3022 return reinterpret_cast<FixedTypedArray<Traits>*>(object); 3021 return reinterpret_cast<FixedTypedArray<Traits>*>(object);
3023 } 3022 }
3024 3023
3025 3024
3026 #define MAKE_STRUCT_CAST(NAME, Name, name) CAST_ACCESSOR(Name) 3025 #define MAKE_STRUCT_CAST(NAME, Name, name) CAST_ACCESSOR(Name)
3027 STRUCT_LIST(MAKE_STRUCT_CAST) 3026 STRUCT_LIST(MAKE_STRUCT_CAST)
3028 #undef MAKE_STRUCT_CAST 3027 #undef MAKE_STRUCT_CAST
3029 3028
3030 3029
3031 template <typename Shape, typename Key> 3030 template <typename Derived, typename Shape, typename Key>
3032 HashTable<Shape, Key>* HashTable<Shape, Key>::cast(Object* obj) { 3031 HashTable<Derived, Shape, Key>*
3032 HashTable<Derived, Shape, Key>::cast(Object* obj) {
3033 ASSERT(obj->IsHashTable()); 3033 ASSERT(obj->IsHashTable());
3034 return reinterpret_cast<HashTable*>(obj); 3034 return reinterpret_cast<HashTable*>(obj);
3035 } 3035 }
3036 3036
3037 3037
3038 SMI_ACCESSORS(FixedArrayBase, length, kLengthOffset) 3038 SMI_ACCESSORS(FixedArrayBase, length, kLengthOffset)
3039 SYNCHRONIZED_SMI_ACCESSORS(FixedArrayBase, length, kLengthOffset) 3039 SYNCHRONIZED_SMI_ACCESSORS(FixedArrayBase, length, kLengthOffset)
3040 3040
3041 SMI_ACCESSORS(FreeSpace, size, kSizeOffset) 3041 SMI_ACCESSORS(FreeSpace, size, kSizeOffset)
3042 NOBARRIER_SMI_ACCESSORS(FreeSpace, size, kSizeOffset) 3042 NOBARRIER_SMI_ACCESSORS(FreeSpace, size, kSizeOffset)
(...skipping 3621 matching lines...) Expand 10 before | Expand all | Expand 10 after
6664 bool AccessorPair::all_can_write() { 6664 bool AccessorPair::all_can_write() {
6665 return BooleanBit::get(access_flags(), kAllCanWriteBit); 6665 return BooleanBit::get(access_flags(), kAllCanWriteBit);
6666 } 6666 }
6667 6667
6668 6668
6669 bool AccessorPair::prohibits_overwriting() { 6669 bool AccessorPair::prohibits_overwriting() {
6670 return BooleanBit::get(access_flags(), kProhibitsOverwritingBit); 6670 return BooleanBit::get(access_flags(), kProhibitsOverwritingBit);
6671 } 6671 }
6672 6672
6673 6673
6674 template<typename Shape, typename Key> 6674 template<typename Derived, typename Shape, typename Key>
6675 void Dictionary<Shape, Key>::SetEntry(int entry, 6675 void Dictionary<Derived, Shape, Key>::SetEntry(int entry,
6676 Object* key, 6676 Object* key,
6677 Object* value) { 6677 Object* value) {
6678 SetEntry(entry, key, value, PropertyDetails(Smi::FromInt(0))); 6678 SetEntry(entry, key, value, PropertyDetails(Smi::FromInt(0)));
6679 } 6679 }
6680 6680
6681 6681
6682 template<typename Shape, typename Key> 6682 template<typename Derived, typename Shape, typename Key>
6683 void Dictionary<Shape, Key>::SetEntry(int entry, 6683 void Dictionary<Derived, Shape, Key>::SetEntry(int entry,
6684 Object* key, 6684 Object* key,
6685 Object* value, 6685 Object* value,
6686 PropertyDetails details) { 6686 PropertyDetails details) {
6687 ASSERT(!key->IsName() || 6687 ASSERT(!key->IsName() ||
6688 details.IsDeleted() || 6688 details.IsDeleted() ||
6689 details.dictionary_index() > 0); 6689 details.dictionary_index() > 0);
6690 int index = HashTable<Shape, Key>::EntryToIndex(entry); 6690 int index = DerivedHashTable::EntryToIndex(entry);
6691 DisallowHeapAllocation no_gc; 6691 DisallowHeapAllocation no_gc;
6692 WriteBarrierMode mode = FixedArray::GetWriteBarrierMode(no_gc); 6692 WriteBarrierMode mode = FixedArray::GetWriteBarrierMode(no_gc);
6693 FixedArray::set(index, key, mode); 6693 FixedArray::set(index, key, mode);
6694 FixedArray::set(index+1, value, mode); 6694 FixedArray::set(index+1, value, mode);
6695 FixedArray::set(index+2, details.AsSmi()); 6695 FixedArray::set(index+2, details.AsSmi());
6696 } 6696 }
6697 6697
6698 6698
6699 bool NumberDictionaryShape::IsMatch(uint32_t key, Object* other) { 6699 bool NumberDictionaryShape::IsMatch(uint32_t key, Object* other) {
6700 ASSERT(other->IsNumber()); 6700 ASSERT(other->IsNumber());
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
6766 uint32_t ObjectHashTableShape::HashForObject(Object* key, Object* other) { 6766 uint32_t ObjectHashTableShape::HashForObject(Object* key, Object* other) {
6767 return Smi::cast(other->GetHash())->value(); 6767 return Smi::cast(other->GetHash())->value();
6768 } 6768 }
6769 6769
6770 6770
6771 MaybeObject* ObjectHashTableShape::AsObject(Heap* heap, Object* key) { 6771 MaybeObject* ObjectHashTableShape::AsObject(Heap* heap, Object* key) {
6772 return key; 6772 return key;
6773 } 6773 }
6774 6774
6775 6775
6776 Handle<ObjectHashTable> ObjectHashTable::Shrink(
6777 Handle<ObjectHashTable> table, Handle<Object> key) {
6778 return HashTable_::Shrink(table, *key);
6779 }
6780
6781
6776 template <int entrysize> 6782 template <int entrysize>
6777 bool WeakHashTableShape<entrysize>::IsMatch(Object* key, Object* other) { 6783 bool WeakHashTableShape<entrysize>::IsMatch(Object* key, Object* other) {
6778 return key->SameValue(other); 6784 return key->SameValue(other);
6779 } 6785 }
6780 6786
6781 6787
6782 template <int entrysize> 6788 template <int entrysize>
6783 uint32_t WeakHashTableShape<entrysize>::Hash(Object* key) { 6789 uint32_t WeakHashTableShape<entrysize>::Hash(Object* key) {
6784 intptr_t hash = reinterpret_cast<intptr_t>(key); 6790 intptr_t hash = reinterpret_cast<intptr_t>(key);
6785 return (uint32_t)(hash & 0xFFFFFFFF); 6791 return (uint32_t)(hash & 0xFFFFFFFF);
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
7089 #undef READ_SHORT_FIELD 7095 #undef READ_SHORT_FIELD
7090 #undef WRITE_SHORT_FIELD 7096 #undef WRITE_SHORT_FIELD
7091 #undef READ_BYTE_FIELD 7097 #undef READ_BYTE_FIELD
7092 #undef WRITE_BYTE_FIELD 7098 #undef WRITE_BYTE_FIELD
7093 #undef NOBARRIER_READ_BYTE_FIELD 7099 #undef NOBARRIER_READ_BYTE_FIELD
7094 #undef NOBARRIER_WRITE_BYTE_FIELD 7100 #undef NOBARRIER_WRITE_BYTE_FIELD
7095 7101
7096 } } // namespace v8::internal 7102 } } // namespace v8::internal
7097 7103
7098 #endif // V8_OBJECTS_INL_H_ 7104 #endif // V8_OBJECTS_INL_H_
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698