23 |
23 |
24 /* |
24 /* |
25 * @test |
25 * @test |
26 * @bug 8015436 |
26 * @bug 8015436 |
27 * @summary the IK _initial_method_idnum value must be adjusted if overpass methods are added |
27 * @summary the IK _initial_method_idnum value must be adjusted if overpass methods are added |
|
28 * @library /test/lib/share/classes / |
|
29 * @modules java.base/jdk.internal.misc |
|
30 * @build compiler.runtime.cr8015436.Test8015436 |
|
31 * compiler.runtime.cr8015436.Driver8015436 |
28 * |
32 * |
29 * @run main compiler.runtime.cr8015436.Test8015436 |
33 * @run driver compiler.runtime.cr8015436.Driver8015436 |
30 */ |
34 */ |
31 |
35 |
32 /* |
36 /* |
33 * The test checks that a MemberName for the defaultMethod() is cached in |
37 * The test checks that a MemberName for the defaultMethod() is cached in |
34 * the class MemberNameTable without a crash in the VM fastdebug mode. |
38 * the class MemberNameTable without a crash in the VM fastdebug mode. |
43 import java.lang.invoke.MethodHandle; |
47 import java.lang.invoke.MethodHandle; |
44 import java.lang.invoke.MethodHandles; |
48 import java.lang.invoke.MethodHandles; |
45 import java.lang.invoke.MethodType; |
49 import java.lang.invoke.MethodType; |
46 |
50 |
47 public class Test8015436 implements InterfaceWithDefaultMethod { |
51 public class Test8015436 implements InterfaceWithDefaultMethod { |
|
52 public static final String SOME_MTD_INVOKED = "someMethod() invoked"; |
|
53 public static final String DEFAULT_MTD_INVOKED_DIRECTLY = "defaultMethod() invoked directly"; |
|
54 public static final String DEFAULT_MTD_INVOKED_MH = "defaultMethod() invoked via a MethodHandle"; |
|
55 |
48 @Override |
56 @Override |
49 public void someMethod() { |
57 public void someMethod() { |
50 System.out.println("someMethod() invoked"); |
58 System.out.println(SOME_MTD_INVOKED); |
51 } |
59 } |
52 |
60 |
53 public static void main(String[] args) throws Throwable { |
61 public static void main(String[] args) throws Throwable { |
54 Test8015436 testObj = new Test8015436(); |
62 Test8015436 testObj = new Test8015436(); |
55 testObj.someMethod(); |
63 testObj.someMethod(); |
56 testObj.defaultMethod("invoked directly"); |
64 testObj.defaultMethod(DEFAULT_MTD_INVOKED_DIRECTLY); |
57 |
65 |
58 MethodHandles.Lookup lookup = MethodHandles.lookup(); |
66 MethodHandles.Lookup lookup = MethodHandles.lookup(); |
59 MethodType mt = MethodType.methodType(void.class, String.class); |
67 MethodType mt = MethodType.methodType(void.class, String.class); |
60 MethodHandle mh = lookup.findVirtual(Test8015436.class, "defaultMethod", mt); |
68 MethodHandle mh = lookup.findVirtual(Test8015436.class, "defaultMethod", mt); |
61 mh.invokeExact(testObj, "invoked via a MethodHandle"); |
69 mh.invokeExact(testObj, DEFAULT_MTD_INVOKED_MH); |
62 } |
70 } |
63 } |
71 } |
64 |
72 |
65 interface InterfaceWithDefaultMethod { |
73 interface InterfaceWithDefaultMethod { |
66 public void someMethod(); |
74 public void someMethod(); |
67 |
75 |
68 default public void defaultMethod(String str){ |
76 default public void defaultMethod(String str){ |
69 System.out.println("defaultMethod() " + str); |
77 System.out.println(str); |
70 } |
78 } |
71 } |
79 } |
72 /* |
80 /* |
73 * A successful execution gives the output: |
81 * A successful execution gives the output: |
74 * someMethod() invoked |
82 * someMethod() invoked |