jdk/test/java/lang/invoke/VarHandles/X-VarHandleTestMethodHandleAccess.java.template
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 VarHandleTestMethodHandleAccess$Type$
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 VarHandleTestMethodHandleAccess$Type$
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 VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    43
    static final $type$ static_final_v = $value1$;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    44
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    45
    static $type$ static_v;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    46
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    47
    final $type$ final_v = $value1$;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    48
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    49
    $type$ 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
                VarHandleTestMethodHandleAccess$Type$.class, "final_v", $type$.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
                VarHandleTestMethodHandleAccess$Type$.class, "v", $type$.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
            VarHandleTestMethodHandleAccess$Type$.class, "static_final_v", $type$.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
            VarHandleTestMethodHandleAccess$Type$.class, "static_v", $type$.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    74
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    75
        vhArray = MethodHandles.arrayElementVarHandle($type$[].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, VarHandleTestMethodHandleAccess$Type$::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, VarHandleTestMethodHandleAccess$Type$::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, VarHandleTestMethodHandleAccess$Type$::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, VarHandleTestMethodHandleAccess$Type$::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, VarHandleTestMethodHandleAccess$Type$::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(VarHandleTestMethodHandleAccess$Type$ 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, $value1$);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   126
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   127
            assertEquals(x, $value1$, "set $type$ 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, $value2$);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   134
            $type$ x = ($type$) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   135
            assertEquals(x, $value2$, "setVolatile $type$ 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, $value1$);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   141
            $type$ x = ($type$) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   142
            assertEquals(x, $value1$, "setRelease $type$ 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, $value2$);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   148
            $type$ x = ($type$) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   149
            assertEquals(x, $value2$, "setOpaque $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   150
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   151
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   152
#if[CAS]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   153
        hs.get(TestAccessMode.SET).invokeExact(recv, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   154
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   155
        // Compare
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   156
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   157
            boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, $value1$, $value2$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   158
            assertEquals(r, true, "success compareAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   159
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   160
            assertEquals(x, $value2$, "success compareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   161
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   162
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   163
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   164
            boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, $value1$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   165
            assertEquals(r, false, "failing compareAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   166
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   167
            assertEquals(x, $value2$, "failing compareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   168
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   169
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   170
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   171
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, $value2$, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   172
            assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   173
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   174
            assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   175
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   176
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   177
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   178
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, $value2$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   179
            assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   180
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   181
            assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   182
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   183
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   184
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   185
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, $value1$, $value2$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   186
            assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   187
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   188
            assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   189
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   190
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   191
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   192
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, $value1$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   193
            assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   194
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   195
            assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   196
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   197
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   198
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   199
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, $value2$, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   200
            assertEquals(r, $value2$, "success compareAndExchangeRelease $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   201
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   202
            assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   203
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   204
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   205
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   206
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, $value2$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   207
            assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   208
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   209
            assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   210
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   211
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   212
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   213
            boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, $value1$, $value2$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   214
            assertEquals(r, true, "weakCompareAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   215
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   216
            assertEquals(x, $value2$, "weakCompareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   217
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   218
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   219
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   220
            boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, $value2$, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   221
            assertEquals(r, true, "weakCompareAndSetAcquire $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   222
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   223
            assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   224
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   225
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   226
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   227
            boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, $value1$, $value2$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   228
            assertEquals(r, true, "weakCompareAndSetRelease $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   229
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   230
            assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   231
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   232
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   233
        {
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   234
            boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(recv, $value2$, $value1$);
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   235
            assertEquals(r, true, "weakCompareAndSetVolatile $type$");
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   236
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   237
            assertEquals(x, $value1$, "weakCompareAndSetVolatile $type$ value");
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   238
        }
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   239
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   240
        // Compare set and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   241
        {
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   242
            $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, $value2$);
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   243
            assertEquals(o, $value1$, "getAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   244
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   245
            assertEquals(x, $value2$, "getAndSet $type$ value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   246
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   247
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   248
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   249
#if[AtomicAdd]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   250
        hs.get(TestAccessMode.SET).invokeExact(recv, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   251
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   252
        // get and add, add and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   253
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   254
            $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   255
            assertEquals(o, $value1$, "getAndAdd $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   256
            $type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(recv, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   257
            assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   258
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   259
#end[AtomicAdd]
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
    static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccess$Type$ recv, Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   263
#if[!CAS]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   264
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   265
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   266
                boolean r = (boolean) hs.get(am).invokeExact(recv, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   267
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   268
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   269
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   270
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   271
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   272
                $type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   273
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   274
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   275
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   276
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   277
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   278
                $type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   279
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   280
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   281
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   282
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   283
#if[!AtomicAdd]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   284
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   285
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   286
                $type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   287
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   288
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   289
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   290
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   291
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   292
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   293
    static void testStaticField(Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   294
        // Plain
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   295
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   296
            hs.get(TestAccessMode.SET).invokeExact($value1$);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   297
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   298
            assertEquals(x, $value1$, "set $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   299
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   300
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   301
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   302
        // Volatile
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
            hs.get(TestAccessMode.SET_VOLATILE).invokeExact($value2$);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   305
            $type$ x = ($type$) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   306
            assertEquals(x, $value2$, "setVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   307
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   308
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   309
        // Lazy
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
            hs.get(TestAccessMode.SET_RELEASE).invokeExact($value1$);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   312
            $type$ x = ($type$) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   313
            assertEquals(x, $value1$, "setRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   314
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   315
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   316
        // Opaque
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
            hs.get(TestAccessMode.SET_OPAQUE).invokeExact($value2$);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   319
            $type$ x = ($type$) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   320
            assertEquals(x, $value2$, "setOpaque $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   321
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   322
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   323
#if[CAS]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   324
        hs.get(TestAccessMode.SET).invokeExact($value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   325
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   326
        // Compare
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   327
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   328
            boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact($value1$, $value2$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   329
            assertEquals(r, true, "success compareAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   330
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   331
            assertEquals(x, $value2$, "success compareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   332
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   333
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   334
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   335
            boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact($value1$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   336
            assertEquals(r, false, "failing compareAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   337
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   338
            assertEquals(x, $value2$, "failing compareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   339
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   340
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   341
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   342
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact($value2$, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   343
            assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   344
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   345
            assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   346
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   347
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   348
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   349
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact($value2$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   350
            assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   351
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   352
            assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   353
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   354
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   355
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   356
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact($value1$, $value2$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   357
            assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   358
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   359
            assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   360
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   361
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   362
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   363
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact($value1$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   364
            assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   365
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   366
            assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   367
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   368
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   369
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   370
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact($value2$, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   371
            assertEquals(r, $value2$, "success compareAndExchangeRelease $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   372
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   373
            assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   374
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   375
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   376
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   377
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact($value2$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   378
            assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   379
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   380
            assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   381
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   382
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   383
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   384
            boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact($value1$, $value2$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   385
            assertEquals(r, true, "weakCompareAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   386
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   387
            assertEquals(x, $value2$, "weakCompareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   388
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   389
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   390
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   391
            boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact($value2$, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   392
            assertEquals(r, true, "weakCompareAndSetAcquire $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   393
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   394
            assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   395
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   396
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   397
        {
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   398
            boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact($value1$, $value2$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   399
            assertEquals(r, true, "weakCompareAndSetRelease $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   400
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   401
            assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   402
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   403
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   404
        {
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   405
            boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact($value2$, $value1$);
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   406
            assertEquals(r, true, "weakCompareAndSetVolatile $type$");
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   407
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   408
            assertEquals(x, $value1$, "weakCompareAndSetVolatile $type$ value");
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   409
        }
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   410
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   411
        // Compare set and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   412
        {
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   413
            $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact($value2$);
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   414
            assertEquals(o, $value1$, "getAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   415
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   416
            assertEquals(x, $value2$, "getAndSet $type$ value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   417
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   418
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   419
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   420
#if[AtomicAdd]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   421
        hs.get(TestAccessMode.SET).invokeExact($value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   422
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   423
        // get and add, add and get
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
            $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact( $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   426
            assertEquals(o, $value1$, "getAndAdd $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   427
            $type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact($value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   428
            assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   429
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   430
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   431
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   432
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   433
    static void testStaticFieldUnsupported(Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   434
#if[!CAS]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   435
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   436
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   437
                boolean r = (boolean) hs.get(am).invokeExact($value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   438
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   439
        }
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
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   442
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   443
                $type$ r = ($type$) hs.get(am).invokeExact($value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   444
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   445
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   446
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   447
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   448
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   449
                $type$ r = ($type$) hs.get(am).invokeExact($value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   450
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   451
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   452
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   453
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   454
#if[!AtomicAdd]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   455
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   456
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   457
                $type$ r = ($type$) hs.get(am).invokeExact($value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   458
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   459
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   460
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   461
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   462
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   463
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   464
    static void testArray(Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   465
        $type$[] array = new $type$[10];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   466
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   467
        for (int i = 0; i < array.length; i++) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   468
            // Plain
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   469
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   470
                hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   471
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   472
                assertEquals(x, $value1$, "get $type$ 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
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   476
            // Volatile
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   477
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   478
                hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, $value2$);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   479
                $type$ x = ($type$) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   480
                assertEquals(x, $value2$, "setVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   481
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   482
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   483
            // Lazy
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   484
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   485
                hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, $value1$);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   486
                $type$ x = ($type$) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   487
                assertEquals(x, $value1$, "setRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   488
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   489
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   490
            // Opaque
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   491
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   492
                hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, $value2$);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   493
                $type$ x = ($type$) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   494
                assertEquals(x, $value2$, "setOpaque $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   495
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   496
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   497
#if[CAS]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   498
            hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   499
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   500
            // Compare
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   501
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   502
                boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, $value1$, $value2$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   503
                assertEquals(r, true, "success compareAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   504
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   505
                assertEquals(x, $value2$, "success compareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   506
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   507
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   508
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   509
                boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, $value1$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   510
                assertEquals(r, false, "failing compareAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   511
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   512
                assertEquals(x, $value2$, "failing compareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   513
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   514
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   515
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   516
                $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, $value2$, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   517
                assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   518
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   519
                assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   520
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   521
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   522
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   523
                $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, $value2$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   524
                assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   525
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   526
                assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   527
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   528
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   529
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   530
                $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, $value1$, $value2$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   531
                assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   532
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   533
                assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   534
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   535
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   536
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   537
                $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, $value1$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   538
                assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   539
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   540
                assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value");
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
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   544
                $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, $value2$, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   545
                assertEquals(r, $value2$, "success compareAndExchangeRelease $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   546
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   547
                assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value");
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
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   551
                $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, $value2$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   552
                assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   553
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   554
                assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   555
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   556
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   557
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   558
                boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, $value1$, $value2$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   559
                assertEquals(r, true, "weakCompareAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   560
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   561
                assertEquals(x, $value2$, "weakCompareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   562
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   563
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   564
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   565
                boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, $value2$, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   566
                assertEquals(r, true, "weakCompareAndSetAcquire $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   567
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   568
                assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   569
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   570
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   571
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   572
                boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, $value1$, $value2$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   573
                assertEquals(r, true, "weakCompareAndSetRelease $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   574
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   575
                assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   576
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   577
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   578
            {
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   579
                boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(array, i, $value2$, $value1$);
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   580
                assertEquals(r, true, "weakCompareAndSetVolatile $type$");
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   581
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   582
                assertEquals(x, $value1$, "weakCompareAndSetVolatile $type$ value");
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   583
            }
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   584
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   585
            // Compare set and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   586
            {
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   587
                $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, $value2$);
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   588
                assertEquals(o, $value1$, "getAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   589
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   590
                assertEquals(x, $value2$, "getAndSet $type$ value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   591
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   592
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   593
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   594
#if[AtomicAdd]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   595
            hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   596
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   597
            // get and add, add and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   598
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   599
                $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   600
                assertEquals(o, $value1$, "getAndAdd $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   601
                $type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(array, i, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   602
                assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   603
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   604
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   605
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   606
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   607
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   608
    static void testArrayUnsupported(Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   609
        $type$[] array = new $type$[10];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   610
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   611
        final int i = 0;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   612
#if[!CAS]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   613
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   614
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   615
                boolean r = (boolean) hs.get(am).invokeExact(array, i, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   616
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   617
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   618
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   619
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   620
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   621
                $type$ r = ($type$) hs.get(am).invokeExact(array, i, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   622
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   623
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   624
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   625
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   626
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   627
                $type$ r = ($type$) hs.get(am).invokeExact(array, i, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   628
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   629
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   630
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   631
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   632
#if[!AtomicAdd]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   633
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   634
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   635
                $type$ o = ($type$) hs.get(am).invokeExact(array, i, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   636
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   637
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   638
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   639
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   640
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   641
    static void testArrayIndexOutOfBounds(Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   642
        $type$[] array = new $type$[10];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   643
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   644
        for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   645
            final int ci = i;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   646
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   647
            for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   648
                checkIOOBE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   649
                    $type$ x = ($type$) hs.get(am).invokeExact(array, ci);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   650
                });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   651
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   652
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   653
            for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   654
                checkIOOBE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   655
                    hs.get(am).invokeExact(array, ci, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   656
                });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   657
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   658
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   659
#if[CAS]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   660
            for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   661
                checkIOOBE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   662
                    boolean r = (boolean) hs.get(am).invokeExact(array, ci, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   663
                });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   664
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   665
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   666
            for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   667
                checkIOOBE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   668
                    $type$ r = ($type$) hs.get(am).invokeExact(array, ci, $value2$, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   669
                });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   670
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   671
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   672
            for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   673
                checkIOOBE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   674
                    $type$ o = ($type$) hs.get(am).invokeExact(array, ci, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   675
                });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   676
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   677
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   678
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   679
#if[AtomicAdd]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   680
            for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   681
                checkIOOBE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   682
                    $type$ o = ($type$) hs.get(am).invokeExact(array, ci, $value3$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   683
                });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   684
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   685
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   686
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   687
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   688
}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   689