blob: 449d4262b7fc9e0e702585d1bf0a127464c9ff18 [file] [log] [blame]
Mads Ager418d1ca2017-05-22 09:35:49 +02001// 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.
4package invokecustom;
5
6import java.lang.invoke.CallSite;
7import java.lang.invoke.ConstantCallSite;
8import java.lang.invoke.MethodHandle;
9import java.lang.invoke.MethodHandles;
10import java.lang.invoke.MethodType;
11
12interface 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
27interface 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
43abstract class Super {
44 public void targetMethodTest5() {
45 System.out.println("targetMethodTest5 from Super");
46 }
47
48 abstract void targetMethodTest10();
49}
50
51public 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 Ager418d1ca2017-05-22 09:35:49 +0200105 public void targetMethodTest8() {
106 System.out.println("targetMethodTest8 from InvokeCustom");
107 }
108
Mads Ager418d1ca2017-05-22 09:35:49 +0200109 public void targetMethodTest10() {
110 System.out.println("targetMethodTest10 from InvokeCustom");
111 }
112
mikaelpeltiera05d3d52017-08-21 15:03:22 +0200113 public static CallSite bsmCreateCallSite(
Mads Ager418d1ca2017-05-22 09:35:49 +0200114 MethodHandles.Lookup caller, String name, MethodType type, MethodHandle mh)
115 throws Throwable {
116 return new ConstantCallSite(mh);
117 }
118}