[K/N][runtime] Used internal isInstance
This commit is contained in:
+2
-2
@@ -273,7 +273,7 @@ internal class CAdapterApiExporter(
|
|||||||
|KObjHeader* DerefStablePointer(void*, KObjHeader**) RUNTIME_NOTHROW;
|
|KObjHeader* DerefStablePointer(void*, KObjHeader**) RUNTIME_NOTHROW;
|
||||||
|void* CreateStablePointer(KObjHeader*) RUNTIME_NOTHROW;
|
|void* CreateStablePointer(KObjHeader*) RUNTIME_NOTHROW;
|
||||||
|void DisposeStablePointer(void*) RUNTIME_NOTHROW;
|
|void DisposeStablePointer(void*) RUNTIME_NOTHROW;
|
||||||
|${prefix}_KBoolean IsInstance(const KObjHeader*, const KTypeInfo*) RUNTIME_NOTHROW;
|
|${prefix}_KBoolean IsInstanceInternal(const KObjHeader*, const KTypeInfo*) RUNTIME_NOTHROW;
|
||||||
|void EnterFrame(KObjHeader** start, int parameters, int count) RUNTIME_NOTHROW;
|
|void EnterFrame(KObjHeader** start, int parameters, int count) RUNTIME_NOTHROW;
|
||||||
|void LeaveFrame(KObjHeader** start, int parameters, int count) RUNTIME_NOTHROW;
|
|void LeaveFrame(KObjHeader** start, int parameters, int count) RUNTIME_NOTHROW;
|
||||||
|void SetCurrentFrame(KObjHeader** start) RUNTIME_NOTHROW;
|
|void SetCurrentFrame(KObjHeader** start) RUNTIME_NOTHROW;
|
||||||
@@ -338,7 +338,7 @@ internal class CAdapterApiExporter(
|
|||||||
| Kotlin_initRuntimeIfNeeded();
|
| Kotlin_initRuntimeIfNeeded();
|
||||||
| ScopedRunnableState stateGuard;
|
| ScopedRunnableState stateGuard;
|
||||||
| KObjHolder holder;
|
| KObjHolder holder;
|
||||||
| return IsInstance(DerefStablePointer(ref, holder.slot()), (const KTypeInfo*)type);
|
| return IsInstanceInternal(DerefStablePointer(ref, holder.slot()), (const KTypeInfo*)type);
|
||||||
|}
|
|}
|
||||||
""".trimMargin())
|
""".trimMargin())
|
||||||
predefinedTypes.forEach {
|
predefinedTypes.forEach {
|
||||||
|
|||||||
@@ -93,11 +93,11 @@ def _type_info_by_address(address, debugger = lldb.debugger):
|
|||||||
return candidates
|
return candidates
|
||||||
|
|
||||||
def is_instance_of(addr, typeinfo):
|
def is_instance_of(addr, typeinfo):
|
||||||
return evaluate("(bool)IsInstance({:#x}, {:#x})".format(addr, typeinfo)).GetValue() == "true"
|
return evaluate("(bool)Konan_DebugIsInstance({:#x}, {:#x})".format(addr, typeinfo)).GetValue() == "true"
|
||||||
|
|
||||||
def is_string_or_array(value):
|
def is_string_or_array(value):
|
||||||
start = time.monotonic()
|
start = time.monotonic()
|
||||||
soa = evaluate("(int)IsInstance({0:#x}, {1:#x}) ? 1 : ((int)Konan_DebugIsArray({0:#x})) ? 2 : 0)"
|
soa = evaluate("(int)Konan_DebugIsInstance({0:#x}, {1:#x}) ? 1 : ((int)Konan_DebugIsArray({0:#x})) ? 2 : 0)"
|
||||||
.format(value.unsigned, _symbol_loaded_address('kclass:kotlin.String'))).unsigned
|
.format(value.unsigned, _symbol_loaded_address('kclass:kotlin.String'))).unsigned
|
||||||
log(lambda: "is_string_or_array:{:#x}:{}".format(value.unsigned, soa))
|
log(lambda: "is_string_or_array:{:#x}:{}".format(value.unsigned, soa))
|
||||||
bench(start, lambda: "is_string_or_array({:#x}) = {}".format(value.unsigned, soa))
|
bench(start, lambda: "is_string_or_array({:#x}) = {}".format(value.unsigned, soa))
|
||||||
|
|||||||
@@ -273,6 +273,10 @@ RUNTIME_USED RUNTIME_WEAK int32_t Konan_DebugIsArray(KRef obj) {
|
|||||||
return impl(obj);
|
return impl(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RUNTIME_USED RUNTIME_WEAK int32_t Konan_DebugIsInstance(KRef obj, const TypeInfo* typeInfo) {
|
||||||
|
return IsInstanceInternal(obj, typeInfo);
|
||||||
|
}
|
||||||
|
|
||||||
RUNTIME_USED RUNTIME_WEAK int32_t Konan_DebugGetFieldCount(KRef obj) {
|
RUNTIME_USED RUNTIME_WEAK int32_t Konan_DebugGetFieldCount(KRef obj) {
|
||||||
auto* impl = getImpl<int32_t (*)(KRef)>(obj, DO_DebugGetFieldCount);
|
auto* impl = getImpl<int32_t (*)(KRef)>(obj, DO_DebugGetFieldCount);
|
||||||
if (impl == nullptr) return 0;
|
if (impl == nullptr) return 0;
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ OBJ_GETTER(Konan_getWeakReferenceImpl, ObjHeader* referred) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if KONAN_OBJC_INTEROP
|
#if KONAN_OBJC_INTEROP
|
||||||
if (IsInstance(referred, theObjCObjectWrapperTypeInfo)) {
|
if (IsInstanceInternal(referred, theObjCObjectWrapperTypeInfo)) {
|
||||||
RETURN_RESULT_OF(makeObjCWeakReferenceImpl, referred->GetAssociatedObject());
|
RETURN_RESULT_OF(makeObjCWeakReferenceImpl, referred->GetAssociatedObject());
|
||||||
}
|
}
|
||||||
#endif // KONAN_OBJC_INTEROP
|
#endif // KONAN_OBJC_INTEROP
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ extern "C" void Kotlin_runUnhandledExceptionHook(KRef exception);
|
|||||||
extern "C" void ReportUnhandledException(KRef exception);
|
extern "C" void ReportUnhandledException(KRef exception);
|
||||||
|
|
||||||
void ThrowException(KRef exception) {
|
void ThrowException(KRef exception) {
|
||||||
RuntimeAssert(exception != nullptr && IsInstance(exception, theThrowableTypeInfo),
|
RuntimeAssert(exception != nullptr && IsInstanceInternal(exception, theThrowableTypeInfo),
|
||||||
"Throwing something non-throwable");
|
"Throwing something non-throwable");
|
||||||
#if KONAN_NO_EXCEPTIONS
|
#if KONAN_NO_EXCEPTIONS
|
||||||
PrintThrowable(exception);
|
PrintThrowable(exception);
|
||||||
|
|||||||
@@ -59,6 +59,9 @@ int32_t Konan_DebugPrint(KRef obj);
|
|||||||
RUNTIME_USED RUNTIME_WEAK
|
RUNTIME_USED RUNTIME_WEAK
|
||||||
int32_t Konan_DebugIsArray(KRef obj);
|
int32_t Konan_DebugIsArray(KRef obj);
|
||||||
|
|
||||||
|
RUNTIME_USED RUNTIME_WEAK
|
||||||
|
int32_t Konan_DebugIsInstance(KRef obj, const TypeInfo* typeInfo);
|
||||||
|
|
||||||
// Returns number of fields in an objects, or elements in an array.
|
// Returns number of fields in an objects, or elements in an array.
|
||||||
RUNTIME_USED RUNTIME_WEAK
|
RUNTIME_USED RUNTIME_WEAK
|
||||||
int32_t Konan_DebugGetFieldCount(KRef obj);
|
int32_t Konan_DebugGetFieldCount(KRef obj);
|
||||||
|
|||||||
@@ -48,9 +48,12 @@ extern "C" RUNTIME_NORETURN void Kotlin_ObjCExport_trapOnUndeclaredException(KRe
|
|||||||
static char kotlinExceptionOriginChar;
|
static char kotlinExceptionOriginChar;
|
||||||
|
|
||||||
static bool isExceptionOfType(KRef exception, const TypeInfo** types) {
|
static bool isExceptionOfType(KRef exception, const TypeInfo** types) {
|
||||||
if (types) for (int i = 0; types[i] != nullptr; ++i) {
|
if (types) {
|
||||||
// TODO: use fast instance check when possible.
|
const TypeInfo* type = exception->type_info();
|
||||||
if (IsInstance(exception, types[i])) return true;
|
for (int i = 0; types[i] != nullptr; ++i) {
|
||||||
|
// TODO: use fast instance check when possible.
|
||||||
|
if (IsSubtype(type, types[i])) return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -8,7 +8,12 @@
|
|||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
KBoolean IsInstance(const ObjHeader* obj, const TypeInfo* type_info) {
|
// Note: keeping it for compatibility with external tools only, will be deprecated and removed in the future.
|
||||||
|
RUNTIME_PURE RUNTIME_USED RUNTIME_WEAK KBoolean IsInstance(const ObjHeader* obj, const TypeInfo* type_info) {
|
||||||
|
return IsInstanceInternal(obj, type_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
KBoolean IsInstanceInternal(const ObjHeader* obj, const TypeInfo* type_info) {
|
||||||
// We assume null check is handled by caller.
|
// We assume null check is handled by caller.
|
||||||
RuntimeAssert(obj != nullptr, "must not be null");
|
RuntimeAssert(obj != nullptr, "must not be null");
|
||||||
const TypeInfo* obj_type_info = obj->type_info();
|
const TypeInfo* obj_type_info = obj->type_info();
|
||||||
@@ -42,7 +47,7 @@ KBoolean IsArray(KConstRef obj) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
KBoolean Kotlin_TypeInfo_isInstance(KConstRef obj, KNativePtr typeInfo) {
|
KBoolean Kotlin_TypeInfo_isInstance(KConstRef obj, KNativePtr typeInfo) {
|
||||||
return IsInstance(obj, reinterpret_cast<const TypeInfo*>(typeInfo));
|
return IsInstanceInternal(obj, reinterpret_cast<const TypeInfo*>(typeInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
OBJ_GETTER(Kotlin_TypeInfo_getPackageName, KNativePtr typeInfo, KBoolean checkFlags) {
|
OBJ_GETTER(Kotlin_TypeInfo_getPackageName, KNativePtr typeInfo, KBoolean checkFlags) {
|
||||||
|
|||||||
@@ -72,7 +72,8 @@ extern const TypeInfo* theWorkerBoundReferenceTypeInfo;
|
|||||||
extern const TypeInfo* theCleanerImplTypeInfo;
|
extern const TypeInfo* theCleanerImplTypeInfo;
|
||||||
extern const TypeInfo* theRegularWeakReferenceImplTypeInfo;
|
extern const TypeInfo* theRegularWeakReferenceImplTypeInfo;
|
||||||
|
|
||||||
KBoolean IsInstance(const ObjHeader* obj, const TypeInfo* type_info) RUNTIME_PURE RUNTIME_USED; // Used in konan_lldb.py
|
KBoolean IsInstance(const ObjHeader* obj, const TypeInfo* type_info) RUNTIME_PURE RUNTIME_USED RUNTIME_WEAK;
|
||||||
|
KBoolean IsInstanceInternal(const ObjHeader* obj, const TypeInfo* type_info) RUNTIME_PURE;
|
||||||
KBoolean IsSubtype(const TypeInfo* obj_type_info, const TypeInfo* type_info) RUNTIME_PURE;
|
KBoolean IsSubtype(const TypeInfo* obj_type_info, const TypeInfo* type_info) RUNTIME_PURE;
|
||||||
KBoolean IsSubclassFast(const TypeInfo* obj_type_info, int32_t lo, int32_t hi) RUNTIME_PURE;
|
KBoolean IsSubclassFast(const TypeInfo* obj_type_info, int32_t lo, int32_t hi) RUNTIME_PURE;
|
||||||
void CheckCast(const ObjHeader* obj, const TypeInfo* type_info);
|
void CheckCast(const ObjHeader* obj, const TypeInfo* type_info);
|
||||||
|
|||||||
@@ -608,7 +608,7 @@ RUNTIME_NOTHROW extern "C" OBJ_GETTER(Konan_getWeakReferenceImpl, ObjHeader* ref
|
|||||||
RETURN_RESULT_OF(makePermanentWeakReferenceImpl, referred);
|
RETURN_RESULT_OF(makePermanentWeakReferenceImpl, referred);
|
||||||
}
|
}
|
||||||
#if KONAN_OBJC_INTEROP
|
#if KONAN_OBJC_INTEROP
|
||||||
if (IsInstance(referred, theObjCObjectWrapperTypeInfo)) {
|
if (IsInstanceInternal(referred, theObjCObjectWrapperTypeInfo)) {
|
||||||
RETURN_RESULT_OF(makeObjCWeakReferenceImpl, referred->GetAssociatedObject());
|
RETURN_RESULT_OF(makeObjCWeakReferenceImpl, referred->GetAssociatedObject());
|
||||||
}
|
}
|
||||||
#endif // KONAN_OBJC_INTEROP
|
#endif // KONAN_OBJC_INTEROP
|
||||||
|
|||||||
Reference in New Issue
Block a user