Disable support for proxy method in nterp.

They do not fall into the regular baseline JIT path (ie they cannot have
profiling info), so just bail on them for now.

Test: 044-proxy, wifi-tests
Bug: 112676029
Bug: 157658616
Bug: 160543640
Change-Id: I292d85f5d6bfd0edaad1d26e53f85f3780254fd7
diff --git a/runtime/art_method.cc b/runtime/art_method.cc
index 135e806..cfb5928 100644
--- a/runtime/art_method.cc
+++ b/runtime/art_method.cc
@@ -762,9 +762,17 @@
           image_pointer_size);
     }
   }
-  // Clear the profiling info for the same reasons as the JIT code.
+    if (interpreter::IsNterpSupported() &&
+        (GetEntryPointFromQuickCompiledCodePtrSize(image_pointer_size) ==
+            interpreter::GetNterpEntryPoint())) {
+    // If the entrypoint is nterp, it's too early to check if the new method
+    // will support it. So for simplicity, use the interpreter bridge.
+    SetEntryPointFromQuickCompiledCodePtrSize(GetQuickToInterpreterBridge(), image_pointer_size);
+  }
+
+  // Clear the data pointer, it will be set if needed by the caller.
   if (!src->IsNative()) {
-    SetProfilingInfoPtrSize(nullptr, image_pointer_size);
+    SetDataPtrSize(nullptr, image_pointer_size);
   }
   // Clear hotness to let the JIT properly decide when to compile this method.
   hotness_count_ = 0;
diff --git a/runtime/art_method.h b/runtime/art_method.h
index 16b4648..3d6b66a 100644
--- a/runtime/art_method.h
+++ b/runtime/art_method.h
@@ -523,11 +523,14 @@
   }
 
   ALWAYS_INLINE void SetProfilingInfo(ProfilingInfo* info) REQUIRES_SHARED(Locks::mutator_lock_) {
-    SetDataPtrSize(info, kRuntimePointerSize);
+    SetProfilingInfoPtrSize(info, kRuntimePointerSize);
   }
 
   ALWAYS_INLINE void SetProfilingInfoPtrSize(ProfilingInfo* info, PointerSize pointer_size)
       REQUIRES_SHARED(Locks::mutator_lock_) {
+    DCHECK(!IsProxyMethod());
+    DCHECK(!IsNative());
+    DCHECK(IsInvokable());
     SetDataPtrSize(info, pointer_size);
   }
 
diff --git a/runtime/interpreter/mterp/nterp.cc b/runtime/interpreter/mterp/nterp.cc
index 1d47f29..f1b6021 100644
--- a/runtime/interpreter/mterp/nterp.cc
+++ b/runtime/interpreter/mterp/nterp.cc
@@ -45,6 +45,9 @@
   return method->SkipAccessChecks() &&
       !method->IsNative() &&
       method->GetDexFile()->IsStandardDexFile() &&
+      // Proxy methods do not go through the JIT like other methods, so we don't
+      // run them with nterp.
+      !method->IsProxyMethod() &&
       NterpGetFrameSize(method) < kNterpMaxFrame;
 }
 
diff --git a/test/044-proxy/src/HotProxy.java b/test/044-proxy/src/HotProxy.java
new file mode 100644
index 0000000..0c5ec1c
--- /dev/null
+++ b/test/044-proxy/src/HotProxy.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2011 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.*;
+
+public class HotProxy {
+
+  public static final String testName = "HotProxy";
+
+  interface MyInterface {
+    void voidFoo();
+  }
+
+  static void check(boolean x) {
+    if (!x) {
+      throw new AssertionError(testName + " Check failed");
+    }
+  }
+
+  static class MyInvocationHandler implements InvocationHandler {
+    public Object invoke(Object proxy, Method method, Object[] args) {
+      check(proxy instanceof Proxy);
+      check(method.getDeclaringClass() == MyInterface.class);
+      return null;
+    }
+  }
+
+  static void testProxy() {
+    MyInvocationHandler myHandler = new MyInvocationHandler();
+    MyInterface proxyMyInterface =
+        (MyInterface)Proxy.newProxyInstance(HotProxy.class.getClassLoader(),
+                                            new Class<?>[] { MyInterface.class },
+                                            myHandler);
+    // Invoke the proxy method multiple times to ensure it becomes hot and the JIT handles it.
+    for (int i = 0; i < 0x10000; i++) {
+      proxyMyInterface.voidFoo();
+    }
+  }
+
+  public static void main(String args[]) {
+    testProxy();
+  }
+}
diff --git a/test/044-proxy/src/Main.java b/test/044-proxy/src/Main.java
index 7b70e65..8be09cf 100644
--- a/test/044-proxy/src/Main.java
+++ b/test/044-proxy/src/Main.java
@@ -33,6 +33,7 @@
         NativeProxy.main(args);
         ConstructorProxy.main();
         OOMEOnDispatch.main(args);
+        HotProxy.main(args);
     }
 
     // The following code maps from the actual proxy class names (eg $Proxy2) to their test output