Prune uses library classes even without profile
The previous pruning relied on the classes being pruned from the
profile, and then using the profile to prune classes. If there was
no profile, the uses library classes were incorrectly left unpruned.
Leaving these classes unpruned caused aborts during compilation.
Bug: 30688277
Test: adb shell dex2oat --runtime-arg -classpath --runtime-arg /system/framework/com.google.android.maps.jar --dex-file=/data/app/comb.BBClient-1/base.apk --dex-location=/data/app/comb.BBClient-1/base.apk --oat-file=/data/app/comb.BBClient-1/oat/arm/base.odex --app-image-file=/data/app/comb.BBClient-1/oat/arm/base.art --image-format=lz4 --compiler-filter=speed
Change-Id: I261b8894847b5b0a4f7330f49666e823a1b38bb0
diff --git a/compiler/image_writer.cc b/compiler/image_writer.cc
index a47e711..b22ca47 100644
--- a/compiler/image_writer.cc
+++ b/compiler/image_writer.cc
@@ -803,6 +803,13 @@
result = result || PruneAppImageClassInternal(klass->GetSuperClass(),
&my_early_exit,
visited);
+ // Remove the class if the dex file is not in the set of dex files. This happens for classes that
+ // are from uses library if there is no profile. b/30688277
+ mirror::DexCache* dex_cache = klass->GetDexCache();
+ if (dex_cache != nullptr) {
+ result = result ||
+ dex_file_oat_index_map_.find(dex_cache->GetDexFile()) == dex_file_oat_index_map_.end();
+ }
// Erase the element we stored earlier since we are exiting the function.
auto it = visited->find(klass);
DCHECK(it != visited->end());