Create empty VerifiedMethod after vdex verification.
The compiler and quicken require the existence of a
VerifiedMethod for compiling a method.
This fixes the regression of not doing any compilation when
passed --input-vdex.
Test: 629-vdex-speed
Change-Id: Ie65578eadd09099df1c1a403d96c15e5da78a901
diff --git a/compiler/dex/verification_results.cc b/compiler/dex/verification_results.cc
index 669d8cd..9d39bf2 100644
--- a/compiler/dex/verification_results.cc
+++ b/compiler/dex/verification_results.cc
@@ -103,6 +103,17 @@
return (it != verified_methods_.end()) ? it->second : nullptr;
}
+void VerificationResults::CreateVerifiedMethodFor(MethodReference ref) {
+ // This method should only be called for classes verified at compile time,
+ // which have no verifier error, nor has methods that we know will throw
+ // at runtime.
+ AtomicMap::InsertResult result = atomic_verified_methods_.Insert(
+ ref,
+ /*expected*/ nullptr,
+ new VerifiedMethod(/* encountered_error_types */ 0, /* has_runtime_throw */ false));
+ DCHECK_EQ(result, AtomicMap::kInsertResultSuccess);
+}
+
void VerificationResults::AddRejectedClass(ClassReference ref) {
{
WriterMutexLock mu(Thread::Current(), rejected_classes_lock_);
diff --git a/compiler/dex/verification_results.h b/compiler/dex/verification_results.h
index ea38f4d..ab735c1 100644
--- a/compiler/dex/verification_results.h
+++ b/compiler/dex/verification_results.h
@@ -47,6 +47,9 @@
REQUIRES_SHARED(Locks::mutator_lock_)
REQUIRES(!verified_methods_lock_);
+ void CreateVerifiedMethodFor(MethodReference ref)
+ REQUIRES(!verified_methods_lock_);
+
const VerifiedMethod* GetVerifiedMethod(MethodReference ref)
REQUIRES(!verified_methods_lock_);
diff --git a/compiler/dex/verified_method.h b/compiler/dex/verified_method.h
index 04331e5..ce53417 100644
--- a/compiler/dex/verified_method.h
+++ b/compiler/dex/verified_method.h
@@ -32,6 +32,8 @@
class VerifiedMethod {
public:
+ VerifiedMethod(uint32_t encountered_error_types, bool has_runtime_throw);
+
// Cast elision set type.
// Since we're adding the dex PCs to the set in increasing order, a sorted vector
// is better for performance (not just memory usage), especially for large sets.
@@ -80,8 +82,6 @@
}
private:
- VerifiedMethod(uint32_t encountered_error_types, bool has_runtime_throw);
-
/*
* Generate the GC map for a method that has just been verified (i.e. we're doing this as part of
* verification). For type-precise determination we have all the data we need, so we just need to
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index 6b62110..a2bab80 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -2005,6 +2005,35 @@
}
}
+static void PopulateVerifiedMethods(const DexFile& dex_file,
+ uint32_t class_def_index,
+ VerificationResults* verification_results) {
+ const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_def_index);
+ const uint8_t* class_data = dex_file.GetClassData(class_def);
+ if (class_data == nullptr) {
+ return;
+ }
+ ClassDataItemIterator it(dex_file, class_data);
+ // Skip fields
+ while (it.HasNextStaticField()) {
+ it.Next();
+ }
+ while (it.HasNextInstanceField()) {
+ it.Next();
+ }
+
+ while (it.HasNextDirectMethod()) {
+ verification_results->CreateVerifiedMethodFor(MethodReference(&dex_file, it.GetMemberIndex()));
+ it.Next();
+ }
+
+ while (it.HasNextVirtualMethod()) {
+ verification_results->CreateVerifiedMethodFor(MethodReference(&dex_file, it.GetMemberIndex()));
+ it.Next();
+ }
+ DCHECK(!it.HasNext());
+}
+
void CompilerDriver::Verify(jobject jclass_loader,
const std::vector<const DexFile*>& dex_files,
TimingLogger* timings) {
@@ -2041,6 +2070,13 @@
} else if (set.find(class_def.class_idx_) == set.end()) {
ObjectLock<mirror::Class> lock(soa.Self(), cls);
mirror::Class::SetStatus(cls, mirror::Class::kStatusVerified, soa.Self());
+ // Create `VerifiedMethod`s for each methods, the compiler expects one for
+ // quickening or compiling.
+ // Note that this means:
+ // - We're only going to compile methods that did verify.
+ // - Quickening will not do checkcast ellision.
+ // TODO(ngeoffray): Reconsider this once we refactor compiler filters.
+ PopulateVerifiedMethods(*dex_file, i, verification_results_);
}
}
}