1*795d594fSAndroid Build Coastguard Worker /* 2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2015 The Android Open Source Project 3*795d594fSAndroid Build Coastguard Worker * 4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*795d594fSAndroid Build Coastguard Worker * 8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*795d594fSAndroid Build Coastguard Worker * 10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*795d594fSAndroid Build Coastguard Worker * limitations under the License. 15*795d594fSAndroid Build Coastguard Worker */ 16*795d594fSAndroid Build Coastguard Worker class Main implements Iface, Iface2 { main(String[] args)17*795d594fSAndroid Build Coastguard Worker public static void main(String[] args) { 18*795d594fSAndroid Build Coastguard Worker System.loadLibrary(args[0]); 19*795d594fSAndroid Build Coastguard Worker // Ensure we JIT compile the methods to test CHA behavior with default 20*795d594fSAndroid Build Coastguard Worker // methods. 21*795d594fSAndroid Build Coastguard Worker ensureJitCompiled(Main.class, "callMain"); 22*795d594fSAndroid Build Coastguard Worker ensureJitCompiled(Main.class, "callIface"); 23*795d594fSAndroid Build Coastguard Worker ensureJitCompiled(Main.class, "callIface2"); 24*795d594fSAndroid Build Coastguard Worker 25*795d594fSAndroid Build Coastguard Worker System.out.println("Create Main instance"); 26*795d594fSAndroid Build Coastguard Worker Main m = new Main(); 27*795d594fSAndroid Build Coastguard Worker System.out.println("Calling functions on concrete Main"); 28*795d594fSAndroid Build Coastguard Worker callMain(m); 29*795d594fSAndroid Build Coastguard Worker System.out.println("Calling functions on interface Iface"); 30*795d594fSAndroid Build Coastguard Worker callIface(m); 31*795d594fSAndroid Build Coastguard Worker System.out.println("Calling functions on interface Iface2"); 32*795d594fSAndroid Build Coastguard Worker callIface2(m); 33*795d594fSAndroid Build Coastguard Worker } callMain(Main m)34*795d594fSAndroid Build Coastguard Worker public static void callMain(Main m) { 35*795d594fSAndroid Build Coastguard Worker System.out.println("Calling non-conflicting function on Main"); 36*795d594fSAndroid Build Coastguard Worker System.out.println(m.charge()); 37*795d594fSAndroid Build Coastguard Worker System.out.println("Calling conflicting function on Main"); 38*795d594fSAndroid Build Coastguard Worker try { 39*795d594fSAndroid Build Coastguard Worker System.out.println(m.sayHi()); 40*795d594fSAndroid Build Coastguard Worker System.out.println("Unexpected no error Thrown on Main"); 41*795d594fSAndroid Build Coastguard Worker } catch (AbstractMethodError e) { 42*795d594fSAndroid Build Coastguard Worker System.out.println("Unexpected AME Thrown on Main"); 43*795d594fSAndroid Build Coastguard Worker } catch (IncompatibleClassChangeError e) { 44*795d594fSAndroid Build Coastguard Worker System.out.println("Expected ICCE Thrown on Main"); 45*795d594fSAndroid Build Coastguard Worker } 46*795d594fSAndroid Build Coastguard Worker System.out.println("Calling non-conflicting function on Main"); 47*795d594fSAndroid Build Coastguard Worker System.out.println(m.charge()); 48*795d594fSAndroid Build Coastguard Worker return; 49*795d594fSAndroid Build Coastguard Worker } callIface(Iface m)50*795d594fSAndroid Build Coastguard Worker public static void callIface(Iface m) { 51*795d594fSAndroid Build Coastguard Worker System.out.println("Calling non-conflicting function on Iface"); 52*795d594fSAndroid Build Coastguard Worker System.out.println(m.charge()); 53*795d594fSAndroid Build Coastguard Worker System.out.println("Calling conflicting function on Iface"); 54*795d594fSAndroid Build Coastguard Worker try { 55*795d594fSAndroid Build Coastguard Worker System.out.println(m.sayHi()); 56*795d594fSAndroid Build Coastguard Worker System.out.println("Unexpected no error Thrown on Iface"); 57*795d594fSAndroid Build Coastguard Worker } catch (AbstractMethodError e) { 58*795d594fSAndroid Build Coastguard Worker System.out.println("Unexpected AME Thrown on Iface"); 59*795d594fSAndroid Build Coastguard Worker } catch (IncompatibleClassChangeError e) { 60*795d594fSAndroid Build Coastguard Worker System.out.println("Expected ICCE Thrown on Iface"); 61*795d594fSAndroid Build Coastguard Worker } 62*795d594fSAndroid Build Coastguard Worker System.out.println("Calling non-conflicting function on Iface"); 63*795d594fSAndroid Build Coastguard Worker System.out.println(m.charge()); 64*795d594fSAndroid Build Coastguard Worker return; 65*795d594fSAndroid Build Coastguard Worker } callIface2(Iface2 m)66*795d594fSAndroid Build Coastguard Worker public static void callIface2(Iface2 m) { 67*795d594fSAndroid Build Coastguard Worker System.out.println("Calling conflicting function on Iface2"); 68*795d594fSAndroid Build Coastguard Worker try { 69*795d594fSAndroid Build Coastguard Worker System.out.println(m.sayHi()); 70*795d594fSAndroid Build Coastguard Worker System.out.println("Unexpected no error Thrown on Iface2"); 71*795d594fSAndroid Build Coastguard Worker } catch (AbstractMethodError e) { 72*795d594fSAndroid Build Coastguard Worker System.out.println("Unexpected AME Thrown on Iface2"); 73*795d594fSAndroid Build Coastguard Worker } catch (IncompatibleClassChangeError e) { 74*795d594fSAndroid Build Coastguard Worker System.out.println("Expected ICCE Thrown on Iface2"); 75*795d594fSAndroid Build Coastguard Worker } 76*795d594fSAndroid Build Coastguard Worker return; 77*795d594fSAndroid Build Coastguard Worker } 78*795d594fSAndroid Build Coastguard Worker ensureJitCompiled(Class<?> cls, String method_name)79*795d594fSAndroid Build Coastguard Worker private static native void ensureJitCompiled(Class<?> cls, String method_name); 80*795d594fSAndroid Build Coastguard Worker } 81