Type the reference member of JValue as an Object pointer.
Previously this had been a void pointer. To avoid adding lots of
casts from the logical Object subtypes to Object the RETURN_PTR macro
silently casts its argument to an Object* before performing an
assignment to the JValue return value. After an inheritance
relationship is established between Object and its subtypes this cast
can be removed.
Change-Id: Id05e5c11e57e2a9afd12bad0be095f1dfe9e1f51
diff --git a/vm/Common.h b/vm/Common.h
index 637ed18..aacbbbd 100644
--- a/vm/Common.h
+++ b/vm/Common.h
@@ -88,7 +88,9 @@
* yield the same result. This seems to be guaranteed by gcc on big- and
* little-endian systems.
*/
-typedef union JValue {
+struct Object;
+
+union JValue {
u1 z;
s1 b;
u2 c;
@@ -97,8 +99,8 @@
s8 j;
float f;
double d;
- void* l;
-} JValue;
+ Object* l;
+};
#define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0])))
diff --git a/vm/Jni.cpp b/vm/Jni.cpp
index 1727402..6ddff9b 100644
--- a/vm/Jni.cpp
+++ b/vm/Jni.cpp
@@ -1919,7 +1919,7 @@
dvmCallMethodV(ts.self(), meth, obj, true, &result, args); \
va_end(args); \
if (_isref && !dvmCheckException(ts.self())) \
- result.l = addLocalReference(env, (Object*)result.l); \
+ result.l = (Object*)addLocalReference(env, result.l); \
return _retok; \
} \
static _ctype Call##_jname##MethodV(JNIEnv* env, jobject jobj, \
@@ -1935,7 +1935,7 @@
} \
dvmCallMethodV(ts.self(), meth, obj, true, &result, args); \
if (_isref && !dvmCheckException(ts.self())) \
- result.l = addLocalReference(env, (Object*)result.l); \
+ result.l = (Object*)addLocalReference(env, result.l); \
return _retok; \
} \
static _ctype Call##_jname##MethodA(JNIEnv* env, jobject jobj, \
@@ -1951,7 +1951,7 @@
} \
dvmCallMethodA(ts.self(), meth, obj, true, &result, args); \
if (_isref && !dvmCheckException(ts.self())) \
- result.l = addLocalReference(env, (Object*)result.l); \
+ result.l = (Object*)addLocalReference(env, result.l); \
return _retok; \
}
CALL_VIRTUAL(jobject, Object, NULL, (jobject) result.l, true);
@@ -1990,7 +1990,7 @@
va_start(args, methodID); \
dvmCallMethodV(ts.self(), meth, obj, true, &result, args); \
if (_isref && !dvmCheckException(ts.self())) \
- result.l = addLocalReference(env, (Object*)result.l); \
+ result.l = (Object*)addLocalReference(env, result.l); \
va_end(args); \
return _retok; \
} \
@@ -2009,7 +2009,7 @@
} \
dvmCallMethodV(ts.self(), meth, obj, true, &result, args); \
if (_isref && !dvmCheckException(ts.self())) \
- result.l = addLocalReference(env, (Object*)result.l); \
+ result.l = (Object*)addLocalReference(env, result.l); \
return _retok; \
} \
static _ctype CallNonvirtual##_jname##MethodA(JNIEnv* env, jobject jobj,\
@@ -2027,7 +2027,7 @@
} \
dvmCallMethodA(ts.self(), meth, obj, true, &result, args); \
if (_isref && !dvmCheckException(ts.self())) \
- result.l = addLocalReference(env, (Object*)result.l); \
+ result.l = (Object*)addLocalReference(env, result.l); \
return _retok; \
}
CALL_NONVIRTUAL(jobject, Object, NULL, (jobject) result.l, true);
@@ -2057,7 +2057,7 @@
dvmCallMethodV(ts.self(), (Method*)methodID, NULL, true, &result, args);\
va_end(args); \
if (_isref && !dvmCheckException(ts.self())) \
- result.l = addLocalReference(env, (Object*)result.l); \
+ result.l = (Object*)addLocalReference(env, result.l); \
return _retok; \
} \
static _ctype CallStatic##_jname##MethodV(JNIEnv* env, jclass jclazz, \
@@ -2068,7 +2068,7 @@
JValue result; \
dvmCallMethodV(ts.self(), (Method*)methodID, NULL, true, &result, args);\
if (_isref && !dvmCheckException(ts.self())) \
- result.l = addLocalReference(env, (Object*)result.l); \
+ result.l = (Object*)addLocalReference(env, result.l); \
return _retok; \
} \
static _ctype CallStatic##_jname##MethodA(JNIEnv* env, jclass jclazz, \
@@ -2079,7 +2079,7 @@
JValue result; \
dvmCallMethodA(ts.self(), (Method*)methodID, NULL, true, &result, args);\
if (_isref && !dvmCheckException(ts.self())) \
- result.l = addLocalReference(env, (Object*)result.l); \
+ result.l = (Object*)addLocalReference(env, result.l); \
return _retok; \
}
CALL_STATIC(jobject, Object, NULL, (jobject) result.l, true);
diff --git a/vm/mterp/c/gotoTargets.cpp b/vm/mterp/c/gotoTargets.cpp
index c615cba..18f4c04 100644
--- a/vm/mterp/c/gotoTargets.cpp
+++ b/vm/mterp/c/gotoTargets.cpp
@@ -106,7 +106,7 @@
dvmWriteBarrierArray(newArray, 0, newArray->length);
}
- retval.l = newArray;
+ retval.l = (Object*)newArray;
}
if (jumboFormat) {
FINISH(5);
diff --git a/vm/mterp/out/InterpC-allstubs.cpp b/vm/mterp/out/InterpC-allstubs.cpp
index 8c3920e..8152736 100644
--- a/vm/mterp/out/InterpC-allstubs.cpp
+++ b/vm/mterp/out/InterpC-allstubs.cpp
@@ -4511,7 +4511,7 @@
dvmWriteBarrierArray(newArray, 0, newArray->length);
}
- retval.l = newArray;
+ retval.l = (Object*)newArray;
}
if (jumboFormat) {
FINISH(5);
diff --git a/vm/mterp/out/InterpC-portable.cpp b/vm/mterp/out/InterpC-portable.cpp
index 9ce1dbf..0eb74c3 100644
--- a/vm/mterp/out/InterpC-portable.cpp
+++ b/vm/mterp/out/InterpC-portable.cpp
@@ -4470,7 +4470,7 @@
dvmWriteBarrierArray(newArray, 0, newArray->length);
}
- retval.l = newArray;
+ retval.l = (Object*)newArray;
}
if (jumboFormat) {
FINISH(5);
diff --git a/vm/mterp/out/InterpC-x86-atom.cpp b/vm/mterp/out/InterpC-x86-atom.cpp
index 96415cb..0a53b14 100644
--- a/vm/mterp/out/InterpC-x86-atom.cpp
+++ b/vm/mterp/out/InterpC-x86-atom.cpp
@@ -1600,7 +1600,7 @@
dvmWriteBarrierArray(newArray, 0, newArray->length);
}
- retval.l = newArray;
+ retval.l = (Object*)newArray;
}
if (jumboFormat) {
FINISH(5);
diff --git a/vm/mterp/out/InterpC-x86.cpp b/vm/mterp/out/InterpC-x86.cpp
index 7f89d62..5f31de6 100644
--- a/vm/mterp/out/InterpC-x86.cpp
+++ b/vm/mterp/out/InterpC-x86.cpp
@@ -1542,7 +1542,7 @@
dvmWriteBarrierArray(newArray, 0, newArray->length);
}
- retval.l = newArray;
+ retval.l = (Object*)newArray;
}
if (jumboFormat) {
FINISH(5);
diff --git a/vm/native/InternalNativePriv.h b/vm/native/InternalNativePriv.h
index 440e60d..9489ca2 100644
--- a/vm/native/InternalNativePriv.h
+++ b/vm/native/InternalNativePriv.h
@@ -34,7 +34,7 @@
#define RETURN_LONG(_val) do { pResult->j = (_val); return; } while(0)
#define RETURN_FLOAT(_val) do { pResult->f = (_val); return; } while(0)
#define RETURN_DOUBLE(_val) do { pResult->d = (_val); return; } while(0)
-#define RETURN_PTR(_val) do { pResult->l = (_val); return; } while(0)
+#define RETURN_PTR(_val) do { pResult->l = (Object*)(_val); return; } while(0)
/*
* Normally a method that has an "inline native" will be invoked using
diff --git a/vm/oo/ObjectInlines.h b/vm/oo/ObjectInlines.h
index ef01834..7035d0e 100644
--- a/vm/oo/ObjectInlines.h
+++ b/vm/oo/ObjectInlines.h
@@ -118,7 +118,7 @@
return alias.dval;
}
INLINE Object* dvmGetFieldObjectVolatile(const Object* obj, int offset) {
- void** ptr = &((JValue*)BYTE_OFFSET(obj, offset))->l;
+ Object** ptr = &((JValue*)BYTE_OFFSET(obj, offset))->l;
return (Object*)android_atomic_acquire_load((int32_t*)ptr);
}
@@ -193,7 +193,7 @@
dvmSetFieldLongVolatile(obj, offset, alias.lval);
}
INLINE void dvmSetFieldObjectVolatile(Object* obj, int offset, Object* val) {
- void** ptr = &((JValue*)BYTE_OFFSET(obj, offset))->l;
+ Object** ptr = &((JValue*)BYTE_OFFSET(obj, offset))->l;
ANDROID_MEMBAR_STORE();
*ptr = val;
ANDROID_MEMBAR_FULL();
@@ -276,7 +276,7 @@
return alias.dval;
}
INLINE Object* dvmGetStaticFieldObjectVolatile(const StaticField* sfield) {
- void* const* ptr = &(sfield->value.l);
+ Object* const* ptr = &(sfield->value.l);
return (Object*)android_atomic_acquire_load((int32_t*)ptr);
}
@@ -345,7 +345,7 @@
dvmSetStaticFieldLongVolatile(sfield, alias.lval);
}
INLINE void dvmSetStaticFieldObjectVolatile(StaticField* sfield, Object* val) {
- void** ptr = &(sfield->value.l);
+ Object** ptr = &(sfield->value.l);
ANDROID_MEMBAR_STORE();
*ptr = val;
ANDROID_MEMBAR_FULL();