1 /*
2  * Copyright (C) 2018 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.MethodHandles;
21 import java.lang.invoke.MethodType;
22 
23 class TestLinkerUnrelatedBSM extends TestBase {
24     @CalledByIndy(
25         bootstrapMethod =
26                 @BootstrapMethod(
27                     enclosingType = UnrelatedBSM.class,
28                     parameterTypes = {
29                         MethodHandles.Lookup.class,
30                         String.class,
31                         MethodType.class,
32                         Class.class
33                     },
34                     name = "bsm"
35                 ),
36         fieldOrMethodName = "_addf",
37         returnType = float.class,
38         parameterTypes = {float.class, float.class},
39         constantArgumentsForBootstrapMethod = {@Constant(classValue = TestLinkerUnrelatedBSM.class)}
40     )
addf(float a, float b)41     private static float addf(float a, float b) {
42         assertNotReached();
43         return Float.MIN_VALUE;
44     }
45 
_addf(float a, float b)46     public static float _addf(float a, float b) {
47         return a + b;
48     }
49 
50     @CalledByIndy(
51         bootstrapMethod =
52                 @BootstrapMethod(
53                     enclosingType = UnrelatedBSM.class,
54                     parameterTypes = {
55                         MethodHandles.Lookup.class,
56                         String.class,
57                         MethodType.class,
58                         Class.class
59                     },
60                     name = "bsm"
61                 ),
62         fieldOrMethodName = "_subf",
63         returnType = float.class,
64         parameterTypes = {float.class, float.class},
65         constantArgumentsForBootstrapMethod = {@Constant(classValue = TestLinkerUnrelatedBSM.class)}
66     )
subf(float a, float b)67     private static float subf(float a, float b) {
68         assertNotReached();
69         return Float.MIN_VALUE;
70     }
71 
_subf(float a, float b)72     private static float _subf(float a, float b) {
73         return a - b;
74     }
75 
test()76     public static void test() {
77         System.out.println(TestLinkerUnrelatedBSM.class.getName());
78         assertEquals(2.5f, addf(2.0f, 0.5f));
79         assertEquals(1.5f, subf(2.0f, 0.5f));
80     }
81 }
82