Fix "jit at first use" for proxy methods.
Test: testrunner.py --host --jit 767-proxy-jit-at-first-use
Bug: 73718713
Change-Id: I1bc68d9a2fb0ae0dee7e8e9f96c2bd73a0ff7d7e
diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc
index 1baa613..6d99ad0 100644
--- a/runtime/jit/jit.cc
+++ b/runtime/jit/jit.cc
@@ -718,7 +718,9 @@
Runtime* runtime = Runtime::Current();
if (UNLIKELY(runtime->UseJitCompilation() && runtime->GetJit()->JitAtFirstUse())) {
// The compiler requires a ProfilingInfo object.
- ProfilingInfo::Create(thread, method, /* retry_allocation */ true);
+ ProfilingInfo::Create(thread,
+ method->GetInterfaceMethodIfProxy(kRuntimePointerSize),
+ /* retry_allocation */ true);
JitCompileTask compile_task(method, JitCompileTask::kCompile);
compile_task.Run(thread);
return;
diff --git a/test/676-proxy-jit-at-first-use/expected.txt b/test/676-proxy-jit-at-first-use/expected.txt
new file mode 100644
index 0000000..6915b2f
--- /dev/null
+++ b/test/676-proxy-jit-at-first-use/expected.txt
@@ -0,0 +1 @@
+Method: public abstract void Interface.foo()
diff --git a/test/676-proxy-jit-at-first-use/info.txt b/test/676-proxy-jit-at-first-use/info.txt
new file mode 100644
index 0000000..90b683b
--- /dev/null
+++ b/test/676-proxy-jit-at-first-use/info.txt
@@ -0,0 +1 @@
+Regression test for "jit at first use" (-Xjitthreshold:0) crash for proxy methods. b/73718713
diff --git a/test/676-proxy-jit-at-first-use/run b/test/676-proxy-jit-at-first-use/run
new file mode 100644
index 0000000..16c9f76
--- /dev/null
+++ b/test/676-proxy-jit-at-first-use/run
@@ -0,0 +1,19 @@
+#!/bin/bash
+#
+# Copyright (C) 2018 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Enable "jit at first use" (-Xjitthreshold:0).
+# Ensure this test is not subject to unexpected code collection.
+${RUN} "${@}" --runtime-option -Xjitthreshold:0 --runtime-option -Xjitinitialsize:32M
diff --git a/test/676-proxy-jit-at-first-use/src/Main.java b/test/676-proxy-jit-at-first-use/src/Main.java
new file mode 100644
index 0000000..4ed773f
--- /dev/null
+++ b/test/676-proxy-jit-at-first-use/src/Main.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+public class Main {
+ public static void main(String[] args) throws Exception {
+ Interface i = (Interface) Proxy.newProxyInstance(Main.class.getClassLoader(),
+ new Class<?>[] { Interface.class },
+ new Handler());
+ i.foo();
+ }
+}
+
+interface Interface {
+ void foo();
+}
+
+class Handler implements InvocationHandler {
+ public Object invoke(Object proxy, Method method, Object[] args) {
+ System.out.println("Method: " + method);
+ return null;
+ }
+}