[arm] Add fast tls support on android.
authorVlad Brezae <brezaevlad@gmail.com>
Tue, 7 Apr 2015 21:39:38 +0000 (21:39 +0000)
committerVlad Brezae <brezaevlad@gmail.com>
Fri, 10 Jul 2015 18:43:42 +0000 (11:43 -0700)
mono/metadata/sgen-mono.c
mono/mini/mini-arm-tls.S
mono/mini/mini-arm.c
mono/utils/mono-compiler.h

index 7f0ece2a1bdc3e1c3b53b21c99a5599da357551a..b142d97108bd52ed6c852ec32b77eee0533d460b 100644 (file)
@@ -1010,7 +1010,7 @@ static gboolean use_managed_allocator = TRUE;
 
 #else
 
-#if defined(TARGET_OSX) || defined(TARGET_WIN32)
+#if defined(TARGET_OSX) || defined(TARGET_WIN32) || defined(TARGET_ANDROID)
 #define EMIT_TLS_ACCESS_NEXT_ADDR(mb)  do {    \
        mono_mb_emit_byte ((mb), MONO_CUSTOM_PREFIX);   \
        mono_mb_emit_byte ((mb), CEE_MONO_TLS);         \
@@ -2750,7 +2750,7 @@ sgen_client_init (void)
 
 #ifndef HAVE_KW_THREAD
        mono_native_tls_alloc (&thread_info_key, NULL);
-#if defined(TARGET_OSX) || defined(TARGET_WIN32)
+#if defined(TARGET_OSX) || defined(TARGET_WIN32) || defined(TARGET_ANDROID)
        /* 
         * CEE_MONO_TLS requires the tls offset, not the key, so the code below only works on darwin,
         * where the two are the same.
index 002f907c06884d851c239031949a5f14c9a7b11b..178cae4e6cab87fa182be1d5fcf0d66c32e486cf 100644 (file)
@@ -28,9 +28,13 @@ _mono_fast_get_tls_key :
        .global mono_fast_get_tls_key
 mono_fast_get_tls_key :
 #endif
-#if defined(HAVE_KW_THREAD) && defined(__linux__)
+#if defined(__linux__)
        mrc     p15, 0, r1, c13, c0, 3
+#if defined(HAVE_KW_THREAD)
        ldr     r0, [r1, r0]
+#elif defined(TARGET_ANDROID)
+       ldr     r0, [r1, r0, lsl #2]
+#endif
        bx      lr
 #else
        nop
@@ -50,13 +54,17 @@ _mono_fallback_get_tls_key :
        .global mono_fallback_get_tls_key
 mono_fallback_get_tls_key :
 #endif
-#if defined(HAVE_KW_THREAD) && defined(__linux__)
+#if defined(__linux__)
        mov     r1, r0
        mvn     r0, #0xf000
        sub     r0, r0, #31
        push    {lr}
        blx     r0
+#if defined(HAVE_KW_THREAD)
        ldr     r0, [r0, r1]
+#elif defined(TARGET_ANDROID)
+       ldr     r0, [r0, r1, lsl #2]
+#endif
        pop     {pc}
 #else
        nop
@@ -76,9 +84,13 @@ _mono_fast_set_tls_key :
        .global mono_fast_set_tls_key
 mono_fast_set_tls_key :
 #endif
-#if defined(HAVE_KW_THREAD) && defined(__linux__)
+#if defined(__linux__)
        mrc     p15, 0, r2, c13, c0, 3
+#if defined(HAVE_KW_THREAD)
        str     r1, [r2, r0]
+#elif defined(TARGET_ANDROID)
+       str     r1, [r2, r0, lsl #2]
+#endif
        bx      lr
 #else
        nop
@@ -98,13 +110,17 @@ _mono_fallback_set_tls_key :
        .global mono_fallback_set_tls_key
 mono_fallback_set_tls_key :
 #endif
-#if defined(HAVE_KW_THREAD) && defined(__linux__)
+#if defined(__linux__)
        mov     r2, r0
        mvn     r0, #0xf000
        sub     r0, r0, #31
        push    {lr}
        blx     r0
+#if defined(HAVE_KW_THREAD)
        str     r1, [r0, r2]
+#elif defined(TARGET_ANDROID)
+       str     r1, [r0, r2, lsl #2]
+#endif
        pop     {pc}
 #else
        nop
index e5124c58d2d5338a0b88ab02efcc6c44445ba353..d423cf32f06fa52c77de8011127fa70eace8aa48 100644 (file)
@@ -29,7 +29,8 @@
 #include "mini-gc.h"
 #include "mono/arch/arm/arm-vfp-codegen.h"
 
-#if defined(HAVE_KW_THREAD) && defined(__linux__)
+#if defined(HAVE_KW_THREAD) && defined(__linux__) \
+       || defined(TARGET_ANDROID)
 #define HAVE_FAST_TLS
 #endif
 
@@ -675,7 +676,8 @@ emit_restore_lmf (MonoCompile *cfg, guint8 *code, gint32 lmf_offset)
 static gboolean
 mono_arm_have_fast_tls (void)
 {
-#if defined(HAVE_KW_THREAD) && defined(__linux__)
+#if (defined(HAVE_KW_THREAD) && defined(__linux__)) \
+       || defined(TARGET_ANDROID)
        guint32* kuser_get_tls = (void*)0xffff0fe0;
        guint32 expected [] = {0xee1d0f70, 0xe12fff1e};
 
index 5c7efe6acd40df5dc544fca2c5e24a0f28da8951..f48b3e51965b50b9d2b06dc7ae266842e4ffc84c 100644 (file)
        pthread_key_t _y;       \
        (void) (&_x == &_y);            \
        y = (gint32) x; })
+
+#elif defined(TARGET_ANDROID) && defined(TARGET_ARM)
+
+#define MONO_HAVE_FAST_TLS
+#define MONO_FAST_TLS_SET(x,y) pthread_setspecific(x, y)
+#define MONO_FAST_TLS_GET(x) pthread_getspecific(x)
+#define MONO_FAST_TLS_INIT(x) pthread_key_create(&x, NULL)
+#define MONO_FAST_TLS_DECLARE(x) static pthread_key_t x;
+
+#define MONO_THREAD_VAR_OFFSET(var, offset) do { offset = (int)var; } while (0)
+
 #else /* no HAVE_KW_THREAD */
 
 #define MONO_THREAD_VAR_OFFSET(var,offset) (offset) = -1