Tue Jan 23 18:09:21 CET 2007 Paolo Molaro <lupus@ximian.com>
authorPaolo Molaro <lupus@oddwiz.org>
Tue, 23 Jan 2007 17:12:20 +0000 (17:12 -0000)
committerPaolo Molaro <lupus@oddwiz.org>
Tue, 23 Jan 2007 17:12:20 +0000 (17:12 -0000)
* class.c, object.c: restrict GC-tracked fields to
UIntPtr fields used inside corlib, so we provide better
type info to the GC and also allow broken packing as in
bug #80580.

svn path=/trunk/mono/; revision=71524

mono/metadata/ChangeLog
mono/metadata/class.c
mono/metadata/object.c

index 1d9178ed57a13dff030f377d85220c8a3b33865b..e1156a9d2cf7d60130810cb7905513f9785c370c 100644 (file)
@@ -1,4 +1,11 @@
 
+Tue Jan 23 18:09:21 CET 2007 Paolo Molaro <lupus@ximian.com>
+
+       * class.c, object.c: restrict GC-tracked fields to
+       UIntPtr fields used inside corlib, so we provide better
+       type info to the GC and also allow broken packing as in
+       bug #80580.
+
 Mon Jan 22 11:24:27 CET 2007 Paolo Molaro <lupus@ximian.com>
 
        * sgen-gc.c: removed duplicated function.
index 1ddcd922000d95dacbc8174092070915a8c3b297..8595fae0112feb0d08a7435b448fb0ee4e17a12c 100644 (file)
@@ -1020,7 +1020,7 @@ mono_class_has_references (MonoClass *klass)
 #ifdef HAVE_SGEN_GC
 #define IS_GC_REFERENCE(t) FALSE
 #else
-#define IS_GC_REFERENCE(t) ((t)->type == MONO_TYPE_U || (t)->type == MONO_TYPE_I || (t)->type == MONO_TYPE_PTR)
+#define IS_GC_REFERENCE(t) ((t)->type == MONO_TYPE_U && class->image == mono_defaults.corlib)
 #endif
 
 /*
@@ -1065,6 +1065,9 @@ mono_class_layout_fields (MonoClass *class)
                if (class->image != mono_defaults.corlib &&
                        class->byval_arg.type != MONO_TYPE_VALUETYPE)
                        gc_aware_layout = TRUE;
+               /* from System.dll, used in metadata/process.h */
+               if (strcmp (class->name, "ProcessStartInfo") == 0)
+                       gc_aware_layout = FALSE;
        }
 
        /* Compute klass->has_references */
@@ -1143,15 +1146,9 @@ mono_class_layout_fields (MonoClass *class)
                                if (field->type->attrs & FIELD_ATTRIBUTE_STATIC)
                                        continue;
 
+                               ftype = mono_type_get_underlying_type (field->type);
                                if (gc_aware_layout) {
-                                       /* 
-                                        * We process fields with reference type in the first pass,
-                                        * and fields with non-reference type in the second pass.
-                                        * We use IS_POINTER instead of IS_REFERENCE because in
-                                        * some internal structures, we store GC_MALLOCed memory
-                                        * in IntPtr fields...
-                                        */
-                                       if (MONO_TYPE_IS_POINTER (field->type)) {
+                                       if (MONO_TYPE_IS_REFERENCE (ftype) || IS_GC_REFERENCE (ftype) || ((MONO_TYPE_ISSTRUCT (ftype) && mono_class_has_references (mono_class_from_mono_type (ftype))))) {
                                                if (pass == 1)
                                                        continue;
                                        } else {
@@ -1173,8 +1170,7 @@ mono_class_layout_fields (MonoClass *class)
                                /* if the field has managed references, we need to force-align it
                                 * see bug #77788
                                 */
-                               ftype = mono_type_get_underlying_type (field->type);
-                               if (MONO_TYPE_IS_REFERENCE (ftype) || ((MONO_TYPE_ISSTRUCT (ftype) && mono_class_has_references (mono_class_from_mono_type (ftype)))))
+                               if (MONO_TYPE_IS_REFERENCE (ftype) || IS_GC_REFERENCE (ftype) || ((MONO_TYPE_ISSTRUCT (ftype) && mono_class_has_references (mono_class_from_mono_type (ftype)))))
                                        align = sizeof (gpointer);
 
                                class->min_align = MAX (align, class->min_align);
index 7189dbe6e355c5c9706c4d0e328ff3dea31a8e15..98f9f88dfaca776c33762708eec5f01301b61576 100644 (file)
@@ -593,13 +593,17 @@ compute_class_bitmap (MonoClass *class, gsize *bitmap, int size, int offset, int
 
                        type = mono_type_get_underlying_type (field->type);
                        switch (type->type) {
-                       /* FIXME: _I and _U and _PTR should be removed eventually */
                        case MONO_TYPE_I:
-                       case MONO_TYPE_U:
                        case MONO_TYPE_PTR:
                        case MONO_TYPE_FNPTR:
+                               break;
+                       /* only UIntPtr is allowed to be GC-tracked and only in mscorlib */
+                       case MONO_TYPE_U:
 #ifdef HAVE_SGEN_GC
                                break;
+#else
+                               if (class->image != mono_defaults.corlib)
+                                       break;
 #endif
                        case MONO_TYPE_STRING:
                        case MONO_TYPE_SZARRAY: