1 /* 2 * Copyright (C) 2016 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 annotations.BootstrapMethod; 18 import annotations.CalledByIndy; 19 import annotations.Constant; 20 import java.lang.invoke.CallSite; 21 import java.lang.invoke.ConstantCallSite; 22 import java.lang.invoke.MethodHandle; 23 import java.lang.invoke.MethodHandles; 24 import java.lang.invoke.MethodType; 25 26 public class TestLinkerMethodMultipleArgumentTypes extends TestBase { 27 28 private static int bootstrapRunCount = 0; 29 30 @CalledByIndy( 31 bootstrapMethod = 32 @BootstrapMethod( 33 enclosingType = TestLinkerMethodMultipleArgumentTypes.class, 34 name = "linkerMethod", 35 parameterTypes = { 36 MethodHandles.Lookup.class, 37 String.class, 38 MethodType.class, 39 int.class, 40 int.class, 41 int.class, 42 int.class, 43 int.class, 44 float.class, 45 double.class, 46 String.class, 47 Class.class, 48 long.class 49 } 50 ), 51 fieldOrMethodName = "_add", 52 returnType = int.class, 53 parameterTypes = {int.class, int.class}, 54 constantArgumentsForBootstrapMethod = { 55 @Constant(intValue = -1), 56 @Constant(intValue = 1), 57 @Constant(intValue = (int) 'a'), 58 @Constant(intValue = 1024), 59 @Constant(intValue = 1), 60 @Constant(floatValue = 11.1f), 61 @Constant(doubleValue = 2.2), 62 @Constant(stringValue = "Hello"), 63 @Constant(classValue = TestLinkerMethodMultipleArgumentTypes.class), 64 @Constant(longValue = 123456789L) 65 } 66 ) add(int a, int b)67 private static int add(int a, int b) { 68 assertNotReached(); 69 return -1; 70 } 71 72 @SuppressWarnings("unused") _add(int a, int b)73 private static int _add(int a, int b) { 74 return a + b; 75 } 76 77 @SuppressWarnings("unused") linkerMethod( MethodHandles.Lookup caller, String name, MethodType methodType, int v1, int v2, int v3, int v4, int v5, float v6, double v7, String v8, Class<?> v9, long v10)78 private static CallSite linkerMethod( 79 MethodHandles.Lookup caller, 80 String name, 81 MethodType methodType, 82 int v1, 83 int v2, 84 int v3, 85 int v4, 86 int v5, 87 float v6, 88 double v7, 89 String v8, 90 Class<?> v9, 91 long v10) 92 throws Throwable { 93 System.out.println("Linking " + name + " " + methodType); 94 assertEquals(-1, v1); 95 assertEquals(1, v2); 96 assertEquals('a', v3); 97 assertEquals(1024, v4); 98 assertEquals(1, v5); 99 assertEquals(11.1f, v6); 100 assertEquals(2.2, v7); 101 assertEquals("Hello", v8); 102 assertEquals(TestLinkerMethodMultipleArgumentTypes.class, v9); 103 assertEquals(123456789L, v10); 104 MethodHandle mh_add = 105 caller.findStatic(TestLinkerMethodMultipleArgumentTypes.class, name, methodType); 106 return new ConstantCallSite(mh_add); 107 } 108 GetBootstrapRunCount()109 public int GetBootstrapRunCount() { 110 return bootstrapRunCount; 111 } 112 test(int x, int y)113 public static void test(int x, int y) throws Throwable { 114 assertEquals(x + y, add(x, y)); 115 System.out.println(x + y); 116 } 117 } 118