Set @NeverCompile methods as not compilable
This change sets methods as not compilable if they are annotated with
@NeverCompile. This is done by adding a new method in
dex_file_annotations.h that checks if a method is annotated (identical
to how @FastNative/@CriticalNative are checked in
GetNativeMethodAnnotationAccessFlags).
Bug: 197753440
Test: Checked that methods in services/core annotated with @NeverCompile
aren't compiled into services.odex. (aosp/1901034)
Change-Id: I22a09054dc9c2d20f5bb7aaf7bb4b504d8b59b00
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 4a60ab3..3f5b09f 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -3673,6 +3673,9 @@
access_flags |= annotations::GetNativeMethodAnnotationAccessFlags(
dex_file, dst->GetClassDef(), dex_method_idx);
}
+ if (annotations::MethodIsNeverCompile(dex_file, dst->GetClassDef(), dex_method_idx)) {
+ access_flags |= kAccCompileDontBother;
+ }
dst->SetAccessFlags(access_flags);
// Must be done after SetAccessFlags since IsAbstract depends on it.
if (klass->IsInterface() && dst->IsAbstract()) {