Просмотр исходного кода

2009-07-22 Mark Probst <[email protected]>

        * sgen-gc.c: Align array bounds calculation to mono_array_size_t
        so that big arrays are handled correctly.  Always use
        safe_object_get_size() to calculate array object sizes, which
        takes bounds into account.

svn path=/trunk/mono/; revision=138406
Mark Probst 16 лет назад
Родитель
Сommit
4becd3d80e
2 измененных файлов с 12 добавлено и 31 удалено
  1. 7 0
      mono/metadata/ChangeLog
  2. 5 31
      mono/metadata/sgen-gc.c

+ 7 - 0
mono/metadata/ChangeLog

@@ -1,3 +1,10 @@
+2009-07-22  Mark Probst  <[email protected]>
+
+	* sgen-gc.c: Align array bounds calculation to mono_array_size_t
+	so that big arrays are handled correctly.  Always use
+	safe_object_get_size() to calculate array object sizes, which
+	takes bounds into account.
+
 2009-07-22  Mark Probst  <[email protected]>
 
 	* sgen-gc.c (mono_gc_wbarrier_value_copy): Make sure the class's

+ 5 - 31
mono/metadata/sgen-gc.c

@@ -456,8 +456,8 @@ safe_object_get_size (MonoObject* o)
 		MonoArray *array = (MonoArray*)o;
 		size_t size = sizeof (MonoArray) + mono_array_element_size (klass) * mono_array_length (array);
 		if (G_UNLIKELY (array->bounds)) {
-			size += 3;
-			size &= ~3;
+			size += sizeof (mono_array_size_t) - 1;
+			size &= ~(sizeof (mono_array_size_t) - 1);
 			size += sizeof (MonoArrayBounds) * klass->rank;
 		}
 		return size;
@@ -1313,9 +1313,6 @@ scan_area (char *start, char *end)
 			skip_size += (ALLOC_ALIGN - 1);
 			skip_size &= ~(ALLOC_ALIGN - 1);
 			OBJ_VECTOR_FOREACH_PTR (vt, start);
-			if (type == DESC_TYPE_ARRAY) {
-				/* account for the bounds */
-			}
 			start += skip_size;
 			type_vector++;
 			continue;
@@ -1345,15 +1342,10 @@ scan_area (char *start, char *end)
 			continue;
 		} else if (type == DESC_TYPE_COMPLEX_ARR) {
 			/* this is an array of complex structs */
-			skip_size = mono_array_element_size (((MonoVTable*)vt)->klass);
-			skip_size *= mono_array_length ((MonoArray*)start);
-			skip_size += sizeof (MonoArray);
+			skip_size = safe_object_get_size ((MonoObject*)start);
 			skip_size += (ALLOC_ALIGN - 1);
 			skip_size &= ~(ALLOC_ALIGN - 1);
 			OBJ_COMPLEX_ARR_FOREACH_PTR (vt, start);
-			if (type == DESC_TYPE_ARRAY) {
-				/* account for the bounds */
-			}
 			start += skip_size;
 			type_complex++;
 			continue;
@@ -1435,9 +1427,6 @@ scan_area_for_domain (MonoDomain *domain, char *start, char *end)
 			skip_size = safe_object_get_size ((MonoObject*)start);
 			skip_size += (ALLOC_ALIGN - 1);
 			skip_size &= ~(ALLOC_ALIGN - 1);
-			if (type == DESC_TYPE_ARRAY) {
-				/* account for the bounds */
-			}
 			if (remove) memset (start, 0, skip_size);
 			start += skip_size;
 			continue;
@@ -1464,14 +1453,9 @@ scan_area_for_domain (MonoDomain *domain, char *start, char *end)
 			continue;
 		} else if (type == DESC_TYPE_COMPLEX_ARR) {
 			/* this is an array of complex structs */
-			skip_size = mono_array_element_size (((MonoVTable*)vt)->klass);
-			skip_size *= mono_array_length ((MonoArray*)start);
-			skip_size += sizeof (MonoArray);
+			skip_size = safe_object_get_size ((MonoObject*)start);
 			skip_size += (ALLOC_ALIGN - 1);
 			skip_size &= ~(ALLOC_ALIGN - 1);
-			if (type == DESC_TYPE_ARRAY) {
-				/* account for the bounds */
-			}
 			if (remove) memset (start, 0, skip_size);
 			start += skip_size;
 			continue;
@@ -5851,10 +5835,6 @@ check_remsets_for_area (char *start, char *end)
 			skip_size += (ALLOC_ALIGN - 1);
 			skip_size &= ~(ALLOC_ALIGN - 1);
 			OBJ_VECTOR_FOREACH_PTR (vt, start);
-			if (((MonoArray*)start)->bounds) {
-				/* account for the bounds */
-				skip_size += sizeof (MonoArrayBounds) * vt->klass->rank;
-			}
 			start += skip_size;
 			type_vector++;
 			continue;
@@ -5884,16 +5864,10 @@ check_remsets_for_area (char *start, char *end)
 			continue;
 		} else if (type == DESC_TYPE_COMPLEX_ARR) {
 			/* this is an array of complex structs */
-			skip_size = mono_array_element_size (((MonoVTable*)vt)->klass);
-			skip_size *= mono_array_length ((MonoArray*)start);
-			skip_size += sizeof (MonoArray);
+			skip_size = safe_object_get_size ((MonoObject*)start);
 			skip_size += (ALLOC_ALIGN - 1);
 			skip_size &= ~(ALLOC_ALIGN - 1);
 			OBJ_COMPLEX_ARR_FOREACH_PTR (vt, start);
-			if (((MonoArray*)start)->bounds) {
-				/* account for the bounds */
-				skip_size += sizeof (MonoArrayBounds) * vt->klass->rank;
-			}
 			start += skip_size;
 			type_complex++;
 			continue;