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

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

Issue 235643002: 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 2857 matching lines...) Expand 10 before | Expand all | Expand 10 after
2868 ASSERT(!marking_->IsMarking() || 2868 ASSERT(!marking_->IsMarking() ||
2869 Marking::Color(array) == Marking::WHITE_OBJECT); 2869 Marking::Color(array) == Marking::WHITE_OBJECT);
2870 } 2870 }
2871 2871
2872 2872
2873 DescriptorArray::WhitenessWitness::~WhitenessWitness() { 2873 DescriptorArray::WhitenessWitness::~WhitenessWitness() {
2874 marking_->LeaveNoMarkingScope(); 2874 marking_->LeaveNoMarkingScope();
2875 } 2875 }
2876 2876
2877 2877
2878 template<typename Shape, typename Key> 2878 template<typename Derived, typename Shape, typename Key>
2879 int HashTable<Shape, Key>::ComputeCapacity(int at_least_space_for) { 2879 int HashTable<Derived, Shape, Key>::ComputeCapacity(int at_least_space_for) {
2880 const int kMinCapacity = 32; 2880 const int kMinCapacity = 32;
2881 int capacity = RoundUpToPowerOf2(at_least_space_for * 2); 2881 int capacity = RoundUpToPowerOf2(at_least_space_for * 2);
2882 if (capacity < kMinCapacity) { 2882 if (capacity < kMinCapacity) {
2883 capacity = kMinCapacity; // Guarantee min capacity. 2883 capacity = kMinCapacity; // Guarantee min capacity.
2884 } 2884 }
2885 return capacity; 2885 return capacity;
2886 } 2886 }
2887 2887
2888 2888
2889 template<typename Shape, typename Key> 2889 template<typename Derived, typename Shape, typename Key>
2890 int HashTable<Shape, Key>::FindEntry(Key key) { 2890 int HashTable<Derived, Shape, Key>::FindEntry(Key key) {
2891 return FindEntry(GetIsolate(), key); 2891 return FindEntry(GetIsolate(), key);
2892 } 2892 }
2893 2893
2894 2894
2895 // Find entry for key otherwise return kNotFound. 2895 // Find entry for key otherwise return kNotFound.
2896 template<typename Shape, typename Key> 2896 template<typename Derived, typename Shape, typename Key>
2897 int HashTable<Shape, Key>::FindEntry(Isolate* isolate, Key key) { 2897 int HashTable<Derived, Shape, Key>::FindEntry(Isolate* isolate, Key key) {
2898 uint32_t capacity = Capacity(); 2898 uint32_t capacity = Capacity();
2899 uint32_t entry = FirstProbe(HashTable<Shape, Key>::Hash(key), capacity); 2899 uint32_t entry = FirstProbe(HashTable::Hash(key), capacity);
2900 uint32_t count = 1; 2900 uint32_t count = 1;
2901 // EnsureCapacity will guarantee the hash table is never full. 2901 // EnsureCapacity will guarantee the hash table is never full.
2902 while (true) { 2902 while (true) {
2903 Object* element = KeyAt(entry); 2903 Object* element = KeyAt(entry);
2904 // Empty entry. Uses raw unchecked accessors because it is called by the 2904 // Empty entry. Uses raw unchecked accessors because it is called by the
2905 // string table during bootstrapping. 2905 // string table during bootstrapping.
2906 if (element == isolate->heap()->raw_unchecked_undefined_value()) break; 2906 if (element == isolate->heap()->raw_unchecked_undefined_value()) break;
2907 if (element != isolate->heap()->raw_unchecked_the_hole_value() && 2907 if (element != isolate->heap()->raw_unchecked_the_hole_value() &&
2908 Shape::IsMatch(key, element)) return entry; 2908 Shape::IsMatch(key, element)) return entry;
2909 entry = NextProbe(entry, count++, capacity); 2909 entry = NextProbe(entry, count++, capacity);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
3014 Traits::kInstanceType); 3014 Traits::kInstanceType);
3015 return reinterpret_cast<FixedTypedArray<Traits>*>(object); 3015 return reinterpret_cast<FixedTypedArray<Traits>*>(object);
3016 } 3016 }
3017 3017
3018 3018
3019 #define MAKE_STRUCT_CAST(NAME, Name, name) CAST_ACCESSOR(Name) 3019 #define MAKE_STRUCT_CAST(NAME, Name, name) CAST_ACCESSOR(Name)
3020 STRUCT_LIST(MAKE_STRUCT_CAST) 3020 STRUCT_LIST(MAKE_STRUCT_CAST)
3021 #undef MAKE_STRUCT_CAST 3021 #undef MAKE_STRUCT_CAST
3022 3022
3023 3023
3024 template <typename Shape, typename Key> 3024 template <typename Derived, typename Shape, typename Key>
3025 HashTable<Shape, Key>* HashTable<Shape, Key>::cast(Object* obj) { 3025 HashTable<Derived, Shape, Key>*
3026 HashTable<Derived, Shape, Key>::cast(Object* obj) {
3026 ASSERT(obj->IsHashTable()); 3027 ASSERT(obj->IsHashTable());
3027 return reinterpret_cast<HashTable*>(obj); 3028 return reinterpret_cast<HashTable*>(obj);
3028 } 3029 }
3029 3030
3030 3031
3031 SMI_ACCESSORS(FixedArrayBase, length, kLengthOffset) 3032 SMI_ACCESSORS(FixedArrayBase, length, kLengthOffset)
3032 SYNCHRONIZED_SMI_ACCESSORS(FixedArrayBase, length, kLengthOffset) 3033 SYNCHRONIZED_SMI_ACCESSORS(FixedArrayBase, length, kLengthOffset)
3033 3034
3034 SMI_ACCESSORS(FreeSpace, size, kSizeOffset) 3035 SMI_ACCESSORS(FreeSpace, size, kSizeOffset)
3035 NOBARRIER_SMI_ACCESSORS(FreeSpace, size, kSizeOffset) 3036 NOBARRIER_SMI_ACCESSORS(FreeSpace, size, kSizeOffset)
(...skipping 3639 matching lines...) Expand 10 before | Expand all | Expand 10 after
6675 bool AccessorPair::all_can_write() { 6676 bool AccessorPair::all_can_write() {
6676 return BooleanBit::get(access_flags(), kAllCanWriteBit); 6677 return BooleanBit::get(access_flags(), kAllCanWriteBit);
6677 } 6678 }
6678 6679
6679 6680
6680 bool AccessorPair::prohibits_overwriting() { 6681 bool AccessorPair::prohibits_overwriting() {
6681 return BooleanBit::get(access_flags(), kProhibitsOverwritingBit); 6682 return BooleanBit::get(access_flags(), kProhibitsOverwritingBit);
6682 } 6683 }
6683 6684
6684 6685
6685 template<typename Shape, typename Key> 6686 template<typename Derived, typename Shape, typename Key>
6686 void Dictionary<Shape, Key>::SetEntry(int entry, 6687 void Dictionary<Derived, Shape, Key>::SetEntry(int entry,
6687 Object* key, 6688 Object* key,
6688 Object* value) { 6689 Object* value) {
6689 SetEntry(entry, key, value, PropertyDetails(Smi::FromInt(0))); 6690 SetEntry(entry, key, value, PropertyDetails(Smi::FromInt(0)));
6690 } 6691 }
6691 6692
6692 6693
6693 template<typename Shape, typename Key> 6694 template<typename Derived, typename Shape, typename Key>
6694 void Dictionary<Shape, Key>::SetEntry(int entry, 6695 void Dictionary<Derived, Shape, Key>::SetEntry(int entry,
6695 Object* key, 6696 Object* key,
6696 Object* value, 6697 Object* value,
6697 PropertyDetails details) { 6698 PropertyDetails details) {
6698 ASSERT(!key->IsName() || 6699 ASSERT(!key->IsName() ||
6699 details.IsDeleted() || 6700 details.IsDeleted() ||
6700 details.dictionary_index() > 0); 6701 details.dictionary_index() > 0);
6701 int index = HashTable<Shape, Key>::EntryToIndex(entry); 6702 int index = DerivedHashTable::EntryToIndex(entry);
6702 DisallowHeapAllocation no_gc; 6703 DisallowHeapAllocation no_gc;
6703 WriteBarrierMode mode = FixedArray::GetWriteBarrierMode(no_gc); 6704 WriteBarrierMode mode = FixedArray::GetWriteBarrierMode(no_gc);
6704 FixedArray::set(index, key, mode); 6705 FixedArray::set(index, key, mode);
6705 FixedArray::set(index+1, value, mode); 6706 FixedArray::set(index+1, value, mode);
6706 FixedArray::set(index+2, details.AsSmi()); 6707 FixedArray::set(index+2, details.AsSmi());
6707 } 6708 }
6708 6709
6709 6710
6710 bool NumberDictionaryShape::IsMatch(uint32_t key, Object* other) { 6711 bool NumberDictionaryShape::IsMatch(uint32_t key, Object* other) {
6711 ASSERT(other->IsNumber()); 6712 ASSERT(other->IsNumber());
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
6777 uint32_t ObjectHashTableShape::HashForObject(Object* key, Object* other) { 6778 uint32_t ObjectHashTableShape::HashForObject(Object* key, Object* other) {
6778 return Smi::cast(other->GetHash())->value(); 6779 return Smi::cast(other->GetHash())->value();
6779 } 6780 }
6780 6781
6781 6782
6782 MaybeObject* ObjectHashTableShape::AsObject(Heap* heap, Object* key) { 6783 MaybeObject* ObjectHashTableShape::AsObject(Heap* heap, Object* key) {
6783 return key; 6784 return key;
6784 } 6785 }
6785 6786
6786 6787
6788 Handle<ObjectHashTable> ObjectHashTable::Shrink(
6789 Handle<ObjectHashTable> table, Handle<Object> key) {
6790 return HashTable_::Shrink(table, *key);
6791 }
6792
6793
6787 template <int entrysize> 6794 template <int entrysize>
6788 bool WeakHashTableShape<entrysize>::IsMatch(Object* key, Object* other) { 6795 bool WeakHashTableShape<entrysize>::IsMatch(Object* key, Object* other) {
6789 return key->SameValue(other); 6796 return key->SameValue(other);
6790 } 6797 }
6791 6798
6792 6799
6793 template <int entrysize> 6800 template <int entrysize>
6794 uint32_t WeakHashTableShape<entrysize>::Hash(Object* key) { 6801 uint32_t WeakHashTableShape<entrysize>::Hash(Object* key) {
6795 intptr_t hash = reinterpret_cast<intptr_t>(key); 6802 intptr_t hash = reinterpret_cast<intptr_t>(key);
6796 return (uint32_t)(hash & 0xFFFFFFFF); 6803 return (uint32_t)(hash & 0xFFFFFFFF);
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
7100 #undef READ_SHORT_FIELD 7107 #undef READ_SHORT_FIELD
7101 #undef WRITE_SHORT_FIELD 7108 #undef WRITE_SHORT_FIELD
7102 #undef READ_BYTE_FIELD 7109 #undef READ_BYTE_FIELD
7103 #undef WRITE_BYTE_FIELD 7110 #undef WRITE_BYTE_FIELD
7104 #undef NOBARRIER_READ_BYTE_FIELD 7111 #undef NOBARRIER_READ_BYTE_FIELD
7105 #undef NOBARRIER_WRITE_BYTE_FIELD 7112 #undef NOBARRIER_WRITE_BYTE_FIELD
7106 7113
7107 } } // namespace v8::internal 7114 } } // namespace v8::internal
7108 7115
7109 #endif // V8_OBJECTS_INL_H_ 7116 #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