1 /* 2 * Copyright (C) 2017 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 import java.lang.invoke.MethodHandle; 18 19 public class TestInvokePolymorphic { testInvokeVoidReturnNoArgs(MethodHandle mh)20 public static void testInvokeVoidReturnNoArgs(MethodHandle mh) throws Throwable { 21 mh.invoke(); 22 } 23 testInvokeExactVoidReturnNoArgs(MethodHandle mh)24 public static void testInvokeExactVoidReturnNoArgs(MethodHandle mh) throws Throwable { 25 mh.invokeExact(); 26 } 27 testInvokeIntReturnNoArgs(MethodHandle mh)28 public static int testInvokeIntReturnNoArgs(MethodHandle mh) throws Throwable { 29 return (int) mh.invoke(); 30 } 31 testInvokeExactIntReturnNoArgs(MethodHandle mh)32 public static int testInvokeExactIntReturnNoArgs(MethodHandle mh) throws Throwable { 33 return (int) mh.invokeExact(); 34 } 35 testInvokeLongReturnNoArgs(MethodHandle mh)36 public static long testInvokeLongReturnNoArgs(MethodHandle mh) throws Throwable { 37 return (long) mh.invoke(); 38 } 39 testInvokeExactLongReturnNoArgs(MethodHandle mh)40 public static long testInvokeExactLongReturnNoArgs(MethodHandle mh) throws Throwable { 41 return (long) mh.invokeExact(); 42 } 43 testInvokeDoubleReturnNoArgs(MethodHandle mh)44 public static double testInvokeDoubleReturnNoArgs(MethodHandle mh) throws Throwable { 45 return (double) mh.invoke(); 46 } 47 testInvokeExactDoubleReturnNoArgs(MethodHandle mh)48 public static double testInvokeExactDoubleReturnNoArgs(MethodHandle mh) throws Throwable { 49 return (double) mh.invokeExact(); 50 } 51 testInvokeDoubleReturn2Arguments(MethodHandle mh, Object o, long l)52 public static double testInvokeDoubleReturn2Arguments(MethodHandle mh, Object o, long l) 53 throws Throwable { 54 return (double) mh.invoke(o, l); 55 } 56 testInvokeExactDoubleReturn2Arguments(MethodHandle mh, Object o, long l)57 public static double testInvokeExactDoubleReturn2Arguments(MethodHandle mh, Object o, long l) 58 throws Throwable { 59 return (double) mh.invokeExact(o, l); 60 } 61 testInvokeVoidReturn3IntArguments(MethodHandle mh, int x, int y, int z)62 public static void testInvokeVoidReturn3IntArguments(MethodHandle mh, int x, int y, int z) 63 throws Throwable { 64 mh.invoke( x, y, z); 65 } 66 testInvokeExactVoidReturn3IntArguments(MethodHandle mh, int x, int y, int z)67 public static void testInvokeExactVoidReturn3IntArguments(MethodHandle mh, int x, int y, int z) 68 throws Throwable { 69 mh.invokeExact(x, y, z); 70 } 71 testInvokeVoidReturn3Arguments(MethodHandle mh, Object o, long l, double d)72 public static void testInvokeVoidReturn3Arguments(MethodHandle mh, Object o, long l, double d) 73 throws Throwable { 74 mh.invoke(o, l, d); 75 } 76 testInvokeExactVoidReturn3Arguments(MethodHandle mh, Object o, long l, double d)77 public static void testInvokeExactVoidReturn3Arguments(MethodHandle mh, Object o, long l, 78 double d) throws Throwable { 79 mh.invokeExact(o, l, d); 80 } 81 testInvokeIntReturn5Arguments(MethodHandle mh, Object o, long l, double d, float f, String s)82 public static int testInvokeIntReturn5Arguments(MethodHandle mh, Object o, long l, double d, 83 float f, String s) throws Throwable { 84 return (int) mh.invoke(o, l, d, f, s); 85 } 86 testInvokeExactIntReturn5Arguments(MethodHandle mh, Object o, long l, double d, float f, String s)87 public static int testInvokeExactIntReturn5Arguments(MethodHandle mh, Object o, long l, 88 double d, float f, String s) 89 throws Throwable { 90 return (int) mh.invokeExact(o, l, d, f, s); 91 } 92 } 93