[sgen] Correctly calculate size of zero-based one-dimensional non-vector arrays.
authorMark Probst <mark.probst@gmail.com>
Wed, 18 Feb 2015 20:26:00 +0000 (12:26 -0800)
committerMark Probst <mark.probst@gmail.com>
Wed, 18 Feb 2015 20:43:31 +0000 (12:43 -0800)
mono/metadata/sgen-alloc.c
mono/metadata/sgen-gc.h

index 47d86bbd5e11af17cb2cc3c96eac99ece0a9ae42..45b756cd10d9efdf64f540b951d958c2411a6e18 100644 (file)
@@ -524,7 +524,7 @@ mono_gc_alloc_vector (MonoVTable *vtable, size_t size, uintptr_t max_length)
                /*This doesn't require fencing since EXIT_CRITICAL_REGION already does it for us*/
                arr->max_length = (mono_array_size_t)max_length;
                EXIT_CRITICAL_REGION;
-               return arr;
+               goto done;
        }
        EXIT_CRITICAL_REGION;
 #endif
@@ -539,8 +539,11 @@ mono_gc_alloc_vector (MonoVTable *vtable, size_t size, uintptr_t max_length)
 
        arr->max_length = (mono_array_size_t)max_length;
 
+
        UNLOCK_GC;
 
+ done:
+       SGEN_ASSERT (6, SGEN_ALIGN_UP (size) == SGEN_ALIGN_UP (sgen_par_object_get_size (vtable, (MonoObject*)arr)), "Vector has incorrect size.");
        return arr;
 }
 
@@ -564,7 +567,7 @@ mono_gc_alloc_array (MonoVTable *vtable, size_t size, uintptr_t max_length, uint
                bounds = (MonoArrayBounds*)((char*)arr + size - bounds_size);
                arr->bounds = bounds;
                EXIT_CRITICAL_REGION;
-               return arr;
+               goto done;
        }
        EXIT_CRITICAL_REGION;
 #endif
@@ -584,6 +587,8 @@ mono_gc_alloc_array (MonoVTable *vtable, size_t size, uintptr_t max_length, uint
 
        UNLOCK_GC;
 
+ done:
+       SGEN_ASSERT (6, SGEN_ALIGN_UP (size) == SGEN_ALIGN_UP (sgen_par_object_get_size (vtable, (MonoObject*)arr)), "Array has incorrect size.");
        return arr;
 }
 
index 25015bd1ae664996e4f2bdd0aaac0279fd1d9928..2bc393ad0acbc8c13d072411f089d1e526df48b6 100644 (file)
@@ -823,7 +823,11 @@ sgen_par_object_get_size (MonoVTable *vtable, MonoObject* o)
                MonoArray *array = (MonoArray*)o;
                size_t size = sizeof (MonoArray) + element_size * mono_array_length_fast (array);
 
-               if (descr & VECTOR_KIND_ARRAY) {
+               /*
+                * Non-vector arrays with a single dimension whose lower bound is zero are
+                * allocated without bounds.
+                */
+               if ((descr & VECTOR_KIND_ARRAY) && array->bounds) {
                        size += sizeof (mono_array_size_t) - 1;
                        size &= ~(sizeof (mono_array_size_t) - 1);
                        size += sizeof (MonoArrayBounds) * vtable->klass->rank;