Add ExtraObjectData (#4602)

This commit is contained in:
Alexander Shabalin
2020-12-22 16:22:18 +03:00
committed by Nikolay Krasko
parent a6c119c3cd
commit d46b2e927c
7 changed files with 240 additions and 38 deletions
@@ -6,6 +6,7 @@
#include "Memory.h"
#include "Exceptions.h"
#include "ExtraObjectData.hpp"
#include "GlobalsRegistry.hpp"
#include "KAssert.h"
#include "Porting.h"
@@ -58,6 +59,39 @@ ALWAYS_INLINE mm::ThreadData* GetThreadData(MemoryState* state) {
} // namespace
ObjHeader** ObjHeader::GetWeakCounterLocation() {
return mm::ExtraObjectData::FromMetaObjHeader(this->meta_object()).GetWeakCounterLocation();
}
#ifdef KONAN_OBJC_INTEROP
void* ObjHeader::GetAssociatedObject() {
if (!has_meta_object()) {
return nullptr;
}
return *GetAssociatedObjectLocation();
}
void** ObjHeader::GetAssociatedObjectLocation() {
return mm::ExtraObjectData::FromMetaObjHeader(this->meta_object()).GetAssociatedObjectLocation();
}
void ObjHeader::SetAssociatedObject(void* obj) {
*GetAssociatedObjectLocation() = obj;
}
#endif // KONAN_OBJC_INTEROP
// static
MetaObjHeader* ObjHeader::createMetaObject(ObjHeader* object) {
return mm::ExtraObjectData::Install(object).AsMetaObjHeader();
}
// static
void ObjHeader::destroyMetaObject(ObjHeader* object) {
mm::ExtraObjectData::Uninstall(object);
}
ALWAYS_INLINE bool isShareable(const ObjHeader* obj) {
// TODO: Remove when legacy MM is gone.
return true;