[mono/mono] 90690f50: [runtime]Properly calculate the bitmap of valuetype [ThreadStatic] variables.

"Rodrigo Kumpera ([email protected])" <[email protected]>
Newsgroups gmane.comp.gnome.mono.patches
Message-ID <00000141e75f509b-a6ff3489-ad10-42f8-92e6-a9dc747a4c62-000000@email.amazonses.com>
   Branch: refs/heads/master
     Home: https://github.com/mono/mono
  Compare: https://github.com/mono/mono/compare/04a90dcbb0e1...90690f50363e

   Commit: 90690f50363e534b534b36dd008acf91d097d696
   Author: Rodrigo Kumpera <[email protected]> (kumpera)
     Date: 2013-10-23 22:09:40 GMT
      URL: https://github.com/mono/mono/commit/90690f50363e534b534b36dd008acf91d097d696

[runtime]Properly calculate the bitmap of valuetype [ThreadStatic] variables.

We must account that a valuetype field offset is relative to a boxed instance
and TLS memory stores a valuetype unboxed.

Changed paths:
  M mono/metadata/object.c
  M mono/tests/Makefile.am
Added paths:
  A mono/tests/thread_static_gc_layout.cs

Modified: mono/metadata/object.c
===================================================================
@@ -2013,7 +2013,7 @@ gboolean release_type_locks (gpointer key, gpointer value, gpointer user)
 					bitmap = default_bitmap;
 				} else if (mono_type_is_struct (field->type)) {
 					fclass = mono_class_from_mono_type (field->type);
-					bitmap = compute_class_bitmap (fclass, default_bitmap, sizeof (default_bitmap) * 8, 0, &max_set, FALSE);
+					bitmap = compute_class_bitmap (fclass, default_bitmap, sizeof (default_bitmap) * 8, - (sizeof (MonoObject) / sizeof (gpointer)), &max_set, FALSE);
 					numbits = max_set + 1;
 				} else {
 					default_bitmap [0] = 0;

Modified: mono/tests/Makefile.am
===================================================================
@@ -389,7 +389,8 @@ BASE_TEST_CS_SRC=		\
 	allow-synchronous-major.cs	\
 	unload-appdomain-on-shutdown.cs	\
 	block_guard_restore_aligment_on_exit.cs	\
-	finally_block_ending_in_dead_bb.cs
+	finally_block_ending_in_dead_bb.cs	\
+	thread_static_gc_layout.cs
 
 TEST_CS_SRC_DIST=	\
 	$(BASE_TEST_CS_SRC)	\

Added: mono/tests/thread_static_gc_layout.cs
===================================================================
@@ -0,0 +1,26 @@
+using System;
+
+public struct Sandwich
+{
+	public IntPtr a;
+	public object b;
+	public IntPtr c;
+	public IntPtr d;
+}
+
+class Driver {
+	[ThreadStatic]
+	static Sandwich blt;
+	// const long initial_val = 0x0100000001L;
+	const int initial_val = 1;
+
+	static int Main ()
+	{
+		blt.a = (IntPtr)initial_val;
+		blt.b = new object ();
+		blt.c = (IntPtr)initial_val;
+		blt.d = (IntPtr)initial_val;
+		GC.Collect ();
+		return (blt.a == blt.c && blt.c == blt.d && blt.a == (IntPtr)initial_val) ? 0 : -1;
+	}
+}
\ No newline at end of file


_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.