Skip to content

Commit 15a7e04

Browse files
sethbrenithCommit Bot
authored andcommitted
[torque] Move Map layout definition to Torque
This commit attempts to change as little behavior as possible, but it does require reordering the fields within Map to abide by Torque rules specifying that strong and weak fields must be in separate sections. Also includes some Torque compiler updates: - Allow enums (types extending from integral types) as class fields - Rename @ifdef to @if and add @ifnot for inverse checks - Allow void fields in class declarations, which take up no space and emit no accessors Bug: v8:8952 Change-Id: I1de6f34c1b15ed87d718666a05176980a218e97c Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1480919 Commit-Queue: Seth Brenith <[email protected]> Reviewed-by: Tobias Tebbi <[email protected]> Cr-Commit-Position: refs/heads/master@{#61588}
1 parent a9eaf66 commit 15a7e04

20 files changed

Lines changed: 170 additions & 126 deletions

src/builtins/base.tq

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,6 @@ type DirectString extends String;
166166

167167
type RootIndex generates 'TNode<Int32T>' constexpr 'RootIndex';
168168

169-
type Map extends HeapObject generates 'TNode<Map>';
170-
171169
@abstract
172170
@noVerifier
173171
extern class FixedArrayBase extends HeapObject {
@@ -184,6 +182,39 @@ extern class WeakFixedArray extends HeapObject { length: Smi; }
184182

185183
extern class ByteArray extends FixedArrayBase {}
186184

185+
type LayoutDescriptor extends ByteArray
186+
generates 'TNode<LayoutDescriptor>';
187+
type TransitionArray extends WeakFixedArray
188+
generates 'TNode<TransitionArray>';
189+
190+
// InstanceType actually extends uint16, but a bunch of methods in
191+
// CodeStubAssembler expect a TNode<Int32T>, so keeping it signed for now.
192+
type InstanceType extends int16 constexpr 'InstanceType';
193+
194+
extern class Map extends HeapObject {
195+
instance_size_in_words: uint8;
196+
in_object_properties_start_or_constructor_function_index: uint8;
197+
used_or_unused_instance_size_in_words: uint8;
198+
visitor_id: uint8;
199+
instance_type: InstanceType;
200+
bit_field: uint8;
201+
bit_field2: uint8;
202+
bit_field3: uint32;
203+
204+
@if(TAGGED_SIZE_8_BYTES) optional_padding: uint32;
205+
@ifnot(TAGGED_SIZE_8_BYTES) optional_padding: void;
206+
207+
prototype: HeapObject;
208+
constructor_or_back_pointer: Object;
209+
instance_descriptors: DescriptorArray;
210+
@if(V8_DOUBLE_FIELDS_UNBOXING) layout_descriptor: LayoutDescriptor;
211+
@ifnot(V8_DOUBLE_FIELDS_UNBOXING) layout_descriptor: void;
212+
dependent_code: DependentCode;
213+
prototype_validity_cell: Smi | Cell;
214+
weak transitions_or_prototype_info: Map | TransitionArray |
215+
PrototypeInfo | Smi;
216+
}
217+
187218
type BytecodeArray extends FixedArrayBase;
188219

189220
@generatePrint
@@ -483,7 +514,7 @@ extern class SharedFunctionInfo extends HeapObject {
483514
expected_nof_properties: uint16;
484515
function_token_offset: int16;
485516
flags: int32;
486-
@ifdef(V8_SFI_HAS_UNIQUE_ID) unique_id: int32;
517+
@if(V8_SFI_HAS_UNIQUE_ID) unique_id: int32;
487518
}
488519

489520
extern class JSBoundFunction extends JSObject {
@@ -703,7 +734,6 @@ extern class PropertyCell extends HeapObject {
703734

704735
extern class JSDataView extends JSArrayBufferView {}
705736

706-
type InstanceType generates 'TNode<Int32T>' constexpr 'InstanceType';
707737
type ElementsKind generates 'TNode<Int32T>' constexpr 'ElementsKind';
708738
type LanguageMode extends Smi constexpr 'LanguageMode';
709739
type ExtractFixedArrayFlags
@@ -2300,8 +2330,6 @@ operator '[]=' macro StoreFixedArrayDirect(a: FixedArray, i: Smi, v: Object) {
23002330
a.objects[i] = v;
23012331
}
23022332

2303-
extern operator '.instance_type' macro LoadMapInstanceType(Map): int32;
2304-
23052333
extern macro GetNumberDictionaryNumberOfElements(NumberDictionary): Smi;
23062334
extern macro GetIteratorMethod(implicit context: Context)(HeapObject): Object
23072335
labels IfIteratorUndefined;

src/code-stub-assembler.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1607,7 +1607,7 @@ TNode<Int32T> CodeStubAssembler::LoadElementsKind(
16071607
TNode<DescriptorArray> CodeStubAssembler::LoadMapDescriptors(
16081608
SloppyTNode<Map> map) {
16091609
CSA_SLOW_ASSERT(this, IsMap(map));
1610-
return CAST(LoadObjectField(map, Map::kDescriptorsOffset));
1610+
return CAST(LoadObjectField(map, Map::kInstanceDescriptorsOffset));
16111611
}
16121612

16131613
TNode<HeapObject> CodeStubAssembler::LoadMapPrototype(SloppyTNode<Map> map) {

src/compiler/access-builder.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ FieldAccess AccessBuilder::ForMapBitField3() {
607607
// static
608608
FieldAccess AccessBuilder::ForMapDescriptors() {
609609
FieldAccess access = {
610-
kTaggedBase, Map::kDescriptorsOffset,
610+
kTaggedBase, Map::kInstanceDescriptorsOffset,
611611
Handle<Name>(), MaybeHandle<Map>(),
612612
Type::OtherInternal(), MachineType::TypeCompressedTaggedPointer(),
613613
kPointerWriteBarrier};

src/globals.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ constexpr int kStackSpaceRequiredForCompilation = 40;
8282
#define V8_DOUBLE_FIELDS_UNBOXING false
8383
#endif
8484

85+
// Determine whether tagged pointers are 8 bytes (used in Torque layouts for
86+
// choosing where to insert padding).
87+
#if V8_TARGET_ARCH_64_BIT && !defined(V8_COMPRESS_POINTERS)
88+
#define TAGGED_SIZE_8_BYTES true
89+
#else
90+
#define TAGGED_SIZE_8_BYTES false
91+
#endif
92+
8593
// Some types of tracing require the SFI to store a unique ID.
8694
#if defined(V8_TRACE_MAPS) || defined(V8_TRACE_IGNITION)
8795
#define V8_SFI_HAS_UNIQUE_ID true
@@ -234,6 +242,7 @@ using AtomicTagged_t = base::AtomicWord;
234242
constexpr bool kUseBranchlessPtrDecompression = true;
235243

236244
STATIC_ASSERT(kTaggedSize == (1 << kTaggedSizeLog2));
245+
STATIC_ASSERT((kTaggedSize == 8) == TAGGED_SIZE_8_BYTES);
237246

238247
using AsAtomicTagged = base::AsAtomicPointerImpl<AtomicTagged_t>;
239248
STATIC_ASSERT(sizeof(Tagged_t) == kTaggedSize);

src/objects-body-descriptors-inl.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -714,18 +714,16 @@ class WasmInstanceObject::BodyDescriptor final : public BodyDescriptorBase {
714714
class Map::BodyDescriptor final : public BodyDescriptorBase {
715715
public:
716716
static bool IsValidSlot(Map map, HeapObject obj, int offset) {
717-
return offset >= Map::kPointerFieldsBeginOffset &&
718-
offset < Map::kPointerFieldsEndOffset;
717+
return offset >= Map::kStartOfPointerFieldsOffset &&
718+
offset < Map::kEndOfTaggedFieldsOffset;
719719
}
720720

721721
template <typename ObjectVisitor>
722722
static inline void IterateBody(Map map, HeapObject obj, int object_size,
723723
ObjectVisitor* v) {
724-
IteratePointers(obj, Map::kPointerFieldsBeginOffset,
725-
Map::kTransitionsOrPrototypeInfoOffset, v);
724+
IteratePointers(obj, Map::kStartOfStrongFieldsOffset,
725+
Map::kEndOfStrongFieldsOffset, v);
726726
IterateMaybeWeakPointer(obj, kTransitionsOrPrototypeInfoOffset, v);
727-
IteratePointers(obj, Map::kTransitionsOrPrototypeInfoOffset + kTaggedSize,
728-
Map::kPointerFieldsEndOffset, v);
729727
}
730728

731729
static inline int SizeOf(Map map, HeapObject obj) { return Map::kSize; }

src/objects-debug.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,7 @@ void JSObject::JSObjectVerify(Isolate* isolate) {
659659
}
660660

661661
void Map::MapVerify(Isolate* isolate) {
662+
TorqueGeneratedClassVerifiers::MapVerify(*this, isolate);
662663
Heap* heap = isolate->heap();
663664
CHECK(!ObjectInYoungGeneration(*this));
664665
CHECK(FIRST_TYPE <= instance_type() && instance_type() <= LAST_TYPE);
@@ -667,8 +668,6 @@ void Map::MapVerify(Isolate* isolate) {
667668
static_cast<size_t>(instance_size()) < heap->Capacity()));
668669
CHECK(GetBackPointer()->IsUndefined(isolate) ||
669670
!Map::cast(GetBackPointer())->is_stable());
670-
HeapObject::VerifyHeapPointer(isolate, prototype());
671-
HeapObject::VerifyHeapPointer(isolate, instance_descriptors());
672671
SLOW_DCHECK(instance_descriptors()->IsSortedNoDuplicates());
673672
DisallowHeapAllocation no_gc;
674673
SLOW_DCHECK(
@@ -698,8 +697,6 @@ void Map::MapVerify(Isolate* isolate) {
698697
DCHECK(prototype_info() == Smi::kZero ||
699698
prototype_info()->IsPrototypeInfo());
700699
}
701-
CHECK(prototype_validity_cell()->IsSmi() ||
702-
prototype_validity_cell()->IsCell());
703700
}
704701

705702
void Map::DictionaryMapVerify(Isolate* isolate) {

src/objects/instance-type.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,10 @@ STATIC_ASSERT(FIRST_NONSTRING_TYPE == Internals::kFirstNonstringType);
387387
STATIC_ASSERT(ODDBALL_TYPE == Internals::kOddballType);
388388
STATIC_ASSERT(FOREIGN_TYPE == Internals::kForeignType);
389389

390+
// Make sure it doesn't matter whether we sign-extend or zero-extend these
391+
// values, because Torque treats InstanceType as signed.
392+
STATIC_ASSERT(LAST_TYPE < 1 << 15);
393+
390394
V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
391395
InstanceType instance_type);
392396

src/objects/map-inl.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,18 @@ OBJECT_CONSTRUCTORS_IMPL(Map, HeapObject)
3131
CAST_ACCESSOR(Map)
3232

3333
DescriptorArray Map::instance_descriptors() const {
34-
return DescriptorArray::cast(READ_FIELD(*this, kDescriptorsOffset));
34+
return DescriptorArray::cast(READ_FIELD(*this, kInstanceDescriptorsOffset));
3535
}
3636

3737
DescriptorArray Map::synchronized_instance_descriptors() const {
38-
return DescriptorArray::cast(ACQUIRE_READ_FIELD(*this, kDescriptorsOffset));
38+
return DescriptorArray::cast(
39+
ACQUIRE_READ_FIELD(*this, kInstanceDescriptorsOffset));
3940
}
4041

4142
void Map::set_synchronized_instance_descriptors(DescriptorArray value,
4243
WriteBarrierMode mode) {
43-
RELEASE_WRITE_FIELD(*this, kDescriptorsOffset, value);
44-
CONDITIONAL_WRITE_BARRIER(*this, kDescriptorsOffset, value, mode);
44+
RELEASE_WRITE_FIELD(*this, kInstanceDescriptorsOffset, value);
45+
CONDITIONAL_WRITE_BARRIER(*this, kInstanceDescriptorsOffset, value, mode);
4546
}
4647

4748
// A freshly allocated layout descriptor can be set on an existing map.

src/objects/map.cc

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,26 +1497,20 @@ Handle<Map> Map::Normalize(Isolate* isolate, Handle<Map> fast_map,
14971497
// applied to the shared map, dependent code and weak cell cache.
14981498
Handle<Map> fresh = Map::CopyNormalized(isolate, fast_map, mode);
14991499

1500+
STATIC_ASSERT(Map::kPrototypeValidityCellOffset ==
1501+
Map::kDependentCodeOffset + kTaggedSize);
1502+
DCHECK_EQ(0, memcmp(reinterpret_cast<void*>(fresh->address()),
1503+
reinterpret_cast<void*>(new_map->address()),
1504+
Map::kDependentCodeOffset));
1505+
int offset = Map::kPrototypeValidityCellOffset + kTaggedSize;
15001506
if (new_map->is_prototype_map()) {
15011507
// For prototype maps, the PrototypeInfo is not copied.
1502-
DCHECK_EQ(0, memcmp(reinterpret_cast<void*>(fresh->address()),
1503-
reinterpret_cast<void*>(new_map->address()),
1504-
kTransitionsOrPrototypeInfoOffset));
1508+
STATIC_ASSERT(Map::kTransitionsOrPrototypeInfoOffset ==
1509+
Map::kPrototypeValidityCellOffset + kTaggedSize);
1510+
offset = kTransitionsOrPrototypeInfoOffset + kTaggedSize;
15051511
DCHECK_EQ(fresh->raw_transitions(),
15061512
MaybeObject::FromObject(Smi::kZero));
1507-
STATIC_ASSERT(kDescriptorsOffset ==
1508-
kTransitionsOrPrototypeInfoOffset + kTaggedSize);
1509-
DCHECK_EQ(0, memcmp(fresh->RawField(kDescriptorsOffset).ToVoidPtr(),
1510-
new_map->RawField(kDescriptorsOffset).ToVoidPtr(),
1511-
kDependentCodeOffset - kDescriptorsOffset));
1512-
} else {
1513-
DCHECK_EQ(0, memcmp(reinterpret_cast<void*>(fresh->address()),
1514-
reinterpret_cast<void*>(new_map->address()),
1515-
Map::kDependentCodeOffset));
15161513
}
1517-
STATIC_ASSERT(Map::kPrototypeValidityCellOffset ==
1518-
Map::kDependentCodeOffset + kTaggedSize);
1519-
int offset = Map::kPrototypeValidityCellOffset + kTaggedSize;
15201514
DCHECK_EQ(0, memcmp(reinterpret_cast<void*>(fresh->address() + offset),
15211515
reinterpret_cast<void*>(new_map->address() + offset),
15221516
Map::kSize - offset));

src/objects/map.h

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "src/objects.h"
1010
#include "src/objects/code.h"
1111
#include "src/objects/heap-object.h"
12+
#include "torque-generated/field-offsets-tq.h"
1213

1314
// Has to be the last include (doesn't have include guards):
1415
#include "src/objects/object-macros.h"
@@ -166,11 +167,6 @@ using MapHandles = std::vector<Handle<Map>>;
166167
// +---------------+---------------------------------------------+
167168
// | TaggedPointer | [constructor_or_backpointer] |
168169
// +---------------+---------------------------------------------+
169-
// | TaggedPointer | If Map is a prototype map: |
170-
// | | [prototype_info] |
171-
// | | Else: |
172-
// | | [raw_transitions] |
173-
// +---------------+---------------------------------------------+
174170
// | TaggedPointer | [instance_descriptors] |
175171
// +*************************************************************+
176172
// ! TaggedPointer ! [layout_descriptors] !
@@ -180,6 +176,13 @@ using MapHandles = std::vector<Handle<Map>>;
180176
// +*************************************************************+
181177
// | TaggedPointer | [dependent_code] |
182178
// +---------------+---------------------------------------------+
179+
// | TaggedPointer | [prototype_validity_cell] |
180+
// +---------------+---------------------------------------------+
181+
// | TaggedPointer | If Map is a prototype map: |
182+
// | | [prototype_info] |
183+
// | | Else: |
184+
// | | [raw_transitions] |
185+
// +---------------+---------------------------------------------+
183186

184187
class Map : public HeapObject {
185188
public:
@@ -828,34 +831,8 @@ class Map : public HeapObject {
828831

829832
static const int kMaxPreAllocatedPropertyFields = 255;
830833

831-
// Layout description.
832-
#define MAP_FIELDS(V) \
833-
/* Raw data fields. */ \
834-
V(kInstanceSizeInWordsOffset, kUInt8Size) \
835-
V(kInObjectPropertiesStartOrConstructorFunctionIndexOffset, kUInt8Size) \
836-
V(kUsedOrUnusedInstanceSizeInWordsOffset, kUInt8Size) \
837-
V(kVisitorIdOffset, kUInt8Size) \
838-
V(kInstanceTypeOffset, kUInt16Size) \
839-
V(kBitFieldOffset, kUInt8Size) \
840-
V(kBitField2Offset, kUInt8Size) \
841-
V(kBitField3Offset, kUInt32Size) \
842-
/* Adds padding to make tagged fields kTaggedSize-aligned. */ \
843-
V(kOptionalPaddingOffset, OBJECT_POINTER_PADDING(kOptionalPaddingOffset)) \
844-
/* Pointer fields. */ \
845-
V(kPointerFieldsBeginOffset, 0) \
846-
V(kPrototypeOffset, kTaggedSize) \
847-
V(kConstructorOrBackPointerOffset, kTaggedSize) \
848-
V(kTransitionsOrPrototypeInfoOffset, kTaggedSize) \
849-
V(kDescriptorsOffset, kTaggedSize) \
850-
V(kLayoutDescriptorOffset, FLAG_unbox_double_fields ? kTaggedSize : 0) \
851-
V(kDependentCodeOffset, kTaggedSize) \
852-
V(kPrototypeValidityCellOffset, kTaggedSize) \
853-
V(kPointerFieldsEndOffset, 0) \
854-
/* Total size. */ \
855-
V(kSize, 0)
856-
857-
DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize, MAP_FIELDS)
858-
#undef MAP_FIELDS
834+
DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
835+
TORQUE_GENERATED_MAP_FIELDS)
859836

860837
STATIC_ASSERT(kInstanceTypeOffset == Internals::kMapInstanceTypeOffset);
861838

0 commit comments

Comments
 (0)