OSDN Git Service

Fix a type error in the allocation of non-moving arrays.
authorCarl Shapiro <cshapiro@google.com>
Mon, 18 Apr 2011 22:08:21 +0000 (15:08 -0700)
committerCarl Shapiro <cshapiro@google.com>
Wed, 20 Apr 2011 01:30:09 +0000 (18:30 -0700)
Originally, non-moving arrays were allocated with dvmAllocObjectArray.
However, dvmAllocObjectArray does not respect the width of the user
supplied element class and substitutes a hard coded value of 4 bytes.
This change replaces dvmAllocObjectArray with dvmAllocArrayByClass.
dvmAllocArrayByClass consults the element class for its width when
computing the storage size for the array being allocated.

Bug: 4309030

vm/native/dalvik_system_VMRuntime.c

index fec24be..eb086a8 100644 (file)
@@ -128,7 +128,6 @@ static void Dalvik_dalvik_system_VMRuntime_newNonMovableArray(const u4* args,
 {
     ClassObject* elementClass = (ClassObject*) args[1];
     int length = args[2];
-    ArrayObject* newArray;
 
     if (elementClass == NULL) {
         dvmThrowException("Ljava/lang/NullPointerException;", NULL);
@@ -142,7 +141,10 @@ static void Dalvik_dalvik_system_VMRuntime_newNonMovableArray(const u4* args,
     // TODO: right now, we don't have a copying collector, so there's no need
     // to do anything special here, but we ought to pass the non-movability
     // through to the allocator.
-    newArray = dvmAllocObjectArray(elementClass, length, ALLOC_DEFAULT);
+    ClassObject* arrayClass = dvmFindArrayClassForElement(elementClass);
+    ArrayObject* newArray = dvmAllocArrayByClass(arrayClass,
+                                                 length,
+                                                 ALLOC_DEFAULT);
     if (newArray == NULL) {
         assert(dvmCheckException(dvmThreadSelf()));
         RETURN_VOID();