Only look for method optimization annotations in the bootstrap class loader.
When checking for an optimization annotation (FastNative or
CriticalNative) on a method, do not resolve the method's annotations'
classes as a side effect -- instead, look them up in the bootstrap
class loader's resolved types. This is to prevent exceptions from being
thrown (during class resolution) in JNI transitions.
This change does not affect annotation lookup rules in the context of
reflection.
Test: art/test/testrunner/testrunner.py -t 656-annotation-lookup-generic-jni
Bug: 38454151
Bug: 34659969
Change-Id: Ie6b8b30b96a08baa629c449e3803a031515508d1
diff --git a/runtime/dex_file_annotations.h b/runtime/dex_file_annotations.h
index 651c984..e108882 100644
--- a/runtime/dex_file_annotations.h
+++ b/runtime/dex_file_annotations.h
@@ -65,8 +65,15 @@
REQUIRES_SHARED(Locks::mutator_lock_);
mirror::ObjectArray<mirror::String>* GetSignatureAnnotationForMethod(ArtMethod* method)
REQUIRES_SHARED(Locks::mutator_lock_);
-bool IsMethodAnnotationPresent(ArtMethod* method, Handle<mirror::Class> annotation_class,
- uint32_t visibility = DexFile::kDexVisibilityRuntime)
+// Check whether `method` is annotated with `annotation_class`.
+// If `lookup_in_resolved_boot_classes` is true, look up any of the
+// method's annotations' classes in the bootstrap class loader's
+// resolved types; if it is false (default value), resolve them as a
+// side effect.
+bool IsMethodAnnotationPresent(ArtMethod* method,
+ Handle<mirror::Class> annotation_class,
+ uint32_t visibility = DexFile::kDexVisibilityRuntime,
+ bool lookup_in_resolved_boot_classes = false)
REQUIRES_SHARED(Locks::mutator_lock_);
// Class annotations.