ART: Stop Hidden API stackwalk for class initializers in j.l.i.
Class initializers in java.lang.invoke retrieve field offsets. The
hiddenapi stack walk does not need to progress past these initializers
as they are permitted irrespective of how their invocation is
triggered.
Bug: 77631986
Test: art/test/run-test --host --64 674-hiddenapi
(cherry picked from commit 29e64cfc32e17c9111a5ed2a6b141bebf891cbe3)
Change-Id: I77a29999177850bd50ca4d043b0cd40c40692fe4
Merged-In: Iaabedc9c016d546e10072107d79c7b6701582c83
diff --git a/runtime/native/java_lang_Class.cc b/runtime/native/java_lang_Class.cc
index 510c5de..bfd7f69 100644
--- a/runtime/native/java_lang_Class.cc
+++ b/runtime/native/java_lang_Class.cc
@@ -77,11 +77,14 @@
if (declaring_class->IsClassClass()) {
return true;
}
+ // Check classes in the java.lang.invoke package. At the time of writing, the
+ // classes of interest are MethodHandles and MethodHandles.Lookup, but this
+ // is subject to change so conservatively cover the entire package.
+ // NB Static initializers within java.lang.invoke are permitted and do not
+ // need further stack inspection.
ObjPtr<mirror::Class> lookup_class = mirror::MethodHandlesLookup::StaticClass();
- if (declaring_class == lookup_class || declaring_class->IsInSamePackage(lookup_class)) {
- // Check classes in the java.lang.invoke package. At the time of writing, the
- // classes of interest are MethodHandles and MethodHandles.Lookup, but this
- // is subject to change so conservatively cover the entire package.
+ if ((declaring_class == lookup_class || declaring_class->IsInSamePackage(lookup_class))
+ && !m->IsClassInitializer()) {
return true;
}
}