[Mono-bugs] [Bug 65414][Nor] Changed - [PATCH] Thread Local Data Slots do not survive nested appdomain transitions

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Tue, 7 Sep 2004 12:05:34 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by bmaurer@users.sf.net.

http://bugzilla.ximian.com/show_bug.cgi?id=65414

--- shadow/65414	2004-09-07 11:29:18.000000000 -0400
+++ shadow/65414.tmp.32427	2004-09-07 12:05:34.000000000 -0400
@@ -58,6 +58,50 @@
 seems to have the appdomain crossing stuff already handled correctly.
 I can remove a bunch of unmanaged code once this is checked in.
 
 ------- Additional Comments From lupus@ximian.com  2004-09-07 11:29 -------
 Why not put the hash in the Thread object?
 [ThreadStatic] fields should be avoided when possible.
+
+------- Additional Comments From bmaurer@users.sf.net  2004-09-07 12:05 -------
+A ThreadStatic variable is static across each thread / appdomain 
+combo. Putting the variable inside the thread object means it will 
+still be shared between appdomains (because the Thread object should 
+also be shared)
+
+BTW, there is no reason to avoid ThreadStatic. With a little patch to 
+the runtime, accessing these fields requires only a few dereferences 
+with constant offsets from a __thread variable. The code looks 
+something like:
+
+mov eax, [fs:MonoThread_offset]
+mov eax, [eax+ThreadStaticOffset]
+mov eax, [eax+ThreadStaticGroup]
+mov eax, [eax+ThreadStaticPos]
+
+I am having a hard time picturing the code would look like with your 
+idea.
+
+
+If we want to optize this construct, there is a better way to do it. 
+Rather than allocating slots in a hashtable, we could allocate space 
+in the ThreadStatic buffer. This would avoid a hashtable lookup on 
+every access. A hashtable lookup is going to consist of:
+
+- A virtual call to get_item
+- A virtual call to GetHashCode () on the dataslot
+- A few ALU ops, including a div
+- A few conditional branches
+- A few indirections
+- An ArrayBoundsCheck
+- Another virtual call to Equals
+
+So the code would look something like:
+
+
+mov eax, [fs:MonoThread_offset]
+mov ecx, [data_slot]
+shr ecx, shift
+mov eax, [eax+ecx*4]
+mov ecx, [data_slot]
+and ecx, 1 << shift - 1
+mov eax, [eax+ecx*4]