Commit 5e16d853 authored by Victor Gomes's avatar Victor Gomes Committed by V8 LUCI CQ

[SharedFunctionInfo] Add available_baseline_code flag

Checks that flags1 are ReadOnly after SFI is finalised.

Bug: v8:12054
Change-Id: Ia2518b8f136a81aa076fd429bf4fcaf742a314e3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3263897
Commit-Queue: Victor Gomes <victorgomes@chromium.org>
Reviewed-by: 's avatarNico Hartmann <nicohartmann@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77816}
parent 604ebab1
...@@ -604,6 +604,10 @@ void InstallUnoptimizedCode(UnoptimizedCompilationInfo* compilation_info, ...@@ -604,6 +604,10 @@ void InstallUnoptimizedCode(UnoptimizedCompilationInfo* compilation_info,
#else #else
UNREACHABLE(); UNREACHABLE();
#endif // V8_ENABLE_WEBASSEMBLY #endif // V8_ENABLE_WEBASSEMBLY
#ifdef DEBUG
shared_info->set_finalized(true);
#endif
} }
} }
......
...@@ -361,6 +361,9 @@ Handle<SharedFunctionInfo> FactoryBase<Impl>::NewSharedFunctionInfo( ...@@ -361,6 +361,9 @@ Handle<SharedFunctionInfo> FactoryBase<Impl>::NewSharedFunctionInfo(
Handle<SharedFunctionInfo> shared = NewSharedFunctionInfo(); Handle<SharedFunctionInfo> shared = NewSharedFunctionInfo();
DisallowGarbageCollection no_gc; DisallowGarbageCollection no_gc;
SharedFunctionInfo raw = *shared; SharedFunctionInfo raw = *shared;
#ifdef DEBUG
raw.set_finalized(false);
#endif
// Function names are assumed to be flat elsewhere. // Function names are assumed to be flat elsewhere.
Handle<String> shared_name; Handle<String> shared_name;
bool has_shared_name = maybe_name.ToHandle(&shared_name); bool has_shared_name = maybe_name.ToHandle(&shared_name);
......
...@@ -2586,7 +2586,7 @@ IGNITION_HANDLER(CreateMappedArguments, InterpreterAssembler) { ...@@ -2586,7 +2586,7 @@ IGNITION_HANDLER(CreateMappedArguments, InterpreterAssembler) {
TNode<SharedFunctionInfo> shared_info = LoadObjectField<SharedFunctionInfo>( TNode<SharedFunctionInfo> shared_info = LoadObjectField<SharedFunctionInfo>(
closure, JSFunction::kSharedFunctionInfoOffset); closure, JSFunction::kSharedFunctionInfoOffset);
TNode<Uint32T> flags = TNode<Uint32T> flags =
LoadObjectField<Uint32T>(shared_info, SharedFunctionInfo::kFlagsOffset); LoadObjectField<Uint32T>(shared_info, SharedFunctionInfo::kFlags2Offset);
TNode<BoolT> has_duplicate_parameters = TNode<BoolT> has_duplicate_parameters =
IsSetWord32<SharedFunctionInfo::HasDuplicateParametersBit>(flags); IsSetWord32<SharedFunctionInfo::HasDuplicateParametersBit>(flags);
Branch(has_duplicate_parameters, &if_duplicate_parameters, Branch(has_duplicate_parameters, &if_duplicate_parameters,
......
...@@ -144,6 +144,8 @@ int32_t SharedFunctionInfo::relaxed_flags() const { ...@@ -144,6 +144,8 @@ int32_t SharedFunctionInfo::relaxed_flags() const {
return flags(kRelaxedLoad); return flags(kRelaxedLoad);
} }
void SharedFunctionInfo::set_relaxed_flags(int32_t flags) { void SharedFunctionInfo::set_relaxed_flags(int32_t flags) {
// These flags should be read only, once SFI is finalized.
DCHECK(!finalized());
return set_flags(flags, kRelaxedStore); return set_flags(flags, kRelaxedStore);
} }
...@@ -256,10 +258,11 @@ SharedFunctionInfo::Inlineability SharedFunctionInfo::GetInlineability( ...@@ -256,10 +258,11 @@ SharedFunctionInfo::Inlineability SharedFunctionInfo::GetInlineability(
return kIsInlineable; return kIsInlineable;
} }
BIT_FIELD_ACCESSORS(SharedFunctionInfo, flags2, class_scope_has_private_brand, BIT_FIELD_ACCESSORS(SharedFunctionInfo, relaxed_flags,
class_scope_has_private_brand,
SharedFunctionInfo::ClassScopeHasPrivateBrandBit) SharedFunctionInfo::ClassScopeHasPrivateBrandBit)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, flags2, BIT_FIELD_ACCESSORS(SharedFunctionInfo, relaxed_flags,
has_static_private_methods_or_accessors, has_static_private_methods_or_accessors,
SharedFunctionInfo::HasStaticPrivateMethodsOrAccessorsBit) SharedFunctionInfo::HasStaticPrivateMethodsOrAccessorsBit)
...@@ -268,21 +271,20 @@ BIT_FIELD_ACCESSORS(SharedFunctionInfo, relaxed_flags, syntax_kind, ...@@ -268,21 +271,20 @@ BIT_FIELD_ACCESSORS(SharedFunctionInfo, relaxed_flags, syntax_kind,
BIT_FIELD_ACCESSORS(SharedFunctionInfo, relaxed_flags, allows_lazy_compilation, BIT_FIELD_ACCESSORS(SharedFunctionInfo, relaxed_flags, allows_lazy_compilation,
SharedFunctionInfo::AllowLazyCompilationBit) SharedFunctionInfo::AllowLazyCompilationBit)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, relaxed_flags, has_duplicate_parameters, BIT_FIELD_ACCESSORS(SharedFunctionInfo, flags2, has_duplicate_parameters,
SharedFunctionInfo::HasDuplicateParametersBit) SharedFunctionInfo::HasDuplicateParametersBit)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, relaxed_flags, native, BIT_FIELD_ACCESSORS(SharedFunctionInfo, relaxed_flags, native,
SharedFunctionInfo::IsNativeBit) SharedFunctionInfo::IsNativeBit)
#if V8_ENABLE_WEBASSEMBLY #if V8_ENABLE_WEBASSEMBLY
BIT_FIELD_ACCESSORS(SharedFunctionInfo, relaxed_flags, is_asm_wasm_broken, BIT_FIELD_ACCESSORS(SharedFunctionInfo, flags2, is_asm_wasm_broken,
SharedFunctionInfo::IsAsmWasmBrokenBit) SharedFunctionInfo::IsAsmWasmBrokenBit)
#endif // V8_ENABLE_WEBASSEMBLY #endif // V8_ENABLE_WEBASSEMBLY
BIT_FIELD_ACCESSORS(SharedFunctionInfo, relaxed_flags, BIT_FIELD_ACCESSORS(SharedFunctionInfo, relaxed_flags,
requires_instance_members_initializer, requires_instance_members_initializer,
SharedFunctionInfo::RequiresInstanceMembersInitializerBit) SharedFunctionInfo::RequiresInstanceMembersInitializerBit)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, relaxed_flags, BIT_FIELD_ACCESSORS(SharedFunctionInfo, flags2, name_should_print_as_anonymous,
name_should_print_as_anonymous,
SharedFunctionInfo::NameShouldPrintAsAnonymousBit) SharedFunctionInfo::NameShouldPrintAsAnonymousBit)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, relaxed_flags, BIT_FIELD_ACCESSORS(SharedFunctionInfo, relaxed_flags,
has_reported_binary_coverage, has_reported_binary_coverage,
...@@ -296,12 +298,21 @@ BIT_FIELD_ACCESSORS(SharedFunctionInfo, relaxed_flags, ...@@ -296,12 +298,21 @@ BIT_FIELD_ACCESSORS(SharedFunctionInfo, relaxed_flags,
private_name_lookup_skips_outer_class, private_name_lookup_skips_outer_class,
SharedFunctionInfo::PrivateNameLookupSkipsOuterClassBit) SharedFunctionInfo::PrivateNameLookupSkipsOuterClassBit)
bool SharedFunctionInfo::available_baseline_code() const {
return AvailableBaselineCodeBit::decode(flags(kRelaxedLoad));
}
void SharedFunctionInfo::set_available_baseline_code(bool value) {
set_flags(AvailableBaselineCodeBit::update(flags(kRelaxedLoad), value),
kRelaxedStore);
}
bool SharedFunctionInfo::optimization_disabled() const { bool SharedFunctionInfo::optimization_disabled() const {
return disabled_optimization_reason() != BailoutReason::kNoReason; return disabled_optimization_reason() != BailoutReason::kNoReason;
} }
BailoutReason SharedFunctionInfo::disabled_optimization_reason() const { BailoutReason SharedFunctionInfo::disabled_optimization_reason() const {
return DisabledOptimizationReasonBits::decode(flags(kRelaxedLoad)); return DisabledOptimizationReasonBits::decode(flags2());
} }
LanguageMode SharedFunctionInfo::language_mode() const { LanguageMode SharedFunctionInfo::language_mode() const {
......
...@@ -228,6 +228,9 @@ void SharedFunctionInfo::SetScript(ReadOnlyRoots roots, ...@@ -228,6 +228,9 @@ void SharedFunctionInfo::SetScript(ReadOnlyRoots roots,
void SharedFunctionInfo::CopyFrom(SharedFunctionInfo other) { void SharedFunctionInfo::CopyFrom(SharedFunctionInfo other) {
PtrComprCageBase cage_base = GetPtrComprCageBase(*this); PtrComprCageBase cage_base = GetPtrComprCageBase(*this);
#ifdef DEBUG
set_finalized(false);
#endif
set_function_data(other.function_data(cage_base, kAcquireLoad), set_function_data(other.function_data(cage_base, kAcquireLoad),
kReleaseStore); kReleaseStore);
set_name_or_scope_info(other.name_or_scope_info(cage_base, kAcquireLoad), set_name_or_scope_info(other.name_or_scope_info(cage_base, kAcquireLoad),
...@@ -248,6 +251,10 @@ void SharedFunctionInfo::CopyFrom(SharedFunctionInfo other) { ...@@ -248,6 +251,10 @@ void SharedFunctionInfo::CopyFrom(SharedFunctionInfo other) {
set_unique_id(other.unique_id()); set_unique_id(other.unique_id());
#endif #endif
#ifdef DEBUG
set_finalized(other.finalized());
#endif
// This should now be byte-for-byte identical to the input. // This should now be byte-for-byte identical to the input.
DCHECK_EQ(memcmp(reinterpret_cast<void*>(address()), DCHECK_EQ(memcmp(reinterpret_cast<void*>(address()),
reinterpret_cast<void*>(other.address()), reinterpret_cast<void*>(other.address()),
...@@ -465,9 +472,7 @@ std::ostream& operator<<(std::ostream& os, const SourceCodeOf& v) { ...@@ -465,9 +472,7 @@ std::ostream& operator<<(std::ostream& os, const SourceCodeOf& v) {
void SharedFunctionInfo::DisableOptimization(BailoutReason reason) { void SharedFunctionInfo::DisableOptimization(BailoutReason reason) {
DCHECK_NE(reason, BailoutReason::kNoReason); DCHECK_NE(reason, BailoutReason::kNoReason);
set_flags2(DisabledOptimizationReasonBits::update(flags2(), reason));
set_flags(DisabledOptimizationReasonBits::update(flags(kRelaxedLoad), reason),
kRelaxedStore);
// Code should be the lazy compilation stub or else interpreted. // Code should be the lazy compilation stub or else interpreted.
Isolate* isolate = GetIsolate(); Isolate* isolate = GetIsolate();
DCHECK(abstract_code(isolate).kind() == CodeKind::INTERPRETED_FUNCTION || DCHECK(abstract_code(isolate).kind() == CodeKind::INTERPRETED_FUNCTION ||
......
...@@ -399,6 +399,9 @@ class SharedFunctionInfo ...@@ -399,6 +399,9 @@ class SharedFunctionInfo
using TorqueGeneratedSharedFunctionInfo::set_function_token_offset; using TorqueGeneratedSharedFunctionInfo::set_function_token_offset;
public: public:
inline bool available_baseline_code() const;
inline void set_available_baseline_code(bool value);
// The position of the 'function' token in the script source. Can return // The position of the 'function' token in the script source. Can return
// kNoSourcePosition if raw_function_token_offset() returns // kNoSourcePosition if raw_function_token_offset() returns
// kFunctionTokenOutOfRange. // kFunctionTokenOutOfRange.
...@@ -407,10 +410,6 @@ class SharedFunctionInfo ...@@ -407,10 +410,6 @@ class SharedFunctionInfo
// Returns true if the function has shared name. // Returns true if the function has shared name.
inline bool HasSharedName() const; inline bool HasSharedName() const;
// [flags] Bit field containing various flags about the function.
DECL_RELAXED_INT32_ACCESSORS(flags)
DECL_UINT8_ACCESSORS(flags2)
// True if the outer class scope contains a private brand for // True if the outer class scope contains a private brand for
// private instance methdos. // private instance methdos.
DECL_BOOLEAN_ACCESSORS(class_scope_has_private_brand) DECL_BOOLEAN_ACCESSORS(class_scope_has_private_brand)
...@@ -670,6 +669,10 @@ class SharedFunctionInfo ...@@ -670,6 +669,10 @@ class SharedFunctionInfo
inline uint16_t get_property_estimate_from_literal(FunctionLiteral* literal); inline uint16_t get_property_estimate_from_literal(FunctionLiteral* literal);
// [flags] Bit field containing various flags about the function.
DECL_RELAXED_INT32_ACCESSORS(flags)
DECL_UINT8_ACCESSORS(flags2)
// For ease of use of the BITFIELD macro. // For ease of use of the BITFIELD macro.
inline int32_t relaxed_flags() const; inline int32_t relaxed_flags() const;
inline void set_relaxed_flags(int32_t flags); inline void set_relaxed_flags(int32_t flags);
......
...@@ -18,6 +18,9 @@ type FunctionKind extends uint8 constexpr 'FunctionKind'; ...@@ -18,6 +18,9 @@ type FunctionKind extends uint8 constexpr 'FunctionKind';
type FunctionSyntaxKind extends uint8 constexpr 'FunctionSyntaxKind'; type FunctionSyntaxKind extends uint8 constexpr 'FunctionSyntaxKind';
type BailoutReason extends uint8 constexpr 'BailoutReason'; type BailoutReason extends uint8 constexpr 'BailoutReason';
// These flags are ReadOnly after SFI is fully inialized,
// except available_sparkplug_code which is set by the concurrent
// Sparkplug compiler.
bitfield struct SharedFunctionInfoFlags extends uint32 { bitfield struct SharedFunctionInfoFlags extends uint32 {
// Have FunctionKind first to make it cheaper to access. // Have FunctionKind first to make it cheaper to access.
function_kind: FunctionKind: 5 bit; function_kind: FunctionKind: 5 bit;
...@@ -25,23 +28,24 @@ bitfield struct SharedFunctionInfoFlags extends uint32 { ...@@ -25,23 +28,24 @@ bitfield struct SharedFunctionInfoFlags extends uint32 {
is_strict: bool: 1 bit; is_strict: bool: 1 bit;
function_syntax_kind: FunctionSyntaxKind: 3 bit; function_syntax_kind: FunctionSyntaxKind: 3 bit;
is_class_constructor: bool: 1 bit; is_class_constructor: bool: 1 bit;
has_duplicate_parameters: bool: 1 bit;
allow_lazy_compilation: bool: 1 bit; allow_lazy_compilation: bool: 1 bit;
is_asm_wasm_broken: bool: 1 bit;
function_map_index: uint32: 5 bit; function_map_index: uint32: 5 bit;
disabled_optimization_reason: BailoutReason: 4 bit;
requires_instance_members_initializer: bool: 1 bit; requires_instance_members_initializer: bool: 1 bit;
construct_as_builtin: bool: 1 bit; construct_as_builtin: bool: 1 bit;
name_should_print_as_anonymous: bool: 1 bit;
has_reported_binary_coverage: bool: 1 bit; has_reported_binary_coverage: bool: 1 bit;
is_top_level: bool: 1 bit; is_top_level: bool: 1 bit;
properties_are_final: bool: 1 bit; properties_are_final: bool: 1 bit;
private_name_lookup_skips_outer_class: bool: 1 bit; private_name_lookup_skips_outer_class: bool: 1 bit;
class_scope_has_private_brand: bool: 1 bit;
has_static_private_methods_or_accessors: bool: 1 bit;
available_baseline_code: bool: 1 bit;
} }
bitfield struct SharedFunctionInfoFlags2 extends uint8 { bitfield struct SharedFunctionInfoFlags2 extends uint8 {
class_scope_has_private_brand: bool: 1 bit; disabled_optimization_reason: BailoutReason: 4 bit;
has_static_private_methods_or_accessors: bool: 1 bit; is_asm_wasm_broken: bool: 1 bit;
name_should_print_as_anonymous: bool: 1 bit;
has_duplicate_parameters: bool: 1 bit;
} }
@generateBodyDescriptor @generateBodyDescriptor
...@@ -79,6 +83,7 @@ extern class SharedFunctionInfo extends HeapObject { ...@@ -79,6 +83,7 @@ extern class SharedFunctionInfo extends HeapObject {
// [unique_id] - For --log-maps purposes, an identifier that's persistent // [unique_id] - For --log-maps purposes, an identifier that's persistent
// even if the GC moves this SharedFunctionInfo. // even if the GC moves this SharedFunctionInfo.
@if(V8_SFI_HAS_UNIQUE_ID) unique_id: int32; @if(V8_SFI_HAS_UNIQUE_ID) unique_id: int32;
@if(DEBUG) finalized: int8;
} }
const kDontAdaptArgumentsSentinel: constexpr int32 const kDontAdaptArgumentsSentinel: constexpr int32
......
...@@ -45,6 +45,7 @@ struct EnumEntry { ...@@ -45,6 +45,7 @@ struct EnumEntry {
class BuildFlags : public ContextualClass<BuildFlags> { class BuildFlags : public ContextualClass<BuildFlags> {
public: public:
BuildFlags() { BuildFlags() {
build_flags_["DEBUG"] = DEBUG_BOOL;
build_flags_["V8_SFI_HAS_UNIQUE_ID"] = V8_SFI_HAS_UNIQUE_ID; build_flags_["V8_SFI_HAS_UNIQUE_ID"] = V8_SFI_HAS_UNIQUE_ID;
build_flags_["V8_EXTERNAL_CODE_SPACE"] = V8_EXTERNAL_CODE_SPACE_BOOL; build_flags_["V8_EXTERNAL_CODE_SPACE"] = V8_EXTERNAL_CODE_SPACE_BOOL;
build_flags_["TAGGED_SIZE_8_BYTES"] = TAGGED_SIZE_8_BYTES; build_flags_["TAGGED_SIZE_8_BYTES"] = TAGGED_SIZE_8_BYTES;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment