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 * @run testng/othervm -Diters=20000 VarHandleTestMethodHandleAccessLong
27 */
28
29 import org.testng.annotations.BeforeClass;
30 import org.testng.annotations.DataProvider;
31 import org.testng.annotations.Test;
32
33 import java.lang.invoke.MethodHandles;
34 import java.lang.invoke.VarHandle;
35 import java.util.ArrayList;
36 import java.util.Arrays;
37 import java.util.List;
38
39 import static org.testng.Assert.*;
40
41 public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest {
42 static final long static_final_v = 0x0123456789ABCDEFL;
43
44 static long static_v;
45
46 final long final_v = 0x0123456789ABCDEFL;
47
48 long v;
49
50 VarHandle vhFinalField;
51
52 VarHandle vhField;
53
54 VarHandle vhStaticField;
55
56 VarHandle vhStaticFinalField;
57
58 VarHandle vhArray;
59
60 @BeforeClass
61 public void setup() throws Exception {
62 vhFinalField = MethodHandles.lookup().findVarHandle(
63 VarHandleTestMethodHandleAccessLong.class, "final_v", long.class);
64
65 vhField = MethodHandles.lookup().findVarHandle(
66 VarHandleTestMethodHandleAccessLong.class, "v", long.class);
67
68 vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
69 VarHandleTestMethodHandleAccessLong.class, "static_final_v", long.class);
70
71 vhStaticField = MethodHandles.lookup().findStaticVarHandle(
72 VarHandleTestMethodHandleAccessLong.class, "static_v", long.class);
73
74 vhArray = MethodHandles.arrayElementVarHandle(long[].class);
75 }
76
77
78 @DataProvider
79 public Object[][] accessTestCaseProvider() throws Exception {
80 List<AccessTestCase<?>> cases = new ArrayList<>();
81
82 for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
83 cases.add(new MethodHandleAccessTestCase("Instance field",
84 vhField, f, hs -> testInstanceField(this, hs)));
85 cases.add(new MethodHandleAccessTestCase("Instance field unsupported",
86 vhField, f, hs -> testInstanceFieldUnsupported(this, hs),
87 false));
88
89 cases.add(new MethodHandleAccessTestCase("Static field",
90 vhStaticField, f, VarHandleTestMethodHandleAccessLong::testStaticField));
91 cases.add(new MethodHandleAccessTestCase("Static field unsupported",
92 vhStaticField, f, VarHandleTestMethodHandleAccessLong::testStaticFieldUnsupported,
93 false));
94
95 cases.add(new MethodHandleAccessTestCase("Array",
96 vhArray, f, VarHandleTestMethodHandleAccessLong::testArray));
97 cases.add(new MethodHandleAccessTestCase("Array unsupported",
98 vhArray, f, VarHandleTestMethodHandleAccessLong::testArrayUnsupported,
99 false));
100 cases.add(new MethodHandleAccessTestCase("Array index out of bounds",
101 vhArray, f, VarHandleTestMethodHandleAccessLong::testArrayIndexOutOfBounds,
102 false));
103 }
104
105 // Work around issue with jtreg summary reporting which truncates
106 // the String result of Object.toString to 30 characters, hence
107 // the first dummy argument
108 return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
109 }
110
111 @Test(dataProvider = "accessTestCaseProvider")
112 public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
113 T t = atc.get();
114 int iters = atc.requiresLoop() ? ITERS : 1;
115 for (int c = 0; c < iters; c++) {
116 atc.testAccess(t);
117 }
118 }
119
120
121 static void testInstanceField(VarHandleTestMethodHandleAccessLong recv, Handles hs) throws Throwable {
122 // Plain
356 assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorAcquire long");
357 long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
358 assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorAcquire long value");
359 }
360
361 {
362 hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
363
364 long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(recv, 0xCAFEBABECAFEBABEL);
365 assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorRelease long");
366 long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
367 assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorRelease long value");
368 }
369 }
370
371 static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessLong recv, Handles hs) throws Throwable {
372
373
374 }
375
376
377 static void testStaticField(Handles hs) throws Throwable {
378 // Plain
379 {
380 hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
381 long x = (long) hs.get(TestAccessMode.GET).invokeExact();
382 assertEquals(x, 0x0123456789ABCDEFL, "set long value");
383 }
384
385
386 // Volatile
387 {
388 hs.get(TestAccessMode.SET_VOLATILE).invokeExact(0xCAFEBABECAFEBABEL);
389 long x = (long) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
390 assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value");
391 }
392
393 // Lazy
394 {
395 hs.get(TestAccessMode.SET_RELEASE).invokeExact(0x0123456789ABCDEFL);
|
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 // -- This file was mechanically generated: Do not edit! -- //
25
26 /*
27 * @test
28 * @run testng/othervm -Diters=20000 VarHandleTestMethodHandleAccessLong
29 */
30
31 import org.testng.annotations.BeforeClass;
32 import org.testng.annotations.DataProvider;
33 import org.testng.annotations.Test;
34
35 import java.lang.invoke.MethodHandles;
36 import java.lang.invoke.VarHandle;
37 import java.util.ArrayList;
38 import java.util.Arrays;
39 import java.util.List;
40
41 import static org.testng.Assert.*;
42
43 public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest {
44 static final Class<?> type = long.class;
45
46 static final long static_final_v = 0x0123456789ABCDEFL;
47
48 static long static_v;
49
50 final long final_v = 0x0123456789ABCDEFL;
51
52 long v;
53
54 VarHandle vhFinalField;
55
56 VarHandle vhField;
57
58 VarHandle vhStaticField;
59
60 VarHandle vhStaticFinalField;
61
62 VarHandle vhArray;
63
64 VarHandle vhValueTypeField;
65
66 @BeforeClass
67 public void setup() throws Exception {
68 vhFinalField = MethodHandles.lookup().findVarHandle(
69 VarHandleTestMethodHandleAccessLong.class, "final_v", type);
70
71 vhField = MethodHandles.lookup().findVarHandle(
72 VarHandleTestMethodHandleAccessLong.class, "v", type);
73
74 vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
75 VarHandleTestMethodHandleAccessLong.class, "static_final_v", type);
76
77 vhStaticField = MethodHandles.lookup().findStaticVarHandle(
78 VarHandleTestMethodHandleAccessLong.class, "static_v", type);
79
80 vhArray = MethodHandles.arrayElementVarHandle(long[].class);
81
82 vhValueTypeField = MethodHandles.lookup().findVarHandle(
83 Value.class, "long_v", type);
84 }
85
86
87 @DataProvider
88 public Object[][] accessTestCaseProvider() throws Exception {
89 List<AccessTestCase<?>> cases = new ArrayList<>();
90
91 for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
92 cases.add(new MethodHandleAccessTestCase("Instance field",
93 vhField, f, hs -> testInstanceField(this, hs)));
94 cases.add(new MethodHandleAccessTestCase("Instance field unsupported",
95 vhField, f, hs -> testInstanceFieldUnsupported(this, hs),
96 false));
97
98 cases.add(new MethodHandleAccessTestCase("Static field",
99 vhStaticField, f, VarHandleTestMethodHandleAccessLong::testStaticField));
100 cases.add(new MethodHandleAccessTestCase("Static field unsupported",
101 vhStaticField, f, VarHandleTestMethodHandleAccessLong::testStaticFieldUnsupported,
102 false));
103
104 cases.add(new MethodHandleAccessTestCase("Array",
105 vhArray, f, VarHandleTestMethodHandleAccessLong::testArray));
106 cases.add(new MethodHandleAccessTestCase("Array unsupported",
107 vhArray, f, VarHandleTestMethodHandleAccessLong::testArrayUnsupported,
108 false));
109 cases.add(new MethodHandleAccessTestCase("Array index out of bounds",
110 vhArray, f, VarHandleTestMethodHandleAccessLong::testArrayIndexOutOfBounds,
111 false));
112 cases.add(new MethodHandleAccessTestCase("Value type field",
113 vhValueTypeField, f, hs -> testValueTypeField(Value.getInstance(), hs)));
114 cases.add(new MethodHandleAccessTestCase("Value type field unsupported",
115 vhValueTypeField, f, hs -> testValueTypeFieldUnsupported(Value.getInstance(), hs),
116 false));
117 }
118
119 // Work around issue with jtreg summary reporting which truncates
120 // the String result of Object.toString to 30 characters, hence
121 // the first dummy argument
122 return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
123 }
124
125 @Test(dataProvider = "accessTestCaseProvider")
126 public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
127 T t = atc.get();
128 int iters = atc.requiresLoop() ? ITERS : 1;
129 for (int c = 0; c < iters; c++) {
130 atc.testAccess(t);
131 }
132 }
133
134
135 static void testInstanceField(VarHandleTestMethodHandleAccessLong recv, Handles hs) throws Throwable {
136 // Plain
370 assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorAcquire long");
371 long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
372 assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorAcquire long value");
373 }
374
375 {
376 hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL);
377
378 long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(recv, 0xCAFEBABECAFEBABEL);
379 assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorRelease long");
380 long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
381 assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorRelease long value");
382 }
383 }
384
385 static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessLong recv, Handles hs) throws Throwable {
386
387
388 }
389
390 static void testValueTypeField(Value recv, Handles hs) throws Throwable {
391 // Plain
392 {
393 long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
394 assertEquals(x, 0x0123456789ABCDEFL, "get long value");
395 }
396 }
397
398 static void testValueTypeFieldUnsupported(Value recv, Handles hs) throws Throwable {
399 // Plain
400 for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
401 checkUOE(am, () -> {
402 hs.get(am).invokeExact(recv, 0x0123456789ABCDEFL);
403 });
404 }
405
406
407 }
408
409 static void testStaticField(Handles hs) throws Throwable {
410 // Plain
411 {
412 hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL);
413 long x = (long) hs.get(TestAccessMode.GET).invokeExact();
414 assertEquals(x, 0x0123456789ABCDEFL, "set long value");
415 }
416
417
418 // Volatile
419 {
420 hs.get(TestAccessMode.SET_VOLATILE).invokeExact(0xCAFEBABECAFEBABEL);
421 long x = (long) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
422 assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value");
423 }
424
425 // Lazy
426 {
427 hs.get(TestAccessMode.SET_RELEASE).invokeExact(0x0123456789ABCDEFL);
|