|
1 /* |
|
2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 |
|
24 /* |
|
25 * @test |
|
26 * @bug 8195650 |
|
27 * @summary Test linking of method references to VarHandle access methods. |
|
28 * @run testng VarHandleMethodReferenceTest |
|
29 */ |
|
30 |
|
31 import org.testng.annotations.Test; |
|
32 |
|
33 import java.lang.invoke.*; |
|
34 |
|
35 public class VarHandleMethodReferenceTest { |
|
36 |
|
37 interface R { |
|
38 void apply(); |
|
39 } |
|
40 |
|
41 @Test |
|
42 public void testMethodReferences() { |
|
43 VarHandle vh = MethodHandles.arrayElementVarHandle(int[].class); |
|
44 |
|
45 // The compilation of these method references will result in the |
|
46 // placement of MethodHandles in the constant pool that reference |
|
47 // VarHandle signature polymorphic methods. |
|
48 // When those constant method handles are loaded the VarHandle invoker |
|
49 // mechanism will be used where the first argument to invocation will be |
|
50 // the bound VarHandle instance |
|
51 |
|
52 // VarHandle invokers are tested by other test classes so here it |
|
53 // is just necessary to check that functional objects can be successfully |
|
54 // obtained, it does not matter about the signature of the functional |
|
55 // interface |
|
56 |
|
57 R r; |
|
58 r = vh::get; |
|
59 r = vh::set; |
|
60 r = vh::getVolatile; |
|
61 r = vh::setVolatile; |
|
62 r = vh::getOpaque; |
|
63 r = vh::setOpaque; |
|
64 r = vh::getAcquire; |
|
65 r = vh::setRelease; |
|
66 |
|
67 r = vh::compareAndSet; |
|
68 r = vh::compareAndExchange; |
|
69 r = vh::compareAndExchangeAcquire; |
|
70 r = vh::compareAndExchangeRelease; |
|
71 r = vh::weakCompareAndSetPlain; |
|
72 r = vh::weakCompareAndSet; |
|
73 r = vh::weakCompareAndSetAcquire; |
|
74 r = vh::weakCompareAndSetRelease; |
|
75 |
|
76 r = vh::getAndSet; |
|
77 r = vh::getAndSetAcquire; |
|
78 r = vh::getAndSetRelease; |
|
79 r = vh::getAndAdd; |
|
80 r = vh::getAndAddAcquire; |
|
81 r = vh::getAndAddRelease; |
|
82 r = vh::getAndBitwiseOr; |
|
83 r = vh::getAndBitwiseOrAcquire; |
|
84 r = vh::getAndBitwiseOrRelease; |
|
85 r = vh::getAndBitwiseAnd; |
|
86 r = vh::getAndBitwiseAndAcquire; |
|
87 r = vh::getAndBitwiseAndRelease; |
|
88 r = vh::getAndBitwiseXor; |
|
89 r = vh::getAndBitwiseXorAcquire; |
|
90 r = vh::getAndBitwiseXorRelease; |
|
91 } |
|
92 } |