proxy: Fix crash when creating proxies with dx-built libcore.
dx and jack can place methods at different offsets within the direct methods
list. This is because (a) dx and jack name their synthetic methods
differently (e.g. 'access$100' vs '-get0') and (b) the methods are
required to be sorted by name.
Instead of hard-coding where <init>(InvocationHandler) is for
java.lang.reflect.Proxy, look it up from the name and signature which
will work regardless of which front-end compiler is used.
Test: ANDROID_FORCE_JACK_ENABLED=disabled make -j32 test-art-host-gtest-proxy_test64
Bug: 35799227
Change-Id: Ie04a37cfe293c146afbe414075a6c568c6a4a0b3
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 9b0ffaf..2788656 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -4428,9 +4428,15 @@
// Create constructor for Proxy that must initialize the method.
CHECK_EQ(GetClassRoot(kJavaLangReflectProxy)->NumDirectMethods(), 23u);
- ArtMethod* proxy_constructor = GetClassRoot(kJavaLangReflectProxy)->GetDirectMethodUnchecked(
- 8, image_pointer_size_);
- DCHECK_EQ(std::string(proxy_constructor->GetName()), "<init>");
+ // Find the <init>(InvocationHandler)V method. The exact method offset varies depending
+ // on which front-end compiler was used to build the libcore DEX files.
+ ArtMethod* proxy_constructor = GetClassRoot(kJavaLangReflectProxy)->
+ FindDeclaredDirectMethod("<init>",
+ "(Ljava/lang/reflect/InvocationHandler;)V",
+ image_pointer_size_);
+ DCHECK(proxy_constructor != nullptr)
+ << "Could not find <init> method in java.lang.reflect.Proxy";
+
// Ensure constructor is in dex cache so that we can use the dex cache to look up the overridden
// constructor method.
GetClassRoot(kJavaLangReflectProxy)->GetDexCache()->SetResolvedMethod(