1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 interface Itf { interfaceMethod()18 public String interfaceMethod(); 19 } 20 21 public class Main implements Itf { 22 main(String[] args)23 public static void main(String[] args) throws Exception { 24 System.loadLibrary(args[0]); 25 ensureJitCompiled(Main.class, "$noinline$invoke"); 26 String result = $noinline$invoke(new Main()); 27 if (!"Main".equals(result)) { 28 throw new Error("Expected Main, got " + result); 29 } 30 31 // Load SubItf dynamically, to avoid prior verification of this method to load it. 32 Class<?> cls = Class.forName("SubItf"); 33 Itf itf = (Itf) cls.newInstance(); 34 35 result = $noinline$invoke(itf); 36 if (!"SubItf".equals(result)) { 37 throw new Error("Expected SubItf, got " + result); 38 } 39 40 } 41 $noinline$invoke(Itf itf)42 public static String $noinline$invoke(Itf itf) { 43 return itf.interfaceMethod(); 44 } 45 interfaceMethod()46 public String interfaceMethod() { 47 return "Main"; 48 } 49 ensureJitCompiled(Class<?> cls, String methodName)50 public static native void ensureJitCompiled(Class<?> cls, String methodName); 51 } 52 53 class SubItf implements Itf { interfaceMethod()54 public String interfaceMethod() { 55 return "SubItf"; 56 } 57 } 58