v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
compilation-cache-table.h
Go to the documentation of this file.
1// Copyright 2017 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_OBJECTS_COMPILATION_CACHE_TABLE_H_
6#define V8_OBJECTS_COMPILATION_CACHE_TABLE_H_
7
12#include "src/roots/roots.h"
13
14// Has to be the last include (doesn't have include guards):
16
17namespace v8 {
18namespace internal {
19
20struct ScriptDetails;
21
22class CompilationCacheShape : public BaseShape<HashTableKey*> {
23 public:
24 static inline bool IsMatch(HashTableKey* key, Tagged<Object> value) {
25 return key->IsMatch(value);
26 }
27
28 static inline uint32_t Hash(ReadOnlyRoots roots, HashTableKey* key) {
29 return key->Hash();
30 }
31
32 static inline uint32_t RegExpHash(Tagged<String> string, Tagged<Smi> flags);
33
34 static inline uint32_t EvalHash(Tagged<String> source,
36 LanguageMode language_mode, int position);
37
38 static inline uint32_t HashForObject(ReadOnlyRoots roots,
39 Tagged<Object> object);
40
41 static const int kPrefixSize = 0;
42 // An 'entry' is essentially a grouped collection of slots. Entries are used
43 // in various ways by the different caches; most store the actual key in the
44 // first entry slot, but it may also be used differently.
45 // Why 3 slots? Because of the eval cache.
46 static const int kEntrySize = 3;
47 static const bool kMatchNeedsHoleCheck = true;
48 static const bool kDoHashSpreading = false;
49 static const uint32_t kHashBits = 0;
50};
51
53 public:
54 InfoCellPair() = default;
55 inline InfoCellPair(Isolate* isolate, Tagged<SharedFunctionInfo> shared,
57
66
67 bool has_feedback_cell() const {
68 return !feedback_cell_.is_null() && is_compiled_scope_.is_compiled();
69 }
70 bool has_shared() const {
71 // Only return true if SFI is compiled - the bytecode could have been
72 // flushed while it's in the compilation cache, and not yet have been
73 // removed form the compilation cache.
74 return !shared_.is_null() && is_compiled_scope_.is_compiled();
75 }
76
77 private:
81};
82
83// A lookup result from the compilation cache for scripts. There are three
84// possible states:
85//
86// 1. Cache miss: script and toplevel_sfi are both null.
87// 2. Cache hit: script and toplevel_sfi are both non-null. toplevel_sfi is
88// guaranteed to be compiled, and to stay compiled while this lookup result
89// instance is alive.
90// 3. Partial cache hit: script is non-null, but toplevel_sfi is null. The
91// script may contain an uncompiled toplevel SharedFunctionInfo.
110
112
114 : public HashTable<CompilationCacheTable, CompilationCacheShape> {
115 public:
117
118 // The 'script' cache contains SharedFunctionInfos. Once a root
119 // SharedFunctionInfo has become old enough that its bytecode is flushed, the
120 // entry is still present and can be used to get the Script.
121 static CompilationCacheScriptLookupResult LookupScript(
123 const ScriptDetails& script_details, Isolate* isolate);
126 MaybeHandle<FixedArray> maybe_wrapped_arguments,
128
129 // Eval code only gets cached after a second probe for the
130 // code object. To do so, on first "put" only a hash identifying the
131 // source is entered into the cache, mapping it to a lifetime count of
132 // the hash. On each call to Age all such lifetimes get reduced, and
133 // removed once they reach zero. If a second put is called while such
134 // a hash is live in the cache, the hash gets replaced by an actual
135 // cache entry. Age also removes stale live entries from the cache.
136 // Such entries are identified by SharedFunctionInfos pointing to
137 // either the recompilation stub, or to "old" code. This avoids memory
138 // leaks due to premature caching of eval strings that are
139 // never needed later.
144 LanguageMode language_mode, int position);
150 DirectHandle<FeedbackCell> feedback_cell, int position);
151
152 // The RegExp cache contains RegExpData objects.
153 DirectHandle<Object> LookupRegExp(DirectHandle<String> source,
154 JSRegExp::Flags flags);
157 DirectHandle<String> src, JSRegExp::Flags flags,
159
160 void Remove(Tagged<Object> value);
161 void RemoveEntry(InternalIndex entry);
162
163 inline Tagged<Object> PrimaryValueAt(InternalIndex entry);
164 inline void SetPrimaryValueAt(InternalIndex entry, Tagged<Object> value,
166 inline Tagged<Object> EvalFeedbackValueAt(InternalIndex entry);
167 inline void SetEvalFeedbackValueAt(
168 InternalIndex entry, Tagged<Object> value,
170
171 // The initial placeholder insertion of the eval cache survives this many GCs.
172 static constexpr int kHashGenerations = 10;
173
174 private:
175 static Handle<CompilationCacheTable> EnsureScriptTableCapacity(
176 Isolate* isolate, Handle<CompilationCacheTable> cache);
177};
178
179} // namespace internal
180} // namespace v8
181
183
184#endif // V8_OBJECTS_COMPILATION_CACHE_TABLE_H_
std::pair< Tagged< Script >, Tagged< SharedFunctionInfo > > RawObjects
static CompilationCacheScriptLookupResult FromRawObjects(RawObjects raw, Isolate *isolate)
MaybeHandle< SharedFunctionInfo > toplevel_sfi() const
static uint32_t EvalHash(Tagged< String > source, Tagged< SharedFunctionInfo > shared, LanguageMode language_mode, int position)
static uint32_t HashForObject(ReadOnlyRoots roots, Tagged< Object > object)
static uint32_t Hash(ReadOnlyRoots roots, HashTableKey *key)
static uint32_t RegExpHash(Tagged< String > string, Tagged< Smi > flags)
static bool IsMatch(HashTableKey *key, Tagged< Object > value)
Tagged< FeedbackCell > feedback_cell_
Tagged< FeedbackCell > feedback_cell() const
Tagged< SharedFunctionInfo > shared_
Tagged< SharedFunctionInfo > shared() const
#define EXTERN_DECLARE_HASH_TABLE(DERIVED, SHAPE)
Definition hash-table.h:293
int position
Definition liveedit.cc:290
@ UPDATE_WRITE_BARRIER
Definition objects.h:55
!IsContextMap !IsContextMap native_context
Definition map-inl.h:877
#define NEVER_READ_ONLY_SPACE
#define DCHECK(condition)
Definition logging.h:482