Author: zoltan
Date: 2005-03-19 16:29:44 -0500 (Sat, 19 Mar 2005)
New Revision: 42033
Modified:
trunk/mono/mono/mini/ChangeLog
trunk/mono/mono/mini/mini-x86.c
trunk/mono/mono/mini/mini.c
trunk/mono/mono/mini/mini.h
Log:
2005-03-19 Zoltan Varga <[EMAIL PROTECTED]>
* mini.h mini.c: Add mono_get_jit_tls_key ().
* mini-x86.c: Enable fast TLS support on windows.
Modified: trunk/mono/mono/mini/ChangeLog
===================================================================
--- trunk/mono/mono/mini/ChangeLog 2005-03-19 15:08:51 UTC (rev 42032)
+++ trunk/mono/mono/mini/ChangeLog 2005-03-19 21:29:44 UTC (rev 42033)
@@ -1,3 +1,9 @@
+2005-03-19 Zoltan Varga <[EMAIL PROTECTED]>
+
+ * mini.h mini.c: Add mono_get_jit_tls_key ().
+
+ * mini-x86.c: Enable fast TLS support on windows.
+
2005-03-17 Sebastien Pouliot <[EMAIL PROTECTED]>
* declsec.c: Renamed aptc to allowpartiallytrustedcallers.
Modified: trunk/mono/mono/mini/mini-x86.c
===================================================================
--- trunk/mono/mono/mini/mini-x86.c 2005-03-19 15:08:51 UTC (rev 42032)
+++ trunk/mono/mono/mini/mini-x86.c 2005-03-19 21:29:44 UTC (rev 42033)
@@ -23,6 +23,7 @@
#include "inssel.h"
#include "cpu-pentium.h"
+/* On windows, these hold the key returned by TlsAlloc () */
static gint lmf_tls_offset = -1;
static gint appdomain_tls_offset = -1;
static gint thread_tls_offset = -1;
@@ -3962,8 +3963,20 @@
break;
}
case OP_TLS_GET: {
+#ifdef PLATFORM_WIN32
+ /*
+ * See the Under the Hood article in the May 1996 issue
of Microsoft Systems
+ * Journal and/or a disassembly of the TlsGet ()
function.
+ */
+ x86_prefix (code, X86_FS_PREFIX);
+ x86_mov_reg_mem (code, ins->dreg, 0x18, 4);
+ /* Dunno what this does but TlsGetValue () contains it
*/
+ x86_alu_membase_imm (code, X86_AND, ins->dreg, 0x34, 0);
+ x86_mov_reg_membase (code, ins->dreg, ins->dreg, 3600 +
(ins->inst_offset * 4), 4);
+#else
x86_prefix (code, X86_GS_PREFIX);
x86_mov_reg_mem (code, ins->dreg, ins->inst_offset, 4);
+#endif
break;
}
case OP_ATOMIC_ADD_I4: {
@@ -4179,8 +4192,19 @@
if (lmf_tls_offset != -1) {
guint8 *buf;
+#ifdef PLATFORM_WIN32
+ /* The TLS key actually contains a pointer to the
MonoJitTlsData structure */
+ x86_prefix (code, X86_FS_PREFIX);
+ x86_mov_reg_mem (code, X86_EAX, 0x18, 4);
+ /* Dunno what this does but TlsGetValue () contains it
*/
+ x86_alu_membase_imm (code, X86_AND, X86_EAX, 0x34, 0);
+ x86_mov_reg_membase (code, X86_EAX, X86_EAX, 3600 +
(lmf_tls_offset * 4), 4);
+ /* FIXME: Add a separate key for LMF to avoid this */
+ x86_alu_reg_imm (code, X86_ADD, X86_EAX,
G_STRUCT_OFFSET (MonoJitTlsData, lmf));
+#else
x86_prefix (code, X86_GS_PREFIX);
x86_mov_reg_mem (code, X86_EAX, lmf_tls_offset, 4);
+#endif
x86_test_reg_reg (code, X86_EAX, X86_EAX);
buf = code;
x86_branch8 (code, X86_CC_NE, 0, 0);
@@ -4218,8 +4242,19 @@
*/
if (lmf_tls_offset != -1) {
/* Load lmf quicky using the GS register */
+#ifdef PLATFORM_WIN32
+ /* The TLS key actually contains a pointer to the
MonoJitTlsData structure */
+ x86_prefix (code, X86_FS_PREFIX);
+ x86_mov_reg_mem (code, X86_EAX, 0x18, 4);
+ /* Dunno what this does but TlsGetValue () contains it
*/
+ x86_alu_membase_imm (code, X86_AND, X86_EAX, 0x34, 0);
+ x86_mov_reg_membase (code, X86_EAX, X86_EAX, 3600 +
(lmf_tls_offset * 4), 4);
+ /* FIXME: Add a separate key for LMF to avoid this */
+ x86_alu_reg_imm (code, X86_ADD, X86_EAX,
G_STRUCT_OFFSET (MonoJitTlsData, lmf));
+#else
x86_prefix (code, X86_GS_PREFIX);
x86_mov_reg_mem (code, X86_EAX, lmf_tls_offset, 4);
+#endif
}
else {
if (cfg->compile_aot) {
@@ -4625,6 +4660,26 @@
struct sigaltstack sa;
#endif
+#ifdef PLATFORM_WIN32
+ /*
+ * We need to init this multiple times, since when we are first called,
the key might not
+ * be initialized yet.
+ */
+ if (!getenv ("MONO_NO_TLS")) {
+ appdomain_tls_offset = mono_domain_get_tls_key ();
+ lmf_tls_offset = mono_get_jit_tls_key ();
+ thread_tls_offset = mono_thread_get_tls_key ();
+
+ /* Only 64 tls entries can be accessed using inline code */
+ if (appdomain_tls_offset >= 64)
+ appdomain_tls_offset = -1;
+ if (lmf_tls_offset >= 64)
+ lmf_tls_offset = -1;
+ if (thread_tls_offset >= 64)
+ thread_tls_offset = -1;
+ }
+#endif
+
if (!tls_offset_inited) {
tls_offset_inited = TRUE;
if (!getenv ("MONO_NO_TLS")) {
@@ -4814,7 +4869,7 @@
if (appdomain_tls_offset == -1)
return NULL;
-
+
MONO_INST_NEW (cfg, ins, OP_TLS_GET);
ins->inst_offset = appdomain_tls_offset;
return ins;
@@ -4823,10 +4878,10 @@
MonoInst* mono_arch_get_thread_intrinsic (MonoCompile* cfg)
{
MonoInst* ins;
-
+
if (thread_tls_offset == -1)
return NULL;
-
+
MONO_INST_NEW (cfg, ins, OP_TLS_GET);
ins->inst_offset = thread_tls_offset;
return ins;
Modified: trunk/mono/mono/mini/mini.c
===================================================================
--- trunk/mono/mono/mini/mini.c 2005-03-19 15:08:51 UTC (rev 42032)
+++ trunk/mono/mono/mini/mini.c 2005-03-19 21:29:44 UTC (rev 42033)
@@ -7336,6 +7336,12 @@
static __thread gpointer mono_lmf_addr MONO_TLS_FAST;
#endif
+guint32
+mono_get_jit_tls_key (void)
+{
+ return mono_jit_tls_id;
+}
+
gint32
mono_get_lmf_tls_offset (void)
{
Modified: trunk/mono/mono/mini/mini.h
===================================================================
--- trunk/mono/mono/mini/mini.h 2005-03-19 15:08:51 UTC (rev 42032)
+++ trunk/mono/mono/mini/mini.h 2005-03-19 21:29:44 UTC (rev 42033)
@@ -783,6 +783,7 @@
gpointer mono_resolve_patch_target (MonoMethod *method, MonoDomain
*domain, guint8 *code, MonoJumpInfo *patch_info, gboolean run_cctors);
MonoLMF** mono_get_lmf_addr (void);
void mono_jit_thread_attach (MonoDomain *domain);
+guint32 mono_get_jit_tls_key (void);
gint32 mono_get_lmf_tls_offset (void);
GList *mono_varlist_insert_sorted (MonoCompile *cfg, GList *list,
MonoMethodVar *mv, gboolean sort_end);
GList *mono_varlist_sort (MonoCompile *cfg, GList *list,
int sort_type);
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches