KT-65949: Bridge intrinsics
Merge-request: KT-MR-14767 Merged-by: Gleb Lukianets <Gleb.Lukianets@jetbrains.com>
This commit is contained in:
committed by
Space Team
parent
7c4c6d2cd9
commit
b46ffc35f1
@@ -605,4 +605,11 @@ RUNTIME_NOTHROW ALWAYS_INLINE extern "C" void Kotlin_processObjectInMark(void* s
|
||||
RUNTIME_NOTHROW ALWAYS_INLINE extern "C" void Kotlin_processArrayInMark(void* state, ObjHeader* object);
|
||||
RUNTIME_NOTHROW ALWAYS_INLINE extern "C" void Kotlin_processEmptyObjectInMark(void* state, ObjHeader* object);
|
||||
|
||||
RUNTIME_NOTHROW extern "C" OBJ_GETTER(Kotlin_Interop_derefSpecialRef, kotlin::mm::RawSpecialRef *ref);
|
||||
RUNTIME_NOTHROW extern "C" kotlin::mm::RawSpecialRef *Kotlin_Interop_createSpecialRef(ObjHeader *object);
|
||||
RUNTIME_NOTHROW extern "C" void Kotlin_Interop_disposeSpecialRef(kotlin::mm::RawSpecialRef *ref);
|
||||
RUNTIME_NOTHROW extern "C" void Kotlin_Interop_retainSpecialRef(kotlin::mm::RawSpecialRef *ref);
|
||||
RUNTIME_NOTHROW extern "C" bool Kotlin_Interop_tryRetainSpecialRef(kotlin::mm::RawSpecialRef *ref);
|
||||
RUNTIME_NOTHROW extern "C" void Kotlin_Interop_releaseSpecialRef(kotlin::mm::RawSpecialRef *ref);
|
||||
|
||||
#endif // RUNTIME_MEMORY_H
|
||||
|
||||
@@ -12,6 +12,31 @@ import kotlin.internal.getProgressionLastElement
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.concurrent.AtomicReference
|
||||
import kotlinx.cinterop.*
|
||||
import kotlinx.cinterop.NativePtr
|
||||
|
||||
@ExperimentalNativeApi
|
||||
@GCUnsafeCall("Kotlin_Interop_derefSpecialRef")
|
||||
public external fun dereferenceSpecialRef(ref: COpaquePointer?): Any?
|
||||
|
||||
@ExperimentalNativeApi
|
||||
@GCUnsafeCall("Kotlin_Interop_createSpecialRef")
|
||||
public external fun createSpecialRef(ref: Any?): COpaquePointer?
|
||||
|
||||
@ExperimentalNativeApi
|
||||
@GCUnsafeCall("Kotlin_Interop_disposeSpecialRef")
|
||||
public external fun disposeSpecialRef(ref: COpaquePointer?)
|
||||
|
||||
@ExperimentalNativeApi
|
||||
@GCUnsafeCall("Kotlin_Interop_retainSpecialRef")
|
||||
public external fun retainSpecialRef(ref: COpaquePointer?)
|
||||
|
||||
@ExperimentalNativeApi
|
||||
@GCUnsafeCall("Kotlin_Interop_tryRetainSpecialRef")
|
||||
public external fun tryRetainSpecialRef(ref: COpaquePointer?): Boolean
|
||||
|
||||
@ExperimentalNativeApi
|
||||
@GCUnsafeCall("Kotlin_Interop_releaseSpecialRef")
|
||||
public external fun releaseSpecialRef(ref: COpaquePointer?)
|
||||
|
||||
@ExportForCppRuntime
|
||||
@PublishedApi
|
||||
|
||||
@@ -14,11 +14,13 @@
|
||||
#include "GlobalsRegistry.hpp"
|
||||
#include "KAssert.h"
|
||||
#include "Natives.h"
|
||||
#include "ObjCBackRef.hpp"
|
||||
#include "ObjectOps.hpp"
|
||||
#include "Porting.h"
|
||||
#include "ReferenceOps.hpp"
|
||||
#include "Runtime.h"
|
||||
#include "SafePoint.hpp"
|
||||
#include "SpecialRefRegistry.hpp"
|
||||
#include "StableRef.hpp"
|
||||
#include "ThreadData.hpp"
|
||||
#include "ThreadRegistry.hpp"
|
||||
@@ -664,3 +666,33 @@ void kotlin::initObjectPool() noexcept {
|
||||
void kotlin::compactObjectPoolInCurrentThread() noexcept {
|
||||
alloc::compactObjectPoolInCurrentThread();
|
||||
}
|
||||
|
||||
RUNTIME_NOTHROW extern "C" OBJ_GETTER(Kotlin_Interop_derefSpecialRef, mm::RawSpecialRef *ref) {
|
||||
RETURN_OBJ(ref ? *mm::ObjCBackRef(ref) : nullptr);
|
||||
}
|
||||
|
||||
RUNTIME_NOTHROW extern "C" mm::RawSpecialRef *Kotlin_Interop_createSpecialRef(ObjHeader *object) {
|
||||
return object ? static_cast<mm::RawSpecialRef *>(mm::ObjCBackRef::create(object)) : nullptr;
|
||||
}
|
||||
|
||||
RUNTIME_NOTHROW extern "C" void Kotlin_Interop_disposeSpecialRef(mm::RawSpecialRef *ref) {
|
||||
if (ref) {
|
||||
mm::ObjCBackRef(ref).dispose();
|
||||
}
|
||||
}
|
||||
|
||||
RUNTIME_NOTHROW extern "C" void Kotlin_Interop_retainSpecialRef(mm::RawSpecialRef *ref) {
|
||||
if (ref) {
|
||||
mm::ObjCBackRef(ref).retain();
|
||||
}
|
||||
}
|
||||
|
||||
RUNTIME_NOTHROW extern "C" bool Kotlin_Interop_tryRetainSpecialRef(mm::RawSpecialRef *ref) {
|
||||
return ref ? mm::ObjCBackRef(ref).tryRetain() : false;
|
||||
}
|
||||
|
||||
RUNTIME_NOTHROW extern "C" void Kotlin_Interop_releaseSpecialRef(mm::RawSpecialRef *ref) {
|
||||
if (ref) {
|
||||
mm::ObjCBackRef(ref).release();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user