Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1 | // Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file |
| 2 | // for details. All rights reserved. Use of this source code is governed by a |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | package invokecustom; |
| 5 | |
| 6 | import java.lang.invoke.CallSite; |
| 7 | import java.lang.invoke.ConstantCallSite; |
| 8 | import java.lang.invoke.MethodHandle; |
| 9 | import java.lang.invoke.MethodHandles; |
| 10 | import java.lang.invoke.MethodType; |
| 11 | |
| 12 | interface J { |
| 13 | |
| 14 | default void targetMethodTest8() { |
| 15 | System.out.println("targetMethodTest8 from J"); |
| 16 | } |
| 17 | |
| 18 | default void targetMethodTest7() { |
| 19 | System.out.println("targetMethodTest7 from J"); |
| 20 | } |
| 21 | |
| 22 | default void targetMethodTest6() { |
| 23 | System.out.println("targetMethodTest6 from J"); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | interface I extends J { |
| 28 | void targetMethodTest8(); |
| 29 | |
| 30 | default void targetMethodTest6() { |
| 31 | System.out.println("targetMethodTest6 from I"); |
| 32 | } |
| 33 | |
| 34 | default void targetMethodTest9() { |
| 35 | System.out.println("targetMethodTest9 from I"); |
| 36 | } |
| 37 | |
| 38 | default void targetMethodTest10() { |
| 39 | System.out.println("targetMethodTest10 from I"); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | abstract class Super { |
| 44 | public void targetMethodTest5() { |
| 45 | System.out.println("targetMethodTest5 from Super"); |
| 46 | } |
| 47 | |
| 48 | abstract void targetMethodTest10(); |
| 49 | } |
| 50 | |
| 51 | public class InvokeCustom extends Super implements I { |
| 52 | |
| 53 | private static String staticField1 = "StaticField1"; |
| 54 | |
| 55 | private String instanceField1 = "instanceField1"; |
| 56 | |
| 57 | private static void targetMethodTest1() { |
| 58 | System.out.println("Hello World!"); |
| 59 | } |
| 60 | |
| 61 | private static void targetMethodTest2(boolean z, byte b, char c, short s, int i, float f, long l, |
| 62 | double d, String str) { |
| 63 | System.out.println(z); |
| 64 | System.out.println(b); |
| 65 | System.out.println(c); |
| 66 | System.out.println(s); |
| 67 | System.out.println(i); |
| 68 | System.out.println(f); |
| 69 | System.out.println(l); |
| 70 | System.out.println(d); |
| 71 | System.out.println(str); |
| 72 | } |
| 73 | |
| 74 | private static void targetMethodTest3() { |
| 75 | } |
| 76 | |
| 77 | public static CallSite bsmLookupStatic(MethodHandles.Lookup caller, String name, MethodType type) |
| 78 | throws NoSuchMethodException, IllegalAccessException { |
| 79 | final MethodHandles.Lookup lookup = MethodHandles.lookup(); |
| 80 | final MethodHandle targetMH = lookup.findStatic(lookup.lookupClass(), name, type); |
| 81 | return new ConstantCallSite(targetMH.asType(type)); |
| 82 | } |
| 83 | |
| 84 | public static CallSite bsmLookupStaticWithExtraArgs( |
| 85 | MethodHandles.Lookup caller, String name, MethodType type, int i, long l, float f, double d) |
| 86 | throws NoSuchMethodException, IllegalAccessException { |
| 87 | System.out.println(i); |
| 88 | System.out.println(l); |
| 89 | System.out.println(f); |
| 90 | System.out.println(d); |
| 91 | final MethodHandles.Lookup lookup = MethodHandles.lookup(); |
| 92 | final MethodHandle targetMH = lookup.findStatic(lookup.lookupClass(), name, type); |
| 93 | return new ConstantCallSite(targetMH.asType(type)); |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public void targetMethodTest5() { |
| 98 | System.out.println("targetMethodTest5 from InvokeCustom"); |
| 99 | } |
| 100 | |
| 101 | private static void targetMethodTest4() { |
| 102 | System.out.println("targetMethodTest4"); |
| 103 | } |
| 104 | |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 105 | public void targetMethodTest8() { |
| 106 | System.out.println("targetMethodTest8 from InvokeCustom"); |
| 107 | } |
| 108 | |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 109 | public void targetMethodTest10() { |
| 110 | System.out.println("targetMethodTest10 from InvokeCustom"); |
| 111 | } |
| 112 | |
mikaelpeltier | a05d3d5 | 2017-08-21 15:03:22 +0200 | [diff] [blame] | 113 | public static CallSite bsmCreateCallSite( |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 114 | MethodHandles.Lookup caller, String name, MethodType type, MethodHandle mh) |
| 115 | throws Throwable { |
| 116 | return new ConstantCallSite(mh); |
| 117 | } |
| 118 | } |