16const int kLiteralEntryLength = 2;
17const int kLiteralInitialLength = 2;
18const int kLiteralContextOffset = 0;
19const int kLiteralLiteralsOffset = 1;
22 InternalIndex cache_entry,
30 DCHECK(!IsFixedArray(obj));
31 if (IsWeakFixedArray(obj)) {
33 int length = literals_map->length();
34 for (
int i = 0;
i <
length;
i += kLiteralEntryLength) {
35 DCHECK(literals_map->get(
i + kLiteralContextOffset).IsWeakOrCleared());
36 if (literals_map->get(
i + kLiteralContextOffset) ==
45void AddToFeedbackCellsMap(DirectHandle<CompilationCacheTable> cache,
46 InternalIndex cache_entry,
48 DirectHandle<FeedbackCell> feedback_cell) {
51 static_assert(kLiteralEntryLength == 2);
52 DirectHandle<WeakFixedArray> new_literals_map;
59 DCHECK(!IsFixedArray(obj));
61 new_literals_map = isolate->factory()->NewWeakFixedArray(
67 entry = SearchLiteralsMapEntry(*cache, cache_entry, *
native_context);
70 old_literals_map->set(entry + kLiteralLiteralsOffset,
77 int length = old_literals_map->length();
78 for (
int i = 0;
i <
length;
i += kLiteralEntryLength) {
79 if (old_literals_map->get(
i + kLiteralContextOffset).IsCleared()) {
80 new_literals_map = old_literals_map;
88 new_literals_map = isolate->factory()->CopyWeakFixedArrayAndGrow(
89 old_literals_map, kLiteralEntryLength);
90 entry = old_literals_map->length();
94 new_literals_map->set(entry + kLiteralContextOffset,
96 new_literals_map->set(entry + kLiteralLiteralsOffset,
100 for (
int i = 0;
i < new_literals_map->
length();
i += kLiteralEntryLength) {
102 new_literals_map->get(
i + kLiteralContextOffset);
103 DCHECK(
object.IsCleared() ||
104 IsNativeContext(
object.GetHeapObjectAssumeWeak()));
105 object = new_literals_map->get(
i + kLiteralLiteralsOffset);
106 DCHECK(
object.IsCleared() ||
107 IsFeedbackCell(
object.GetHeapObjectAssumeWeak()));
111 Tagged<Object> old_literals_map = cache->EvalFeedbackValueAt(cache_entry);
112 if (old_literals_map != *new_literals_map) {
113 cache->SetEvalFeedbackValueAt(cache_entry, *new_literals_map);
118 InternalIndex cache_entry,
121 int entry = SearchLiteralsMapEntry(cache, cache_entry,
native_context);
125 DCHECK_LE(entry + kLiteralEntryLength, literals_map->length());
127 literals_map->get(entry + kLiteralLiteralsOffset);
129 if (!
object.IsCleared()) {
138class EvalCacheKey :
public HashTableKey {
150 EvalCacheKey(DirectHandle<String> source,
151 DirectHandle<SharedFunctionInfo> shared,
153 : HashTableKey(CompilationCacheShape::EvalHash(*source, *shared,
162 if (!IsFixedArray(other)) {
165 return Hash() == other_hash;
168 DCHECK(IsSharedFunctionInfo(other_array->get(0)));
169 if (*shared_ != other_array->get(0))
return false;
170 int language_unchecked =
Smi::ToInt(other_array->get(2));
173 if (language_mode != language_mode_)
return false;
175 if (
position != position_)
return false;
177 return source->Equals(*source_);
180 DirectHandle<Object> AsHandle(Isolate* isolate) {
181 DirectHandle<FixedArray> array = isolate->factory()->NewFixedArray(4);
182 array->set(0, *shared_);
183 array->set(1, *source_);
186 array->set_map(isolate, ReadOnlyRoots(isolate).fixed_cow_array_map());
198class RegExpKey :
public HashTableKey {
200 RegExpKey(Isolate* isolate, DirectHandle<String>
string,
201 JSRegExp::Flags flags)
216 return string_->Equals(val->source()) && (
flags_ == val->flags());
226class CodeKey :
public HashTableKey {
237 MaybeDirectHandle<Object> maybe_name,
int line_offset,
243 if (DirectHandle<Object> name;
244 maybe_name.ToHandle(&name) && IsString(*name, isolate)) {
247 column_offset, origin_options.
Flags());
264 if (!
name_.ToHandle(&name)) {
265 return IsUndefined(script->name(),
isolate_);
268 if (
line_offset_ != script->line_offset())
return false;
284 if (!script->is_wrapped()) {
289 int length = wrapped_arguments->length();
290 if (length != other_wrapped_arguments->length()) {
297 DCHECK(IsString(other_arg));
302 }
else if (script->is_wrapped()) {
308 if (script->deserialized() &&
309 script->host_defined_options() ==
322 int length = host_defined_options->length();
323 if (length != script_options->length())
return false;
330 script_options->get(
i))) {
341 script_details->line_offset, script_details->column_offset,
342 script_details->origin_options,
343 script_details->host_defined_options,
344 script_details->wrapped_arguments, isolate) {}
347 int line_offset,
int column_offset,
352 :
HashTableKey(static_cast<uint32_t>(ScriptHash(*source, name, line_offset,
354 origin_options, isolate)
358 line_offset_(line_offset),
359 column_offset_(column_offset),
360 origin_options_(origin_options),
361 host_defined_options_(host_defined_options),
362 wrapped_arguments_(maybe_wrapped_arguments),
367 if (maybe_wrapped_arguments.
ToHandle(&wrapped_arguments)) {
368 int length = wrapped_arguments->length();
379 DCHECK(IsWeakFixedArray(other));
385 uint32_t other_hash =
386 static_cast<uint32_t
>(other_array->get(
kHash).ToSmi().
value());
387 if (other_hash !=
Hash())
return false;
403 isolate->factory()->NewWeakFixedArray(
kEnd);
406 DCHECK(IsScript(shared->script()));
429 if (!raw.first.is_null()) {
432 if (!raw.second.is_null()) {
433 result.is_compiled_scope_ = raw.second->is_compiled_scope(isolate);
434 if (
result.is_compiled_scope_.is_compiled()) {
453 .GetHeapObjectAssumeWeak());
457 if (!IsUndefined(obj, isolate)) {
459 DCHECK_EQ(toplevel_sfi->script(), script);
463 std::make_pair(script, toplevel_sfi), isolate);
475 EvalCacheKey
key(src, outer_info, language_mode,
position);
479 if (!IsFixedArray(table->KeyAt(entry)))
return empty_result;
481 if (!IsSharedFunctionInfo(obj))
return empty_result;
491 Isolate* isolate = GetIsolate();
493 RegExpKey
key(isolate, src, flags);
495 if (entry.
is_not_found())
return isolate->factory()->undefined_value();
501 if (cache->HasSufficientCapacityToAdd(1))
return cache;
509 if (!cache->ToKey(isolate, entry, &
key))
continue;
513 DCHECK(IsUndefined(cache->PrimaryValueAt(entry)));
514 cache->RemoveEntry(entry);
519 return EnsureCapacity(isolate, cache);
529 if (IsString(script->name(), isolate)) {
530 script_name =
handle(script->name(), isolate);
535 script->column_offset(), script->origin_options(),
536 host_defined_options, maybe_wrapped_arguments, isolate);
543 bool found_existing = entry.
is_found();
544 if (!found_existing) {
546 entry = cache->FindInsertionEntry(isolate,
key.Hash());
558 cache->SetKeyAt(entry, *k);
559 cache->SetPrimaryValueAt(entry, *value);
560 if (!found_existing) {
561 cache->ElementAdded();
574 EvalCacheKey
key(src, outer_info, value->language_mode(),
position);
582 cache->SetKeyAt(entry, *k);
583 if (cache->PrimaryValueAt(entry) != *value) {
584 cache->SetPrimaryValueAt(entry, *value);
587 cache->SetEvalFeedbackValueAt(entry,
593 AddToFeedbackCellsMap(cache, entry,
native_context, feedback_cell);
600 cache = EnsureCapacity(isolate, cache);
603 isolate->factory()->NewNumber(
static_cast<double>(
key.Hash()));
604 cache->SetKeyAt(entry, *k);
606 cache->ElementAdded();
614 RegExpKey
key(isolate, src, flags);
615 cache = EnsureCapacity(isolate, cache);
619 cache->SetKeyAt(entry, value->wrapper());
620 cache->SetPrimaryValueAt(entry, value->wrapper());
621 cache->ElementAdded();
635 int entry_index = EntryToIndex(entry);
637 for (
int i = 0;
i < kEntrySize;
i++) {
MaybeHandle< SharedFunctionInfo > toplevel_sfi_
std::pair< Tagged< Script >, Tagged< SharedFunctionInfo > > RawObjects
static CompilationCacheScriptLookupResult FromRawObjects(RawObjects raw, Isolate *isolate)
MaybeHandle< SharedFunctionInfo > toplevel_sfi() const
MaybeHandle< Script > script() const
MaybeHandle< Script > script_
RawObjects GetRawObjects() const
static const int kEntrySize
static uint32_t RegExpHash(Tagged< String > string, Tagged< Smi > flags)
static InfoCellPair LookupEval(DirectHandle< CompilationCacheTable > table, DirectHandle< String > src, DirectHandle< SharedFunctionInfo > shared, DirectHandle< NativeContext > native_context, LanguageMode language_mode, int position)
Tagged< Object > PrimaryValueAt(InternalIndex entry)
void Remove(Tagged< Object > value)
DirectHandle< Object > LookupRegExp(DirectHandle< String > source, JSRegExp::Flags flags)
static NEVER_READ_ONLY_SPACE CompilationCacheScriptLookupResult LookupScript(DirectHandle< CompilationCacheTable > table, Handle< String > src, const ScriptDetails &script_details, Isolate *isolate)
void RemoveEntry(InternalIndex entry)
static Handle< CompilationCacheTable > EnsureScriptTableCapacity(Isolate *isolate, Handle< CompilationCacheTable > cache)
static DirectHandle< CompilationCacheTable > PutRegExp(Isolate *isolate, DirectHandle< CompilationCacheTable > cache, DirectHandle< String > src, JSRegExp::Flags flags, DirectHandle< RegExpData > value)
static DirectHandle< CompilationCacheTable > PutEval(DirectHandle< CompilationCacheTable > cache, DirectHandle< String > src, DirectHandle< SharedFunctionInfo > outer_info, DirectHandle< SharedFunctionInfo > value, DirectHandle< NativeContext > native_context, DirectHandle< FeedbackCell > feedback_cell, int position)
static constexpr int kHashGenerations
static DirectHandle< CompilationCacheTable > PutScript(Handle< CompilationCacheTable > cache, Handle< String > src, MaybeHandle< FixedArray > maybe_wrapped_arguments, DirectHandle< SharedFunctionInfo > value, Isolate *isolate)
bool is_not_found() const
v8::internal::Factory * factory()
V8_WARN_UNUSED_RESULT V8_INLINE bool ToHandle(Handle< S > *out) const
static double NumberValue(Tagged< Number > obj)
static V8_EXPORT_PRIVATE bool StrictEquals(Tagged< Object > obj, Tagged< Object > that)
MaybeHandle< FixedArray > wrapped_arguments_
MaybeHandle< Object > host_defined_options_
ScriptCacheKey(Handle< String > source, const ScriptDetails *script_details, Isolate *isolate)
DirectHandle< Object > AsHandle(Isolate *isolate, DirectHandle< SharedFunctionInfo > shared)
bool MatchesScript(Tagged< Script > script)
v8::ScriptOriginOptions origin_options_
bool IsMatch(Tagged< Object > other) override
MaybeHandle< Object > name_
static constexpr Tagged< Smi > FromEnum(E value)
static constexpr int ToInt(const Tagged< Object > object)
static constexpr Tagged< Smi > FromInt(int value)
static constexpr Tagged< Smi > From31BitPattern(int value)
static bool constexpr IsValid(T value)
static V8_INLINE HandleType< String > Flatten(Isolate *isolate, HandleType< T > string, AllocationType allocation=AllocationType::kYoung)
bool GetHeapObjectIfWeak(Tagged< HeapObject > *result) const
LanguageMode language_mode_
Handle< SharedFunctionInfo > key_
DirectHandle< String > string_
Tagged< SharedFunctionInfo > shared_
ZoneVector< RpoNumber > & result
V8_INLINE size_t hash_combine(size_t seed, size_t hash)
bool is_valid_language_mode(int language_mode)
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
PerThreadAssertScopeDebugOnly< false, SAFEPOINTS_ASSERT, HEAP_ALLOCATION_ASSERT > DisallowGarbageCollection
bool IsNumber(Tagged< Object > obj)
ReadOnlyRoots GetReadOnlyRoots()
Tagged(T object) -> Tagged< T >
kStaticElementsTemplateOffset kInstancePropertiesTemplateOffset Tagged< FixedArray >
too high values may cause the compiler to set high thresholds for inlining to as much as possible avoid inlined allocation of objects that cannot escape trace load stores from virtual maglev objects use TurboFan fast string builder analyze liveness of environment slots and zap dead values trace TurboFan load elimination emit data about basic block usage in builtins to this enable builtin reordering when run mksnapshot flag for emit warnings when applying builtin profile data verify register allocation in TurboFan randomly schedule instructions to stress dependency tracking enable store store elimination in TurboFan rewrite far to near simulate GC compiler thread race related to allow float parameters to be passed in simulator mode JS Wasm Run additional turbo_optimize_inlined_js_wasm_wrappers enable experimental feedback collection in generic lowering enable Turboshaft s WasmLoadElimination enable Turboshaft s low level load elimination for JS enable Turboshaft s escape analysis for string concatenation use enable Turbolev features that we want to ship in the not too far future trace individual Turboshaft reduction steps trace intermediate Turboshaft reduction steps invocation count threshold for early optimization Enables optimizations which favor memory size over execution speed Enables sampling allocation profiler with X as a sample interval min size of a semi the new space consists of two semi spaces max size of the Collect garbage after Collect garbage after keeps maps alive for< n > old space garbage collections print one detailed trace line in name
bool IsPrimitive(Tagged< Object > obj)
static uint32_t Hash(RegisteredExtension *extension)
Tagged< MaybeWeak< T > > MakeWeak(Tagged< T > value)
template const char * string
kInterpreterTrampolineOffset script
!IsContextMap !IsContextMap native_context
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
#define DCHECK_LE(v1, v2)
#define DCHECK(condition)
#define DCHECK_LT(v1, v2)
#define DCHECK_EQ(v1, v2)