42 set_builtin_id(Builtin::kIllegal);
51 set_raw_outer_scope_info_or_feedback_metadata(ro_roots.the_hole_value(),
55 set_unique_id(unique_id);
60 set_expected_nof_properties(0);
61 set_raw_function_token_offset(0);
65 set_flags(ConstructAsBuiltinBit::encode(
true),
kRelaxedStore);
85 if (IsBytecodeArray(data)) {
87 DCHECK(HasBytecodeArray());
88 return isolate->builtins()->code(Builtin::kInterpreterEntryTrampoline);
95 if (IsInterpreterData(data)) {
98 DCHECK(code->is_interpreter_trampoline_builtin());
101 if (IsUncompiledData(data)) {
105 return isolate->builtins()->code(Builtin::kCompileLazy);
107#if V8_ENABLE_WEBASSEMBLY
108 if (IsWasmExportedFunctionData(data)) {
110 DCHECK(HasWasmExportedFunctionData());
111 return wasm_exported_function_data()->wrapper_code(isolate);
113 if (IsWasmJSFunctionData(data)) {
114 return wasm_js_function_data()->wrapper_code(isolate);
116 if (IsWasmCapiFunctionData(data)) {
117 return wasm_capi_function_data()->wrapper_code(isolate);
127 return isolate->builtins()->code(builtin_id());
129 if (IsFunctionTemplateInfo(data)) {
132 return isolate->builtins()->code(Builtin::kHandleApiCallOrConstruct);
134#if V8_ENABLE_WEBASSEMBLY
135 if (IsAsmWasmData(data)) {
138 return isolate->builtins()->code(Builtin::kInstantiateAsmJs);
140 if (IsWasmResumeData(data)) {
141 if (
static_cast<wasm::OnResume>(wasm_resume_data()->on_resume()) ==
143 return isolate->builtins()->code(Builtin::kWasmResume);
145 return isolate->builtins()->code(Builtin::kWasmReject);
159 : infos_(infos),
index_(0) {}
166 !IsSharedFunctionInfo(heap_object)) {
176 infos_ =
handle(script->infos(), isolate);
183 int function_literal_id,
184 bool reset_preparsed_scope_data) {
187 if (
script() == script_object)
return;
197 if (IsScript(script_object)) {
202 DCHECK_LT(function_literal_id, list->length());
219 if (function_literal_id < infos->
length()) {
223 old_script->infos()->set(function_literal_id, roots.undefined_value());
234 if (other->HasTrustedData()) {
241 set_name_or_scope_info(other->name_or_scope_info(cage_base,
kAcquireLoad),
243 set_outer_scope_info_or_feedback_metadata(
244 other->outer_scope_info_or_feedback_metadata(cage_base));
247 set_length(other->length());
248 set_formal_parameter_count(other->formal_parameter_count());
249 set_function_token_offset(other->function_token_offset());
250 set_expected_nof_properties(other->expected_nof_properties());
251 set_flags2(other->flags2());
253 set_function_literal_id(other->function_literal_id());
254 set_unique_id(other->unique_id());
260 DCHECK_EQ(memcmp(
reinterpret_cast<void*
>(address()),
261 reinterpret_cast<void*
>(other.address()),
262 SharedFunctionInfo::kAgeOffset),
265 constexpr Address kPastAgeOffset =
267 DCHECK_EQ(memcmp(
reinterpret_cast<void*
>(address() + kPastAgeOffset),
268 reinterpret_cast<void*
>(other.address() + kPastAgeOffset),
269 SharedFunctionInfo::kSize - kPastAgeOffset),
275 return isolate->debug()->HasDebugInfo(*
this);
293 return isolate->debug()->TryGetDebugInfo(*this).value();
298 return isolate->debug()->TryGetDebugInfo(*
this);
302 return isolate->debug()->HasBreakInfo(*
this);
306 return isolate->debug()->BreakAtEntry(*
this);
310 return isolate->debug()->HasCoverageInfo(*
this);
320#if V8_ENABLE_WEBASSEMBLY
321 if (HasWasmExportedFunctionData()) {
323 wasm_exported_function_data()->
sig());
328 if (function_name->length() == 0) function_name = inferred_name();
329 return function_name->ToCString();
335#if V8_ENABLE_WEBASSEMBLY
336 if (shared->HasWasmExportedFunctionData()) {
337 return isolate->factory()
345 ? isolate->factory()->instance_members_initializer_string()
346 : isolate->factory()->static_initializer_string();
350 if (function_name->length() == 0) function_name = shared->inferred_name();
351 return handle(function_name, isolate);
356 if (
V8_LIKELY(raw_filter[0] ==
'*' && raw_filter[1] ==
'\0')) {
366 return !IsUndefined(
script(), roots) &&
375 gc_notify_updated_slot) {
380 PrintF(scope.
file(),
"[discarding compiled metadata for ");
387 outer_scope_info = scope_info()->OuterScopeInfo();
394 set_raw_outer_scope_info_or_feedback_metadata(outer_scope_info);
395 gc_notify_updated_slot(
397 RawField(SharedFunctionInfo::kOuterScopeInfoOrFeedbackMetadataOffset),
400 DCHECK(IsScopeInfo(outer_scope_info()) || IsTheHole(outer_scope_info()));
409 DCHECK(shared_info->CanDiscardCompiled());
411 Handle<String> inferred_name_val(shared_info->inferred_name(), isolate);
412 int start_position = shared_info->StartPosition();
413 int end_position = shared_info->EndPosition();
416 if (!shared_info->HasUncompiledDataWithPreparseData()) {
418 data = isolate->factory()->NewUncompiledDataWithoutPreparseData(
419 inferred_name_val, start_position, end_position);
426 shared_info->DiscardCompiledMetadata(isolate);
429 if (shared_info->HasUncompiledDataWithPreparseData()) {
432 shared_info->ClearPreparseData(isolate);
438 shared_info->SetTrustedData(*data.ToHandleChecked());
445 if (!shared->HasSourceCode())
return isolate->factory()->undefined_value();
448 return isolate->factory()->NewSubString(source, shared->StartPosition(),
449 shared->EndPosition());
455 if (!shared->HasSourceCode())
return isolate->factory()->undefined_value();
458 int start_pos = shared->function_token_position();
461 script_source, start_pos, shared->EndPosition());
462 if (!shared->is_wrapped())
return source;
464 DCHECK(!shared->name_should_print_as_anonymous());
470 Cast<Script>(shared->script())->wrapped_arguments(), isolate);
471 int argc =
args->length();
472 for (
int i = 0;
i < argc;
i++) {
489 if (!s->HasSourceCode())
return os <<
"<No Source>";
497 if (!s->is_toplevel()) {
500 if (name->length() > 0) {
505 int len = s->EndPosition() - s->StartPosition();
507 script_source->PrintUC16(os, s->StartPosition(), s->EndPosition());
510 script_source->PrintUC16(os, s->StartPosition(),
512 return os <<
"...\n";
518 DCHECK_NE(reason, BailoutReason::kNoReason);
525 CHECK(
kind == CodeKind::INTERPRETED_FUNCTION ||
kind == CodeKind::BUILTIN);
532 PrintF(scope.
file(),
"[disabled optimization for ");
539template <
typename IsolateT>
551 raw_sfi->set_internal_formal_parameter_count(
562 raw_sfi->set_requires_instance_members_initializer(
566 raw_sfi->set_class_scope_has_private_brand(
570 raw_sfi->set_has_static_private_methods_or_accessors(
573 raw_sfi->set_is_toplevel(is_toplevel);
574 DCHECK(IsTheHole(raw_sfi->outer_scope_info()));
576 if (outer_scope && (!is_toplevel || !outer_scope->
is_script_scope())) {
577 raw_sfi->set_outer_scope_info(*outer_scope->
scope_info());
578 raw_sfi->set_private_name_lookup_skips_outer_class(
593 raw_sfi->UpdateAndFinalizeExpectedNofPropertiesFromEstimate(lit);
602 raw_sfi->UpdateExpectedNofPropertiesFromEstimate(lit);
607template <
typename IsolateT>
613 if (scope_data !=
nullptr) {
617 data = isolate->factory()->NewUncompiledDataWithPreparseDataAndJob(
621 data = isolate->factory()->NewUncompiledDataWithPreparseData(
627 data = isolate->factory()->NewUncompiledDataWithoutPreparseDataWithJob(
631 data = isolate->factory()->NewUncompiledDataWithoutPreparseData(
656 int estimate =
literal->expected_property_count();
660 estimate += expected_nof_properties();
671 set_expected_nof_properties(std::min(estimate,
kMaxUInt8));
677 if (are_properties_final()) {
684 if (estimate == 0) estimate = 2;
689 estimate = std::min(estimate,
kMaxUInt8);
691 set_expected_nof_properties(estimate);
692 set_are_properties_final(
true);
696 int start_position) {
707 set_raw_function_token_offset(
offset);
712 if (IsScopeInfo(maybe_scope_info)) {
714 if (info->HasPositionInfo()) {
715 return info->StartPosition();
726#if V8_ENABLE_WEBASSEMBLY
727 if (HasWasmExportedFunctionData()) {
729 wasm_exported_function_data()->instance_data();
730 int func_index = wasm_exported_function_data()->function_index();
731 auto& function =
instance_data->module()->functions[func_index];
732 return static_cast<int>(function.code.offset());
740 if (IsScopeInfo(maybe_scope_info)) {
742 if (info->HasPositionInfo()) {
743 return info->EndPosition();
754#if V8_ENABLE_WEBASSEMBLY
755 if (HasWasmExportedFunctionData()) {
757 wasm_exported_function_data()->instance_data();
758 int func_index = wasm_exported_function_data()->function_index();
759 auto& function =
instance_data->module()->functions[func_index];
760 return static_cast<int>(function.code.end_offset());
770 set_live_edited(
true);
772 if (IsScopeInfo(maybe_scope_info)) {
777 DCHECK(new_scope_info->Equals(old_scope_info,
true));
778 old_scope_info->SetPositionInfo(new_scope_info->position_info_start(),
779 new_scope_info->position_info_end());
788 if (!is_toplevel()) {
793 set_raw_outer_scope_info_or_feedback_metadata(
803 return CachedTieringDecisionBits::decode(
flags2());
808 set_flags2(CachedTieringDecisionBits::update(
flags2(), decision));
815 if (!shared_info->HasBytecodeArray()) {
818 FATAL(
"Failed to compile shared info that was already compiled before");
820 DCHECK(shared_info->GetBytecodeArray(isolate)->HasSourcePositionTable());
829 if (shared_info->CanCollectSourcePosition(isolate)) {
830 std::optional<Isolate::ExceptionScope> exception_scope;
831 if (isolate->has_exception()) {
832 exception_scope.emplace(isolate);
841 DCHECK(shared->HasBytecodeArray());
843 shared->GetBytecodeArray(isolate), isolate);
853 debug_info->set_debug_bytecode_array(*debug_bytecode_array,
kReleaseStore);
854 shared->SetActiveBytecodeArray(*debug_bytecode_array, isolate);
865 debug_info->OriginalBytecodeArray(isolate);
866 DCHECK(!shared->HasBaselineCode());
868 debug_info->clear_original_bytecode_array();
869 debug_info->clear_debug_bytecode_array();
874 if (
v8_flags.flush_code_based_on_time ||
875 v8_flags.flush_code_based_on_tab_visibility) {
878 sfi->set_age(
v8_flags.bytecode_old_age);
884bool SharedFunctionInfo::UniqueIdsAreUnique(
Isolate* isolate) {
885 std::unordered_set<uint32_t> ids({isolate->next_unique_sfi_id()});
886 CombinedHeapObjectIterator it(isolate->heap());
888 if (!IsSharedFunctionInfo(o))
continue;
891 if (!
result.second)
return false;
901 os <<
"has no script";
904 os <<
"needs binary coverage";
910 os <<
"is not user code";
913 os <<
"has no bytecode";
916 os <<
"exceeds bytecode limit";
919 os <<
"may contain breakpoints";
922 os <<
"has optimization disabled";
925 os <<
"is inlineable (!)";
union v8::internal::@341::BuiltinMetadata::KindSpecificData data
static bool Compile(Isolate *isolate, Handle< SharedFunctionInfo > shared, ClearExceptionFlag flag, IsCompiledScope *is_compiled_scope, CreateSourcePositions create_source_positions_flag=CreateSourcePositions::kNo)
static bool CollectSourcePositions(Isolate *isolate, DirectHandle< SharedFunctionInfo > shared)
FunctionSyntaxKind syntax_kind() const
FunctionKind kind() const
int function_literal_id() const
int function_token_position() const
bool has_duplicate_parameters() const
Handle< SharedFunctionInfo > shared_function_info() const
V8_EXPORT_PRIVATE LanguageMode language_mode() const
bool AllowsLazyCompilation()
int start_position() const
bool has_static_private_methods_or_accessors() const
ProducedPreparseData * produced_preparse_data() const
bool class_scope_has_private_brand() const
Handle< String > GetInferredName(Isolate *isolate)
bool requires_instance_members_initializer() const
bool should_parallel_compile() const
DeclarationScope * scope() const
V8_EXPORT_PRIVATE bool ShouldEagerCompile() const
MaybeDirectHandle< String > Finish()
V8_INLINE void AppendCharacter(uint8_t c)
V8_INLINE void AppendString(std::string_view str)
V8_INLINE void AppendCStringLiteral(const char(&literal)[N])
static const int kMaxInObjectProperties
virtual Handle< PreparseData > Serialize(Isolate *isolate)=0
bool private_name_lookup_skips_outer_class() const
Scope * GetOuterScopeWithContext()
bool is_script_scope() const
Handle< ScopeInfo > scope_info() const
void Reset(Isolate *isolate, Tagged< Script > script)
V8_EXPORT_PRIVATE ScriptIterator(Isolate *isolate, Tagged< Script > script)
V8_EXPORT_PRIVATE Tagged< SharedFunctionInfo > Next()
Tagged< Object > GetUntrustedData() const
static void UninstallDebugBytecode(Tagged< SharedFunctionInfo > shared, Isolate *isolate)
static constexpr uint16_t kMaxAge
void Init(ReadOnlyRoots roots, int unique_id)
Tagged< CoverageInfo > GetCoverageInfo(Isolate *isolate) const
bool HasCoverageInfo(Isolate *isolate) const
void SetFunctionTokenPosition(int function_token_position, int start_position)
bool IsApiFunction() const
static DirectHandle< Object > GetSourceCode(Isolate *isolate, DirectHandle< SharedFunctionInfo > shared)
static void InstallDebugBytecode(DirectHandle< SharedFunctionInfo > shared, Isolate *isolate)
static const uint16_t kFunctionTokenOutOfRange
void set_cached_tiering_decision(CachedTieringDecision decision)
int function_token_position() const
bool HasOuterScopeInfo() const
static const int kMaximumFunctionTokenOffset
bool HasTrustedData() const
void DisableOptimization(Isolate *isolate, BailoutReason reason)
void UpdateAndFinalizeExpectedNofPropertiesFromEstimate(FunctionLiteral *literal)
static void EnsureSourcePositionsAvailable(Isolate *isolate, DirectHandle< SharedFunctionInfo > shared_info)
static void EnsureBytecodeArrayAvailable(Isolate *isolate, Handle< SharedFunctionInfo > shared_info, IsCompiledScope *is_compiled_scope, CreateSourcePositions flag=CreateSourcePositions::kNo)
bool is_class_constructor() const
bool HasUncompiledDataWithPreparseData() const
uint16_t get_property_estimate_from_literal(FunctionLiteral *literal)
bool PassesFilter(const char *raw_filter)
FunctionKind kind() const
int UniqueIdInScript() const
V8_EXPORT_PRIVATE uint32_t Hash()
Tagged< AbstractCode > abstract_code(Isolate *isolate)
Tagged< Code > InterpreterTrampoline(IsolateForSandbox isolate) const
static Handle< Object > GetSourceCodeHarmony(Isolate *isolate, DirectHandle< SharedFunctionInfo > shared)
static V8_EXPORT_PRIVATE constexpr Tagged< Smi > const kNoSharedNameSentinel
void SetTrustedData(Tagged< ExposedTrustedObject > value, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
void ClearPreparseData(IsolateForSandbox isolate)
Tagged< HeapObject > script() const
bool HasUncompiledData() const
Tagged< String > Name() const
static constexpr int kAgeSize
bool HasUntrustedData() const
CachedTieringDecision cached_tiering_decision()
V8_EXPORT_PRIVATE std::optional< Tagged< DebugInfo > > TryGetDebugInfo(Isolate *isolate) const
Tagged< Object > GetTrustedData() const
V8_EXPORT_PRIVATE Tagged< DebugInfo > GetDebugInfo(Isolate *isolate) const
void SetUntrustedData(Tagged< Object > value, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
void CopyFrom(Tagged< SharedFunctionInfo > other, IsolateForSandbox isolate)
V8_EXPORT_PRIVATE int StartPosition() const
Tagged< UncompiledData > uncompiled_data(IsolateForSandbox isolate) const
V8_EXPORT_PRIVATE void UpdateFromFunctionLiteralForLiveEdit(IsolateForSandbox isolate, FunctionLiteral *lit)
bool BreakAtEntry(Isolate *isolate) const
static void CreateAndSetUncompiledData(IsolateT *isolate, FunctionLiteral *lit)
bool HasBuiltinId() const
static Handle< String > DebugName(Isolate *isolate, DirectHandle< SharedFunctionInfo > shared)
static V8_EXPORT_PRIVATE void DiscardCompiled(Isolate *isolate, DirectHandle< SharedFunctionInfo > shared_info)
std::unique_ptr< char[]> DebugNameCStr() const
void UpdateExpectedNofPropertiesFromEstimate(FunctionLiteral *literal)
V8_EXPORT_PRIVATE int EndPosition() const
bool HasSourceCode() const
bool HasFeedbackMetadata() const
V8_EXPORT_PRIVATE Tagged< Code > GetCode(Isolate *isolate) const
V8_EXPORT_PRIVATE void SetScript(IsolateForSandbox isolate, ReadOnlyRoots roots, Tagged< HeapObject > script_object, int function_literal_id, bool reset_preparsed_scope_data=true)
void set_internal_formal_parameter_count(int value)
void UpdateFunctionMapIndex()
static V8_EXPORT_PRIVATE void EnsureOldForTesting(Tagged< SharedFunctionInfo > sfu)
IsCompiledScope is_compiled_scope(IsolateT *isolate) const
void DiscardCompiledMetadata(Isolate *isolate, std::function< void(Tagged< HeapObject > object, ObjectSlot slot, Tagged< HeapObject > target)> gc_notify_updated_slot=[](Tagged< HeapObject > object, ObjectSlot slot, Tagged< HeapObject > target) {})
V8_EXPORT_PRIVATE bool HasBreakInfo(Isolate *isolate) const
@ kHasOptimizationDisabled
static void InitFromFunctionLiteral(IsolateT *isolate, FunctionLiteral *lit, bool is_toplevel)
bool HasDebugInfo(Isolate *isolate) const
static constexpr Tagged< Smi > zero()
bool GetHeapObjectIfWeak(Tagged< HeapObject > *result) const
bool GetHeapObject(Tagged< HeapObject > *result) const
static std::unique_ptr< char[]> GetDebugName(const wasm::CanonicalSig *sig)
#define PROFILE(the_isolate, Call)
base::Vector< const DirectHandle< Object > > args
#define EXPORT_TEMPLATE_DEFINE(export)
ZoneVector< RpoNumber > & result
FunctionLiteral * literal
InstructionOperand source
V8_INLINE size_t hash_combine(size_t seed, size_t hash)
Vector< const char > CStrVector(const char *data)
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
constexpr int kNoSourcePosition
bool IsClassConstructor(FunctionKind kind)
ReadOnlyRoots GetReadOnlyRoots()
void PrintF(const char *format,...)
SharedFunctionInfo::HasStaticPrivateMethodsOrAccessorsBit SharedFunctionInfo::MaglevCompilationFailedBit syntax_kind
Tagged(T object) -> Tagged< T >
kWasmInternalFunctionIndirectPointerTag instance_data
V8_INLINE constexpr bool IsSmi(TaggedImpl< kRefType, StorageType > obj)
V8_INLINE IndirectHandle< T > indirect_handle(DirectHandle< T > handle)
kInterpreterTrampolineOffset Tagged< HeapObject >
V8_INLINE DirectHandle< T > direct_handle(Tagged< T > object, Isolate *isolate)
kWasmInternalFunctionIndirectPointerTag kProtectedInstanceDataOffset sig
std::ostream & operator<<(std::ostream &os, AtomicMemoryOrder order)
V8_INLINE IsolateForSandbox GetIsolateForSandbox(Tagged< HeapObject >)
constexpr int kInvalidInfoId
Handle< To > UncheckedCast(Handle< From > value)
V8_INLINE PtrComprCageBase GetPtrComprCageBase()
void ShortPrint(Tagged< Object > obj, FILE *out)
const char * GetBailoutReason(BailoutReason reason)
bool PassesFilter(base::Vector< const char > name, base::Vector< const char > filter)
Tagged< MaybeWeak< T > > MakeWeak(Tagged< T > value)
constexpr int kFunctionLiteralIdTopLevel
V8_EXPORT_PRIVATE FlagValues v8_flags
constexpr int JSParameterCount(int param_count_without_receiver)
bool IsClassMembersInitializerFunction(FunctionKind kind)
bool IsDefaultConstructor(FunctionKind kind)
@ kClassMembersInitializerFunction
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
static constexpr ReleaseStoreTag kReleaseStore
static constexpr RelaxedLoadTag kRelaxedLoad
static constexpr RelaxedStoreTag kRelaxedStore
static constexpr AcquireLoadTag kAcquireLoad
#define DCHECK_IMPLIES(v1, v2)
#define DCHECK_NE(v1, v2)
#define DCHECK(condition)
#define DCHECK_LT(v1, v2)
#define DCHECK_EQ(v1, v2)
#define V8_EXPORT_PRIVATE
const Tagged< SharedFunctionInfo > value
#define V8_LIKELY(condition)