Cleanup Stubs.cpp (#4593)

This commit is contained in:
Alexander Shabalin
2020-12-15 10:30:15 +03:00
committed by Stanislav Erokhin
parent f160d8ec36
commit 92f8eff958
10 changed files with 161 additions and 95 deletions
+53 -2
View File
@@ -6,6 +6,8 @@
#include "Memory.h"
#include "GlobalsRegistry.hpp"
#include "KAssert.h"
#include "Porting.h"
#include "StableRefRegistry.hpp"
#include "ThreadData.hpp"
#include "ThreadRegistry.hpp"
@@ -55,6 +57,11 @@ ALWAYS_INLINE mm::ThreadData* GetThreadData(MemoryState* state) {
} // namespace
ALWAYS_INLINE bool isShareable(const ObjHeader* obj) {
// TODO: Remove when legacy MM is gone.
return true;
}
extern "C" MemoryState* InitMemory(bool firstRuntime) {
return ToMemoryState(mm::ThreadRegistry::Instance().RegisterCurrentThread());
}
@@ -63,21 +70,27 @@ extern "C" void DeinitMemory(MemoryState* state, bool destroyRuntime) {
mm::ThreadRegistry::Instance().Unregister(FromMemoryState(state));
}
extern "C" void RestoreMemory(MemoryState*) {
// TODO: Remove when legacy MM is gone.
}
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
// singleton will be created on a different thread and here we should check that, instead of creating
// another one (and registering `location` twice).
mm::GlobalsRegistry::Instance().RegisterStorageForGlobal(threadData, location);
RuntimeCheck(false, "Unimplemented");
TODO();
}
extern "C" RUNTIME_NOTHROW void InitAndRegisterGlobal(ObjHeader** location, const ObjHeader* initialValue) {
auto* threadData = mm::ThreadRegistry::Instance().CurrentThreadData();
mm::GlobalsRegistry::Instance().RegisterStorageForGlobal(threadData, location);
RuntimeCheck(false, "Unimplemented");
TODO();
}
extern "C" const MemoryModel CurrentMemoryModel = MemoryModel::kExperimental;
extern "C" RUNTIME_NOTHROW void AddTLSRecord(MemoryState* memory, void** key, int size) {
GetThreadData(memory)->tls().AddRecord(key, size);
}
@@ -94,6 +107,31 @@ extern "C" RUNTIME_NOTHROW ObjHeader** LookupTLS(void** key, int index) {
return mm::ThreadRegistry::Instance().CurrentThreadData()->tls().Lookup(key, index);
}
extern "C" RUNTIME_NOTHROW void GC_RegisterWorker(void* worker) {
// TODO: Remove when legacy MM is gone.
// Nothing to do
}
extern "C" RUNTIME_NOTHROW void GC_UnregisterWorker(void* worker) {
// TODO: Remove when legacy MM is gone.
// Nothing to do
}
extern "C" RUNTIME_NOTHROW void GC_CollectorCallback(void* worker) {
// TODO: Remove when legacy MM is gone.
// Nothing to do
}
extern "C" bool Kotlin_Any_isShareable(ObjHeader* thiz) {
// TODO: Remove when legacy MM is gone.
return true;
}
extern "C" RUNTIME_NOTHROW bool ClearSubgraphReferences(ObjHeader* root, bool checked) {
// TODO: Remove when legacy MM is gone.
return true;
}
extern "C" RUNTIME_NOTHROW void* CreateStablePointer(ObjHeader* object) {
auto* threadData = mm::ThreadRegistry::Instance().CurrentThreadData();
return mm::StableRefRegistry::Instance().RegisterStableRef(threadData, object);
@@ -120,6 +158,14 @@ extern "C" RUNTIME_NOTHROW OBJ_GETTER(AdoptStablePointer, void* pointer) {
return object;
}
extern "C" RUNTIME_NOTHROW void CheckLifetimesConstraint(ObjHeader* obj, ObjHeader* pointee) {
if (!obj->local() && pointee != nullptr && pointee->local()) {
konan::consolePrintf("Attempt to store a stack object %p into a heap object %p\n", pointee, obj);
konan::consolePrintf("This is a compiler bug, please report it to https://kotl.in/issue\n");
konan::abort();
}
}
extern "C" ForeignRefContext InitForeignRef(ObjHeader* object) {
auto* threadData = mm::ThreadRegistry::Instance().CurrentThreadData();
auto* node = mm::StableRefRegistry::Instance().RegisterStableRef(threadData, object);
@@ -142,3 +188,8 @@ extern "C" void AdoptReferenceFromSharedVariable(ObjHeader* object) {
// TODO: Remove when legacy MM is gone.
// Nothing to do.
}
void CheckGlobalsAccessible() {
// TODO: Remove when legacy MM is gone.
// Always accessible
}