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

Side by Side Diff: src/objects.cc

Issue 126262: Reimplemented the KeyedLookupCache to speed up access. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 6 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.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 6738 matching lines...) Expand 10 before | Expand all | Expand 10 after
6749 return hash; 6749 return hash;
6750 } 6750 }
6751 6751
6752 bool IsStringKey() { return false; } 6752 bool IsStringKey() { return false; }
6753 6753
6754 private: 6754 private:
6755 FixedArray* symbols_; 6755 FixedArray* symbols_;
6756 }; 6756 };
6757 6757
6758 6758
6759 // MapNameKeys are used as keys in lookup caches.
6760 class MapNameKey : public HashTableKey {
6761 public:
6762 MapNameKey(Map* map, String* name)
6763 : map_(map), name_(name) { }
6764
6765 bool IsMatch(Object* other) {
6766 if (!other->IsFixedArray()) return false;
6767 FixedArray* pair = FixedArray::cast(other);
6768 Map* map = Map::cast(pair->get(0));
6769 if (map != map_) return false;
6770 String* name = String::cast(pair->get(1));
6771 return name->Equals(name_);
6772 }
6773
6774 typedef uint32_t (*HashFunction)(Object* obj);
6775
6776 virtual HashFunction GetHashFunction() { return MapNameHash; }
6777
6778 static uint32_t MapNameHashHelper(Map* map, String* name) {
6779 // Uses only lower 32 bits if pointers are larger.
6780 uintptr_t addr_hash =
6781 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(map));
6782 return addr_hash ^ name->Hash();
6783 }
6784
6785 static uint32_t MapNameHash(Object* obj) {
6786 FixedArray* pair = FixedArray::cast(obj);
6787 Map* map = Map::cast(pair->get(0));
6788 String* name = String::cast(pair->get(1));
6789 return MapNameHashHelper(map, name);
6790 }
6791
6792 virtual uint32_t Hash() {
6793 return MapNameHashHelper(map_, name_);
6794 }
6795
6796 virtual Object* GetObject() {
6797 Object* obj = Heap::AllocateFixedArray(2);
6798 if (obj->IsFailure()) return obj;
6799 FixedArray* pair = FixedArray::cast(obj);
6800 pair->set(0, map_);
6801 pair->set(1, name_);
6802 return pair;
6803 }
6804
6805 virtual bool IsStringKey() { return false; }
6806
6807 private:
6808 Map* map_;
6809 String* name_;
6810 };
6811
6812
6813 Object* MapCache::Lookup(FixedArray* array) { 6759 Object* MapCache::Lookup(FixedArray* array) {
6814 SymbolsKey key(array); 6760 SymbolsKey key(array);
6815 int entry = FindEntry(&key); 6761 int entry = FindEntry(&key);
6816 if (entry == -1) return Heap::undefined_value(); 6762 if (entry == -1) return Heap::undefined_value();
6817 return get(EntryToIndex(entry) + 1); 6763 return get(EntryToIndex(entry) + 1);
6818 } 6764 }
6819 6765
6820 6766
6821 Object* MapCache::Put(FixedArray* array, Map* value) { 6767 Object* MapCache::Put(FixedArray* array, Map* value) {
6822 SymbolsKey key(array); 6768 SymbolsKey key(array);
6823 Object* obj = EnsureCapacity(1, &key); 6769 Object* obj = EnsureCapacity(1, &key);
6824 if (obj->IsFailure()) return obj; 6770 if (obj->IsFailure()) return obj;
6825 6771
6826 MapCache* cache = reinterpret_cast<MapCache*>(obj); 6772 MapCache* cache = reinterpret_cast<MapCache*>(obj);
6827 int entry = cache->FindInsertionEntry(array, key.Hash()); 6773 int entry = cache->FindInsertionEntry(array, key.Hash());
6828 cache->set(EntryToIndex(entry), array); 6774 cache->set(EntryToIndex(entry), array);
6829 cache->set(EntryToIndex(entry) + 1, value); 6775 cache->set(EntryToIndex(entry) + 1, value);
6830 cache->ElementAdded(); 6776 cache->ElementAdded();
6831 return cache; 6777 return cache;
6832 } 6778 }
6833 6779
6834 6780
6835 int LookupCache::Lookup(Map* map, String* name) {
6836 MapNameKey key(map, name);
6837 int entry = FindEntry(&key);
6838 if (entry == -1) return kNotFound;
6839 return Smi::cast(get(EntryToIndex(entry) + 1))->value();
6840 }
6841
6842
6843 Object* LookupCache::Put(Map* map, String* name, int value) {
6844 MapNameKey key(map, name);
6845 Object* obj = EnsureCapacity(1, &key);
6846 if (obj->IsFailure()) return obj;
6847 Object* k = key.GetObject();
6848 if (k->IsFailure()) return k;
6849
6850 LookupCache* cache = reinterpret_cast<LookupCache*>(obj);
6851 int entry = cache->FindInsertionEntry(k, key.Hash());
6852 int index = EntryToIndex(entry);
6853 cache->set(index, k);
6854 cache->set(index + 1, Smi::FromInt(value), SKIP_WRITE_BARRIER);
6855 cache->ElementAdded();
6856 return cache;
6857 }
6858
6859
6860 Object* Dictionary::Allocate(int at_least_space_for) { 6781 Object* Dictionary::Allocate(int at_least_space_for) {
6861 Object* obj = DictionaryBase::Allocate(at_least_space_for); 6782 Object* obj = DictionaryBase::Allocate(at_least_space_for);
6862 // Initialize the next enumeration index. 6783 // Initialize the next enumeration index.
6863 if (!obj->IsFailure()) { 6784 if (!obj->IsFailure()) {
6864 Dictionary::cast(obj)-> 6785 Dictionary::cast(obj)->
6865 SetNextEnumerationIndex(PropertyDetails::kInitialIndex); 6786 SetNextEnumerationIndex(PropertyDetails::kInitialIndex);
6866 } 6787 }
6867 return obj; 6788 return obj;
6868 } 6789 }
6869 6790
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
7558 // No break point. 7479 // No break point.
7559 if (break_point_objects()->IsUndefined()) return 0; 7480 if (break_point_objects()->IsUndefined()) return 0;
7560 // Single beak point. 7481 // Single beak point.
7561 if (!break_point_objects()->IsFixedArray()) return 1; 7482 if (!break_point_objects()->IsFixedArray()) return 1;
7562 // Multiple break points. 7483 // Multiple break points.
7563 return FixedArray::cast(break_point_objects())->length(); 7484 return FixedArray::cast(break_point_objects())->length();
7564 } 7485 }
7565 #endif 7486 #endif
7566 7487
7567 } } // namespace v8::internal 7488 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698