staticvoid ThrowArrayStoreException_NotAnArray(constchar* identifier,
ObjPtr<mirror::Object> array)
REQUIRES_SHARED(Locks::mutator_lock_) {
std::string actualType(mirror::Object::PrettyTypeOf(array));
Thread* self = Thread::Current();
self->ThrowNewExceptionF("Ljava/lang/ArrayStoreException;", "%s of type %s is not an array", identifier, actualType.c_str());
}
staticvoid System_arraycopy(JNIEnv* env, jclass, jobject javaSrc, jint srcPos, jobject javaDst,
jint dstPos, jint length) { // The API is defined in terms of length, but length is somewhat overloaded so we use count. const jint count = length;
ScopedFastNativeObjectAccess soa(env);
if (LIKELY(srcComponentType == dstComponentType)) { // Trivial assignability. switch (dstComponentPrimitiveType) { case Primitive::kPrimVoid:
LOG(FATAL) << "Unreachable, cannot have arrays of type void";
UNREACHABLE(); case Primitive::kPrimBoolean: case Primitive::kPrimByte:
DCHECK_EQ(Primitive::ComponentSize(dstComponentPrimitiveType), 1U); // Note: Treating BooleanArray as ByteArray.
ObjPtr<mirror::ByteArray>::DownCast(dstArray)->Memmove(
dstPos, ObjPtr<mirror::ByteArray>::DownCast(srcArray), srcPos, count); return; case Primitive::kPrimChar: case Primitive::kPrimShort:
DCHECK_EQ(Primitive::ComponentSize(dstComponentPrimitiveType), 2U); // Note: Treating CharArray as ShortArray.
ObjPtr<mirror::ShortArray>::DownCast(dstArray)->Memmove(
dstPos, ObjPtr<mirror::ShortArray>::DownCast(srcArray), srcPos, count); return; case Primitive::kPrimInt: case Primitive::kPrimFloat:
DCHECK_EQ(Primitive::ComponentSize(dstComponentPrimitiveType), 4U); // Note: Treating FloatArray as IntArray.
ObjPtr<mirror::IntArray>::DownCast(dstArray)->Memmove(
dstPos, ObjPtr<mirror::IntArray>::DownCast(srcArray), srcPos, count); return; case Primitive::kPrimLong: case Primitive::kPrimDouble:
DCHECK_EQ(Primitive::ComponentSize(dstComponentPrimitiveType), 8U); // Note: Treating DoubleArray as LongArray.
ObjPtr<mirror::LongArray>::DownCast(dstArray)->Memmove(
dstPos, ObjPtr<mirror::LongArray>::DownCast(srcArray), srcPos, count); return; case Primitive::kPrimNot: {
ObjPtr<mirror::ObjectArray<mirror::Object>> dstObjArray =
dstArray->AsObjectArray<mirror::Object>();
ObjPtr<mirror::ObjectArray<mirror::Object>> srcObjArray =
srcArray->AsObjectArray<mirror::Object>();
dstObjArray->AssignableMemmove(dstPos, srcObjArray, srcPos, count); return;
} default:
LOG(FATAL) << "Unknown array type: " << srcArray->PrettyTypeOf();
UNREACHABLE();
}
} // If one of the arrays holds a primitive type the other array must hold the exact same type. if (UNLIKELY((dstComponentPrimitiveType != Primitive::kPrimNot) ||
srcComponentType->IsPrimitive())) {
std::string srcType(srcArray->PrettyTypeOf());
std::string dstType(dstArray->PrettyTypeOf());
soa.Self()->ThrowNewExceptionF("Ljava/lang/ArrayStoreException;", "Incompatible types: src=%s, dst=%s",
srcType.c_str(), dstType.c_str()); return;
} // Arrays hold distinct types and so therefore can't alias - use memcpy instead of memmove.
ObjPtr<mirror::ObjectArray<mirror::Object>> dstObjArray =
dstArray->AsObjectArray<mirror::Object>();
ObjPtr<mirror::ObjectArray<mirror::Object>> srcObjArray =
srcArray->AsObjectArray<mirror::Object>(); // If we're assigning into say Object[] then we don't need per element checks. if (dstComponentType->IsAssignableFrom(srcComponentType)) {
dstObjArray->AssignableMemcpy(dstPos, srcObjArray, srcPos, count); return;
} // This code is never run under a transaction.
DCHECK(!Runtime::Current()->IsActiveTransaction());
dstObjArray->AssignableCheckingMemcpy<false>(dstPos, srcObjArray, srcPos, count, true);
}
// Template to convert general array to that of its specific primitive type. template <typename T> inline ObjPtr<T> AsPrimitiveArray(ObjPtr<mirror::Array> array)
REQUIRES_SHARED(Locks::mutator_lock_) { return ObjPtr<T>::DownCast(array);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.