[K/N] Support of aligned fields

For now only alignment by at most 8 is supported for instance fields.

^KT-54944
This commit is contained in:
Pavel Kunyavskiy
2022-11-28 15:10:37 +01:00
committed by Space Team
parent 6da66649e7
commit a11f6fd9cb
15 changed files with 193 additions and 86 deletions
@@ -11,6 +11,7 @@
namespace kotlin {
// Must match objectAlignment in Runtime.kt
constexpr size_t kObjectAlignment = 8;
template <typename T>
@@ -656,6 +656,7 @@ static const TypeInfo* createTypeInfo(
result->superType_ = superType;
if (fieldsInfo == nullptr) {
result->instanceSize_ = superType->instanceSize_;
result->instanceAlignment_ = superType->instanceAlignment_;
result->objOffsets_ = superType->objOffsets_;
result->objOffsetsCount_ = superType->objOffsetsCount_; // So TF_IMMUTABLE can also be inherited:
if ((superType->flags_ & TF_IMMUTABLE) != 0) {
@@ -664,6 +665,7 @@ static const TypeInfo* createTypeInfo(
result->processObjectInMark = superType->processObjectInMark;
} else {
result->instanceSize_ = fieldsInfo->instanceSize_;
result->instanceAlignment_ = fieldsInfo->instanceAlignment_;
result->objOffsets_ = fieldsInfo->objOffsets_;
result->objOffsetsCount_ = fieldsInfo->objOffsetsCount_;
result->processObjectInMark = fieldsInfo->processObjectInMark;
@@ -30,6 +30,7 @@ private:
std_support::vector<int32_t> objOffsets_;
int32_t objOffsetsCount_ = 0;
int32_t flags_ = 0;
int32_t instanceAlignment_ = 8;
const TypeInfo* superType_ = nullptr;
void (*processObjectInMark_)(void*, ObjHeader*) = nullptr;
};
@@ -90,6 +91,7 @@ public:
typeInfo_.processObjectInMark = builder.processObjectInMark_;
typeInfo_.flags_ = builder.flags_;
typeInfo_.superType_ = builder.superType_;
typeInfo_.instanceAlignment_ = builder.instanceAlignment_;
}
TypeInfo* typeInfo() noexcept { return &typeInfo_; }
@@ -90,6 +90,10 @@ struct InterfaceTableRecord {
// This struct represents runtime type information and by itself is the compile time
// constant.
// When adding a field here do not forget to adjust:
// 1. RTTIGenerator
// 2. ObjectTestSupport TypeInfoHolder
// 3. createTypeInfo in ObjcExport.mm
struct TypeInfo {
// Reference to self, to allow simple obtaining TypeInfo via meta-object.
const TypeInfo* typeInfo_;
@@ -136,6 +140,10 @@ struct TypeInfo {
// TODO: Consider providing a generic traverse method instead.
void (*processObjectInMark)(void* state, ObjHeader* object);
// Required alignment of instance
uint32_t instanceAlignment_;
// vtable starts just after declared contents of the TypeInfo:
// void* const vtable_[];
#ifdef __cplusplus