summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChao Yang <chao.yang@linaro.org>2011-10-13 15:52:08 +0100
committerChao Yang <chao.yang@linaro.org>2011-10-13 15:52:08 +0100
commit9270c4d07a2cd9f22fb580d0277ceec530abb3b2 (patch)
treebb710f6c32c6da13ba1a529aea88969f288339bf
parent87dc8dd69f81bb07007969dee9e71bce7fa82807 (diff)
downloaddalvik-linaro_android_2.3.7.tar.gz
dalvik: Remove strict aliasing violationslinaro_android_2.3.7linaro_android_2.3.5
In build/core/combo/select.mk, -fno-strict-aliasing is deleted. Then aliasing violations are found with the default flag "-fstrict-aliasing=2". This patch removes those violations. Change-Id: Ia46126a1d76c15a192aac156ebdecbd5c2263511
-rw-r--r--vm/Exception.c11
-rw-r--r--vm/InlineNative.c26
-rw-r--r--vm/Jni.c20
-rw-r--r--vm/Sync.c7
-rw-r--r--vm/UtfString.c23
-rw-r--r--vm/alloc/MarkSweep.c4
-rw-r--r--vm/alloc/VisitInlines.h4
-rw-r--r--vm/hprof/HprofHeap.c12
-rw-r--r--vm/interp/Stack.c7
-rw-r--r--vm/jdwp/JdwpAdb.c10
-rw-r--r--vm/mterp/out/InterpC-allstubs.c12
-rw-r--r--vm/mterp/out/InterpC-portdbg.c12
-rw-r--r--vm/mterp/out/InterpC-portstd.c12
-rw-r--r--vm/mterp/out/InterpC-x86.c4
-rw-r--r--vm/native/dalvik_system_VMDebug.c4
-rw-r--r--vm/native/dalvik_system_Zygote.c14
-rw-r--r--vm/native/java_lang_Class.c4
-rw-r--r--vm/native/java_lang_System.c10
-rw-r--r--vm/native/java_lang_reflect_Array.c4
-rw-r--r--vm/oo/Array.c9
-rw-r--r--vm/oo/ObjectInlines.h4
-rw-r--r--vm/reflect/Annotation.c4
-rw-r--r--vm/reflect/Proxy.c35
23 files changed, 183 insertions, 69 deletions
diff --git a/vm/Exception.c b/vm/Exception.c
index 3a73420db..a86bdfb78 100644
--- a/vm/Exception.c
+++ b/vm/Exception.c
@@ -99,6 +99,11 @@ the way the stack works.
static bool initException(Object* exception, const char* msg, Object* cause,
Thread* self);
+static inline int* local_cast(void* p){
+ union{const void* src; int* dst}u_cast;
+ u_cast.src = p;
+ return u_cast.dst;
+}
/*
* Cache pointers to some of the exception classes we use locally.
@@ -1047,7 +1052,7 @@ void* dvmFillInStackTraceInternal(Thread* thread, bool wantObject, int* pCount)
assert(dvmCheckException(dvmThreadSelf()));
goto bail;
}
- intPtr = (int*) stackData->contents;
+ intPtr = local_cast(stackData->contents);
} else {
/* array of ints; first entry is stack depth */
assert(sizeof(Method*) == sizeof(int));
@@ -1112,7 +1117,7 @@ ArrayObject* dvmGetStackTrace(const Object* ostackData)
int stackSize;
stackSize = stackData->length / 2;
- intVals = (const int*) stackData->contents;
+ intVals = local_cast(stackData->contents);
return dvmGetStackTraceRaw(intVals, stackSize);
}
@@ -1271,7 +1276,7 @@ static void logStackTraceOf(Object* exception)
}
stackSize = stackData->length / 2;
- intVals = (const int*) stackData->contents;
+ intVals = local_cast(stackData->contents);
dvmLogRawStackTrace(intVals, stackSize);
}
diff --git a/vm/InlineNative.c b/vm/InlineNative.c
index a3a9ac87d..6fc2af2dd 100644
--- a/vm/InlineNative.c
+++ b/vm/InlineNative.c
@@ -114,6 +114,16 @@ static bool org_apache_harmony_dalvik_NativeTestTarget_emptyInlineMethod(
return true;
}
+/*
+ * This functions cast the pointer to u2* with the purpose of
+ * removing aliasing violations
+ *
+*/
+static inline u2* local_cast(void* p){
+ union {const void* src; u2* dst;}u_cast;
+ u_cast.src = p;
+ return u_cast.dst;
+}
/*
* ===========================================================================
@@ -144,7 +154,7 @@ static bool javaLangString_charAt(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
chars = (ArrayObject*)
dvmGetFieldObject((Object*) arg0, STRING_FIELDOFF_VALUE);
- pResult->i = ((const u2*) chars->contents)[arg1 + offset];
+ pResult->i = (local_cast(chars->contents))[arg1 + offset];
return true;
}
}
@@ -182,10 +192,10 @@ static void badMatch(StringObject* thisStrObj, StringObject* compStrObj,
LOGE(" this (o=%d l=%d) '%s'\n", thisOffset, thisCount, thisStr);
LOGE(" comp (o=%d l=%d) '%s'\n", compOffset, compCount, compStr);
dvmPrintHexDumpEx(ANDROID_LOG_INFO, LOG_TAG,
- ((const u2*) thisArray->contents) + thisOffset, thisCount*2,
+ (local_cast(thisArray->contents)) + thisOffset, thisCount*2,
kHexDumpLocal);
dvmPrintHexDumpEx(ANDROID_LOG_INFO, LOG_TAG,
- ((const u2*) compArray->contents) + compOffset, compCount*2,
+ (local_cast(compArray->contents)) + compOffset, compCount*2,
kHexDumpLocal);
dvmAbort();
}
@@ -237,8 +247,8 @@ static bool javaLangString_compareTo(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
dvmGetFieldObject((Object*) arg0, STRING_FIELDOFF_VALUE);
compArray = (ArrayObject*)
dvmGetFieldObject((Object*) arg1, STRING_FIELDOFF_VALUE);
- thisChars = ((const u2*) thisArray->contents) + thisOffset;
- compChars = ((const u2*) compArray->contents) + compOffset;
+ thisChars = (local_cast(thisArray->contents)) + thisOffset;
+ compChars = (local_cast(compArray->contents)) + compOffset;
#ifdef HAVE__MEMCMP16
/*
@@ -341,8 +351,8 @@ static bool javaLangString_equals(u4 arg0, u4 arg1, u4 arg2, u4 arg3,
dvmGetFieldObject((Object*) arg0, STRING_FIELDOFF_VALUE);
compArray = (ArrayObject*)
dvmGetFieldObject((Object*) arg1, STRING_FIELDOFF_VALUE);
- thisChars = ((const u2*) thisArray->contents) + thisOffset;
- compChars = ((const u2*) compArray->contents) + compOffset;
+ thisChars = (local_cast(thisArray->contents)) + thisOffset;
+ compChars = (local_cast(compArray->contents)) + compOffset;
#ifdef HAVE__MEMCMP16
pResult->i = (__memcmp16(thisChars, compChars, thisCount) == 0);
@@ -430,7 +440,7 @@ static inline int indexOfCommon(Object* strObj, int ch, int start)
/* pull out the basic elements */
ArrayObject* charArray =
(ArrayObject*) dvmGetFieldObject(strObj, STRING_FIELDOFF_VALUE);
- const u2* chars = (const u2*) charArray->contents;
+ const u2* chars = local_cast(charArray->contents);
int offset = dvmGetFieldInt(strObj, STRING_FIELDOFF_OFFSET);
int count = dvmGetFieldInt(strObj, STRING_FIELDOFF_COUNT);
//LOGI("String.indexOf(0x%08x, 0x%04x, %d) off=%d count=%d\n",
diff --git a/vm/Jni.c b/vm/Jni.c
index ef0749a78..2d65ea205 100644
--- a/vm/Jni.c
+++ b/vm/Jni.c
@@ -3149,8 +3149,10 @@ static jobjectArray NewObjectArray(JNIEnv* env, jsize length,
* Initialize the array. Trashes "length".
*/
if (jinitialElement != NULL) {
+ union {const void* src; Object** dst;}u_cast;
Object* initialElement = dvmDecodeIndirectRef(env, jinitialElement);
- Object** arrayData = (Object**) newObj->contents;
+ u_cast.src = newObj->contents;
+ Object** arrayData = (Object**) u_cast.dst;
while (length--)
*arrayData++ = initialElement;
@@ -3170,6 +3172,7 @@ bail:
static jobject GetObjectArrayElement(JNIEnv* env, jobjectArray jarr,
jsize index)
{
+ union {const void* src; Object** dst;}u_cast;
JNI_ENTER();
ArrayObject* arrayObj = (ArrayObject*) dvmDecodeIndirectRef(env, jarr);
@@ -3184,7 +3187,8 @@ static jobject GetObjectArrayElement(JNIEnv* env, jobjectArray jarr,
goto bail;
}
- Object* value = ((Object**) arrayObj->contents)[index];
+ u_cast.src = arrayObj->contents;
+ Object* value = ((Object**) u_cast.dst)[index];
retval = addLocalReference(env, value);
bail:
@@ -3260,12 +3264,14 @@ NEW_PRIMITIVE_ARRAY(jdoubleArray, Double, 'D');
static _ctype* Get##_jname##ArrayElements(JNIEnv* env, \
_ctype##Array jarr, jboolean* isCopy) \
{ \
+ union{const void* src; _ctype* dst;}cast; \
JNI_ENTER(); \
_ctype* data; \
ArrayObject* arrayObj = \
(ArrayObject*) dvmDecodeIndirectRef(env, jarr); \
pinPrimitiveArray(arrayObj); \
- data = (_ctype*) arrayObj->contents; \
+ cast.src = arrayObj->contents; \
+ data = (_ctype*) cast.dst; \
if (isCopy != NULL) \
*isCopy = JNI_FALSE; \
JNI_EXIT(); \
@@ -3300,10 +3306,12 @@ NEW_PRIMITIVE_ARRAY(jdoubleArray, Double, 'D');
static void Get##_jname##ArrayRegion(JNIEnv* env, \
_ctype##Array jarr, jsize start, jsize len, _ctype* buf) \
{ \
+ union{const void* src; _ctype* dst;}cast; \
JNI_ENTER(); \
ArrayObject* arrayObj = \
(ArrayObject*) dvmDecodeIndirectRef(env, jarr); \
- _ctype* data = (_ctype*) arrayObj->contents; \
+ cast.src = arrayObj->contents; \
+ _ctype* data = (_ctype*) cast.dst; \
if (start < 0 || len < 0 || start + len > (int) arrayObj->length) { \
dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
arrayObj->obj.clazz->descriptor); \
@@ -3320,10 +3328,12 @@ NEW_PRIMITIVE_ARRAY(jdoubleArray, Double, 'D');
static void Set##_jname##ArrayRegion(JNIEnv* env, \
_ctype##Array jarr, jsize start, jsize len, const _ctype* buf) \
{ \
+ union{const void* src; _ctype* dst;}cast; \
JNI_ENTER(); \
ArrayObject* arrayObj = \
(ArrayObject*) dvmDecodeIndirectRef(env, jarr); \
- _ctype* data = (_ctype*) arrayObj->contents; \
+ cast.src = arrayObj->contents; \
+ _ctype* data = (_ctype*) cast.dst; \
if (start < 0 || len < 0 || start + len > (int) arrayObj->length) { \
dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
arrayObj->obj.clazz->descriptor); \
diff --git a/vm/Sync.c b/vm/Sync.c
index b771b1c97..dfa6fe20f 100644
--- a/vm/Sync.c
+++ b/vm/Sync.c
@@ -156,6 +156,11 @@ struct Monitor {
#endif
};
+static inline int32_t* local_cast(void* p){
+ union {const void* src; int32_t* dst;}u_cast;
+ u_cast.src = p;
+ return u_cast.dst;
+}
/*
* Create and initialize a monitor.
@@ -180,7 +185,7 @@ Monitor* dvmCreateMonitor(Object* obj)
do {
mon->next = gDvm.monitorList;
} while (android_atomic_release_cas((int32_t)mon->next, (int32_t)mon,
- (int32_t*)(void*)&gDvm.monitorList) != 0);
+ local_cast(&gDvm.monitorList)) != 0);
return mon;
}
diff --git a/vm/UtfString.c b/vm/UtfString.c
index f560dac28..5d12a0741 100644
--- a/vm/UtfString.c
+++ b/vm/UtfString.c
@@ -24,6 +24,11 @@
#include "Dalvik.h"
#include <stdlib.h>
+static inline u2* local_cast(void* p){
+ union {const void* src;const u2* dst;}u_cast;
+ u_cast.src = p;
+ return u_cast.dst;
+}
/*
* Initialize string globals.
*
@@ -251,7 +256,7 @@ u4 dvmComputeStringHash(const StringObject* strObj) {
len = dvmGetFieldInt((Object*) strObj, STRING_FIELDOFF_COUNT);
offset = dvmGetFieldInt((Object*) strObj, STRING_FIELDOFF_OFFSET);
- return dvmComputeUtf16Hash((u2*) chars->contents + offset, len);
+ return dvmComputeUtf16Hash(local_cast(chars->contents) + offset, len);
}
/*
@@ -307,8 +312,8 @@ StringObject* dvmCreateStringFromCstrAndLength(const char* utf8Str,
dvmReleaseTrackedAlloc((Object*) newObj, NULL);
return NULL;
}
- dvmConvertUtf8ToUtf16((u2*)chars->contents, utf8Str);
- hashCode = dvmComputeUtf16Hash((u2*) chars->contents, utf16Length);
+ dvmConvertUtf8ToUtf16(local_cast(chars->contents), utf8Str);
+ hashCode = dvmComputeUtf16Hash(local_cast(chars->contents), utf16Length);
dvmSetFieldObject((Object*)newObj, STRING_FIELDOFF_VALUE,
(Object*)chars);
@@ -362,7 +367,7 @@ StringObject* dvmCreateStringFromUnicode(const u2* unichars, int len)
}
if (len > 0)
memcpy(chars->contents, unichars, len * sizeof(u2));
- hashCode = dvmComputeUtf16Hash((u2*) chars->contents, len);
+ hashCode = dvmComputeUtf16Hash(local_cast(chars->contents), len);
dvmSetFieldObject((Object*)newObj, STRING_FIELDOFF_VALUE,
(Object*)chars);
@@ -400,7 +405,7 @@ char* dvmCreateCstrFromString(StringObject* jstr)
offset = dvmGetFieldInt((Object*) jstr, STRING_FIELDOFF_OFFSET);
chars = (ArrayObject*) dvmGetFieldObject((Object*) jstr,
STRING_FIELDOFF_VALUE);
- data = (const u2*) chars->contents + offset;
+ data = local_cast(chars->contents) + offset;
assert(offset + len <= (int) chars->length);
byteLen = utf16_utf8ByteLen(data, len);
@@ -445,7 +450,7 @@ int dvmStringUtf8ByteLen(StringObject* jstr)
offset = dvmGetFieldInt((Object*) jstr, STRING_FIELDOFF_OFFSET);
chars = (ArrayObject*) dvmGetFieldObject((Object*) jstr,
STRING_FIELDOFF_VALUE);
- data = (const u2*) chars->contents + offset;
+ data = local_cast(chars->contents) + offset;
assert(offset + len <= (int) chars->length);
return utf16_utf8ByteLen(data, len);
@@ -479,7 +484,7 @@ const u2* dvmStringChars(StringObject* jstr)
offset = dvmGetFieldInt((Object*) jstr, STRING_FIELDOFF_OFFSET);
chars = (ArrayObject*) dvmGetFieldObject((Object*) jstr,
STRING_FIELDOFF_VALUE);
- return (const u2*) chars->contents + offset;
+ return local_cast(chars->contents) + offset;
}
@@ -517,7 +522,7 @@ int dvmHashcmpStrings(const void* vstrObj1, const void* vstrObj2)
assert(offset1 + len1 <= (int) chars1->length);
assert(offset2 + len2 <= (int) chars2->length);
- return memcmp((const u2*) chars1->contents + offset1,
- (const u2*) chars2->contents + offset2,
+ return memcmp(local_cast(chars1->contents) + offset1,
+ local_cast(chars2->contents) + offset2,
len1 * sizeof(u2));
}
diff --git a/vm/alloc/MarkSweep.c b/vm/alloc/MarkSweep.c
index 62a4ccc9f..d29e79023 100644
--- a/vm/alloc/MarkSweep.c
+++ b/vm/alloc/MarkSweep.c
@@ -368,7 +368,9 @@ static void scanArrayObject(const ArrayObject *obj, GcMarkContext *ctx)
markObject((Object *)obj->obj.clazz, ctx);
if (IS_CLASS_FLAG_SET(obj->obj.clazz, CLASS_ISOBJECTARRAY)) {
/* Scan the array contents. */
- Object **contents = (Object **)obj->contents;
+ union{const void* src; Object** dst;}u_cast;
+ u_cast.src = obj->contents;
+ Object **contents = (Object **)u_cast.dst;
for (i = 0; i < obj->length; ++i) {
markObject(contents[i], ctx);
}
diff --git a/vm/alloc/VisitInlines.h b/vm/alloc/VisitInlines.h
index 84a456a6e..536243707 100644
--- a/vm/alloc/VisitInlines.h
+++ b/vm/alloc/VisitInlines.h
@@ -121,8 +121,10 @@ static void visitArrayObject(Visitor *visitor, Object *obj, void *arg)
assert(obj->clazz != NULL);
(*visitor)(&obj->clazz, arg);
if (IS_CLASS_FLAG_SET(obj->clazz, CLASS_ISOBJECTARRAY)) {
+ union {void* src; Object** dst;}u_cast;
ArrayObject *array = (ArrayObject *)obj;
- Object **contents = (Object **)array->contents;
+ u_cast.src = array->contents;
+ Object **contents = (Object **)u_cast.dst;
size_t i;
for (i = 0; i < array->length; ++i) {
(*visitor)(&contents[i], arg);
diff --git a/vm/hprof/HprofHeap.c b/vm/hprof/HprofHeap.c
index 75a1d2b4e..8fe7e86ee 100644
--- a/vm/hprof/HprofHeap.c
+++ b/vm/hprof/HprofHeap.c
@@ -376,6 +376,7 @@ hprofDumpHeapObject(hprof_context_t *ctx, const Object *obj)
u4 length = aobj->length;
if (IS_CLASS_FLAG_SET(clazz, CLASS_ISOBJECTARRAY)) {
+ union {void* src; const hprof_object_id* dst}u_cast;
/* obj is an object array.
*/
hprofAddU1ToRecord(rec, HPROF_OBJECT_ARRAY_DUMP);
@@ -387,8 +388,9 @@ hprofDumpHeapObject(hprof_context_t *ctx, const Object *obj)
/* Dump the elements, which are always objects or NULL.
*/
+ u_cast.src = aobj->contents;
hprofAddIdListToRecord(rec,
- (const hprof_object_id *)aobj->contents, length);
+ (const hprof_object_id *)u_cast.dst, length);
} else {
hprof_basic_type t;
size_t size;
@@ -416,10 +418,14 @@ hprofDumpHeapObject(hprof_context_t *ctx, const Object *obj)
hprofAddU1ListToRecord(rec, (const u1 *)aobj->contents,
length);
} else if (size == 2) {
- hprofAddU2ListToRecord(rec, (const u2 *)aobj->contents,
+ union {void* src; const u2* dst;}u_cast;
+ u_cast.src = aobj->contents;
+ hprofAddU2ListToRecord(rec, (const u2 *)u_cast.dst,
length);
} else if (size == 4) {
- hprofAddU4ListToRecord(rec, (const u4 *)aobj->contents,
+ union {void* src; const u4* dst;}u_cast;
+ u_cast.src = aobj->contents;
+ hprofAddU4ListToRecord(rec, (const u4 *)u_cast.dst,
length);
} else if (size == 8) {
hprofAddU8ListToRecord(rec, (const u8 *)aobj->contents,
diff --git a/vm/interp/Stack.c b/vm/interp/Stack.c
index 695aa4494..27cd24045 100644
--- a/vm/interp/Stack.c
+++ b/vm/interp/Stack.c
@@ -698,9 +698,12 @@ Object* dvmInvokeMethod(Object* obj, const Method* method,
DataObject** args;
ClassObject** types;
int i;
+ union {const void* src; DataObject** data_p; ClassObject** class_p;}u_cast;
- args = (DataObject**) argList->contents;
- types = (ClassObject**) params->contents;
+ u_cast.src = argList->contents;
+ args = (DataObject**) u_cast.data_p;
+ u_cast.src = params->contents;
+ types = (ClassObject**) u_cast.class_p;
for (i = 0; i < argListLength; i++) {
int width;
diff --git a/vm/jdwp/JdwpAdb.c b/vm/jdwp/JdwpAdb.c
index c3a1a72ad..1a3a8f3be 100644
--- a/vm/jdwp/JdwpAdb.c
+++ b/vm/jdwp/JdwpAdb.c
@@ -148,6 +148,10 @@ static int receiveClientFd(JdwpNetState* netState)
char buffer[CMSG_SPACE(sizeof(int))];
} cm_un;
int ret;
+ union {
+ const void* src;
+ int* dst;
+ } u_cast;
iov.iov_base = &dummy;
iov.iov_len = 1;
@@ -163,7 +167,8 @@ static int receiveClientFd(JdwpNetState* netState)
cmsg->cmsg_len = msg.msg_controllen;
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
- ((int*)CMSG_DATA(cmsg))[0] = -1;
+ u_cast.src = CMSG_DATA(cmsg);
+ ((int*)u_cast.dst)[0] = -1;
do {
ret = recvmsg(netState->controlSock, &msg, 0);
@@ -181,7 +186,8 @@ static int receiveClientFd(JdwpNetState* netState)
return -1;
}
- return ((int*)CMSG_DATA(cmsg))[0];
+ u_cast.src = CMSG_DATA(cmsg);
+ return ((int*)u_cast.dst)[0];
}
/*
diff --git a/vm/mterp/out/InterpC-allstubs.c b/vm/mterp/out/InterpC-allstubs.c
index ce6192c0d..61da77e76 100644
--- a/vm/mterp/out/InterpC-allstubs.c
+++ b/vm/mterp/out/InterpC-allstubs.c
@@ -986,6 +986,7 @@ GOTO_TARGET_DECL(exceptionThrown);
#define HANDLE_OP_AGET(_opcode, _opname, _type, _regsize) \
HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
{ \
+ union{const void* src; _type* dst;}cast; \
ArrayObject* arrayObj; \
u2 arrayInfo; \
EXPORT_PC(); \
@@ -1004,8 +1005,9 @@ GOTO_TARGET_DECL(exceptionThrown);
NULL); \
GOTO_exceptionThrown(); \
} \
+ cast.src = arrayObj->contents; \
SET_REGISTER##_regsize(vdst, \
- ((_type*) arrayObj->contents)[GET_REGISTER(vsrc2)]); \
+ ((_type*) cast.dst)[GET_REGISTER(vsrc2)]); \
ILOGV("+ AGET[%d]=0x%x", GET_REGISTER(vsrc2), GET_REGISTER(vdst)); \
} \
FINISH(2);
@@ -1013,6 +1015,7 @@ GOTO_TARGET_DECL(exceptionThrown);
#define HANDLE_OP_APUT(_opcode, _opname, _type, _regsize) \
HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
{ \
+ union{const void* src; _type* dst;}cast; \
ArrayObject* arrayObj; \
u2 arrayInfo; \
EXPORT_PC(); \
@@ -1030,7 +1033,8 @@ GOTO_TARGET_DECL(exceptionThrown);
GOTO_exceptionThrown(); \
} \
ILOGV("+ APUT[%d]=0x%08x", GET_REGISTER(vsrc2), GET_REGISTER(vdst));\
- ((_type*) arrayObj->contents)[GET_REGISTER(vsrc2)] = \
+ cast.src = arrayObj->contents; \
+ ((_type*) cast.dst)[GET_REGISTER(vsrc2)] = \
GET_REGISTER##_regsize(vdst); \
} \
FINISH(2);
@@ -3144,6 +3148,7 @@ GOTO_TARGET(filledNewArray, bool methodCallRange)
char typeCh;
int i;
u4 arg5;
+ union{const void* src; u4* dst;}u_cast;
EXPORT_PC();
@@ -3207,7 +3212,8 @@ GOTO_TARGET(filledNewArray, bool methodCallRange)
/*
* Fill in the elements. It's legal for vsrc1 to be zero.
*/
- contents = (u4*) newArray->contents;
+ u_cast.src = newArray->contents;
+ contents = (u4*) u_cast.dst;
if (methodCallRange) {
for (i = 0; i < vsrc1; i++)
contents[i] = GET_REGISTER(vdst+i);
diff --git a/vm/mterp/out/InterpC-portdbg.c b/vm/mterp/out/InterpC-portdbg.c
index e909db45b..a95769da4 100644
--- a/vm/mterp/out/InterpC-portdbg.c
+++ b/vm/mterp/out/InterpC-portdbg.c
@@ -977,6 +977,7 @@ GOTO_TARGET_DECL(exceptionThrown);
#define HANDLE_OP_AGET(_opcode, _opname, _type, _regsize) \
HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
{ \
+ union{const void* src; _type* dst;}cast; \
ArrayObject* arrayObj; \
u2 arrayInfo; \
EXPORT_PC(); \
@@ -995,8 +996,9 @@ GOTO_TARGET_DECL(exceptionThrown);
NULL); \
GOTO_exceptionThrown(); \
} \
+ cast.src = arrayObj->contents; \
SET_REGISTER##_regsize(vdst, \
- ((_type*) arrayObj->contents)[GET_REGISTER(vsrc2)]); \
+ ((_type*) cast.dst)[GET_REGISTER(vsrc2)]); \
ILOGV("+ AGET[%d]=0x%x", GET_REGISTER(vsrc2), GET_REGISTER(vdst)); \
} \
FINISH(2);
@@ -1004,6 +1006,7 @@ GOTO_TARGET_DECL(exceptionThrown);
#define HANDLE_OP_APUT(_opcode, _opname, _type, _regsize) \
HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
{ \
+ union{const void* src; _type* dst;}cast; \
ArrayObject* arrayObj; \
u2 arrayInfo; \
EXPORT_PC(); \
@@ -1021,7 +1024,8 @@ GOTO_TARGET_DECL(exceptionThrown);
GOTO_exceptionThrown(); \
} \
ILOGV("+ APUT[%d]=0x%08x", GET_REGISTER(vsrc2), GET_REGISTER(vdst));\
- ((_type*) arrayObj->contents)[GET_REGISTER(vsrc2)] = \
+ cast.src = arrayObj->contents; \
+ ((_type*) cast.dst)[GET_REGISTER(vsrc2)] = \
GET_REGISTER##_regsize(vdst); \
} \
FINISH(2);
@@ -3423,6 +3427,7 @@ GOTO_TARGET(filledNewArray, bool methodCallRange)
char typeCh;
int i;
u4 arg5;
+ union{const void* src; u4* dst;}u_cast;
EXPORT_PC();
@@ -3486,7 +3491,8 @@ GOTO_TARGET(filledNewArray, bool methodCallRange)
/*
* Fill in the elements. It's legal for vsrc1 to be zero.
*/
- contents = (u4*) newArray->contents;
+ u_cast.src = newArray->contents;
+ contents = (u4*) u_cast.dst;
if (methodCallRange) {
for (i = 0; i < vsrc1; i++)
contents[i] = GET_REGISTER(vdst+i);
diff --git a/vm/mterp/out/InterpC-portstd.c b/vm/mterp/out/InterpC-portstd.c
index f82c97d3a..028fd860e 100644
--- a/vm/mterp/out/InterpC-portstd.c
+++ b/vm/mterp/out/InterpC-portstd.c
@@ -968,6 +968,7 @@ GOTO_TARGET_DECL(exceptionThrown);
#define HANDLE_OP_AGET(_opcode, _opname, _type, _regsize) \
HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
{ \
+ union{const void* src; _type* dst;}cast; \
ArrayObject* arrayObj; \
u2 arrayInfo; \
EXPORT_PC(); \
@@ -986,8 +987,9 @@ GOTO_TARGET_DECL(exceptionThrown);
NULL); \
GOTO_exceptionThrown(); \
} \
+ cast.src = arrayObj->contents; \
SET_REGISTER##_regsize(vdst, \
- ((_type*) arrayObj->contents)[GET_REGISTER(vsrc2)]); \
+ ((_type*) cast.dst)[GET_REGISTER(vsrc2)]); \
ILOGV("+ AGET[%d]=0x%x", GET_REGISTER(vsrc2), GET_REGISTER(vdst)); \
} \
FINISH(2);
@@ -995,6 +997,7 @@ GOTO_TARGET_DECL(exceptionThrown);
#define HANDLE_OP_APUT(_opcode, _opname, _type, _regsize) \
HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \
{ \
+ union{const void* src; _type* dst;}cast; \
ArrayObject* arrayObj; \
u2 arrayInfo; \
EXPORT_PC(); \
@@ -1012,7 +1015,8 @@ GOTO_TARGET_DECL(exceptionThrown);
GOTO_exceptionThrown(); \
} \
ILOGV("+ APUT[%d]=0x%08x", GET_REGISTER(vsrc2), GET_REGISTER(vdst));\
- ((_type*) arrayObj->contents)[GET_REGISTER(vsrc2)] = \
+ cast.src = arrayObj->contents; \
+ ((_type*) cast.dst)[GET_REGISTER(vsrc2)] = \
GET_REGISTER##_regsize(vdst); \
} \
FINISH(2);
@@ -3173,6 +3177,7 @@ GOTO_TARGET(filledNewArray, bool methodCallRange)
char typeCh;
int i;
u4 arg5;
+ union{const void* src; u4* dst;}u_cast;
EXPORT_PC();
@@ -3236,7 +3241,8 @@ GOTO_TARGET(filledNewArray, bool methodCallRange)
/*
* Fill in the elements. It's legal for vsrc1 to be zero.
*/
- contents = (u4*) newArray->contents;
+ u_cast.src = newArray->contents;
+ contents = (u4*) u_cast.dst;
if (methodCallRange) {
for (i = 0; i < vsrc1; i++)
contents[i] = GET_REGISTER(vdst+i);
diff --git a/vm/mterp/out/InterpC-x86.c b/vm/mterp/out/InterpC-x86.c
index 4882184e0..4e3a7bc29 100644
--- a/vm/mterp/out/InterpC-x86.c
+++ b/vm/mterp/out/InterpC-x86.c
@@ -1275,6 +1275,7 @@ GOTO_TARGET(filledNewArray, bool methodCallRange)
char typeCh;
int i;
u4 arg5;
+ union {const void* src; u4* dst;}u_cast;
EXPORT_PC();
@@ -1338,7 +1339,8 @@ GOTO_TARGET(filledNewArray, bool methodCallRange)
/*
* Fill in the elements. It's legal for vsrc1 to be zero.
*/
- contents = (u4*) newArray->contents;
+ u_cast.src = newArray->contents;
+ contents = (u4*) u_cast.dst;
if (methodCallRange) {
for (i = 0; i < vsrc1; i++)
contents[i] = GET_REGISTER(vdst+i);
diff --git a/vm/native/dalvik_system_VMDebug.c b/vm/native/dalvik_system_VMDebug.c
index 192a8f2b8..ab413cf89 100644
--- a/vm/native/dalvik_system_VMDebug.c
+++ b/vm/native/dalvik_system_VMDebug.c
@@ -563,8 +563,10 @@ static void Dalvik_dalvik_system_VMDebug_getInstructionCount(const u4* args,
{
ArrayObject* countArray = (ArrayObject*) args[0];
int* storage;
+ union {const void* src; int* dst;}u_cast;
- storage = (int*) countArray->contents;
+ u_cast.src = countArray->contents;
+ storage = (int*) u_cast.dst;
sched_yield();
memcpy(storage, gDvm.executedInstrCounts,
kNumDalvikInstructions * sizeof(int));
diff --git a/vm/native/dalvik_system_Zygote.c b/vm/native/dalvik_system_Zygote.c
index bcc2313d3..195899639 100644
--- a/vm/native/dalvik_system_Zygote.c
+++ b/vm/native/dalvik_system_Zygote.c
@@ -40,6 +40,12 @@ enum {
DEBUG_ENABLE_SAFEMODE = 1 << 3,
};
+static inline s4* local_cast(void* p){
+ union {const void* src; s4* dst;}u_cast;
+ u_cast.src = p;
+ return u_cast.dst;
+}
+
/*
* This signal handler is for zygote mode, since the zygote
* must reap its children
@@ -168,7 +174,7 @@ static int setgroupsIntarray(ArrayObject* gidArray)
/* just in case gid_t and u4 are different... */
gids = alloca(sizeof(gid_t) * gidArray->length);
- contents = (s4 *)gidArray->contents;
+ contents = local_cast(gidArray->contents);
for (i = 0 ; i < gidArray->length ; i++) {
gids[i] = (gid_t) contents[i];
@@ -189,6 +195,7 @@ static int setrlimitsFromArray(ArrayObject* rlimits)
{
u4 i;
struct rlimit rlim;
+ union {const void* src; ArrayObject** dst;}u_cast;
if (rlimits == NULL) {
return 0;
@@ -196,11 +203,12 @@ static int setrlimitsFromArray(ArrayObject* rlimits)
memset (&rlim, 0, sizeof(rlim));
- ArrayObject** tuples = (ArrayObject **)(rlimits->contents);
+ u_cast.src = rlimits->contents;
+ ArrayObject** tuples = (ArrayObject **)(u_cast.dst);
for (i = 0; i < rlimits->length; i++) {
ArrayObject * rlimit_tuple = tuples[i];
- s4* contents = (s4 *)rlimit_tuple->contents;
+ s4* contents = local_cast(rlimit_tuple->contents);
int err;
if (rlimit_tuple->length != 3) {
diff --git a/vm/native/java_lang_Class.c b/vm/native/java_lang_Class.c
index 3c772d9e3..e9f30bc8e 100644
--- a/vm/native/java_lang_Class.c
+++ b/vm/native/java_lang_Class.c
@@ -192,7 +192,9 @@ static void Dalvik_java_lang_Class_getDeclaredClasses(const u4* args,
}
} else if (publicOnly) {
u4 count, newIdx, publicCount = 0;
- ClassObject** pSource = (ClassObject**) classes->contents;
+ union {const void* src; ClassObject** dst;}u_cast;
+ u_cast.src = classes->contents;
+ ClassObject** pSource = (ClassObject**) u_cast.dst;
u4 length = classes->length;
/* count up public classes */
diff --git a/vm/native/java_lang_System.c b/vm/native/java_lang_System.c
index 4af0dfa42..e0396a2b9 100644
--- a/vm/native/java_lang_System.c
+++ b/vm/native/java_lang_System.c
@@ -20,6 +20,12 @@
#include "Dalvik.h"
#include "native/InternalNativePriv.h"
+static inline Object** local_cast(void* p){
+ union {const void* src; Object** dst;}u_cast;
+ u_cast.src = p;
+ return u_cast.dst;
+}
+
/*
* Call the appropriate copy function given the circumstances.
*/
@@ -195,8 +201,8 @@ static void Dalvik_java_lang_System_arraycopy(const u4* args, JValue* pResult)
int copyCount;
ClassObject* clazz = NULL;
- srcObj = ((Object**) srcArray->contents) + srcPos;
- dstObj = ((Object**) dstArray->contents) + dstPos;
+ srcObj = (local_cast(srcArray->contents)) + srcPos;
+ dstObj = (local_cast(dstArray->contents)) + dstPos;
if (length > 0 && srcObj[0] != NULL)
{
diff --git a/vm/native/java_lang_reflect_Array.c b/vm/native/java_lang_reflect_Array.c
index e7713f679..e2ee7447c 100644
--- a/vm/native/java_lang_reflect_Array.c
+++ b/vm/native/java_lang_reflect_Array.c
@@ -72,6 +72,7 @@ static void Dalvik_java_lang_reflect_Array_createMultiArray(const u4* args,
char* acDescriptor;
int numDim, i;
int* dimensions;
+ union {const void* src; int* dst;}u_cast;
LOGV("createMultiArray: '%s' [%d]\n",
elementClass->descriptor, dimArray->length);
@@ -88,7 +89,8 @@ static void Dalvik_java_lang_reflect_Array_createMultiArray(const u4* args,
numDim = dimArray->length;
assert(numDim > 0 && numDim <= 255);
- dimensions = (int*) dimArray->contents;
+ u_cast.src = dimArray->contents;
+ dimensions = (int*) u_cast.dst;
for (i = 0; i < numDim; i++) {
if (dimensions[i] < 0) {
dvmThrowException("Ljava/lang/NegativeArraySizeException;", NULL);
diff --git a/vm/oo/Array.c b/vm/oo/Array.c
index 4166a8567..5e892405d 100644
--- a/vm/oo/Array.c
+++ b/vm/oo/Array.c
@@ -30,6 +30,11 @@ static ClassObject* createPrimitiveClass(int idx);
static const char gPrimLetter[] = PRIM_TYPE_TO_LETTER;
+static inline Object** local_cast(void* p){
+ union {const void* src; Object** dst;}u_cast;
+ u_cast.src = p;
+ return u_cast.dst;
+}
/*
* Allocate space for a new array object. This is the lowest-level array
* allocation function.
@@ -662,7 +667,7 @@ static ClassObject* createPrimitiveClass(int idx)
bool dvmCopyObjectArray(ArrayObject* dstArray, const ArrayObject* srcArray,
ClassObject* dstElemClass)
{
- Object** src = (Object**)srcArray->contents;
+ Object** src = local_cast(srcArray->contents);
u4 length, count;
assert(srcArray->length == dstArray->length);
@@ -691,7 +696,7 @@ bool dvmCopyObjectArray(ArrayObject* dstArray, const ArrayObject* srcArray,
bool dvmUnboxObjectArray(ArrayObject* dstArray, const ArrayObject* srcArray,
ClassObject* dstElemClass)
{
- Object** src = (Object**)srcArray->contents;
+ Object** src = local_cast(srcArray->contents);
void* dst = (void*)dstArray->contents;
u4 count = dstArray->length;
PrimitiveType typeIndex = dstElemClass->primitiveType;
diff --git a/vm/oo/ObjectInlines.h b/vm/oo/ObjectInlines.h
index 23a72b232..e316a1865 100644
--- a/vm/oo/ObjectInlines.h
+++ b/vm/oo/ObjectInlines.h
@@ -26,7 +26,9 @@
*/
INLINE void dvmSetObjectArrayElement(const ArrayObject* obj, int index,
Object* val) {
- ((Object **)(obj)->contents)[index] = val;
+ union {const Object* src; Object ** dst;}u_cast;
+ u_cast.src = (obj)->contents;
+ ((Object **)u_cast.dst)[index] = val;
if (val != NULL) {
dvmWriteBarrierArray(obj, index, index + 1);
}
diff --git a/vm/reflect/Annotation.c b/vm/reflect/Annotation.c
index a5007bae5..e3e9c60cd 100644
--- a/vm/reflect/Annotation.c
+++ b/vm/reflect/Annotation.c
@@ -187,7 +187,9 @@ static ArrayObject* emptyAnnoArrayArray(int numElements)
arr = dvmAllocArrayByClass(gDvm.classJavaLangAnnotationAnnotationArrayArray,
numElements, ALLOC_DEFAULT);
if (arr != NULL) {
- ArrayObject** elems = (ArrayObject**) arr->contents;
+ union {const void* src; ArrayObject** dst;}u_cast;
+ u_cast.src = arr->contents;
+ ArrayObject** elems = (ArrayObject**) u_cast.dst;
for (i = 0; i < numElements; i++) {
elems[i] = emptyAnnoArray();
dvmReleaseTrackedAlloc((Object*)elems[i], self);
diff --git a/vm/reflect/Proxy.c b/vm/reflect/Proxy.c
index eef658dd1..de5ec6977 100644
--- a/vm/reflect/Proxy.c
+++ b/vm/reflect/Proxy.c
@@ -45,6 +45,17 @@ static void proxyInvoker(const u4* args, JValue* pResult,
const Method* method, Thread* self);
static bool mustWrapException(const Method* method, const Object* throwable);
+static inline Object** cast_to_object(void* p){
+ union {const void* src; Object** dst;}u_cast;
+ u_cast.src = p;
+ return u_cast.dst;
+}
+static inline ClassObject** cast_to_classobject(void* p){
+ union {const void* src; ClassObject** dst;}u_cast;
+ u_cast.src = p;
+ return u_cast.dst;
+}
+
/* private static fields in the Proxy class */
#define kThrowsField 0
#define kProxySFieldCount 1
@@ -223,7 +234,7 @@ ClassObject* dvmGenerateProxyClass(StringObject* str, ArrayObject* interfaces,
* Add interface list.
*/
int interfaceCount = interfaces->length;
- ClassObject** ifArray = (ClassObject**) interfaces->contents;
+ ClassObject** ifArray = cast_to_classobject(interfaces->contents);
newClass->interfaceCount = interfaceCount;
newClass->interfaces = (ClassObject**)dvmLinearAlloc(newClass->classLoader,
sizeof(ClassObject*) * interfaceCount);
@@ -315,7 +326,7 @@ static bool gatherMethods(ArrayObject* interfaces, Method*** pMethods,
*/
maxCount = 3; // 3 methods in java.lang.Object
numInterfaces = interfaces->length;
- classes = (ClassObject**) interfaces->contents;
+ classes = cast_to_classobject(interfaces->contents);
for (i = 0; i < numInterfaces; i++, classes++) {
ClassObject* clazz = *classes;
@@ -351,7 +362,7 @@ static bool gatherMethods(ArrayObject* interfaces, Method*** pMethods,
/*
* Add the methods from each interface, in order.
*/
- classes = (ClassObject**) interfaces->contents;
+ classes = cast_to_classobject(interfaces->contents);
for (i = 0; i < numInterfaces; i++, classes++) {
ClassObject* clazz = *classes;
int j;
@@ -556,14 +567,14 @@ static int copyWithoutDuplicates(Method** allMethods, int allCount,
return -1;
}
- contents = (Object**) throwArray->contents;
+ contents = cast_to_object(throwArray->contents);
for (ent = 0; ent < commonCount; ent++) {
contents[ent] = (Object*)
dvmPointerSetGetEntry(commonThrows, ent);
}
/* add it to the array of arrays */
- contents = (Object**) throwLists->contents;
+ contents = cast_to_object(throwLists->contents);
contents[outCount] = (Object*) throwArray;
dvmReleaseTrackedAlloc((Object*) throwArray, NULL);
}
@@ -589,7 +600,7 @@ static int copyWithoutDuplicates(Method** allMethods, int allCount,
if (exceptionArray != NULL) {
Object** contents;
- contents = (Object**) throwLists->contents;
+ contents = cast_to_object(throwLists->contents);
contents[outCount] = (Object*) exceptionArray;
dvmReleaseTrackedAlloc((Object*) exceptionArray, NULL);
}
@@ -627,7 +638,7 @@ static int copyWithoutDuplicates(Method** allMethods, int allCount,
*/
static void reduceExceptionClassList(ArrayObject* exceptionArray)
{
- const ClassObject** classes = (const ClassObject**)exceptionArray->contents;
+ const ClassObject** classes = cast_to_classobject(exceptionArray->contents);
int len = exceptionArray->length;
int i, j;
@@ -675,7 +686,7 @@ static bool createExceptionClassList(const Method* method, PointerSet** pThrows)
const ClassObject** contents;
int i;
- contents = (const ClassObject**) exceptionArray->contents;
+ contents = cast_to_classobject(exceptionArray->contents);
for (i = 0; i < (int) exceptionArray->length; i++) {
if (contents[i] != NULL)
dvmPointerSetAddEntry(*pThrows, contents[i]);
@@ -720,7 +731,7 @@ static void updateExceptionClassList(const Method* method, PointerSet* throws)
const ClassObject* mixSet[mixLen];
int declLen = exceptionArray->length;
- const ClassObject** declSet = (const ClassObject**)exceptionArray->contents;
+ const ClassObject** declSet = cast_to_classobject(exceptionArray->contents);
int i, j;
@@ -859,7 +870,7 @@ static ArrayObject* boxMethodArgs(const Method* method, const u4* args)
kObjectArrayRefWidth, ALLOC_DEFAULT);
if (argArray == NULL)
goto bail;
- argObjects = (Object**) argArray->contents;
+ argObjects = cast_to_object(argArray->contents);
/*
* Fill in the array.
@@ -1074,7 +1085,7 @@ static bool mustWrapException(const Method* method, const Object* throwable)
int methodIndex = method - method->clazz->virtualMethods;
assert(methodIndex >= 0 && methodIndex < method->clazz->virtualMethodCount);
- contents = (const Object**) throws->contents;
+ contents = cast_to_object(throws->contents);
methodThrows = (ArrayObject*) contents[methodIndex];
if (methodThrows == NULL) {
@@ -1084,7 +1095,7 @@ static bool mustWrapException(const Method* method, const Object* throwable)
}
int throwCount = methodThrows->length;
- classes = (const ClassObject**) methodThrows->contents;
+ classes = cast_to_classobject(methodThrows->contents);
int i;
//printf("%s.%s list:\n", method->clazz->descriptor, method->name);