blob: e8447a3635c1f8dfe6671dfe93a5792946aca6e1 [file] [log] [blame]
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +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
12
13public class InvokeCustom {
14
15 private static String staticField1 = "StaticField1";
16
17 private static void targetMethodTest1() {
18 System.out.println("Hello World!");
19 }
20
21 private static void targetMethodTest2(MethodHandle mhInvokeStatic, MethodHandle mhGetStatic)
22 throws Throwable {
23 mhInvokeStatic.invokeExact();
24 System.out.println(mhGetStatic.invoke());
25 }
26
Mikaël Peltiercfd6dac2017-10-10 13:45:55 +020027 private static void targetMethodTest3(MethodType mt)
28 throws Throwable {
29 System.out.println("MethodType: " + mt.toString());
30 }
31
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +020032 public static CallSite bsmLookupStatic(MethodHandles.Lookup caller, String name, MethodType type)
33 throws NoSuchMethodException, IllegalAccessException {
34 final MethodHandles.Lookup lookup = MethodHandles.lookup();
35 final MethodHandle targetMH = lookup.findStatic(lookup.lookupClass(), name, type);
36 return new ConstantCallSite(targetMH.asType(type));
37 }
Mikaël Peltier7b7b53a2017-10-09 13:33:21 +020038}