// Check for size_t overflow if this was an unreasonable request // but let the caller throw OutOfMemoryError. #ifdef __LP64__ // 64-bit. No overflow as component_count is 32-bit and the maximum // component size is 8.
DCHECK_LE((1U << component_size_shift), 8U); #else // 32-bit.
DCHECK_NE(header_size, 0U);
DCHECK_EQ(RoundUp(header_size, component_size), header_size); // The array length limit (exclusive). const size_t length_limit = (0U - header_size) >> component_size_shift; if (UNLIKELY(length_limit <= static_cast<size_t>(component_count))) { return0; // failure
} #endif return size;
}
// Used for setting the array length in the allocation code path to ensure it is guarded by a // StoreStore fence. class SetLengthVisitor { public: explicit SetLengthVisitor(int32_t length) : length_(length) {
}
voidoperator()(ObjPtr<Object> obj, [[maybe_unused]] size_t usable_size) const
REQUIRES_SHARED(Locks::mutator_lock_) { // Avoid AsArray as object is not yet in live bitmap or allocation stack.
ObjPtr<Array> array = ObjPtr<Array>::DownCast(obj); // DCHECK(array->IsArrayInstance());
array->SetLength(length_);
}
private: const int32_t length_;
DISALLOW_COPY_AND_ASSIGN(SetLengthVisitor);
};
// Similar to SetLengthVisitor, used for setting the array length to fill the usable size of an // array. class SetLengthToUsableSizeVisitor { public:
SetLengthToUsableSizeVisitor(int32_t min_length, size_t header_size,
size_t component_size_shift) :
minimum_length_(min_length), header_size_(header_size),
component_size_shift_(component_size_shift) {
}
voidoperator()(ObjPtr<Object> obj, size_t usable_size) const
REQUIRES_SHARED(Locks::mutator_lock_) { // Avoid AsArray as object is not yet in live bitmap or allocation stack.
ObjPtr<Array> array = ObjPtr<Array>::DownCast(obj); // DCHECK(array->IsArrayInstance());
int32_t length = (usable_size - header_size_) >> component_size_shift_;
DCHECK_GE(length, minimum_length_);
uint8_t* old_end = reinterpret_cast<uint8_t*>(array->GetRawData(1U << component_size_shift_,
minimum_length_));
uint8_t* new_end = reinterpret_cast<uint8_t*>(array->GetRawData(1U << component_size_shift_,
length)); // Ensure space beyond original allocation is zeroed.
memset(old_end, 0, new_end - old_end);
array->SetLength(length);
}
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.