Replace atomic 64-bit operations with spinlock protected operations on ios_arm32. (#2647)
This commit is contained in:
@@ -95,14 +95,13 @@ KLong Kotlin_AtomicLong_addAndGet(KRef thiz, KLong delta) {
|
|||||||
return addAndGetImpl(thiz, delta);
|
return addAndGetImpl(thiz, delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __mips
|
#if KONAN_NO_64BIT_ATOMIC
|
||||||
static int lock64 = 0;
|
static int lock64 = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
KLong Kotlin_AtomicLong_compareAndSwap(KRef thiz, KLong expectedValue, KLong newValue) {
|
KLong Kotlin_AtomicLong_compareAndSwap(KRef thiz, KLong expectedValue, KLong newValue) {
|
||||||
#ifdef __mips
|
#if KONAN_NO_64BIT_ATOMIC
|
||||||
// Potentially huge performance penalty, but correct.
|
// Potentially huge performance penalty, but correct.
|
||||||
// TODO: reconsider, once target MIPS can do proper 64-bit CAS.
|
|
||||||
while (compareAndSwap(&lock64, 0, 1) != 0);
|
while (compareAndSwap(&lock64, 0, 1) != 0);
|
||||||
volatile KLong* address = getValueLocation<KLong>(thiz);
|
volatile KLong* address = getValueLocation<KLong>(thiz);
|
||||||
KLong old = *address;
|
KLong old = *address;
|
||||||
@@ -117,9 +116,8 @@ KLong Kotlin_AtomicLong_compareAndSwap(KRef thiz, KLong expectedValue, KLong new
|
|||||||
}
|
}
|
||||||
|
|
||||||
KBoolean Kotlin_AtomicLong_compareAndSet(KRef thiz, KLong expectedValue, KLong newValue) {
|
KBoolean Kotlin_AtomicLong_compareAndSet(KRef thiz, KLong expectedValue, KLong newValue) {
|
||||||
#ifdef __mips
|
#if KONAN_NO_64BIT_ATOMIC
|
||||||
// Potentially huge performance penalty, but correct.
|
// Potentially huge performance penalty, but correct.
|
||||||
// TODO: reconsider, once target MIPS can do proper 64-bit CAS.
|
|
||||||
KBoolean result = false;
|
KBoolean result = false;
|
||||||
while (compareAndSwap(&lock64, 0, 1) != 0);
|
while (compareAndSwap(&lock64, 0, 1) != 0);
|
||||||
volatile KLong* address = getValueLocation<KLong>(thiz);
|
volatile KLong* address = getValueLocation<KLong>(thiz);
|
||||||
@@ -136,9 +134,8 @@ KBoolean Kotlin_AtomicLong_compareAndSet(KRef thiz, KLong expectedValue, KLong n
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Kotlin_AtomicLong_set(KRef thiz, KLong newValue) {
|
void Kotlin_AtomicLong_set(KRef thiz, KLong newValue) {
|
||||||
#ifdef __mips
|
#if KONAN_NO_64BIT_ATOMIC
|
||||||
// Potentially huge performance penalty, but correct.
|
// Potentially huge performance penalty, but correct.
|
||||||
// TODO: reconsider, once target MIPS can do proper 64-bit atomic store.
|
|
||||||
while (compareAndSwap(&lock64, 0, 1) != 0);
|
while (compareAndSwap(&lock64, 0, 1) != 0);
|
||||||
volatile KLong* address = getValueLocation<KLong>(thiz);
|
volatile KLong* address = getValueLocation<KLong>(thiz);
|
||||||
*address = newValue;
|
*address = newValue;
|
||||||
@@ -149,9 +146,8 @@ void Kotlin_AtomicLong_set(KRef thiz, KLong newValue) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
KLong Kotlin_AtomicLong_get(KRef thiz) {
|
KLong Kotlin_AtomicLong_get(KRef thiz) {
|
||||||
#ifdef __mips
|
#if KONAN_NO_64BIT_ATOMIC
|
||||||
// Potentially huge performance penalty, but correct.
|
// Potentially huge performance penalty, but correct.
|
||||||
// TODO: reconsider, once target MIPS can do proper 64-bit atomic store.
|
|
||||||
while (compareAndSwap(&lock64, 0, 1) != 0);
|
while (compareAndSwap(&lock64, 0, 1) != 0);
|
||||||
volatile KLong* address = getValueLocation<KLong>(thiz);
|
volatile KLong* address = getValueLocation<KLong>(thiz);
|
||||||
KLong value = *address;
|
KLong value = *address;
|
||||||
|
|||||||
@@ -135,12 +135,16 @@ class ClangArgs(private val configurables: Configurables) : Configurables by con
|
|||||||
KonanTarget.LINUX_MIPS32 ->
|
KonanTarget.LINUX_MIPS32 ->
|
||||||
listOf("-DUSE_GCC_UNWIND=1",
|
listOf("-DUSE_GCC_UNWIND=1",
|
||||||
"-DUSE_ELF_SYMBOLS=1",
|
"-DUSE_ELF_SYMBOLS=1",
|
||||||
"-DELFSIZE=32")
|
"-DELFSIZE=32",
|
||||||
|
// TODO: reconsider, once target MIPS can do proper 64-bit load/store/CAS.
|
||||||
|
"-DKONAN_NO_64BIT_ATOMIC=1")
|
||||||
|
|
||||||
KonanTarget.LINUX_MIPSEL32 ->
|
KonanTarget.LINUX_MIPSEL32 ->
|
||||||
listOf("-DUSE_GCC_UNWIND=1",
|
listOf("-DUSE_GCC_UNWIND=1",
|
||||||
"-DUSE_ELF_SYMBOLS=1",
|
"-DUSE_ELF_SYMBOLS=1",
|
||||||
"-DELFSIZE=32")
|
"-DELFSIZE=32",
|
||||||
|
// TODO: reconsider, once target MIPS can do proper 64-bit load/store/CAS.
|
||||||
|
"-DKONAN_NO_64BIT_ATOMIC=1")
|
||||||
|
|
||||||
KonanTarget.MINGW_X64 ->
|
KonanTarget.MINGW_X64 ->
|
||||||
listOf("-DUSE_GCC_UNWIND=1",
|
listOf("-DUSE_GCC_UNWIND=1",
|
||||||
@@ -155,11 +159,22 @@ class ClangArgs(private val configurables: Configurables) : Configurables by con
|
|||||||
"-DKONAN_CORE_SYMBOLICATION=1",
|
"-DKONAN_CORE_SYMBOLICATION=1",
|
||||||
"-DKONAN_HAS_CXX11_EXCEPTION_FUNCTIONS=1")
|
"-DKONAN_HAS_CXX11_EXCEPTION_FUNCTIONS=1")
|
||||||
|
|
||||||
KonanTarget.IOS_ARM32, KonanTarget.IOS_ARM64 ->
|
KonanTarget.IOS_ARM32 ->
|
||||||
listOf("-DKONAN_OBJC_INTEROP=1",
|
listOf("-DKONAN_OBJC_INTEROP=1",
|
||||||
"-DKONAN_HAS_CXX11_EXCEPTION_FUNCTIONS=1",
|
"-DKONAN_HAS_CXX11_EXCEPTION_FUNCTIONS=1",
|
||||||
"-DKONAN_REPORT_BACKTRACE_TO_IOS_CRASH_LOG=1",
|
"-DKONAN_REPORT_BACKTRACE_TO_IOS_CRASH_LOG=1",
|
||||||
"-DMACHSIZE=${target.architecture.bitness}")
|
"-DMACHSIZE=32",
|
||||||
|
// While not 100% correct here, using atomic ops on iOS armv7 requires 8 byte alignment,
|
||||||
|
// and general ABI requires 4-byte alignment on 64-bit long fields as mentioned in
|
||||||
|
// https://developer.apple.com/library/archive/documentation/Xcode/Conceptual/iPhoneOSABIReference/Articles/ARMv6FunctionCallingConventions.html#//apple_ref/doc/uid/TP40009021-SW1
|
||||||
|
// See https://github.com/ktorio/ktor/issues/941 for the context.
|
||||||
|
"-DKONAN_NO_64BIT_ATOMIC=1")
|
||||||
|
|
||||||
|
KonanTarget.IOS_ARM64 ->
|
||||||
|
listOf("-DKONAN_OBJC_INTEROP=1",
|
||||||
|
"-DKONAN_HAS_CXX11_EXCEPTION_FUNCTIONS=1",
|
||||||
|
"-DKONAN_REPORT_BACKTRACE_TO_IOS_CRASH_LOG=1",
|
||||||
|
"-DMACHSIZE=64")
|
||||||
|
|
||||||
KonanTarget.IOS_X64 ->
|
KonanTarget.IOS_X64 ->
|
||||||
listOf("-DKONAN_OBJC_INTEROP=1",
|
listOf("-DKONAN_OBJC_INTEROP=1",
|
||||||
|
|||||||
Reference in New Issue
Block a user