jdk/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessLong.java
author psandoz
Tue, 17 May 2016 12:06:41 +0200
changeset 38328 40435a469d25
parent 37719 add11bc0e6e2
child 38368 c8eb5d6812c5
permissions -rw-r--r--
8156485: MethodHandles.varHandleExactInvoker should perform exact checks Reviewed-by: vlivanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     1
/*
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     4
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     7
 * published by the Free Software Foundation.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     8
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    13
 * accompanied this code).
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    14
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    18
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    21
 * questions.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    22
 */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    23
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    24
/*
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    25
 * @test
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    26
 * @run testng/othervm -Diters=20000 VarHandleTestMethodHandleAccessLong
38328
40435a469d25 8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents: 37719
diff changeset
    27
 * @run testng/othervm -Diters=20000 -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false VarHandleTestMethodHandleAccessLong
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    28
 */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    29
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    30
import org.testng.annotations.BeforeClass;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    31
import org.testng.annotations.DataProvider;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    32
import org.testng.annotations.Test;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    33
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    34
import java.lang.invoke.MethodHandles;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    35
import java.lang.invoke.VarHandle;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    36
import java.util.ArrayList;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    37
import java.util.Arrays;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    38
import java.util.List;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    39
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    40
import static org.testng.Assert.*;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    41
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    42
public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    43
    static final long static_final_v = 1L;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    44
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    45
    static long static_v;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    46
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    47
    final long final_v = 1L;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    48
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    49
    long v;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    50
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    51
    VarHandle vhFinalField;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    52
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    53
    VarHandle vhField;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    54
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    55
    VarHandle vhStaticField;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    56
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    57
    VarHandle vhStaticFinalField;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    58
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    59
    VarHandle vhArray;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    60
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    61
    @BeforeClass
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    62
    public void setup() throws Exception {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    63
        vhFinalField = MethodHandles.lookup().findVarHandle(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    64
                VarHandleTestMethodHandleAccessLong.class, "final_v", long.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    65
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    66
        vhField = MethodHandles.lookup().findVarHandle(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    67
                VarHandleTestMethodHandleAccessLong.class, "v", long.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    68
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    69
        vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    70
            VarHandleTestMethodHandleAccessLong.class, "static_final_v", long.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    71
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    72
        vhStaticField = MethodHandles.lookup().findStaticVarHandle(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    73
            VarHandleTestMethodHandleAccessLong.class, "static_v", long.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    74
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    75
        vhArray = MethodHandles.arrayElementVarHandle(long[].class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    76
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    77
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    78
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    79
    @DataProvider
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    80
    public Object[][] accessTestCaseProvider() throws Exception {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    81
        List<AccessTestCase<?>> cases = new ArrayList<>();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    82
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    83
        for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    84
            cases.add(new MethodHandleAccessTestCase("Instance field",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    85
                                                     vhField, f, hs -> testInstanceField(this, hs)));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    86
            cases.add(new MethodHandleAccessTestCase("Instance field unsupported",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    87
                                                     vhField, f, hs -> testInstanceFieldUnsupported(this, hs),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    88
                                                     false));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    89
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    90
            cases.add(new MethodHandleAccessTestCase("Static field",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    91
                                                     vhStaticField, f, VarHandleTestMethodHandleAccessLong::testStaticField));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    92
            cases.add(new MethodHandleAccessTestCase("Static field unsupported",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    93
                                                     vhStaticField, f, VarHandleTestMethodHandleAccessLong::testStaticFieldUnsupported,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    94
                                                     false));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    95
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    96
            cases.add(new MethodHandleAccessTestCase("Array",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    97
                                                     vhArray, f, VarHandleTestMethodHandleAccessLong::testArray));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    98
            cases.add(new MethodHandleAccessTestCase("Array unsupported",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    99
                                                     vhArray, f, VarHandleTestMethodHandleAccessLong::testArrayUnsupported,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   100
                                                     false));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   101
            cases.add(new MethodHandleAccessTestCase("Array index out of bounds",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   102
                                                     vhArray, f, VarHandleTestMethodHandleAccessLong::testArrayIndexOutOfBounds,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   103
                                                     false));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   104
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   105
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   106
        // Work around issue with jtreg summary reporting which truncates
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   107
        // the String result of Object.toString to 30 characters, hence
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   108
        // the first dummy argument
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   109
        return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   110
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   111
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   112
    @Test(dataProvider = "accessTestCaseProvider")
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   113
    public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   114
        T t = atc.get();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   115
        int iters = atc.requiresLoop() ? ITERS : 1;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   116
        for (int c = 0; c < iters; c++) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   117
            atc.testAccess(t);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   118
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   119
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   120
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   121
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   122
    static void testInstanceField(VarHandleTestMethodHandleAccessLong recv, Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   123
        // Plain
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   124
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   125
            hs.get(TestAccessMode.SET).invokeExact(recv, 1L);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   126
            long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   127
            assertEquals(x, 1L, "set long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   128
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   129
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   130
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   131
        // Volatile
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   132
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   133
            hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, 2L);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   134
            long x = (long) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   135
            assertEquals(x, 2L, "setVolatile long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   136
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   137
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   138
        // Lazy
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   139
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   140
            hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, 1L);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   141
            long x = (long) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   142
            assertEquals(x, 1L, "setRelease long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   143
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   144
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   145
        // Opaque
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   146
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   147
            hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, 2L);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   148
            long x = (long) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   149
            assertEquals(x, 2L, "setOpaque long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   150
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   151
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   152
        hs.get(TestAccessMode.SET).invokeExact(recv, 1L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   153
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   154
        // Compare
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   155
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   156
            boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 1L, 2L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   157
            assertEquals(r, true, "success compareAndSet long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   158
            long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   159
            assertEquals(x, 2L, "success compareAndSet long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   160
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   161
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   162
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   163
            boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 1L, 3L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   164
            assertEquals(r, false, "failing compareAndSet long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   165
            long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   166
            assertEquals(x, 2L, "failing compareAndSet long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   167
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   168
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   169
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   170
            long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, 2L, 1L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   171
            assertEquals(r, 2L, "success compareAndExchangeVolatile long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   172
            long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   173
            assertEquals(x, 1L, "success compareAndExchangeVolatile long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   174
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   175
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   176
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   177
            long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, 2L, 3L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   178
            assertEquals(r, 1L, "failing compareAndExchangeVolatile long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   179
            long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   180
            assertEquals(x, 1L, "failing compareAndExchangeVolatile long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   181
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   182
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   183
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   184
            long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1L, 2L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   185
            assertEquals(r, 1L, "success compareAndExchangeAcquire long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   186
            long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   187
            assertEquals(x, 2L, "success compareAndExchangeAcquire long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   188
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   189
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   190
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   191
            long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1L, 3L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   192
            assertEquals(r, 2L, "failing compareAndExchangeAcquire long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   193
            long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   194
            assertEquals(x, 2L, "failing compareAndExchangeAcquire long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   195
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   196
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   197
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   198
            long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2L, 1L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   199
            assertEquals(r, 2L, "success compareAndExchangeRelease long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   200
            long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   201
            assertEquals(x, 1L, "success compareAndExchangeRelease long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   202
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   203
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   204
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   205
            long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2L, 3L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   206
            assertEquals(r, 1L, "failing compareAndExchangeRelease long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   207
            long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   208
            assertEquals(x, 1L, "failing compareAndExchangeRelease long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   209
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   210
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   211
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   212
            boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, 1L, 2L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   213
            assertEquals(r, true, "weakCompareAndSet long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   214
            long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   215
            assertEquals(x, 2L, "weakCompareAndSet long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   216
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   217
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   218
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   219
            boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, 2L, 1L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   220
            assertEquals(r, true, "weakCompareAndSetAcquire long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   221
            long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   222
            assertEquals(x, 1L, "weakCompareAndSetAcquire long");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   223
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   224
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   225
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   226
            boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, 1L, 2L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   227
            assertEquals(r, true, "weakCompareAndSetRelease long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   228
            long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   229
            assertEquals(x, 2L, "weakCompareAndSetRelease long");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   230
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   231
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   232
        {
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   233
            boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(recv, 2L, 1L);
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   234
            assertEquals(r, true, "weakCompareAndSetVolatile long");
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   235
            long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   236
            assertEquals(x, 1L, "weakCompareAndSetVolatile long value");
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   237
        }
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   238
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   239
        // Compare set and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   240
        {
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   241
            long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, 2L);
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   242
            assertEquals(o, 1L, "getAndSet long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   243
            long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv);
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   244
            assertEquals(x, 2L, "getAndSet long value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   245
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   246
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   247
        hs.get(TestAccessMode.SET).invokeExact(recv, 1L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   248
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   249
        // get and add, add and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   250
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   251
            long o = (long) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, 3L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   252
            assertEquals(o, 1L, "getAndAdd long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   253
            long c = (long) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(recv, 3L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   254
            assertEquals(c, 1L + 3L + 3L, "getAndAdd long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   255
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   256
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   257
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   258
    static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessLong recv, Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   259
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   260
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   261
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   262
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   263
    static void testStaticField(Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   264
        // Plain
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   265
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   266
            hs.get(TestAccessMode.SET).invokeExact(1L);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   267
            long x = (long) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   268
            assertEquals(x, 1L, "set long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   269
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   270
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   271
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   272
        // Volatile
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   273
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   274
            hs.get(TestAccessMode.SET_VOLATILE).invokeExact(2L);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   275
            long x = (long) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   276
            assertEquals(x, 2L, "setVolatile long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   277
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   278
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   279
        // Lazy
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   280
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   281
            hs.get(TestAccessMode.SET_RELEASE).invokeExact(1L);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   282
            long x = (long) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   283
            assertEquals(x, 1L, "setRelease long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   284
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   285
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   286
        // Opaque
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   287
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   288
            hs.get(TestAccessMode.SET_OPAQUE).invokeExact(2L);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   289
            long x = (long) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   290
            assertEquals(x, 2L, "setOpaque long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   291
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   292
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   293
        hs.get(TestAccessMode.SET).invokeExact(1L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   294
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   295
        // Compare
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   296
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   297
            boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1L, 2L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   298
            assertEquals(r, true, "success compareAndSet long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   299
            long x = (long) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   300
            assertEquals(x, 2L, "success compareAndSet long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   301
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   302
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   303
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   304
            boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1L, 3L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   305
            assertEquals(r, false, "failing compareAndSet long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   306
            long x = (long) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   307
            assertEquals(x, 2L, "failing compareAndSet long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   308
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   309
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   310
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   311
            long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(2L, 1L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   312
            assertEquals(r, 2L, "success compareAndExchangeVolatile long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   313
            long x = (long) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   314
            assertEquals(x, 1L, "success compareAndExchangeVolatile long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   315
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   316
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   317
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   318
            long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(2L, 3L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   319
            assertEquals(r, 1L, "failing compareAndExchangeVolatile long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   320
            long x = (long) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   321
            assertEquals(x, 1L, "failing compareAndExchangeVolatile long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   322
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   323
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   324
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   325
            long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1L, 2L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   326
            assertEquals(r, 1L, "success compareAndExchangeAcquire long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   327
            long x = (long) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   328
            assertEquals(x, 2L, "success compareAndExchangeAcquire long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   329
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   330
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   331
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   332
            long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1L, 3L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   333
            assertEquals(r, 2L, "failing compareAndExchangeAcquire long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   334
            long x = (long) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   335
            assertEquals(x, 2L, "failing compareAndExchangeAcquire long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   336
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   337
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   338
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   339
            long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2L, 1L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   340
            assertEquals(r, 2L, "success compareAndExchangeRelease long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   341
            long x = (long) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   342
            assertEquals(x, 1L, "success compareAndExchangeRelease long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   343
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   344
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   345
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   346
            long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2L, 3L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   347
            assertEquals(r, 1L, "failing compareAndExchangeRelease long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   348
            long x = (long) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   349
            assertEquals(x, 1L, "failing compareAndExchangeRelease long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   350
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   351
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   352
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   353
            boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(1L, 2L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   354
            assertEquals(r, true, "weakCompareAndSet long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   355
            long x = (long) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   356
            assertEquals(x, 2L, "weakCompareAndSet long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   357
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   358
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   359
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   360
            boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(2L, 1L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   361
            assertEquals(r, true, "weakCompareAndSetAcquire long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   362
            long x = (long) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   363
            assertEquals(x, 1L, "weakCompareAndSetAcquire long");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   364
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   365
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   366
        {
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   367
            boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(1L, 2L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   368
            assertEquals(r, true, "weakCompareAndSetRelease long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   369
            long x = (long) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   370
            assertEquals(x, 2L, "weakCompareAndSetRelease long");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   371
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   372
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   373
        {
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   374
            boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(2L, 1L);
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   375
            assertEquals(r, true, "weakCompareAndSetVolatile long");
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   376
            long x = (long) hs.get(TestAccessMode.GET).invokeExact();
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   377
            assertEquals(x, 1L, "weakCompareAndSetVolatile long value");
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   378
        }
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   379
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   380
        // Compare set and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   381
        {
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   382
            long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact(2L);
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   383
            assertEquals(o, 1L, "getAndSet long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   384
            long x = (long) hs.get(TestAccessMode.GET).invokeExact();
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   385
            assertEquals(x, 2L, "getAndSet long value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   386
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   387
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   388
        hs.get(TestAccessMode.SET).invokeExact(1L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   389
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   390
        // get and add, add and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   391
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   392
            long o = (long) hs.get(TestAccessMode.GET_AND_ADD).invokeExact( 3L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   393
            assertEquals(o, 1L, "getAndAdd long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   394
            long c = (long) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(3L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   395
            assertEquals(c, 1L + 3L + 3L, "getAndAdd long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   396
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   397
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   398
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   399
    static void testStaticFieldUnsupported(Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   400
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   401
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   402
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   403
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   404
    static void testArray(Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   405
        long[] array = new long[10];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   406
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   407
        for (int i = 0; i < array.length; i++) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   408
            // Plain
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   409
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   410
                hs.get(TestAccessMode.SET).invokeExact(array, i, 1L);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   411
                long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   412
                assertEquals(x, 1L, "get long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   413
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   414
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   415
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   416
            // Volatile
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   417
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   418
                hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, 2L);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   419
                long x = (long) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   420
                assertEquals(x, 2L, "setVolatile long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   421
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   422
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   423
            // Lazy
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   424
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   425
                hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, 1L);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   426
                long x = (long) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   427
                assertEquals(x, 1L, "setRelease long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   428
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   429
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   430
            // Opaque
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   431
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   432
                hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, 2L);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   433
                long x = (long) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   434
                assertEquals(x, 2L, "setOpaque long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   435
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   436
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   437
            hs.get(TestAccessMode.SET).invokeExact(array, i, 1L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   438
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   439
            // Compare
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   440
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   441
                boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1L, 2L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   442
                assertEquals(r, true, "success compareAndSet long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   443
                long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   444
                assertEquals(x, 2L, "success compareAndSet long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   445
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   446
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   447
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   448
                boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1L, 3L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   449
                assertEquals(r, false, "failing compareAndSet long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   450
                long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   451
                assertEquals(x, 2L, "failing compareAndSet long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   452
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   453
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   454
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   455
                long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, 2L, 1L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   456
                assertEquals(r, 2L, "success compareAndExchangeVolatile long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   457
                long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   458
                assertEquals(x, 1L, "success compareAndExchangeVolatile long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   459
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   460
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   461
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   462
                long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, 2L, 3L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   463
                assertEquals(r, 1L, "failing compareAndExchangeVolatile long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   464
                long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   465
                assertEquals(x, 1L, "failing compareAndExchangeVolatile long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   466
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   467
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   468
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   469
                long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1L, 2L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   470
                assertEquals(r, 1L, "success compareAndExchangeAcquire long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   471
                long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   472
                assertEquals(x, 2L, "success compareAndExchangeAcquire long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   473
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   474
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   475
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   476
                long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1L, 3L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   477
                assertEquals(r, 2L, "failing compareAndExchangeAcquire long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   478
                long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   479
                assertEquals(x, 2L, "failing compareAndExchangeAcquire long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   480
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   481
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   482
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   483
                long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2L, 1L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   484
                assertEquals(r, 2L, "success compareAndExchangeRelease long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   485
                long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   486
                assertEquals(x, 1L, "success compareAndExchangeRelease long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   487
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   488
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   489
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   490
                long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2L, 3L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   491
                assertEquals(r, 1L, "failing compareAndExchangeRelease long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   492
                long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   493
                assertEquals(x, 1L, "failing compareAndExchangeRelease long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   494
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   495
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   496
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   497
                boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, 1L, 2L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   498
                assertEquals(r, true, "weakCompareAndSet long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   499
                long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   500
                assertEquals(x, 2L, "weakCompareAndSet long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   501
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   502
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   503
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   504
                boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 2L, 1L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   505
                assertEquals(r, true, "weakCompareAndSetAcquire long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   506
                long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   507
                assertEquals(x, 1L, "weakCompareAndSetAcquire long");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   508
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   509
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   510
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   511
                boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, 1L, 2L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   512
                assertEquals(r, true, "weakCompareAndSetRelease long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   513
                long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   514
                assertEquals(x, 2L, "weakCompareAndSetRelease long");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   515
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   516
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   517
            {
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   518
                boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(array, i, 2L, 1L);
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   519
                assertEquals(r, true, "weakCompareAndSetVolatile long");
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   520
                long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   521
                assertEquals(x, 1L, "weakCompareAndSetVolatile long value");
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   522
            }
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   523
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   524
            // Compare set and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   525
            {
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   526
                long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, 2L);
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   527
                assertEquals(o, 1L, "getAndSet long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   528
                long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i);
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   529
                assertEquals(x, 2L, "getAndSet long value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   530
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   531
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   532
            hs.get(TestAccessMode.SET).invokeExact(array, i, 1L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   533
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   534
            // get and add, add and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   535
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   536
                long o = (long) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, 3L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   537
                assertEquals(o, 1L, "getAndAdd long");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   538
                long c = (long) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(array, i, 3L);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   539
                assertEquals(c, 1L + 3L + 3L, "getAndAdd long value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   540
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   541
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   542
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   543
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   544
    static void testArrayUnsupported(Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   545
        long[] array = new long[10];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   546
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   547
        final int i = 0;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   548
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   549
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   550
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   551
    static void testArrayIndexOutOfBounds(Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   552
        long[] array = new long[10];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   553
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   554
        for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   555
            final int ci = i;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   556
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   557
            for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   558
                checkIOOBE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   559
                    long x = (long) hs.get(am).invokeExact(array, ci);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   560
                });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   561
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   562
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   563
            for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   564
                checkIOOBE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   565
                    hs.get(am).invokeExact(array, ci, 1L);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   566
                });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   567
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   568
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   569
            for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   570
                checkIOOBE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   571
                    boolean r = (boolean) hs.get(am).invokeExact(array, ci, 1L, 2L);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   572
                });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   573
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   574
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   575
            for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   576
                checkIOOBE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   577
                    long r = (long) hs.get(am).invokeExact(array, ci, 2L, 1L);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   578
                });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   579
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   580
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   581
            for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   582
                checkIOOBE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   583
                    long o = (long) hs.get(am).invokeExact(array, ci, 1L);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   584
                });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   585
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   586
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   587
            for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   588
                checkIOOBE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   589
                    long o = (long) hs.get(am).invokeExact(array, ci, 3L);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   590
                });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   591
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   592
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   593
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   594
}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   595