1 /* 2 * Copyright (C) 2020 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 public class Main { 18 public static class Base { sayHi()19 public void sayHi() { 20 System.out.println("Hello from Base"); 21 } 22 } 23 public static class Ext extends Base{ sayHi()24 public void sayHi() { 25 System.out.println("Hello from Ext"); 26 } 27 } main(String[] args)28 public static void main(String[] args) throws Exception { 29 System.loadLibrary(args[0]); 30 try { 31 System.out.println("Call lookup: Base, caller: Base, Obj: Base"); 32 callSayHiMethodNonvirtualWith(Base.class, Base.class, new Base()); 33 } catch (Exception e) { 34 System.out.println("Caught exception " + e); 35 } 36 try { 37 System.out.println("Call lookup: Base, caller: Base, Obj: Ext"); 38 callSayHiMethodNonvirtualWith(Base.class, Base.class, new Ext()); 39 } catch (Exception e) { 40 System.out.println("Caught exception " + e); 41 } 42 try { 43 System.out.println("Call lookup: Base, caller: Ext, Obj: Ext"); 44 callSayHiMethodNonvirtualWith(Base.class, Ext.class, new Ext()); 45 } catch (Exception e) { 46 System.out.println("Caught exception " + e); 47 } 48 try { 49 System.out.println("Call lookup: Ext, caller: Ext, Obj: Ext"); 50 callSayHiMethodNonvirtualWith(Ext.class, Ext.class, new Ext()); 51 } catch (Exception e) { 52 System.out.println("Caught exception " + e); 53 } 54 } 55 callSayHiMethodNonvirtualWith(Class<?> lookup, Class<?> caller, Object recv)56 private static native void callSayHiMethodNonvirtualWith(Class<?> lookup, Class<?> caller, Object recv); 57 } 58