Commit e112e4d1 authored by Igor Sheludko's avatar Igor Sheludko Committed by V8 LUCI CQ

[ext-code-space] Fix TSAN issue in JSFunction::ShouldFlushBaselineCode()

Drive-by: cleanup accessor declaration and definition macros.

Bug: v8:11880, v8:12596
Cq-Include-Trybots: luci.v8.try:v8_linux64_tsan_rel_ng
Change-Id: Ia04a7f21d911386e610f963f55cbc1d310b2f442
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3439917Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78972}
parent becce45b
......@@ -982,7 +982,7 @@ void CodeDataContainer::clear_padding() {
kSize - kUnalignedSize);
}
INT_ACCESSORS(CodeDataContainer, flags, kFlagsOffset)
RELAXED_UINT16_ACCESSORS(CodeDataContainer, flags, kFlagsOffset)
// Ensure builtin_id field fits into int16_t, so that we can rely on sign
// extension to convert int16_t{-1} to kNoBuiltinId.
......@@ -992,15 +992,17 @@ STATIC_ASSERT(Builtins::kBuiltinCount < std::numeric_limits<int16_t>::max());
void CodeDataContainer::initialize_flags(CodeKind kind, Builtin builtin_id) {
CHECK(V8_EXTERNAL_CODE_SPACE_BOOL);
int value = KindField::encode(kind);
set_flags(value);
uint16_t value = KindField::encode(kind);
set_flags(value, kRelaxedStore);
WriteField<int16_t>(kBuiltinIdOffset, static_cast<int16_t>(builtin_id));
}
#ifdef V8_EXTERNAL_CODE_SPACE
CodeKind CodeDataContainer::kind() const { return KindField::decode(flags()); }
CodeKind CodeDataContainer::kind() const {
return KindField::decode(flags(kRelaxedLoad));
}
Builtin CodeDataContainer::builtin_id() const {
CHECK(V8_EXTERNAL_CODE_SPACE_BOOL);
......
......@@ -202,7 +202,7 @@ class CodeDataContainer : public HeapObject {
// When V8_EXTERNAL_CODE_SPACE is enabled the flags field contains cached
// values of some flags of the from the respective Code object.
DECL_INT_ACCESSORS(flags)
DECL_RELAXED_UINT16_ACCESSORS(flags)
friend Factory;
friend FactoryBase<Factory>;
......
......@@ -291,7 +291,7 @@ bool JSFunction::ShouldFlushBaselineCode(
// SFI / FV to JSFunction but it is safe in practice.
Object maybe_code = ACQUIRE_READ_FIELD(*this, kCodeOffset);
if (!maybe_code.IsCodeT()) return false;
Code code = FromCodeT(CodeT::cast(maybe_code));
CodeT code = CodeT::cast(maybe_code);
if (code.kind() != CodeKind::BASELINE) return false;
SharedFunctionInfo shared = SharedFunctionInfo::cast(maybe_shared);
......
......@@ -16,10 +16,13 @@
#undef DECL_BOOLEAN_ACCESSORS
#undef DECL_INT_ACCESSORS
#undef DECL_INT32_ACCESSORS
#undef DECL_RELAXED_INT32_ACCESSORS
#undef DECL_SANDBOXED_POINTER_ACCESSORS
#undef DECL_UINT16_ACCESSORS
#undef DECL_INT16_ACCESSORS
#undef DECL_UINT8_ACCESSORS
#undef DECL_RELAXED_PRIMITIVE_ACCESSORS
#undef DECL_RELAXED_INT32_ACCESSORS
#undef DECL_RELAXED_UINT16_ACCESSORS
#undef DECL_GETTER
#undef DEF_GETTER
#undef DEF_RELAXED_GETTER
......@@ -37,16 +40,18 @@
#undef DECL_RELEASE_ACQUIRE_WEAK_ACCESSORS
#undef DECL_CAST
#undef CAST_ACCESSOR
#undef DEF_PRIMITIVE_ACCESSORS
#undef INT_ACCESSORS
#undef INT32_ACCESSORS
#undef RELAXED_INT32_ACCESSORS
#undef UINT16_ACCESSORS
#undef UINT8_ACCESSORS
#undef RELAXED_INT32_ACCESSORS
#undef RELAXED_UINT16_ACCESSORS
#undef ACCESSORS_CHECKED2
#undef ACCESSORS_CHECKED
#undef ACCESSORS
#undef RENAME_TORQUE_ACCESSORS
#undef RENAME_UINT16_TORQUE_ACCESSORS
#undef RENAME_PRIMITIVE_TORQUE_ACCESSORS
#undef ACCESSORS_RELAXED_CHECKED2
#undef ACCESSORS_RELAXED_CHECKED
#undef ACCESSORS_RELAXED
......@@ -89,6 +94,7 @@
#undef CONDITIONAL_WRITE_BARRIER
#undef CONDITIONAL_WEAK_WRITE_BARRIER
#undef CONDITIONAL_EPHEMERON_KEY_WRITE_BARRIER
#undef ACQUIRE_READ_INT8_FIELD
#undef ACQUIRE_READ_INT32_FIELD
#undef RELAXED_WRITE_INT8_FIELD
#undef RELAXED_READ_INT8_FIELD
......@@ -99,6 +105,7 @@
#undef RELAXED_READ_UINT32_FIELD
#undef ACQUIRE_READ_UINT32_FIELD
#undef RELAXED_WRITE_UINT32_FIELD
#undef RELEASE_WRITE_INT8_FIELD
#undef RELEASE_WRITE_UINT32_FIELD
#undef RELAXED_READ_INT32_FIELD
#undef RELEASE_WRITE_INT32_FIELD
......
......@@ -61,21 +61,21 @@
DECL_PRIMITIVE_GETTER(name, type) \
DECL_PRIMITIVE_SETTER(name, type)
#define DECL_RELAXED_INT32_ACCESSORS(name) \
inline int32_t name(RelaxedLoadTag) const; \
inline void set_##name(int32_t value, RelaxedStoreTag);
#define DECL_UINT16_ACCESSORS(name) DECL_PRIMITIVE_ACCESSORS(name, uint16_t)
#define DECL_UINT16_ACCESSORS(name) \
inline uint16_t name() const; \
inline void set_##name(int value);
#define DECL_INT16_ACCESSORS(name) DECL_PRIMITIVE_ACCESSORS(name, int16_t)
#define DECL_INT16_ACCESSORS(name) \
inline int16_t name() const; \
inline void set_##name(int16_t value);
#define DECL_UINT8_ACCESSORS(name) DECL_PRIMITIVE_ACCESSORS(name, uint8_t)
#define DECL_UINT8_ACCESSORS(name) \
inline uint8_t name() const; \
inline void set_##name(int value);
#define DECL_RELAXED_PRIMITIVE_ACCESSORS(name, type) \
inline type name(RelaxedLoadTag) const; \
inline void set_##name(type value, RelaxedStoreTag);
#define DECL_RELAXED_INT32_ACCESSORS(name) \
DECL_RELAXED_PRIMITIVE_ACCESSORS(name, int32_t)
#define DECL_RELAXED_UINT16_ACCESSORS(name) \
DECL_RELAXED_PRIMITIVE_ACCESSORS(name, uint16_t)
// TODO(ishell): eventually isolate-less getters should not be used anymore.
// For full pointer-mode the C++ compiler should optimize away unused isolate
......@@ -154,13 +154,21 @@
#define CAST_ACCESSOR(Type) \
Type Type::cast(Object object) { return Type(object.ptr()); }
#define INT_ACCESSORS(holder, name, offset) \
int holder::name() const { return ReadField<int>(offset); } \
void holder::set_##name(int value) { WriteField<int>(offset, value); }
#define DEF_PRIMITIVE_ACCESSORS(holder, name, offset, type) \
type holder::name() const { return ReadField<type>(offset); } \
void holder::set_##name(type value) { WriteField<type>(offset, value); }
#define INT_ACCESSORS(holder, name, offset) \
DEF_PRIMITIVE_ACCESSORS(holder, name, offset, int)
#define INT32_ACCESSORS(holder, name, offset) \
DEF_PRIMITIVE_ACCESSORS(holder, name, offset, int32_t)
#define INT32_ACCESSORS(holder, name, offset) \
int32_t holder::name() const { return ReadField<int32_t>(offset); } \
void holder::set_##name(int32_t value) { WriteField<int32_t>(offset, value); }
#define UINT16_ACCESSORS(holder, name, offset) \
DEF_PRIMITIVE_ACCESSORS(holder, name, offset, uint16_t)
#define UINT8_ACCESSORS(holder, name, offset) \
DEF_PRIMITIVE_ACCESSORS(holder, name, offset, uint8_t)
#define RELAXED_INT32_ACCESSORS(holder, name, offset) \
int32_t holder::name(RelaxedLoadTag) const { \
......@@ -170,20 +178,12 @@
RELAXED_WRITE_INT32_FIELD(*this, offset, value); \
}
#define UINT16_ACCESSORS(holder, name, offset) \
uint16_t holder::name() const { return ReadField<uint16_t>(offset); } \
void holder::set_##name(int value) { \
DCHECK_GE(value, 0); \
DCHECK_LE(value, static_cast<uint16_t>(-1)); \
WriteField<uint16_t>(offset, value); \
}
#define UINT8_ACCESSORS(holder, name, offset) \
uint8_t holder::name() const { return ReadField<uint8_t>(offset); } \
void holder::set_##name(int value) { \
DCHECK_GE(value, 0); \
DCHECK_LE(value, static_cast<uint8_t>(-1)); \
WriteField<uint8_t>(offset, value); \
#define RELAXED_UINT16_ACCESSORS(holder, name, offset) \
uint16_t holder::name(RelaxedLoadTag) const { \
return RELAXED_READ_UINT16_FIELD(*this, offset); \
} \
void holder::set_##name(uint16_t value, RelaxedStoreTag) { \
RELAXED_WRITE_UINT16_FIELD(*this, offset, value); \
}
#define ACCESSORS_CHECKED2(holder, name, type, offset, get_condition, \
......@@ -213,13 +213,10 @@
TorqueGeneratedClass::set_##torque_name(value, mode); \
}
#define RENAME_UINT16_TORQUE_ACCESSORS(holder, name, torque_name) \
uint16_t holder::name() const { \
return TorqueGeneratedClass::torque_name(); \
} \
void holder::set_##name(int value) { \
DCHECK_EQ(value, static_cast<uint16_t>(value)); \
TorqueGeneratedClass::set_##torque_name(value); \
#define RENAME_PRIMITIVE_TORQUE_ACCESSORS(holder, name, torque_name, type) \
type holder::name() const { return TorqueGeneratedClass::torque_name(); } \
void holder::set_##name(type value) { \
TorqueGeneratedClass::set_##torque_name(value); \
}
#define ACCESSORS_RELAXED_CHECKED2(holder, name, type, offset, get_condition, \
......
......@@ -138,8 +138,8 @@ void SharedFunctionInfo::set_internal_formal_parameter_count(int value) {
TorqueGeneratedClass::set_formal_parameter_count(value);
}
RENAME_UINT16_TORQUE_ACCESSORS(SharedFunctionInfo, raw_function_token_offset,
function_token_offset)
RENAME_PRIMITIVE_TORQUE_ACCESSORS(SharedFunctionInfo, raw_function_token_offset,
function_token_offset, uint16_t)
RELAXED_INT32_ACCESSORS(SharedFunctionInfo, flags, kFlagsOffset)
int32_t SharedFunctionInfo::relaxed_flags() const {
......
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