// Copyright 2017 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef V8_OBJECTS_COMPILATION_CACHE_TABLE_H_ #define V8_OBJECTS_COMPILATION_CACHE_TABLE_H_ #include "src/objects/feedback-cell.h" #include "src/objects/hash-table.h" #include "src/objects/js-regexp.h" #include "src/objects/shared-function-info.h" #include "src/roots/roots.h" // Has to be the last include (doesn't have include guards): #include "src/objects/object-macros.h" namespace v8 { namespace internal { struct ScriptDetails; class CompilationCacheShape : public BaseShape { public: static inline bool IsMatch(HashTableKey* key, Object value) { return key->IsMatch(value); } static inline uint32_t Hash(ReadOnlyRoots roots, HashTableKey* key) { return key->Hash(); } static inline uint32_t RegExpHash(String string, Smi flags); static inline uint32_t EvalHash(String source, SharedFunctionInfo shared, LanguageMode language_mode, int position); static inline uint32_t HashForObject(ReadOnlyRoots roots, Object object); static const int kPrefixSize = 0; // An 'entry' is essentially a grouped collection of slots. Entries are used // in various ways by the different caches; most store the actual key in the // first entry slot, but it may also be used differently. // Why 3 slots? Because of the eval cache. static const int kEntrySize = 3; static const bool kMatchNeedsHoleCheck = true; }; class InfoCellPair { public: InfoCellPair() = default; inline InfoCellPair(Isolate* isolate, SharedFunctionInfo shared, FeedbackCell feedback_cell); FeedbackCell feedback_cell() const { DCHECK(is_compiled_scope_.is_compiled()); return feedback_cell_; } SharedFunctionInfo shared() const { DCHECK(is_compiled_scope_.is_compiled()); return shared_; } bool has_feedback_cell() const { return !feedback_cell_.is_null() && is_compiled_scope_.is_compiled(); } bool has_shared() const { // Only return true if SFI is compiled - the bytecode could have been // flushed while it's in the compilation cache, and not yet have been // removed form the compilation cache. return !shared_.is_null() && is_compiled_scope_.is_compiled(); } private: IsCompiledScope is_compiled_scope_; SharedFunctionInfo shared_; FeedbackCell feedback_cell_; }; // A lookup result from the compilation cache for scripts. There are three // possible states: // // 1. Cache miss: script and toplevel_sfi are both null. // 2. Cache hit: script and toplevel_sfi are both non-null. toplevel_sfi is // guaranteed to be compiled, and to stay compiled while this lookup result // instance is alive. // 3. Partial cache hit: script is non-null, but toplevel_sfi is null. The // script may contain an uncompiled toplevel SharedFunctionInfo. class CompilationCacheScriptLookupResult { public: MaybeHandle