1 // Copyright 2016 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_LOOKUP_CACHE_H_ 6 #define V8_LOOKUP_CACHE_H_ 7 8 #include "src/objects.h" 9 10 namespace v8 { 11 namespace internal { 12 13 // Cache for mapping (map, property name) into descriptor index. 14 // The cache contains both positive and negative results. 15 // Descriptor index equals kNotFound means the property is absent. 16 // Cleared at startup and prior to any gc. 17 class DescriptorLookupCache { 18 public: 19 // Lookup descriptor index for (map, name). 20 // If absent, kAbsent is returned. 21 inline int Lookup(Map* source, Name* name); 22 23 // Update an element in the cache. 24 inline void Update(Map* source, Name* name, int result); 25 26 // Clear the cache. 27 void Clear(); 28 29 static const int kAbsent = -2; 30 31 private: DescriptorLookupCache()32 DescriptorLookupCache() { 33 for (int i = 0; i < kLength; ++i) { 34 keys_[i].source = NULL; 35 keys_[i].name = NULL; 36 results_[i] = kAbsent; 37 } 38 } 39 40 static inline int Hash(Object* source, Name* name); 41 42 static const int kLength = 64; 43 struct Key { 44 Map* source; 45 Name* name; 46 }; 47 48 Key keys_[kLength]; 49 int results_[kLength]; 50 51 friend class Isolate; 52 DISALLOW_COPY_AND_ASSIGN(DescriptorLookupCache); 53 }; 54 55 } // namespace internal 56 } // namespace v8 57 58 #endif // V8_LOOKUP_CACHE_H_ 59