Sketch mm::ObjectFactory (#4583)

This commit is contained in:
Alexander Shabalin
2020-12-21 19:12:21 +03:00
committed by Nikolay Krasko
parent d239ff7f5a
commit 72fc5f5aee
11 changed files with 1181 additions and 12 deletions
@@ -5,6 +5,7 @@
#include "Memory.h"
#include "Exceptions.h"
#include "GlobalsRegistry.hpp"
#include "KAssert.h"
#include "Porting.h"
@@ -74,6 +75,22 @@ extern "C" void RestoreMemory(MemoryState*) {
// TODO: Remove when legacy MM is gone.
}
extern "C" RUNTIME_NOTHROW OBJ_GETTER(AllocInstance, const TypeInfo* typeInfo) {
auto* threadData = mm::ThreadRegistry::Instance().CurrentThreadData();
auto* object = threadData->objectFactoryThreadQueue().CreateObject(typeInfo);
RETURN_OBJ(object);
}
extern "C" OBJ_GETTER(AllocArrayInstance, const TypeInfo* typeInfo, int32_t elements) {
if (elements < 0) {
ThrowIllegalArgumentException();
}
auto* threadData = mm::ThreadRegistry::Instance().CurrentThreadData();
auto* array = threadData->objectFactoryThreadQueue().CreateArray(typeInfo, static_cast<uint32_t>(elements));
// `ArrayHeader` and `ObjHeader` are expected to be compatible.
RETURN_OBJ(reinterpret_cast<ObjHeader*>(array));
}
extern "C" OBJ_GETTER(InitSingleton, ObjHeader** location, const TypeInfo* typeInfo, void (*ctor)(ObjHeader*)) {
auto* threadData = mm::ThreadRegistry::Instance().CurrentThreadData();
// TODO: This should only be called if singleton is actually created here. It's possible that the