fix incorrect array sizing in populateMultiArray

We were assuming the array element size was always the native word
size, which is not correct in general for primitive arrays, and this
led to wasted space at best and memory corruption at worst.
This commit is contained in:
Joel Dice 2012-06-26 10:43:47 -06:00
parent cfd9dc6656
commit 156644b8e5
2 changed files with 16 additions and 1 deletions

View File

@ -4889,7 +4889,10 @@ populateMultiArray(Thread* t, object array, int32_t* counts,
PROTECT(t, class_);
for (int32_t i = 0; i < counts[index]; ++i) {
object a = makeArray(t, counts[index + 1]);
object a = makeArray
(t, ceiling
(counts[index + 1] * classArrayElementSize(t, class_), BytesPerWord));
arrayLength(t, a) = counts[index + 1];
setObjectClass(t, a, class_);
set(t, array, ArrayBody + (i * BytesPerWord), a);

View File

@ -260,5 +260,17 @@ public class Floats {
int result = Float.floatToIntBits(number);
expect(result == orig);
}
for (int x = 0; x < 1000; ++x) {
int m = 100;
int n = 200;
double array[][] = new double[m][n];
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
array[i][j] = 1234567890.0;
}
}
}
}
}