Commit 52a56bec authored by Sigurd Schneider's avatar Sigurd Schneider Committed by Commit Bot

Cleanup handling of {Strong,Weak}Fields sections

This is mainly a torque change, but as a drive-by we get rid of
kStartOfPointerFieldsOffset
kEndOfTaggedFieldsOffset
which often are used to enclose a section of pointers in an object.

Bug: v8:7793
Change-Id: I52d83d09249a3cc6a99e7e7506e154ccfca53a12
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1615249
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61722}
parent 90059ee5
...@@ -230,12 +230,17 @@ extern class SourcePositionTableWithFrameCache extends Struct { ...@@ -230,12 +230,17 @@ extern class SourcePositionTableWithFrameCache extends Struct {
stack_frame_cache: Object; stack_frame_cache: Object;
} }
// We make this class abstract because it is missing the variable-sized part,
// which is still impossible to express in Torque.
@abstract
extern class DescriptorArray extends HeapObject { extern class DescriptorArray extends HeapObject {
number_of_all_descriptors: uint16; number_of_all_descriptors: uint16;
number_of_descriptors: uint16; number_of_descriptors: uint16;
raw_number_of_marked_descriptors: uint16; raw_number_of_marked_descriptors: uint16;
filler16_bits: uint16; filler16_bits: uint16;
enum_cache: EnumCache; enum_cache: EnumCache;
// DescriptorEntry needs to be a struct with three fields.
// desriptors : DescriptorEntry[number_of_all_descriptors]
} }
// These intrinsics should never be called from Torque code. They're used // These intrinsics should never be called from Torque code. They're used
......
...@@ -1697,7 +1697,7 @@ void WasmInstanceObject::WasmInstanceObjectVerify(Isolate* isolate) { ...@@ -1697,7 +1697,7 @@ void WasmInstanceObject::WasmInstanceObjectVerify(Isolate* isolate) {
// Just generically check all tagged fields. Don't check the untagged fields, // Just generically check all tagged fields. Don't check the untagged fields,
// as some of them might still contain the "undefined" value if the // as some of them might still contain the "undefined" value if the
// WasmInstanceObject is not fully set up yet. // WasmInstanceObject is not fully set up yet.
for (int offset = kHeaderSize; offset < kEndOfTaggedFieldsOffset; for (int offset = kHeaderSize; offset < kEndOfStrongFieldsOffset;
offset += kTaggedSize) { offset += kTaggedSize) {
VerifyObjectField(isolate, offset); VerifyObjectField(isolate, offset);
} }
......
...@@ -248,8 +248,11 @@ class JSWeakRef::BodyDescriptor final : public BodyDescriptorBase { ...@@ -248,8 +248,11 @@ class JSWeakRef::BodyDescriptor final : public BodyDescriptorBase {
class SharedFunctionInfo::BodyDescriptor final : public BodyDescriptorBase { class SharedFunctionInfo::BodyDescriptor final : public BodyDescriptorBase {
public: public:
static bool IsValidSlot(Map map, HeapObject obj, int offset) { static bool IsValidSlot(Map map, HeapObject obj, int offset) {
return FixedBodyDescriptor<kStartOfPointerFieldsOffset, static_assert(kEndOfWeakFieldsOffset == kStartOfStrongFieldsOffset,
kEndOfTaggedFieldsOffset, "Leverage that strong fields directly follow weak fields"
"to call FixedBodyDescriptor<...>::IsValidSlot below");
return FixedBodyDescriptor<kStartOfWeakFieldsOffset,
kEndOfStrongFieldsOffset,
kAlignedSize>::IsValidSlot(map, obj, offset); kAlignedSize>::IsValidSlot(map, obj, offset);
} }
...@@ -258,7 +261,7 @@ class SharedFunctionInfo::BodyDescriptor final : public BodyDescriptorBase { ...@@ -258,7 +261,7 @@ class SharedFunctionInfo::BodyDescriptor final : public BodyDescriptorBase {
ObjectVisitor* v) { ObjectVisitor* v) {
IterateCustomWeakPointer(obj, kFunctionDataOffset, v); IterateCustomWeakPointer(obj, kFunctionDataOffset, v);
IteratePointers(obj, SharedFunctionInfo::kStartOfStrongFieldsOffset, IteratePointers(obj, SharedFunctionInfo::kStartOfStrongFieldsOffset,
SharedFunctionInfo::kEndOfTaggedFieldsOffset, v); SharedFunctionInfo::kEndOfStrongFieldsOffset, v);
} }
static inline int SizeOf(Map map, HeapObject object) { static inline int SizeOf(Map map, HeapObject object) {
...@@ -714,8 +717,12 @@ class WasmInstanceObject::BodyDescriptor final : public BodyDescriptorBase { ...@@ -714,8 +717,12 @@ class WasmInstanceObject::BodyDescriptor final : public BodyDescriptorBase {
class Map::BodyDescriptor final : public BodyDescriptorBase { class Map::BodyDescriptor final : public BodyDescriptorBase {
public: public:
static bool IsValidSlot(Map map, HeapObject obj, int offset) { static bool IsValidSlot(Map map, HeapObject obj, int offset) {
return offset >= Map::kStartOfPointerFieldsOffset && static_assert(
offset < Map::kEndOfTaggedFieldsOffset; Map::kEndOfStrongFieldsOffset == Map::kStartOfWeakFieldsOffset,
"Leverage that weak fields directly follow strong fields for the "
"check below");
return offset >= Map::kStartOfStrongFieldsOffset &&
offset < Map::kEndOfWeakFieldsOffset;
} }
template <typename ObjectVisitor> template <typename ObjectVisitor>
......
...@@ -92,7 +92,11 @@ int DescriptorArray::SearchWithCache(Isolate* isolate, Name name, Map map) { ...@@ -92,7 +92,11 @@ int DescriptorArray::SearchWithCache(Isolate* isolate, Name name, Map map) {
} }
ObjectSlot DescriptorArray::GetFirstPointerSlot() { ObjectSlot DescriptorArray::GetFirstPointerSlot() {
return RawField(DescriptorArray::kStartOfPointerFieldsOffset); static_assert(kEndOfStrongFieldsOffset == kStartOfWeakFieldsOffset,
"Weak and strong fields are continuous.");
static_assert(kEndOfWeakFieldsOffset == kHeaderSize,
"Weak fields extend up to the end of the header.");
return RawField(DescriptorArray::kStartOfStrongFieldsOffset);
} }
ObjectSlot DescriptorArray::GetDescriptorSlot(int descriptor) { ObjectSlot DescriptorArray::GetDescriptorSlot(int descriptor) {
......
...@@ -141,9 +141,7 @@ class DescriptorArray : public HeapObject { ...@@ -141,9 +141,7 @@ class DescriptorArray : public HeapObject {
// Layout description. // Layout description.
DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize, DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
TORQUE_GENERATED_DESCRIPTOR_ARRAY_FIELDS) TORQUE_GENERATED_DESCRIPTOR_ARRAY_FIELDS)
static constexpr int kHeaderSize = kSize; STATIC_ASSERT(IsAligned(kStartOfWeakFieldsOffset, kTaggedSize));
STATIC_ASSERT(IsAligned(kStartOfPointerFieldsOffset, kTaggedSize));
STATIC_ASSERT(IsAligned(kHeaderSize, kTaggedSize)); STATIC_ASSERT(IsAligned(kHeaderSize, kTaggedSize));
// Garbage collection support. // Garbage collection support.
...@@ -165,8 +163,13 @@ class DescriptorArray : public HeapObject { ...@@ -165,8 +163,13 @@ class DescriptorArray : public HeapObject {
inline ObjectSlot GetKeySlot(int descriptor); inline ObjectSlot GetKeySlot(int descriptor);
inline MaybeObjectSlot GetValueSlot(int descriptor); inline MaybeObjectSlot GetValueSlot(int descriptor);
using BodyDescriptor = static_assert(kEndOfStrongFieldsOffset == kStartOfWeakFieldsOffset,
FlexibleWeakBodyDescriptor<kStartOfPointerFieldsOffset>; "Weak fields follow strong fields.");
static_assert(kEndOfWeakFieldsOffset == kHeaderSize,
"Weak fields extend up to the end of the header.");
// We use this visitor to also visitor to also visit the enum_cache, which is
// the only tagged field in the header, and placed at the end of the header.
using BodyDescriptor = FlexibleWeakBodyDescriptor<kStartOfStrongFieldsOffset>;
// Layout of descriptor. // Layout of descriptor.
// Naming is consistent with Dictionary classes for easy templating. // Naming is consistent with Dictionary classes for easy templating.
......
...@@ -119,9 +119,9 @@ class UncompiledData : public HeapObject { ...@@ -119,9 +119,9 @@ class UncompiledData : public HeapObject {
// Layout description. // Layout description.
#define UNCOMPILED_DATA_FIELDS(V) \ #define UNCOMPILED_DATA_FIELDS(V) \
V(kStartOfPointerFieldsOffset, 0) \ V(kStartOfStrongFieldsOffset, 0) \
V(kInferredNameOffset, kTaggedSize) \ V(kInferredNameOffset, kTaggedSize) \
V(kEndOfTaggedFieldsOffset, 0) \ V(kEndOfStrongFieldsOffset, 0) \
/* Raw data fields. */ \ /* Raw data fields. */ \
V(kStartPositionOffset, kInt32Size) \ V(kStartPositionOffset, kInt32Size) \
V(kEndPositionOffset, kInt32Size) \ V(kEndPositionOffset, kInt32Size) \
...@@ -133,8 +133,8 @@ class UncompiledData : public HeapObject { ...@@ -133,8 +133,8 @@ class UncompiledData : public HeapObject {
DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize, UNCOMPILED_DATA_FIELDS) DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize, UNCOMPILED_DATA_FIELDS)
#undef UNCOMPILED_DATA_FIELDS #undef UNCOMPILED_DATA_FIELDS
using BodyDescriptor = FixedBodyDescriptor<kStartOfPointerFieldsOffset, using BodyDescriptor = FixedBodyDescriptor<kStartOfStrongFieldsOffset,
kEndOfTaggedFieldsOffset, kSize>; kEndOfStrongFieldsOffset, kSize>;
// Clear uninitialized padding space. // Clear uninitialized padding space.
inline void clear_padding(); inline void clear_padding();
...@@ -180,9 +180,9 @@ class UncompiledDataWithPreparseData : public UncompiledData { ...@@ -180,9 +180,9 @@ class UncompiledDataWithPreparseData : public UncompiledData {
// Layout description. // Layout description.
#define UNCOMPILED_DATA_WITH_PREPARSE_DATA_FIELDS(V) \ #define UNCOMPILED_DATA_WITH_PREPARSE_DATA_FIELDS(V) \
V(kStartOfPointerFieldsOffset, 0) \ V(kStartOfStrongFieldsOffset, 0) \
V(kPreparseDataOffset, kTaggedSize) \ V(kPreparseDataOffset, kTaggedSize) \
V(kEndOfTaggedFieldsOffset, 0) \ V(kEndOfStrongFieldsOffset, 0) \
/* Total size. */ \ /* Total size. */ \
V(kSize, 0) V(kSize, 0)
...@@ -195,7 +195,7 @@ class UncompiledDataWithPreparseData : public UncompiledData { ...@@ -195,7 +195,7 @@ class UncompiledDataWithPreparseData : public UncompiledData {
using BodyDescriptor = SubclassBodyDescriptor< using BodyDescriptor = SubclassBodyDescriptor<
UncompiledData::BodyDescriptor, UncompiledData::BodyDescriptor,
FixedBodyDescriptor<kStartOfPointerFieldsOffset, kEndOfTaggedFieldsOffset, FixedBodyDescriptor<kStartOfStrongFieldsOffset, kEndOfStrongFieldsOffset,
kSize>>; kSize>>;
OBJECT_CONSTRUCTORS(UncompiledDataWithPreparseData, UncompiledData); OBJECT_CONSTRUCTORS(UncompiledDataWithPreparseData, UncompiledData);
......
This diff is collapsed.
...@@ -704,8 +704,8 @@ class WasmCapiFunctionData : public Struct { ...@@ -704,8 +704,8 @@ class WasmCapiFunctionData : public Struct {
DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize, DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
TORQUE_GENERATED_WASM_CAPI_FUNCTION_DATA_FIELDS) TORQUE_GENERATED_WASM_CAPI_FUNCTION_DATA_FIELDS)
STATIC_ASSERT(kStartOfPointerFieldsOffset == kWrapperCodeOffset); STATIC_ASSERT(kStartOfStrongFieldsOffset == kWrapperCodeOffset);
typedef FlexibleBodyDescriptor<kStartOfPointerFieldsOffset> BodyDescriptor; typedef FlexibleBodyDescriptor<kStartOfStrongFieldsOffset> BodyDescriptor;
OBJECT_CONSTRUCTORS(WasmCapiFunctionData, Struct); OBJECT_CONSTRUCTORS(WasmCapiFunctionData, Struct);
}; };
......
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