#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"
#include "src/objects/object-macros.h"
namespace v8 {
namespace internal {
struct ScriptDetails;
class CompilationCacheShape : public BaseShape<HashTableKey*> {
public:
static inline bool IsMatch(HashTableKey* key, Tagged<Object> value) {
return key->IsMatch(value);
}
static inline uint32_t Hash(ReadOnlyRoots roots, HashTableKey* key) {
return key->Hash();
}
static inline uint32_t RegExpHash(Tagged<String> string, Tagged<Smi> flags);
static inline uint32_t EvalHash(Tagged<String> source,
Tagged<SharedFunctionInfo> shared,
LanguageMode language_mode, int position);
static inline uint32_t HashForObject(ReadOnlyRoots roots,
Tagged<Object> object);
static const int kPrefixSize = 0;
static const int kEntrySize = 3;
static const bool kMatchNeedsHoleCheck = true;
static const bool kDoHashSpreading = false;
static const uint32_t kHashBits = 0;
};
class InfoCellPair {
public:
InfoCellPair() = default;
inline InfoCellPair(Isolate* isolate, Tagged<SharedFunctionInfo> shared,
Tagged<JSFunction> js_function);
Tagged<JSFunction> js_function() const {
DCHECK(is_compiled_scope_.is_compiled());
return js_function_;
}
Tagged<SharedFunctionInfo> shared() const {
DCHECK(is_compiled_scope_.is_compiled());
return shared_;
}
bool has_js_function() const {
return !js_function_.is_null() && is_compiled_scope_.is_compiled();
}
bool has_shared() const {
return !shared_.is_null() && is_compiled_scope_.is_compiled();
}
private:
IsCompiledScope is_compiled_scope_;
Tagged<SharedFunctionInfo> shared_;
Tagged<JSFunction> js_function_;
};
class CompilationCacheScriptLookupResult {
public:
MaybeHandle<Script> script() const { return script_; }
MaybeHandle<SharedFunctionInfo> toplevel_sfi() const { return toplevel_sfi_; }
IsCompiledScope is_compiled_scope() const { return is_compiled_scope_; }
using RawObjects = std::pair<Tagged<Script>, Tagged<SharedFunctionInfo>>;
RawObjects GetRawObjects() const;
static CompilationCacheScriptLookupResult FromRawObjects(RawObjects raw,
Isolate* isolate);
private:
MaybeHandle<Script> script_;
MaybeHandle<SharedFunctionInfo> toplevel_sfi_;
IsCompiledScope is_compiled_scope_;
};
EXTERN_DECLARE_HASH_TABLE(CompilationCacheTable, CompilationCacheShape)
class CompilationCacheTable
: public HashTable<CompilationCacheTable, CompilationCacheShape> {
public:
static CompilationCacheScriptLookupResult LookupScript(
DirectHandle<CompilationCacheTable> table, Handle<String> src,
const ScriptDetails& script_details, Isolate* isolate);
static DirectHandle<CompilationCacheTable> PutScript(
Handle<CompilationCacheTable> cache, Handle<String> src,
MaybeHandle<FixedArray> maybe_wrapped_arguments,
DirectHandle<SharedFunctionInfo> value, Isolate* isolate);
static InfoCellPair LookupEval(DirectHandle<CompilationCacheTable> table,
DirectHandle<String> src,
DirectHandle<SharedFunctionInfo> shared,
DirectHandle<NativeContext> native_context,
LanguageMode language_mode, int position);
static void UpdateEval(DirectHandle<CompilationCacheTable> table,
DirectHandle<String> src,
DirectHandle<SharedFunctionInfo> outer_info,
DirectHandle<JSFunction> js_function,
LanguageMode language_mode, int position);
static DirectHandle<CompilationCacheTable> PutEval(
DirectHandle<CompilationCacheTable> cache, DirectHandle<String> src,
DirectHandle<SharedFunctionInfo> outer_info,
DirectHandle<JSFunction> js_function, int position);
DirectHandle<Object> LookupRegExp(DirectHandle<String> source,
JSRegExp::Flags flags);
static DirectHandle<CompilationCacheTable> PutRegExp(
Isolate* isolate, DirectHandle<CompilationCacheTable> cache,
DirectHandle<String> src, JSRegExp::Flags flags,
DirectHandle<RegExpData> value);
void Remove(Tagged<Object> value);
void RemoveEntry(InternalIndex entry);
inline Tagged<Object> PrimaryValueAt(InternalIndex entry);
inline void SetPrimaryValueAt(InternalIndex entry, Tagged<Object> value,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
inline Tagged<UnionOf<TheHole, WeakFixedArray>> EvalJSFunctionsValueAt(
InternalIndex entry);
inline void SetEvalJSFunctionsValueAt(
InternalIndex entry, Tagged<UnionOf<TheHole, WeakFixedArray>> value,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
static constexpr int kHashGenerations = 10;
private:
static Handle<CompilationCacheTable> EnsureScriptTableCapacity(
Isolate* isolate, Handle<CompilationCacheTable> cache);
};
}
}
#include "src/objects/object-macros-undef.h"
#endif