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/art_method.h b/runtime/art_method.h
index 396c878..96306af 100644
--- a/runtime/art_method.h
+++ b/runtime/art_method.h
@@ -723,7 +723,10 @@
private:
uint16_t FindObsoleteDexClassDefIndex() REQUIRES_SHARED(Locks::mutator_lock_);
- bool IsAnnotatedWith(jclass klass, uint32_t visibility);
+ // 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; otherwise, resolve them as a side effect.
+ bool IsAnnotatedWith(jclass klass, uint32_t visibility, bool lookup_in_resolved_boot_classes);
static constexpr size_t PtrSizedFieldsOffset(PointerSize pointer_size) {
// Round up to pointer size for padding field. Tested in art_method.cc.