Line data Source code
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 : #include "src/objects/map.h"
10 : #include "src/objects/name.h"
11 :
12 : namespace v8 {
13 : namespace internal {
14 :
15 : // Cache for mapping (map, property name) into descriptor index.
16 : // The cache contains both positive and negative results.
17 : // Descriptor index equals kNotFound means the property is absent.
18 : // Cleared at startup and prior to any gc.
19 : class DescriptorLookupCache {
20 : public:
21 : // Lookup descriptor index for (map, name).
22 : // If absent, kAbsent is returned.
23 : inline int Lookup(Map source, Name name);
24 :
25 : // Update an element in the cache.
26 : inline void Update(Map source, Name name, int result);
27 :
28 : // Clear the cache.
29 : void Clear();
30 :
31 : static const int kAbsent = -2;
32 :
33 : private:
34 62424 : DescriptorLookupCache() {
35 8052696 : for (int i = 0; i < kLength; ++i) {
36 3995136 : keys_[i].source = Map();
37 3995136 : keys_[i].name = Name();
38 3995136 : results_[i] = kAbsent;
39 : }
40 : }
41 :
42 : static inline int Hash(Map source, Name name);
43 :
44 : static const int kLength = 64;
45 : struct Key {
46 : Map source;
47 : Name name;
48 : };
49 :
50 : Key keys_[kLength];
51 : int results_[kLength];
52 :
53 : friend class Isolate;
54 : DISALLOW_COPY_AND_ASSIGN(DescriptorLookupCache);
55 : };
56 :
57 : } // namespace internal
58 : } // namespace v8
59 :
60 : #endif // V8_LOOKUP_CACHE_H_
|