From 104883b04617a850adf11f05e57c2fd29e09c83c Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Fri, 9 Nov 2018 17:12:23 +0000 Subject: Clean up primitive array helpers in Object. Refactor these helpers and avoid read barriers. Remove Class::Is{Int,Long}ArrayClass() and use the Object helpers instead. Remove the AsByteSizedArray() and AsShortSizedArray() helpers that essentially break the type system and rewrite their users, adding appropriate notes. {Float,Double}Array uses in Unsafe would have previously failed a DCHECK(). Test: Additional test in 004-UnsafeTest. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Change-Id: I88b7e3df7de883f64cfc5eb437a40646f2884685 --- runtime/native/java_lang_System.cc | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'runtime/native/java_lang_System.cc') diff --git a/runtime/native/java_lang_System.cc b/runtime/native/java_lang_System.cc index 2c4184c285..e4bc8ce5a2 100644 --- a/runtime/native/java_lang_System.cc +++ b/runtime/native/java_lang_System.cc @@ -101,32 +101,36 @@ static void System_arraycopy(JNIEnv* env, jclass, jobject javaSrc, jint srcPos, case Primitive::kPrimBoolean: case Primitive::kPrimByte: DCHECK_EQ(Primitive::ComponentSize(dstComponentPrimitiveType), 1U); - dstArray->AsByteSizedArray()->Memmove(dstPos, srcArray->AsByteSizedArray(), srcPos, count); + // Note: Treating BooleanArray as ByteArray. + ObjPtr::DownCast(dstArray)->Memmove( + dstPos, ObjPtr::DownCast(srcArray), srcPos, count); return; case Primitive::kPrimChar: case Primitive::kPrimShort: DCHECK_EQ(Primitive::ComponentSize(dstComponentPrimitiveType), 2U); - dstArray->AsShortSizedArray()->Memmove(dstPos, srcArray->AsShortSizedArray(), srcPos, count); + // Note: Treating CharArray as ShortArray. + ObjPtr::DownCast(dstArray)->Memmove( + dstPos, ObjPtr::DownCast(srcArray), srcPos, count); return; case Primitive::kPrimInt: - DCHECK_EQ(Primitive::ComponentSize(dstComponentPrimitiveType), 4U); - dstArray->AsIntArray()->Memmove(dstPos, srcArray->AsIntArray(), srcPos, count); - return; case Primitive::kPrimFloat: DCHECK_EQ(Primitive::ComponentSize(dstComponentPrimitiveType), 4U); - dstArray->AsFloatArray()->Memmove(dstPos, srcArray->AsFloatArray(), srcPos, count); + // Note: Treating FloatArray as IntArray. + ObjPtr::DownCast(dstArray)->Memmove( + dstPos, ObjPtr::DownCast(srcArray), srcPos, count); return; case Primitive::kPrimLong: - DCHECK_EQ(Primitive::ComponentSize(dstComponentPrimitiveType), 8U); - dstArray->AsLongArray()->Memmove(dstPos, srcArray->AsLongArray(), srcPos, count); - return; case Primitive::kPrimDouble: DCHECK_EQ(Primitive::ComponentSize(dstComponentPrimitiveType), 8U); - dstArray->AsDoubleArray()->Memmove(dstPos, srcArray->AsDoubleArray(), srcPos, count); + // Note: Treating DoubleArray as LongArray. + ObjPtr::DownCast(dstArray)->Memmove( + dstPos, ObjPtr::DownCast(srcArray), srcPos, count); return; case Primitive::kPrimNot: { - mirror::ObjectArray* dstObjArray = dstArray->AsObjectArray(); - mirror::ObjectArray* srcObjArray = srcArray->AsObjectArray(); + mirror::ObjectArray* dstObjArray = + dstArray->AsObjectArray(); + mirror::ObjectArray* srcObjArray = + srcArray->AsObjectArray(); dstObjArray->AssignableMemmove(dstPos, srcObjArray, srcPos, count); return; } -- cgit v1.2.3-59-g8ed1b