| Orion Hodson | 36bce3b | 2018-02-26 10:04:25 +0000 | [diff] [blame] | 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 | |
| Orion Hodson | 4c213cb | 2018-02-26 10:25:41 +0000 | [diff] [blame] | 17 | import annotations.BootstrapMethod; |
| Orion Hodson | 36bce3b | 2018-02-26 10:04:25 +0000 | [diff] [blame] | 18 | import annotations.CalledByIndy; |
| 19 | import annotations.Constant; |
| Orion Hodson | 36bce3b | 2018-02-26 10:04:25 +0000 | [diff] [blame] | 20 | import java.lang.invoke.MethodHandles; |
| 21 | import java.lang.invoke.MethodType; |
| 22 | |
| 23 | class TestLinkerUnrelatedBSM extends TestBase { |
| 24 | @CalledByIndy( |
| Orion Hodson | 4c213cb | 2018-02-26 10:25:41 +0000 | [diff] [blame] | 25 | bootstrapMethod = |
| 26 | @BootstrapMethod( |
| Orion Hodson | 36bce3b | 2018-02-26 10:04:25 +0000 | [diff] [blame] | 27 | enclosingType = UnrelatedBSM.class, |
| Orion Hodson | 4c213cb | 2018-02-26 10:25:41 +0000 | [diff] [blame] | 28 | parameterTypes = { |
| Orion Hodson | 36bce3b | 2018-02-26 10:04:25 +0000 | [diff] [blame] | 29 | MethodHandles.Lookup.class, |
| 30 | String.class, |
| 31 | MethodType.class, |
| 32 | Class.class |
| 33 | }, |
| 34 | name = "bsm" |
| 35 | ), |
| Orion Hodson | 4c213cb | 2018-02-26 10:25:41 +0000 | [diff] [blame] | 36 | fieldOrMethodName = "_addf", |
| Orion Hodson | 36bce3b | 2018-02-26 10:04:25 +0000 | [diff] [blame] | 37 | returnType = float.class, |
| Orion Hodson | 4c213cb | 2018-02-26 10:25:41 +0000 | [diff] [blame] | 38 | parameterTypes = {float.class, float.class}, |
| 39 | constantArgumentsForBootstrapMethod = {@Constant(classValue = TestLinkerUnrelatedBSM.class)} |
| Orion Hodson | 36bce3b | 2018-02-26 10:04:25 +0000 | [diff] [blame] | 40 | ) |
| 41 | private static float addf(float a, float b) { |
| 42 | assertNotReached(); |
| 43 | return Float.MIN_VALUE; |
| 44 | } |
| 45 | |
| 46 | public static float _addf(float a, float b) { |
| 47 | return a + b; |
| 48 | } |
| 49 | |
| 50 | @CalledByIndy( |
| Orion Hodson | 4c213cb | 2018-02-26 10:25:41 +0000 | [diff] [blame] | 51 | bootstrapMethod = |
| 52 | @BootstrapMethod( |
| Orion Hodson | 36bce3b | 2018-02-26 10:04:25 +0000 | [diff] [blame] | 53 | enclosingType = UnrelatedBSM.class, |
| Orion Hodson | 4c213cb | 2018-02-26 10:25:41 +0000 | [diff] [blame] | 54 | parameterTypes = { |
| Orion Hodson | 36bce3b | 2018-02-26 10:04:25 +0000 | [diff] [blame] | 55 | MethodHandles.Lookup.class, |
| 56 | String.class, |
| 57 | MethodType.class, |
| 58 | Class.class |
| 59 | }, |
| 60 | name = "bsm" |
| 61 | ), |
| Orion Hodson | 4c213cb | 2018-02-26 10:25:41 +0000 | [diff] [blame] | 62 | fieldOrMethodName = "_subf", |
| Orion Hodson | 36bce3b | 2018-02-26 10:04:25 +0000 | [diff] [blame] | 63 | returnType = float.class, |
| Orion Hodson | 4c213cb | 2018-02-26 10:25:41 +0000 | [diff] [blame] | 64 | parameterTypes = {float.class, float.class}, |
| 65 | constantArgumentsForBootstrapMethod = {@Constant(classValue = TestLinkerUnrelatedBSM.class)} |
| Orion Hodson | 36bce3b | 2018-02-26 10:04:25 +0000 | [diff] [blame] | 66 | ) |
| 67 | private static float subf(float a, float b) { |
| 68 | assertNotReached(); |
| 69 | return Float.MIN_VALUE; |
| 70 | } |
| 71 | |
| 72 | private static float _subf(float a, float b) { |
| 73 | return a - b; |
| 74 | } |
| 75 | |
| 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 | } |