inlinevoidClass::CheckObjectAlloc() {
DCHECK(!IsArrayClass())
<< PrettyClass()
<< "A array shouldn't be allocated through this "
<< "as it requires a pre-fence visitor that sets the class size.";
DCHECK(!IsClassClass())
<< PrettyClass()
<< "A class object shouldn't be allocated through this "
<< "as it requires a pre-fence visitor that sets the class size.";
DCHECK(!IsStringClass())
<< PrettyClass()
<< "A string shouldn't be allocated through this "
<< "as it requires a pre-fence visitor that sets the class size.";
DCHECK(IsInstantiable()) << PrettyClass(); // TODO: decide whether we want this check. It currently fails during bootstrap. // DCHECK(!Runtime::Current()->IsStarted() || IsInitializing()) << PrettyClass();
DCHECK_GE(this->object_size_, sizeof(Object));
}
template<bool kIsInstrumented, Class::AddFinalizer kAddFinalizer, bool kCheckAddFinalizer> inline ObjPtr<Object> Class::Alloc(Thread* self, gc::AllocatorType allocator_type) {
CheckObjectAlloc();
gc::Heap* heap = Runtime::Current()->GetHeap(); bool add_finalizer; switch (kAddFinalizer) { caseClass::AddFinalizer::kUseClassTag:
add_finalizer = IsFinalizable(); break; caseClass::AddFinalizer::kNoAddFinalizer:
add_finalizer = false;
DCHECK_IMPLIES(kCheckAddFinalizer, !IsFinalizable()); break;
} // Note that the `this` pointer may be invalidated after the allocation.
ObjPtr<Object> obj =
heap->AllocObjectWithAllocator<kIsInstrumented, /*kCheckLargeObject=*/ false>(
self, this, this->object_size_, allocator_type, VoidFunctor()); if (add_finalizer && LIKELY(obj != nullptr)) {
heap->AddFinalizerReference(self, &obj); if (UNLIKELY(self->IsExceptionPending())) { // Failed to allocate finalizer reference, it means that the whole allocation failed.
obj = nullptr;
}
} return obj;
}
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.