verifier: Pass ClassDef as a reference
Tiny refactor. ClassDef should never be null, yet we pass it as
a pointer, check it is not null and dereference everywhere.
Change-Id: Id89a1f599f1289d3cc00846306a890e06e438f88
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index 39f01d8..b5bc2fb 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -2289,7 +2289,7 @@
&dex_file,
dex_cache,
class_loader,
- &class_def,
+ class_def,
Runtime::Current()->GetCompilerCallbacks(),
true /* allow soft failures */,
log_level_,
diff --git a/oatdump/oatdump.cc b/oatdump/oatdump.cc
index 36421ff..c87a18b 100644
--- a/oatdump/oatdump.cc
+++ b/oatdump/oatdump.cc
@@ -1268,7 +1268,7 @@
DCHECK(options_.class_loader_ != nullptr);
return verifier::MethodVerifier::VerifyMethodAndDump(
soa.Self(), vios, dex_method_idx, dex_file, dex_cache, *options_.class_loader_,
- &class_def, code_item, nullptr, method_access_flags);
+ class_def, code_item, nullptr, method_access_flags);
}
return nullptr;
diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc
index 2259b41..589e71c 100644
--- a/runtime/verifier/method_verifier.cc
+++ b/runtime/verifier/method_verifier.cc
@@ -159,7 +159,7 @@
&dex_file,
dex_cache,
class_loader,
- class_def,
+ *class_def,
callbacks,
allow_soft_failures,
log_level,
@@ -190,7 +190,7 @@
MethodVerifier::FailureData MethodVerifier::VerifyMethods(Thread* self,
ClassLinker* linker,
const DexFile* dex_file,
- const DexFile::ClassDef* class_def,
+ const DexFile::ClassDef& class_def,
ClassDataItemIterator* it,
Handle<mirror::DexCache> dex_cache,
Handle<mirror::ClassLoader> class_loader,
@@ -214,7 +214,7 @@
continue;
}
previous_method_idx = method_idx;
- InvokeType type = it->GetMethodInvokeType(*class_def);
+ InvokeType type = it->GetMethodInvokeType(class_def);
ArtMethod* method = linker->ResolveMethod<ClassLinker::kNoICCECheckForCache>(
*dex_file, method_idx, dex_cache, class_loader, nullptr, type);
if (method == nullptr) {
@@ -247,7 +247,7 @@
} else {
// If we didn't log a hard failure before, print the header of the message.
*error_string += "Verifier rejected class ";
- *error_string += PrettyDescriptor(dex_file->GetClassDescriptor(*class_def));
+ *error_string += PrettyDescriptor(dex_file->GetClassDescriptor(class_def));
*error_string += ":";
}
*error_string += " ";
@@ -264,23 +264,22 @@
const DexFile* dex_file,
Handle<mirror::DexCache> dex_cache,
Handle<mirror::ClassLoader> class_loader,
- const DexFile::ClassDef* class_def,
+ const DexFile::ClassDef& class_def,
CompilerCallbacks* callbacks,
bool allow_soft_failures,
LogSeverity log_level,
std::string* error) {
- DCHECK(class_def != nullptr);
ScopedTrace trace(__FUNCTION__);
// A class must not be abstract and final.
- if ((class_def->access_flags_ & (kAccAbstract | kAccFinal)) == (kAccAbstract | kAccFinal)) {
+ if ((class_def.access_flags_ & (kAccAbstract | kAccFinal)) == (kAccAbstract | kAccFinal)) {
*error = "Verifier rejected class ";
- *error += PrettyDescriptor(dex_file->GetClassDescriptor(*class_def));
+ *error += PrettyDescriptor(dex_file->GetClassDescriptor(class_def));
*error += ": class is abstract and final.";
return kHardFailure;
}
- const uint8_t* class_data = dex_file->GetClassData(*class_def);
+ const uint8_t* class_data = dex_file->GetClassData(class_def);
if (class_data == nullptr) {
// empty class, probably a marker interface
return kNoFailure;
@@ -327,7 +326,7 @@
// warning.
std::string tmp =
StringPrintf("Class %s failed lock verification and will run slower.",
- PrettyDescriptor(dex_file->GetClassDescriptor(*class_def)).c_str());
+ PrettyDescriptor(dex_file->GetClassDescriptor(class_def)).c_str());
if (!gPrintedDxMonitorText) {
tmp = tmp + "\nCommon causes for lock verification issues are non-optimized dex code\n"
"and incorrect proguard optimizations.";
@@ -355,7 +354,7 @@
const DexFile* dex_file,
Handle<mirror::DexCache> dex_cache,
Handle<mirror::ClassLoader> class_loader,
- const DexFile::ClassDef* class_def,
+ const DexFile::ClassDef& class_def,
const DexFile::CodeItem* code_item,
ArtMethod* method,
uint32_t method_access_flags,
@@ -436,7 +435,7 @@
if (callbacks != nullptr) {
// Let the interested party know that we failed the class.
- ClassReference ref(dex_file, dex_file->GetIndexForClassDef(*class_def));
+ ClassReference ref(dex_file, dex_file->GetIndexForClassDef(class_def));
callbacks->ClassRejected(ref);
}
}
@@ -463,7 +462,7 @@
const DexFile* dex_file,
Handle<mirror::DexCache> dex_cache,
Handle<mirror::ClassLoader> class_loader,
- const DexFile::ClassDef* class_def,
+ const DexFile::ClassDef& class_def,
const DexFile::CodeItem* code_item,
ArtMethod* method,
uint32_t method_access_flags) {
@@ -499,7 +498,7 @@
const DexFile* dex_file,
Handle<mirror::DexCache> dex_cache,
Handle<mirror::ClassLoader> class_loader,
- const DexFile::ClassDef* class_def,
+ const DexFile::ClassDef& class_def,
const DexFile::CodeItem* code_item,
uint32_t dex_method_idx,
ArtMethod* method,
@@ -544,7 +543,6 @@
is_constructor_(false),
link_(nullptr) {
self->PushVerifier(this);
- DCHECK(class_def != nullptr);
}
MethodVerifier::~MethodVerifier() {
@@ -561,7 +559,7 @@
m->GetDexFile(),
dex_cache,
class_loader,
- &m->GetClassDef(),
+ m->GetClassDef(),
m->GetCodeItem(),
m->GetDexMethodIndex(),
m,
@@ -616,7 +614,7 @@
m->GetDexFile(),
dex_cache,
class_loader,
- &m->GetClassDef(),
+ m->GetClassDef(),
m->GetCodeItem(),
m->GetDexMethodIndex(),
m,
@@ -656,7 +654,7 @@
m->GetDexFile(),
dex_cache,
class_loader,
- &m->GetClassDef(),
+ m->GetClassDef(),
m->GetCodeItem(),
m->GetDexMethodIndex(),
m,
@@ -761,7 +759,7 @@
return false;
}
}
- if ((class_def_->GetJavaAccessFlags() & kAccInterface) != 0) {
+ if ((class_def_.GetJavaAccessFlags() & kAccInterface) != 0) {
// Interface methods must be public and abstract (if default methods are disabled).
uint32_t kRequired = kAccPublic;
if ((method_access_flags_ & kRequired) != kRequired) {
@@ -792,7 +790,7 @@
return false;
}
- if ((class_def_->GetJavaAccessFlags() & kAccInterface) != 0) {
+ if ((class_def_.GetJavaAccessFlags() & kAccInterface) != 0) {
// Interfaces may always have static initializers for their fields. If we are running with
// default methods enabled we also allow other public, static, non-final methods to have code.
// Otherwise that is the only type of method allowed.
@@ -4023,7 +4021,7 @@
}
if (reference_class->IsInterface()) {
// TODO Can we verify anything else.
- if (class_idx == class_def_->class_idx_) {
+ if (class_idx == class_def_.class_idx_) {
Fail(VERIFY_ERROR_CLASS_CHANGE) << "Cannot invoke-super on self as interface";
return nullptr;
}
diff --git a/runtime/verifier/method_verifier.h b/runtime/verifier/method_verifier.h
index e838900..d4e12f7 100644
--- a/runtime/verifier/method_verifier.h
+++ b/runtime/verifier/method_verifier.h
@@ -159,7 +159,7 @@
const DexFile* dex_file,
Handle<mirror::DexCache> dex_cache,
Handle<mirror::ClassLoader> class_loader,
- const DexFile::ClassDef* class_def,
+ const DexFile::ClassDef& class_def,
CompilerCallbacks* callbacks,
bool allow_soft_failures,
LogSeverity log_level,
@@ -172,7 +172,7 @@
const DexFile* dex_file,
Handle<mirror::DexCache> dex_cache,
Handle<mirror::ClassLoader> class_loader,
- const DexFile::ClassDef* class_def,
+ const DexFile::ClassDef& class_def,
const DexFile::CodeItem* code_item, ArtMethod* method,
uint32_t method_access_flags)
REQUIRES_SHARED(Locks::mutator_lock_);
@@ -283,7 +283,7 @@
const DexFile* dex_file,
Handle<mirror::DexCache> dex_cache,
Handle<mirror::ClassLoader> class_loader,
- const DexFile::ClassDef* class_def,
+ const DexFile::ClassDef& class_def,
const DexFile::CodeItem* code_item,
uint32_t method_idx,
ArtMethod* method,
@@ -330,7 +330,7 @@
static FailureData VerifyMethods(Thread* self,
ClassLinker* linker,
const DexFile* dex_file,
- const DexFile::ClassDef* class_def,
+ const DexFile::ClassDef& class_def,
ClassDataItemIterator* it,
Handle<mirror::DexCache> dex_cache,
Handle<mirror::ClassLoader> class_loader,
@@ -356,7 +356,7 @@
const DexFile* dex_file,
Handle<mirror::DexCache> dex_cache,
Handle<mirror::ClassLoader> class_loader,
- const DexFile::ClassDef* class_def_idx,
+ const DexFile::ClassDef& class_def_idx,
const DexFile::CodeItem* code_item,
ArtMethod* method,
uint32_t method_access_flags,
@@ -759,7 +759,7 @@
Handle<mirror::DexCache> dex_cache_ GUARDED_BY(Locks::mutator_lock_);
// The class loader for the declaring class of the method.
Handle<mirror::ClassLoader> class_loader_ GUARDED_BY(Locks::mutator_lock_);
- const DexFile::ClassDef* const class_def_; // The class def of the declaring class of the method.
+ const DexFile::ClassDef& class_def_; // The class def of the declaring class of the method.
const DexFile::CodeItem* const code_item_; // The code item containing the code for the method.
const RegType* declaring_class_; // Lazily computed reg type of the method's declaring class.
// Instruction widths and flags, one entry per code unit.