[vm] Auto-generate InstanceSize definitions for array objects in runtime_api

Previously, compiler::target::Foo::InstanceSize(intptr_t length)
definitions were hand-written and compiler::target::Foo::InstanceSize()
were often defined using the size of UntaggedFoo for array-like objects.
This results in an unnecessary code duplication and discrepancy
between Foo::InstanceSize() which returns 0 and
compiler::target::Foo::InstanceSize() which returns size of the header.

This change adds ARRAY_SIZEOF variant to runtime_offsets_list.h
and switches array-like objects to auto-generated InstanceSize methods.

Also, this change strengthens assertions around host and target
values of InstanceSize() and NextFieldOffset() being the same
unless DART_PRECOMPILER is defined (which may do cross-compilation).

Stronger assertions flushed out a few discrepancies between
runtime_api.h and object.h, which are also fixed in this change.

TEST=ci

Change-Id: I9f67c6a71b9300af5e656fdc70f6a3e341c1d029
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196345
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
This commit is contained in:
Alexander Markov 2021-04-22 18:21:16 +00:00 committed by commit-bot@chromium.org
parent bf02e85330
commit 9af507e0f5
12 changed files with 689 additions and 668 deletions

View file

@ -1914,7 +1914,7 @@ class CodeSerializationCluster : public SerializationCluster {
const int32_t state_bits = code->untag()->state_bits_;
s->Write<int32_t>(state_bits);
if (!Code::DiscardedBit::decode(state_bits)) {
target_memory_size_ += compiler::target::Code::InstanceSize();
target_memory_size_ += compiler::target::Code::InstanceSize(0);
}
}

View file

@ -51,7 +51,9 @@ class OffsetsExtractor : public AllStatic {
//
// TODO(dartbug.com/43646): Add DART_PRECOMPILER as another axis.
// This doesn't use any special constants, just method calls, so no output.
// These macros don't use any special constants, just method calls, so no
// output.
#define PRINT_ARRAY_SIZEOF(Class, Name, ElementOffset)
#define PRINT_PAYLOAD_SIZEOF(Class, Name, HeaderSize)
#if defined(DART_PRECOMPILED_RUNTIME)
@ -135,18 +137,21 @@ class OffsetsExtractor : public AllStatic {
<< Class::Name << ";\n";
JIT_OFFSETS_LIST(PRINT_FIELD_OFFSET, PRINT_ARRAY_LAYOUT, PRINT_SIZEOF,
PRINT_PAYLOAD_SIZEOF, PRINT_RANGE, PRINT_CONSTANT)
PRINT_ARRAY_SIZEOF, PRINT_PAYLOAD_SIZEOF, PRINT_RANGE,
PRINT_CONSTANT)
#endif // defined(DART_PRECOMPILED_RUNTIME)
COMMON_OFFSETS_LIST(PRINT_FIELD_OFFSET, PRINT_ARRAY_LAYOUT, PRINT_SIZEOF,
PRINT_PAYLOAD_SIZEOF, PRINT_RANGE, PRINT_CONSTANT)
PRINT_ARRAY_SIZEOF, PRINT_PAYLOAD_SIZEOF, PRINT_RANGE,
PRINT_CONSTANT)
#undef PRINT_FIELD_OFFSET
#undef PRINT_ARRAY_LAYOUT
#undef PRINT_SIZEOF
#undef PRINT_RANGE
#undef PRINT_CONSTANT
#undef PRINT_ARRAY_SIZEOF
#undef PRINT_PAYLOAD_SIZEOF
}
};

View file

@ -211,7 +211,7 @@ word TypedDataElementSizeInBytes(classid_t cid) {
}
word TypedDataMaxNewSpaceElements(classid_t cid) {
return (dart::Heap::kNewAllocatableSize - target::TypedData::InstanceSize()) /
return (dart::Heap::kNewAllocatableSize - target::TypedData::HeaderSize()) /
TypedDataElementSizeInBytes(cid);
}
@ -517,14 +517,6 @@ word ICData::EntryPointIndexFor(word num_args) {
const word MegamorphicCache::kSpreadFactor =
dart::MegamorphicCache::kSpreadFactor;
word Context::InstanceSize(word n) {
return TranslateOffsetInWords(dart::Context::InstanceSize(n));
}
word Context::variable_offset(word n) {
return TranslateOffsetInWords(dart::Context::variable_offset(n));
}
// Currently we have two different axes for offset generation:
//
// * Target architecture
@ -534,6 +526,12 @@ word Context::variable_offset(word n) {
#define DEFINE_CONSTANT(Class, Name) const word Class::Name = Class##_##Name;
#define DEFINE_ARRAY_SIZEOF(clazz, name, ElementOffset) \
word clazz::name() { return 0; } \
word clazz::name(intptr_t length) { \
return RoundedAllocationSize(clazz::ElementOffset(length)); \
}
#define DEFINE_PAYLOAD_SIZEOF(clazz, name, header) \
word clazz::name() { return 0; } \
word clazz::name(word payload_size) { \
@ -562,6 +560,7 @@ word Context::variable_offset(word n) {
JIT_OFFSETS_LIST(DEFINE_FIELD,
DEFINE_ARRAY,
DEFINE_SIZEOF,
DEFINE_ARRAY_SIZEOF,
DEFINE_PAYLOAD_SIZEOF,
DEFINE_RANGE,
DEFINE_CONSTANT)
@ -569,6 +568,7 @@ JIT_OFFSETS_LIST(DEFINE_FIELD,
COMMON_OFFSETS_LIST(DEFINE_FIELD,
DEFINE_ARRAY,
DEFINE_SIZEOF,
DEFINE_ARRAY_SIZEOF,
DEFINE_PAYLOAD_SIZEOF,
DEFINE_RANGE,
DEFINE_CONSTANT)
@ -614,6 +614,7 @@ COMMON_OFFSETS_LIST(DEFINE_FIELD,
JIT_OFFSETS_LIST(DEFINE_JIT_FIELD,
DEFINE_JIT_ARRAY,
DEFINE_JIT_SIZEOF,
DEFINE_ARRAY_SIZEOF,
DEFINE_PAYLOAD_SIZEOF,
DEFINE_JIT_RANGE,
DEFINE_CONSTANT)
@ -657,6 +658,7 @@ JIT_OFFSETS_LIST(DEFINE_JIT_FIELD,
COMMON_OFFSETS_LIST(DEFINE_FIELD,
DEFINE_ARRAY,
DEFINE_SIZEOF,
DEFINE_ARRAY_SIZEOF,
DEFINE_PAYLOAD_SIZEOF,
DEFINE_RANGE,
DEFINE_CONSTANT)
@ -877,10 +879,6 @@ word ObjectPool::NextFieldOffset() {
return -kWordSize;
}
word ObjectPool::InstanceSize(intptr_t length) {
return RoundedAllocationSize(ObjectPool::element_offset(length));
}
word Class::NextFieldOffset() {
return -kWordSize;
}
@ -910,10 +908,6 @@ intptr_t Array::index_at_offset(intptr_t offset_in_bytes) {
TranslateOffsetInWordsToHost(offset_in_bytes));
}
word Array::InstanceSize(intptr_t length) {
return RoundedAllocationSize(Array::element_offset(length));
}
word GrowableObjectArray::NextFieldOffset() {
return -kWordSize;
}
@ -926,10 +920,6 @@ word TypedData::NextFieldOffset() {
return -kWordSize;
}
word TypedData::InstanceSize(intptr_t lengthInBytes) {
return RoundedAllocationSize(TypedData::InstanceSize() + lengthInBytes);
}
word ExternalTypedData::NextFieldOffset() {
return -kWordSize;
}
@ -978,20 +968,10 @@ word OneByteString::NextFieldOffset() {
return -kWordSize;
}
word OneByteString::InstanceSize(intptr_t length) {
return RoundedAllocationSize(OneByteString::InstanceSize() +
length * dart::OneByteString::kBytesPerElement);
}
word TwoByteString::NextFieldOffset() {
return -kWordSize;
}
word TwoByteString::InstanceSize(intptr_t length) {
return RoundedAllocationSize(TwoByteString::InstanceSize() +
length * dart::TwoByteString::kBytesPerElement);
}
word ExternalOneByteString::NextFieldOffset() {
return -kWordSize;
}
@ -1052,6 +1032,10 @@ word CompressedStackMaps::NextFieldOffset() {
return -kWordSize;
}
word LocalVarDescriptors::InstanceSize() {
return 0;
}
word LocalVarDescriptors::NextFieldOffset() {
return -kWordSize;
}
@ -1060,18 +1044,10 @@ word ExceptionHandlers::NextFieldOffset() {
return -kWordSize;
}
word ExceptionHandlers::InstanceSize(intptr_t length) {
return RoundedAllocationSize(ExceptionHandlers::element_offset(length));
}
word ContextScope::NextFieldOffset() {
return -kWordSize;
}
word ContextScope::InstanceSize(intptr_t length) {
return RoundedAllocationSize(ContextScope::element_offset(length));
}
word UnlinkedCall::NextFieldOffset() {
return -kWordSize;
}
@ -1125,7 +1101,11 @@ word StackTrace::NextFieldOffset() {
}
word Integer::NextFieldOffset() {
return -kWordSize;
return TranslateOffsetInWords(dart::Integer::NextFieldOffset());
}
word Smi::InstanceSize() {
return 0;
}
word Smi::NextFieldOffset() {
@ -1141,7 +1121,7 @@ word MirrorReference::NextFieldOffset() {
}
word Number::NextFieldOffset() {
return -kWordSize;
return TranslateOffsetInWords(dart::Number::NextFieldOffset());
}
word MonomorphicSmiableCall::NextFieldOffset() {
@ -1152,12 +1132,6 @@ word InstructionsSection::NextFieldOffset() {
return -kWordSize;
}
word InstructionsTable::InstanceSize(intptr_t length) {
return RoundedAllocationSize(InstructionsTable::InstanceSize() +
length *
dart::InstructionsTable::kBytesPerElement);
}
word InstructionsTable::NextFieldOffset() {
return -kWordSize;
}
@ -1210,10 +1184,6 @@ word TypeArguments::NextFieldOffset() {
return -kWordSize;
}
word TypeArguments::InstanceSize(intptr_t length) {
return RoundedAllocationSize(TypeArguments::type_at_offset(length));
}
word FreeListElement::FakeInstance::NextFieldOffset() {
return -kWordSize;
}

View file

@ -460,8 +460,6 @@ class Class : public AllStatic {
public:
static word host_type_arguments_field_offset_in_words_offset();
static word target_type_arguments_field_offset_in_words_offset();
static word declaration_type_offset();
static word super_type_offset();
@ -603,8 +601,9 @@ class TypedDataBase : public PointerBase {
class TypedData : public AllStatic {
public:
static word data_offset();
static word InstanceSize(intptr_t lengthInBytes);
static word HeaderSize();
static word InstanceSize();
static word InstanceSize(word lengthInBytes);
static word NextFieldOffset();
};
@ -742,6 +741,9 @@ class OneByteString : public AllStatic {
static word InstanceSize(intptr_t length);
static word InstanceSize();
static word NextFieldOffset();
private:
static word element_offset(intptr_t index);
};
class TwoByteString : public AllStatic {
@ -750,6 +752,9 @@ class TwoByteString : public AllStatic {
static word InstanceSize(intptr_t length);
static word InstanceSize();
static word NextFieldOffset();
private:
static word element_offset(intptr_t index);
};
class ExternalOneByteString : public AllStatic {
@ -1201,9 +1206,13 @@ class InstructionsSection : public AllStatic {
class InstructionsTable : public AllStatic {
public:
static word InstanceSize(intptr_t length);
static word HeaderSize();
static word InstanceSize();
static word InstanceSize(intptr_t length);
static word NextFieldOffset();
private:
static word element_offset(intptr_t index);
};
class Instructions : public AllStatic {
@ -1231,8 +1240,13 @@ class Code : public AllStatic {
static word entry_point_offset(CodeEntryKind kind = CodeEntryKind::kNormal);
static word saved_instructions_offset();
static word owner_offset();
static word HeaderSize();
static word InstanceSize();
static word InstanceSize(intptr_t length);
static word NextFieldOffset();
private:
static word element_offset(intptr_t index);
};
class WeakSerializationReference : public AllStatic {
@ -1269,8 +1283,8 @@ class Context : public AllStatic {
static word header_size();
static word parent_offset();
static word num_variables_offset();
static word variable_offset(word i);
static word InstanceSize(word n);
static word variable_offset(intptr_t index);
static word InstanceSize(intptr_t length);
static word InstanceSize();
static word NextFieldOffset();
};

File diff suppressed because it is too large Load diff

View file

@ -22,6 +22,10 @@
// ARRAY(Class, Name) Offset of the first element and the size of the elements
// in an array of this class.
// SIZEOF(Class, Name, What) Class::Name() is defined as sizeof(What).
// ARRAY_SIZEOF(Class, Name, ElementOffset) Instance size for an array object.
// Defines Class::Name(intptr_t length) and uses
// Class::ElementOffset(length) to calculate size of the instance. Also
// defines Class::Name() (with no length argument) to be 0.
// PAYLOAD_SIZEOF(Class, Name, HeaderSize) Instance size for a payload object.
// Defines Class::Name(word payload_size) and uses Class::HeaderSize(),
// which should give the size of the header before the payload. Also
@ -38,11 +42,29 @@
//
// TODO(dartbug.com/43646): Add DART_PRECOMPILER as another axis.
#define COMMON_OFFSETS_LIST(FIELD, ARRAY, SIZEOF, PAYLOAD_SIZEOF, RANGE, \
CONSTANT) \
#define COMMON_OFFSETS_LIST(FIELD, ARRAY, SIZEOF, ARRAY_SIZEOF, \
PAYLOAD_SIZEOF, RANGE, CONSTANT) \
ARRAY(Array, element_offset) \
NOT_IN_PRODUCT(ARRAY(ClassTable, ClassOffsetFor)) \
ARRAY(Code, element_offset) \
ARRAY(Context, variable_offset) \
ARRAY(ContextScope, element_offset) \
ARRAY(ExceptionHandlers, element_offset) \
ARRAY(InstructionsTable, element_offset) \
ARRAY(ObjectPool, element_offset) \
ARRAY(OneByteString, element_offset) \
ARRAY(TypeArguments, type_at_offset) \
ARRAY(TwoByteString, element_offset) \
ARRAY_SIZEOF(Array, InstanceSize, element_offset) \
ARRAY_SIZEOF(Code, InstanceSize, element_offset) \
ARRAY_SIZEOF(Context, InstanceSize, variable_offset) \
ARRAY_SIZEOF(ContextScope, InstanceSize, element_offset) \
ARRAY_SIZEOF(ExceptionHandlers, InstanceSize, element_offset) \
ARRAY_SIZEOF(InstructionsTable, InstanceSize, element_offset) \
ARRAY_SIZEOF(ObjectPool, InstanceSize, element_offset) \
ARRAY_SIZEOF(OneByteString, InstanceSize, element_offset) \
ARRAY_SIZEOF(TypeArguments, InstanceSize, type_at_offset) \
ARRAY_SIZEOF(TwoByteString, InstanceSize, element_offset) \
CONSTANT(Array, kMaxElements) \
CONSTANT(Array, kMaxNewSpaceElements) \
CONSTANT(Instructions, kMonomorphicEntryOffsetJIT) \
@ -295,9 +317,6 @@
FIELD(MonomorphicSmiableCall, target_offset) \
FIELD(WeakProperty, key_offset) \
FIELD(WeakProperty, value_offset) \
ARRAY(Array, element_offset) \
ARRAY(TypeArguments, type_at_offset) \
NOT_IN_PRODUCT(ARRAY(ClassTable, ClassOffsetFor)) \
RANGE(Code, entry_point_offset, CodeEntryKind, CodeEntryKind::kNormal, \
CodeEntryKind::kMonomorphicUnchecked, \
[](CodeEntryKind value) { return true; }) \
@ -308,22 +327,17 @@
\
SIZEOF(AbstractType, InstanceSize, UntaggedAbstractType) \
SIZEOF(ApiError, InstanceSize, UntaggedApiError) \
SIZEOF(Array, InstanceSize, UntaggedArray) \
SIZEOF(Array, header_size, UntaggedArray) \
SIZEOF(Bool, InstanceSize, UntaggedBool) \
SIZEOF(Capability, InstanceSize, UntaggedCapability) \
SIZEOF(Class, InstanceSize, UntaggedClass) \
SIZEOF(Closure, InstanceSize, UntaggedClosure) \
SIZEOF(ClosureData, InstanceSize, UntaggedClosureData) \
SIZEOF(Code, InstanceSize, UntaggedCode) \
SIZEOF(CodeSourceMap, HeaderSize, UntaggedCodeSourceMap) \
SIZEOF(CompressedStackMaps, HeaderSize, UntaggedCompressedStackMaps) \
SIZEOF(Context, InstanceSize, UntaggedContext) \
SIZEOF(Context, header_size, UntaggedContext) \
SIZEOF(ContextScope, InstanceSize, UntaggedContextScope) \
SIZEOF(Double, InstanceSize, UntaggedDouble) \
SIZEOF(DynamicLibrary, InstanceSize, UntaggedDynamicLibrary) \
SIZEOF(ExceptionHandlers, InstanceSize, UntaggedExceptionHandlers) \
SIZEOF(ExternalOneByteString, InstanceSize, UntaggedExternalOneByteString) \
SIZEOF(ExternalTwoByteString, InstanceSize, UntaggedExternalTwoByteString) \
SIZEOF(ExternalTypedData, InstanceSize, UntaggedExternalTypedData) \
@ -340,7 +354,6 @@
SIZEOF(Instructions, UnalignedHeaderSize, UntaggedInstructions) \
SIZEOF(InstructionsSection, UnalignedHeaderSize, \
UntaggedInstructionsSection) \
SIZEOF(InstructionsTable, InstanceSize, UntaggedInstructionsTable) \
SIZEOF(Int32x4, InstanceSize, UntaggedInt32x4) \
SIZEOF(Integer, InstanceSize, UntaggedInteger) \
SIZEOF(KernelProgramInfo, InstanceSize, UntaggedKernelProgramInfo) \
@ -348,7 +361,6 @@
SIZEOF(Library, InstanceSize, UntaggedLibrary) \
SIZEOF(LibraryPrefix, InstanceSize, UntaggedLibraryPrefix) \
SIZEOF(LinkedHashMap, InstanceSize, UntaggedLinkedHashMap) \
SIZEOF(LocalVarDescriptors, InstanceSize, UntaggedLocalVarDescriptors) \
SIZEOF(MegamorphicCache, InstanceSize, UntaggedMegamorphicCache) \
SIZEOF(Mint, InstanceSize, UntaggedMint) \
SIZEOF(MirrorReference, InstanceSize, UntaggedMirrorReference) \
@ -357,8 +369,6 @@
SIZEOF(NativeArguments, StructSize, NativeArguments) \
SIZEOF(Number, InstanceSize, UntaggedNumber) \
SIZEOF(Object, InstanceSize, UntaggedObject) \
SIZEOF(ObjectPool, InstanceSize, UntaggedObjectPool) \
SIZEOF(OneByteString, InstanceSize, UntaggedOneByteString) \
SIZEOF(PatchClass, InstanceSize, UntaggedPatchClass) \
SIZEOF(PcDescriptors, HeaderSize, UntaggedPcDescriptors) \
SIZEOF(Pointer, InstanceSize, UntaggedPointer) \
@ -367,18 +377,15 @@
SIZEOF(Script, InstanceSize, UntaggedScript) \
SIZEOF(SendPort, InstanceSize, UntaggedSendPort) \
SIZEOF(SingleTargetCache, InstanceSize, UntaggedSingleTargetCache) \
SIZEOF(Smi, InstanceSize, UntaggedSmi) \
SIZEOF(StackTrace, InstanceSize, UntaggedStackTrace) \
SIZEOF(String, InstanceSize, UntaggedString) \
SIZEOF(SubtypeTestCache, InstanceSize, UntaggedSubtypeTestCache) \
SIZEOF(LoadingUnit, InstanceSize, UntaggedLoadingUnit) \
SIZEOF(TransferableTypedData, InstanceSize, UntaggedTransferableTypedData) \
SIZEOF(TwoByteString, InstanceSize, UntaggedTwoByteString) \
SIZEOF(Type, InstanceSize, UntaggedType) \
SIZEOF(TypeArguments, InstanceSize, UntaggedTypeArguments) \
SIZEOF(TypeParameter, InstanceSize, UntaggedTypeParameter) \
SIZEOF(TypeRef, InstanceSize, UntaggedTypeRef) \
SIZEOF(TypedData, InstanceSize, UntaggedTypedData) \
SIZEOF(TypedData, HeaderSize, UntaggedTypedData) \
SIZEOF(TypedDataBase, InstanceSize, UntaggedTypedDataBase) \
SIZEOF(TypedDataView, InstanceSize, UntaggedTypedDataView) \
SIZEOF(UnhandledException, InstanceSize, UntaggedUnhandledException) \
@ -391,10 +398,11 @@
PAYLOAD_SIZEOF(CodeSourceMap, InstanceSize, HeaderSize) \
PAYLOAD_SIZEOF(CompressedStackMaps, InstanceSize, HeaderSize) \
PAYLOAD_SIZEOF(InstructionsSection, InstanceSize, HeaderSize) \
PAYLOAD_SIZEOF(PcDescriptors, InstanceSize, HeaderSize)
PAYLOAD_SIZEOF(PcDescriptors, InstanceSize, HeaderSize) \
PAYLOAD_SIZEOF(TypedData, InstanceSize, HeaderSize)
#define JIT_OFFSETS_LIST(FIELD, ARRAY, SIZEOF, PAYLOAD_SIZEOF, RANGE, \
CONSTANT) \
#define JIT_OFFSETS_LIST(FIELD, ARRAY, SIZEOF, ARRAY_SIZEOF, PAYLOAD_SIZEOF, \
RANGE, CONSTANT) \
FIELD(Function, usage_counter_offset) \
FIELD(ICData, receivers_static_type_offset)

View file

@ -3443,7 +3443,7 @@ void StubCodeCompiler::GenerateAllocateTypedDataArrayStub(Assembler* assembler,
__ b(&call_runtime, HI);
__ mov(R2, Operand(R2, LSL, scale_shift));
const intptr_t fixed_size_plus_alignment_padding =
target::TypedData::InstanceSize() +
target::TypedData::HeaderSize() +
target::ObjectAlignment::kObjectAlignment - 1;
__ AddImmediate(R2, fixed_size_plus_alignment_padding);
__ bic(R2, R2, Operand(target::ObjectAlignment::kObjectAlignment - 1));
@ -3500,7 +3500,7 @@ void StubCodeCompiler::GenerateAllocateTypedDataArrayStub(Assembler* assembler,
/* data area to be initialized. */
__ LoadImmediate(R8, 0);
__ mov(R9, Operand(R8));
__ AddImmediate(R3, R0, target::TypedData::InstanceSize() - 1);
__ AddImmediate(R3, R0, target::TypedData::HeaderSize() - 1);
__ StoreInternalPointer(
R0, FieldAddress(R0, target::TypedDataBase::data_field_offset()), R3);
Label init_loop;

View file

@ -3593,7 +3593,7 @@ void StubCodeCompiler::GenerateAllocateTypedDataArrayStub(Assembler* assembler,
__ b(&call_runtime, HI);
__ LslImmediate(R2, R2, scale_shift);
const intptr_t fixed_size_plus_alignment_padding =
target::TypedData::InstanceSize() +
target::TypedData::HeaderSize() +
target::ObjectAlignment::kObjectAlignment - 1;
__ AddImmediate(R2, fixed_size_plus_alignment_padding);
__ andi(R2, R2,
@ -3647,7 +3647,7 @@ void StubCodeCompiler::GenerateAllocateTypedDataArrayStub(Assembler* assembler,
/* R3: scratch register. */
/* data area to be initialized. */
__ mov(R3, ZR);
__ AddImmediate(R2, R0, target::TypedData::InstanceSize() - 1);
__ AddImmediate(R2, R0, target::TypedData::HeaderSize() - 1);
__ StoreInternalPointer(
R0, FieldAddress(R0, target::TypedDataBase::data_field_offset()), R2);
Label init_loop, done;

View file

@ -2944,7 +2944,7 @@ void StubCodeCompiler::GenerateAllocateTypedDataArrayStub(Assembler* assembler,
}
const intptr_t fixed_size_plus_alignment_padding =
target::TypedData::InstanceSize() +
target::TypedData::HeaderSize() +
target::ObjectAlignment::kObjectAlignment - 1;
__ leal(EDI, Address(EDI, scale_factor, fixed_size_plus_alignment_padding));
__ andl(EDI, Immediate(-target::ObjectAlignment::kObjectAlignment));
@ -3002,7 +3002,7 @@ void StubCodeCompiler::GenerateAllocateTypedDataArrayStub(Assembler* assembler,
/* ECX: scratch register. */
/* data area to be initialized. */
__ xorl(ECX, ECX); /* Zero. */
__ leal(EDI, FieldAddress(EAX, target::TypedData::InstanceSize()));
__ leal(EDI, FieldAddress(EAX, target::TypedData::HeaderSize()));
__ StoreInternalPointer(
EAX, FieldAddress(EAX, target::TypedDataBase::data_field_offset()),
EDI);

View file

@ -3539,7 +3539,7 @@ void StubCodeCompiler::GenerateAllocateTypedDataArrayStub(Assembler* assembler,
scale_factor = TIMES_8;
}
const intptr_t fixed_size_plus_alignment_padding =
target::TypedData::InstanceSize() +
target::TypedData::HeaderSize() +
target::ObjectAlignment::kObjectAlignment - 1;
__ leaq(RDI, Address(RDI, scale_factor, fixed_size_plus_alignment_padding));
__ andq(RDI, Immediate(-target::ObjectAlignment::kObjectAlignment));
@ -3598,7 +3598,7 @@ void StubCodeCompiler::GenerateAllocateTypedDataArrayStub(Assembler* assembler,
/* RBX: scratch register. */
/* data area to be initialized. */
__ xorq(RBX, RBX); /* Zero. */
__ leaq(RDI, FieldAddress(RAX, target::TypedData::InstanceSize()));
__ leaq(RDI, FieldAddress(RAX, target::TypedData::HeaderSize()));
__ StoreInternalPointer(
RAX, FieldAddress(RAX, target::TypedDataBase::data_field_offset()),
RDI);

View file

@ -103,7 +103,8 @@ static void CheckOffsets() {
ok = false; \
}
// No consistency checks needed for this construct.
// No consistency checks needed for these constructs.
#define CHECK_ARRAY_SIZEOF(Class, Name, ElementOffset)
#define CHECK_PAYLOAD_SIZEOF(Class, Name, HeaderSize)
#if defined(DART_PRECOMPILED_RUNTIME)
@ -144,11 +145,12 @@ static void CheckOffsets() {
#endif // defined(DART_PRECOMPILED_RUNTIME)
COMMON_OFFSETS_LIST(CHECK_FIELD, CHECK_ARRAY, CHECK_SIZEOF,
CHECK_PAYLOAD_SIZEOF, CHECK_RANGE, CHECK_CONSTANT)
CHECK_ARRAY_SIZEOF, CHECK_PAYLOAD_SIZEOF, CHECK_RANGE,
CHECK_CONSTANT)
NOT_IN_PRECOMPILED_RUNTIME(
JIT_OFFSETS_LIST(CHECK_FIELD, CHECK_ARRAY, CHECK_SIZEOF,
CHECK_PAYLOAD_SIZEOF, CHECK_RANGE, CHECK_CONSTANT))
NOT_IN_PRECOMPILED_RUNTIME(JIT_OFFSETS_LIST(
CHECK_FIELD, CHECK_ARRAY, CHECK_SIZEOF, CHECK_ARRAY_SIZEOF,
CHECK_PAYLOAD_SIZEOF, CHECK_RANGE, CHECK_CONSTANT))
if (!ok) {
FATAL(

View file

@ -970,13 +970,15 @@ class Class : public Object {
intptr_t target_value) const {
ASSERT(Utils::IsAligned((host_value * kWordSize), kObjectAlignment));
StoreNonPointer(&untag()->host_instance_size_in_words_, host_value);
#if !defined(DART_PRECOMPILER)
// Could be different only during cross-compilation.
ASSERT_EQUAL(host_value, target_value);
#endif // !defined(DART_PRECOMPILER)
#if !defined(DART_PRECOMPILED_RUNTIME)
ASSERT(Utils::IsAligned((target_value * compiler::target::kWordSize),
compiler::target::kObjectAlignment));
StoreNonPointer(&untag()->target_instance_size_in_words_, target_value);
#else
ASSERT(host_value == target_value);
#endif // #!defined(DART_PRECOMPILED_RUNTIME)
#endif // !defined(DART_PRECOMPILED_RUNTIME)
}
intptr_t host_next_field_offset() const {
@ -988,7 +990,7 @@ class Class : public Object {
compiler::target::kWordSize;
#else
return host_next_field_offset();
#endif // #!defined(DART_PRECOMPILED_RUNTIME)
#endif // !defined(DART_PRECOMPILED_RUNTIME)
}
void set_next_field_offset(intptr_t host_value_in_bytes,
intptr_t target_value_in_bytes) const {
@ -1004,6 +1006,10 @@ class Class : public Object {
(!Utils::IsAligned((host_value * kWordSize), kObjectAlignment) &&
((host_value + 1) == untag()->host_instance_size_in_words_)));
StoreNonPointer(&untag()->host_next_field_offset_in_words_, host_value);
#if !defined(DART_PRECOMPILER)
// Could be different only during cross-compilation.
ASSERT_EQUAL(host_value, target_value);
#endif // !defined(DART_PRECOMPILER)
#if !defined(DART_PRECOMPILED_RUNTIME)
ASSERT((target_value == -1) ||
(Utils::IsAligned((target_value * compiler::target::kWordSize),
@ -1013,9 +1019,7 @@ class Class : public Object {
compiler::target::kObjectAlignment) &&
((target_value + 1) == untag()->target_instance_size_in_words_)));
StoreNonPointer(&untag()->target_next_field_offset_in_words_, target_value);
#else
ASSERT(host_value == target_value);
#endif // #!defined(DART_PRECOMPILED_RUNTIME)
#endif // !defined(DART_PRECOMPILED_RUNTIME)
}
static bool is_valid_id(intptr_t value) {
@ -1171,26 +1175,19 @@ class Class : public Object {
intptr_t target_value) const {
StoreNonPointer(&untag()->host_type_arguments_field_offset_in_words_,
host_value);
#if !defined(DART_PRECOMPILER)
// Could be different only during cross-compilation.
ASSERT_EQUAL(host_value, target_value);
#endif // !defined(DART_PRECOMPILER)
#if !defined(DART_PRECOMPILED_RUNTIME)
StoreNonPointer(&untag()->target_type_arguments_field_offset_in_words_,
target_value);
#else
ASSERT(host_value == target_value);
#endif // !defined(DART_PRECOMPILED_RUNTIME)
}
static intptr_t host_type_arguments_field_offset_in_words_offset() {
return OFFSET_OF(UntaggedClass, host_type_arguments_field_offset_in_words_);
}
static intptr_t target_type_arguments_field_offset_in_words_offset() {
#if !defined(DART_PRECOMPILED_RUNTIME)
return OFFSET_OF(UntaggedClass,
target_type_arguments_field_offset_in_words_);
#else
return host_type_arguments_field_offset_in_words_offset();
#endif // !defined(DART_PRECOMPILED_RUNTIME)
}
// The super type of this class, Object type if not explicitly specified.
AbstractTypePtr super_type() const {
ASSERT(is_declaration_loaded());
@ -5459,6 +5456,13 @@ class InstructionsTable : public Object {
static const uint32_t kPayloadMask = ~(kPayloadAlignment - 1);
COMPILE_ASSERT((kPayloadMask & kHasMonomorphicEntrypointFlag) == 0);
struct ArrayTraits {
static intptr_t elements_start_offset() {
return sizeof(UntaggedInstructionsTable);
}
static constexpr intptr_t kElementSize = kBytesPerElement;
};
static intptr_t InstanceSize() {
ASSERT_EQUAL(sizeof(UntaggedInstructionsTable),
OFFSET_OF_RETURNED_VALUE(UntaggedInstructionsTable, data));
@ -6421,6 +6425,11 @@ class Code : public Object {
sizeof(reinterpret_cast<UntaggedCode*>(0)->data()[0]);
static const intptr_t kMaxElements = kSmiMax / kBytesPerElement;
struct ArrayTraits {
static intptr_t elements_start_offset() { return sizeof(UntaggedCode); }
static constexpr intptr_t kElementSize = kBytesPerElement;
};
static intptr_t InstanceSize() {
ASSERT(sizeof(UntaggedCode) ==
OFFSET_OF_RETURNED_VALUE(UntaggedCode, data));
@ -6713,6 +6722,11 @@ class Context : public Object {
static const intptr_t kFutureWaitFutureIndex = 2;
static const intptr_t kIsSyncIndex = 2;
struct ArrayTraits {
static intptr_t elements_start_offset() { return sizeof(UntaggedContext); }
static constexpr intptr_t kElementSize = kBytesPerElement;
};
static intptr_t variable_offset(intptr_t context_index) {
return OFFSET_OF_RETURNED_VALUE(UntaggedContext, data) +
(kWordSize * context_index);
@ -8921,6 +8935,10 @@ class String : public Instance {
static intptr_t HeaderSize() { return String::kSizeofRawString; }
static intptr_t InstanceSize() {
return RoundedAllocationSize(sizeof(UntaggedString));
}
class CodePointIterator : public ValueObject {
public:
explicit CodePointIterator(const String& str)
@ -9301,6 +9319,13 @@ class OneByteString : public AllStatic {
static const intptr_t kBytesPerElement = 1;
static const intptr_t kMaxElements = String::kMaxElements;
struct ArrayTraits {
static intptr_t elements_start_offset() {
return sizeof(UntaggedOneByteString);
}
static constexpr intptr_t kElementSize = kBytesPerElement;
};
static intptr_t data_offset() {
return OFFSET_OF_RETURNED_VALUE(UntaggedOneByteString, data);
}
@ -9441,6 +9466,13 @@ class TwoByteString : public AllStatic {
static const intptr_t kBytesPerElement = 2;
static const intptr_t kMaxElements = String::kMaxElements;
struct ArrayTraits {
static intptr_t elements_start_offset() {
return sizeof(UntaggedTwoByteString);
}
static constexpr intptr_t kElementSize = kBytesPerElement;
};
static intptr_t data_offset() {
return OFFSET_OF_RETURNED_VALUE(UntaggedTwoByteString, data);
}