inline size_t Array::SizeOf(size_t component_size_shift, int32_t component_count) { // This is safe from overflow because the array was already allocated.
size_t header_size = DataOffset(1U << component_size_shift).SizeValue();
size_t data_size = component_count << component_size_shift; return header_size + data_size;
}
template <VerifyObjectFlags kVerifyFlags, ReadBarrierOption kReadBarrierOption> inline size_t Array::SizeOf() {
size_t component_size_shift = GetClass<kVerifyFlags, kReadBarrierOption>()
->template GetComponentSizeShift<kReadBarrierOption>(); // Don't need to check this since we already check this in GetClass. returnSizeOf<static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis)>(component_size_shift);
}
template<typename T> inline T PrimitiveArray<T>::Get(int32_t i) { if (!CheckIsValidIndex(i)) {
DCHECK(Thread::Current()->IsExceptionPending()); return T(0);
} return GetWithoutChecks(i);
}
template<typename T> inlinevoid PrimitiveArray<T>::Set(int32_t i, T value) { if (Runtime::Current()->IsActiveTransaction()) {
Set<true>(i, value);
} else {
Set<false>(i, value);
}
}
template<typename T> template<bool kTransactionActive, bool kCheckTransaction> inlinevoid PrimitiveArray<T>::Set(int32_t i, T value) { if (CheckIsValidIndex(i)) {
SetWithoutChecks<kTransactionActive, kCheckTransaction>(i, value);
} else {
DCHECK(Thread::Current()->IsExceptionPending());
}
}
template<typename T> template<bool kTransactionActive, bool kCheckTransaction, VerifyObjectFlags kVerifyFlags> inlinevoid PrimitiveArray<T>::SetWithoutChecks(int32_t i, T value) { if (kCheckTransaction) {
DCHECK_EQ(kTransactionActive, Runtime::Current()->IsActiveTransaction());
} if (kTransactionActive) {
Runtime::Current()->GetClassLinker()->RecordWriteArray(this, i, GetWithoutChecks(i));
}
DCHECK(CheckIsValidIndex<kVerifyFlags>(i)) << i << " " << GetLength<kVerifyFlags>();
GetData()[i] = value;
} // Backward copy where elements are of aligned appropriately for T. Count is in T sized units. // Copies are guaranteed not to tear when the sizeof T is less-than 64bit. template<typename T> staticinlinevoid ArrayBackwardCopy(T* d, const T* s, int32_t count) {
d += count;
s += count; for (int32_t i = 0; i < count; ++i) {
d--;
s--;
*d = *s;
}
}
// Forward copy where elements are of aligned appropriately for T. Count is in T sized units. // Copies are guaranteed not to tear when the sizeof T is less-than 64bit. template<typename T> staticinlinevoid ArrayForwardCopy(T* d, const T* s, int32_t count) { for (int32_t i = 0; i < count; ++i) {
*d = *s;
d++;
s++;
}
}
template<typename T, PointerSize kPointerSize, VerifyObjectFlags kVerifyFlags> inline T PointerArray::GetElementPtrSizeUnchecked(uint32_t idx) { // C style casts here since we sometimes have T be a pointer, or sometimes an integer // (for stack traces). using ConversionType = typename std::conditional_t<std::is_pointer_v<T>, uintptr_t, T>; // Note: we cast the array directly when unchecked as this code gets called by // runtime_image, which can pass a 64bit pointer and therefore cannot be held // by an ObjPtr. if (kPointerSize == PointerSize::k64) {
uint64_t value = static_cast<uint64_t>(reinterpret_cast<LongArray*>(this)->GetWithoutChecks(idx)); return (T) dchecked_integral_cast<ConversionType>(value);
} else {
uint32_t value = static_cast<uint32_t>(reinterpret_cast<IntArray*>(this)->GetWithoutChecks(idx)); return (T) dchecked_integral_cast<ConversionType>(value);
}
}
template<bool kTransactionActive, bool kCheckTransaction, bool kUnchecked> inlinevoid PointerArray::SetElementPtrSize(uint32_t idx, uint64_t element, PointerSize ptr_size) { // Note: we cast the array directly when unchecked as this code gets called by // runtime_image, which can pass a 64bit pointer and therefore cannot be held // by an ObjPtr. if (ptr_size == PointerSize::k64) {
(kUnchecked ? reinterpret_cast<LongArray*>(this) : AsLongArray().Ptr())->
SetWithoutChecks<kTransactionActive, kCheckTransaction>(idx, element);
} else {
uint32_t element32 = dchecked_integral_cast<uint32_t>(element);
(kUnchecked ? reinterpret_cast<IntArray*>(this) : AsIntArray().Ptr())
->SetWithoutChecks<kTransactionActive, kCheckTransaction>(idx, element32);
}
}
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.