// If the method is not a constructor, or has parameter annotations // for each parameter, then we can return those annotations // unmodified. Otherwise, we need to look at whether the // constructor has implicit parameters as these may need padding // with empty parameter annotations. if (!method->IsConstructor() ||
annotations->GetLength() == static_cast<int>(method->GetNumberOfParameters())) { return soa.AddLocalReference<jobjectArray>(annotations.Get());
}
// If declaring class is a local or an enum, do not pad parameter // annotations, as the implicit constructor parameters are an implementation // detail rather than required by JLS.
Handle<mirror::Class> declaring_class = hs.NewHandle(method->GetDeclaringClass()); if (annotations::GetEnclosingMethod(declaring_class) != nullptr ||
declaring_class->IsEnum()) { return soa.AddLocalReference<jobjectArray>(annotations.Get());
}
// Prepare to resize the annotations so there is 1:1 correspondence // with the constructor parameters.
Handle<mirror::ObjectArray<mirror::Object>> resized_annotations = hs.NewHandle(
mirror::ObjectArray<mirror::Object>::Alloc(
soa.Self(),
annotations->GetClass(), static_cast<int>(method->GetNumberOfParameters()))); if (resized_annotations.IsNull()) {
DCHECK(soa.Self()->IsExceptionPending()); return nullptr;
}
static constexpr bool kTransactionActive = false; const int32_t offset = resized_annotations->GetLength() - annotations->GetLength(); if (offset > 0) { // Workaround for dexers (d8/dx) that do not insert annotations // for implicit parameters (b/68033708).
ObjPtr<mirror::Class> annotation_array_class =
WellKnownClasses::ToClass(WellKnownClasses::java_lang_annotation_Annotation__array);
Handle<mirror::ObjectArray<mirror::Object>> empty_annotations = hs.NewHandle(
mirror::ObjectArray<mirror::Object>::Alloc(soa.Self(), annotation_array_class, 0)); if (empty_annotations.IsNull()) {
DCHECK(soa.Self()->IsExceptionPending()); return nullptr;
} for (int i = 0; i < offset; ++i) {
resized_annotations->SetWithoutChecks<kTransactionActive>(i, empty_annotations.Get());
} for (int i = 0; i < annotations->GetLength(); ++i) {
ObjPtr<mirror::Object> annotation = annotations->GetWithoutChecks(i);
resized_annotations->SetWithoutChecks<kTransactionActive>(i + offset, annotation);
}
} else { // Workaround for Jack (defunct) erroneously inserting annotations // for local classes (b/68033708).
DCHECK_LT(offset, 0); for (int i = 0; i < resized_annotations->GetLength(); ++i) {
ObjPtr<mirror::Object> annotation = annotations->GetWithoutChecks(i - offset);
resized_annotations->SetWithoutChecks<kTransactionActive>(i, annotation);
}
} return soa.AddLocalReference<jobjectArray>(resized_annotations.Get());
}
// Mutable handles used in the loop below to ensure cleanup without scaling the number of // handles by the number of parameters.
MutableHandle<mirror::String> name = hs.NewHandle<mirror::String>(nullptr);
// Populate the Parameter[] to return. for (int32_t parameter_index = 0; parameter_index < names_count; parameter_index++) {
name.Assign(names.Get()->Get(parameter_index));
int32_t modifiers = access_flags.Get()->Get(parameter_index);
// Create the Parameter to add to parameter_array.
ObjPtr<mirror::Object> parameter = parameter_init->NewObject<'L', 'I', 'L', 'I'>(
self, name, modifiers, executable, parameter_index); if (UNLIKELY(parameter == nullptr)) {
DCHECK(self->IsExceptionPending()); return nullptr;
}
// We're initializing a newly allocated array object, so we do not need to record that under // a transaction. If the transaction is aborted, the whole object shall be unreachable.
parameter_array->SetWithoutChecks</*kTransactionActive=*/ false, /*kCheckTransaction=*/ false>(
parameter_index, parameter);
} return soa.AddLocalReference<jobjectArray>(parameter_array.Get());
}
// Get dex files early. (`ArtMethod::GetParameterTypeList()` includes `GetDexFile()`, // so the compiler should deduplicate these subexpressions after inlining.) const DexFile* this_dex_file = this_method->GetDexFile(); const DexFile* other_dex_file = other_method->GetDexFile();
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.