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

Unified Diff: src/heap.h

Issue 141046: Added descriptor lookup cache to eliminate some search overhead.... (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/heap.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/heap.h
===================================================================
--- src/heap.h (revision 2237)
+++ src/heap.h (working copy)
@@ -1148,7 +1148,7 @@
static void Clear();
private:
inline static int Hash(Map* map, String* name);
- static const int kLength = 128;
+ static const int kLength = 64;
struct Key {
Map* map;
String* name;
@@ -1158,6 +1158,60 @@
};
+
+// Cache for mapping (array, property name) into descriptor index.
+// The cache contains both positive and negative results.
+// Descriptor index equals kNotFound means the property is absent.
+// Cleared at startup and prior to any gc.
+class DescriptorLookupCache {
+ public:
+ // Lookup descriptor index for (map, name).
+ // If absent, kAbsent is returned.
+ static int Lookup(DescriptorArray* array, String* name) {
+ if(!StringShape(name).IsSymbol()) return kAbsent;
+ int index = Hash(array, name);
+ Key& key = keys_[index];
+ if ((key.array == array) && (key.name == name)) return results_[index];
+ return kAbsent;
+ }
+
+ // Update an element in the cache.
+ static void Update(DescriptorArray* array, String* name, int result) {
+ ASSERT(result != kAbsent);
+ if(StringShape(name).IsSymbol()) {
+ int index = Hash(array, name);
+ Key& key = keys_[index];
+ key.array = array;
+ key.name = name;
+ results_[index] = result;
+ }
+ }
+
+ // Clear the cache.
+ static void Clear();
+
+ static const int kAbsent = -2;
+ private:
+ static int Hash(DescriptorArray* array, String* name) {
+ // Uses only lower 32 bits if pointers are larger.
+ uintptr_t array_hash =
+ static_cast<uint32_t>(reinterpret_cast<uintptr_t>(array)) >> 2;
+ uintptr_t name_hash =
+ static_cast<uint32_t>(reinterpret_cast<uintptr_t>(name)) >> 2;
+ return (array_hash ^ name_hash) % kLength;
+ }
+
+ static const int kLength = 64;
+ struct Key {
+ DescriptorArray* array;
+ String* name;
+ };
+
+ static Key keys_[kLength];
+ static int results_[kLength];
+};
+
+
// ----------------------------------------------------------------------------
// Marking stack for tracing live objects.
« no previous file with comments | « no previous file | src/heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698