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

Side by Side Diff: src/lookup.h

Issue 2316503004: KeyedLookupCache and DescriptorLookupCache -> lookup-cache{-inl.h,.cc,.h} (Closed)
Patch Set: Created 4 years, 3 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
« no previous file with comments | « BUILD.gn ('k') | src/lookup.cc » ('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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_LOOKUP_H_ 5 #ifndef V8_LOOKUP_H_
6 #define V8_LOOKUP_H_ 6 #define V8_LOOKUP_H_
7 7
8 #include "src/factory.h" 8 #include "src/factory.h"
9 #include "src/isolate.h" 9 #include "src/isolate.h"
10 #include "src/objects.h" 10 #include "src/objects.h"
11 11
12 namespace v8 { 12 namespace v8 {
13 namespace internal { 13 namespace internal {
14 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 DescriptorLookupCache() {
35 for (int i = 0; i < kLength; ++i) {
36 keys_[i].source = NULL;
37 keys_[i].name = NULL;
38 results_[i] = kAbsent;
39 }
40 }
41
42 static inline int Hash(Object* 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 // Cache for mapping (map, property name) into field offset.
58 // Cleared at startup and prior to mark sweep collection.
59 class KeyedLookupCache {
60 public:
61 // Lookup field offset for (map, name). If absent, -1 is returned.
62 int Lookup(Handle<Map> map, Handle<Name> name);
63
64 // Update an element in the cache.
65 void Update(Handle<Map> map, Handle<Name> name, int field_offset);
66
67 // Clear the cache.
68 void Clear();
69
70 static const int kLength = 256;
71 static const int kCapacityMask = kLength - 1;
72 static const int kMapHashShift = 5;
73 static const int kHashMask = -4; // Zero the last two bits.
74 static const int kEntriesPerBucket = 4;
75 static const int kEntryLength = 2;
76 static const int kMapIndex = 0;
77 static const int kKeyIndex = 1;
78 static const int kNotFound = -1;
79
80 // kEntriesPerBucket should be a power of 2.
81 STATIC_ASSERT((kEntriesPerBucket & (kEntriesPerBucket - 1)) == 0);
82 STATIC_ASSERT(kEntriesPerBucket == -kHashMask);
83
84 private:
85 KeyedLookupCache() {
86 for (int i = 0; i < kLength; ++i) {
87 keys_[i].map = NULL;
88 keys_[i].name = NULL;
89 field_offsets_[i] = kNotFound;
90 }
91 }
92
93 static inline int Hash(Handle<Map> map, Handle<Name> name);
94
95 // Get the address of the keys and field_offsets arrays. Used in
96 // generated code to perform cache lookups.
97 Address keys_address() { return reinterpret_cast<Address>(&keys_); }
98
99 Address field_offsets_address() {
100 return reinterpret_cast<Address>(&field_offsets_);
101 }
102
103 struct Key {
104 Map* map;
105 Name* name;
106 };
107
108 Key keys_[kLength];
109 int field_offsets_[kLength];
110
111 friend class ExternalReference;
112 friend class Isolate;
113 DISALLOW_COPY_AND_ASSIGN(KeyedLookupCache);
114 };
115
116 class LookupIterator final BASE_EMBEDDED { 15 class LookupIterator final BASE_EMBEDDED {
117 public: 16 public:
118 enum Configuration { 17 enum Configuration {
119 // Configuration bits. 18 // Configuration bits.
120 kInterceptor = 1 << 0, 19 kInterceptor = 1 << 0,
121 kPrototypeChain = 1 << 1, 20 kPrototypeChain = 1 << 1,
122 21
123 // Convience combinations of bits. 22 // Convience combinations of bits.
124 OWN_SKIP_INTERCEPTOR = 0, 23 OWN_SKIP_INTERCEPTOR = 0,
125 OWN = kInterceptor, 24 OWN = kInterceptor,
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 const Handle<JSReceiver> initial_holder_; 353 const Handle<JSReceiver> initial_holder_;
455 const uint32_t index_; 354 const uint32_t index_;
456 uint32_t number_; 355 uint32_t number_;
457 }; 356 };
458 357
459 358
460 } // namespace internal 359 } // namespace internal
461 } // namespace v8 360 } // namespace v8
462 361
463 #endif // V8_LOOKUP_H_ 362 #endif // V8_LOOKUP_H_
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | src/lookup.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698