1 /* 2 * Copyright (C) 2015 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 class Main implements Iface, Iface2 { main(String[] args)17 public static void main(String[] args) { 18 System.loadLibrary(args[0]); 19 // Ensure we JIT compile the methods to test CHA behavior with default 20 // methods. 21 ensureJitCompiled(Main.class, "callMain"); 22 ensureJitCompiled(Main.class, "callIface"); 23 ensureJitCompiled(Main.class, "callIface2"); 24 25 System.out.println("Create Main instance"); 26 Main m = new Main(); 27 System.out.println("Calling functions on concrete Main"); 28 callMain(m); 29 System.out.println("Calling functions on interface Iface"); 30 callIface(m); 31 System.out.println("Calling functions on interface Iface2"); 32 callIface2(m); 33 } callMain(Main m)34 public static void callMain(Main m) { 35 System.out.println("Calling non-conflicting function on Main"); 36 System.out.println(m.charge()); 37 System.out.println("Calling conflicting function on Main"); 38 try { 39 System.out.println(m.sayHi()); 40 System.out.println("Unexpected no error Thrown on Main"); 41 } catch (AbstractMethodError e) { 42 System.out.println("Unexpected AME Thrown on Main"); 43 } catch (IncompatibleClassChangeError e) { 44 System.out.println("Expected ICCE Thrown on Main"); 45 } 46 System.out.println("Calling non-conflicting function on Main"); 47 System.out.println(m.charge()); 48 return; 49 } callIface(Iface m)50 public static void callIface(Iface m) { 51 System.out.println("Calling non-conflicting function on Iface"); 52 System.out.println(m.charge()); 53 System.out.println("Calling conflicting function on Iface"); 54 try { 55 System.out.println(m.sayHi()); 56 System.out.println("Unexpected no error Thrown on Iface"); 57 } catch (AbstractMethodError e) { 58 System.out.println("Unexpected AME Thrown on Iface"); 59 } catch (IncompatibleClassChangeError e) { 60 System.out.println("Expected ICCE Thrown on Iface"); 61 } 62 System.out.println("Calling non-conflicting function on Iface"); 63 System.out.println(m.charge()); 64 return; 65 } callIface2(Iface2 m)66 public static void callIface2(Iface2 m) { 67 System.out.println("Calling conflicting function on Iface2"); 68 try { 69 System.out.println(m.sayHi()); 70 System.out.println("Unexpected no error Thrown on Iface2"); 71 } catch (AbstractMethodError e) { 72 System.out.println("Unexpected AME Thrown on Iface2"); 73 } catch (IncompatibleClassChangeError e) { 74 System.out.println("Expected ICCE Thrown on Iface2"); 75 } 76 return; 77 } 78 ensureJitCompiled(Class<?> cls, String method_name)79 private static native void ensureJitCompiled(Class<?> cls, String method_name); 80 } 81