// maps.
KeyedLookupCache::Clear();
ContextSlotCache::Clear();
+ DescriptorLookupCache::Clear();
CompilationCache::MarkCompactPrologue();
// Implements Cheney's copying algorithm
LOG(ResourceEvent("scavenge", "begin"));
+ // Clear descriptor cache.
+ DescriptorLookupCache::Clear();
+
// Used for updating survived_since_last_expansion_ at function end.
int survived_watermark = PromotedSpaceSize();
// Initialize context slot cache.
ContextSlotCache::Clear();
+ // Initialize descriptor cache.
+ DescriptorLookupCache::Clear();
+
// Initialize compilation cache.
CompilationCache::Clear();
int KeyedLookupCache::field_offsets_[KeyedLookupCache::kLength];
+void DescriptorLookupCache::Clear() {
+ for (int index = 0; index < kLength; index++) keys_[index].array = NULL;
+}
+
+
+DescriptorLookupCache::Key
+DescriptorLookupCache::keys_[DescriptorLookupCache::kLength];
+
+int DescriptorLookupCache::results_[DescriptorLookupCache::kLength];
+
+
#ifdef DEBUG
bool Heap::GarbageCollectionGreedyCheck() {
ASSERT(FLAG_gc_greedy);
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;
};
+
+// 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.
void JSObject::LookupInDescriptor(String* name, LookupResult* result) {
DescriptorArray* descriptors = map()->instance_descriptors();
- int number = descriptors->Search(name);
+ int number = DescriptorLookupCache::Lookup(descriptors, name);
+ if (number == DescriptorLookupCache::kAbsent) {
+ number = descriptors->Search(name);
+ DescriptorLookupCache::Update(descriptors, name, number);
+ }
if (number != DescriptorArray::kNotFound) {
result->DescriptorResult(this, descriptors->GetDetails(number), number);
} else {