jdk/test/java/lang/invoke/VarHandles/X-VarHandleTestMethodHandleAccess.java.template
author psandoz
Fri, 29 Apr 2016 13:46:19 -0700
changeset 37719 add11bc0e6e2
parent 37343 35a2231828a7
child 38328 40435a469d25
child 38358 cb99c6d2af1b
permissions -rw-r--r--
8154755: Add a VarHandle weakCompareAndSet with volatile semantics Reviewed-by: shade, 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$
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    27
 */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    28
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    29
import org.testng.annotations.BeforeClass;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    30
import org.testng.annotations.DataProvider;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    31
import org.testng.annotations.Test;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    32
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    33
import java.lang.invoke.MethodHandles;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    34
import java.lang.invoke.VarHandle;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    35
import java.util.ArrayList;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    36
import java.util.Arrays;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    37
import java.util.List;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    38
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    39
import static org.testng.Assert.*;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    40
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    41
public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    42
    static final $type$ static_final_v = $value1$;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    43
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    44
    static $type$ static_v;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    45
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    46
    final $type$ final_v = $value1$;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    47
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    48
    $type$ v;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    49
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    50
    VarHandle vhFinalField;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    51
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    52
    VarHandle vhField;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    53
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    54
    VarHandle vhStaticField;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    55
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    56
    VarHandle vhStaticFinalField;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    57
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    58
    VarHandle vhArray;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    59
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    60
    @BeforeClass
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    61
    public void setup() throws Exception {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    62
        vhFinalField = MethodHandles.lookup().findVarHandle(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    63
                VarHandleTestMethodHandleAccess$Type$.class, "final_v", $type$.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    64
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    65
        vhField = MethodHandles.lookup().findVarHandle(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    66
                VarHandleTestMethodHandleAccess$Type$.class, "v", $type$.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    67
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    68
        vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    69
            VarHandleTestMethodHandleAccess$Type$.class, "static_final_v", $type$.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    70
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    71
        vhStaticField = MethodHandles.lookup().findStaticVarHandle(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    72
            VarHandleTestMethodHandleAccess$Type$.class, "static_v", $type$.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    73
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    74
        vhArray = MethodHandles.arrayElementVarHandle($type$[].class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    75
    }
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
    @DataProvider
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    79
    public Object[][] accessTestCaseProvider() throws Exception {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    80
        List<AccessTestCase<?>> cases = new ArrayList<>();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    81
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    82
        for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    83
            cases.add(new MethodHandleAccessTestCase("Instance field",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    84
                                                     vhField, f, hs -> testInstanceField(this, hs)));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    85
            cases.add(new MethodHandleAccessTestCase("Instance field unsupported",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    86
                                                     vhField, f, hs -> testInstanceFieldUnsupported(this, hs),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    87
                                                     false));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    88
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    89
            cases.add(new MethodHandleAccessTestCase("Static field",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    90
                                                     vhStaticField, f, VarHandleTestMethodHandleAccess$Type$::testStaticField));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    91
            cases.add(new MethodHandleAccessTestCase("Static field unsupported",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    92
                                                     vhStaticField, f, VarHandleTestMethodHandleAccess$Type$::testStaticFieldUnsupported,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    93
                                                     false));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    94
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    95
            cases.add(new MethodHandleAccessTestCase("Array",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    96
                                                     vhArray, f, VarHandleTestMethodHandleAccess$Type$::testArray));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    97
            cases.add(new MethodHandleAccessTestCase("Array unsupported",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    98
                                                     vhArray, f, VarHandleTestMethodHandleAccess$Type$::testArrayUnsupported,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    99
                                                     false));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   100
            cases.add(new MethodHandleAccessTestCase("Array index out of bounds",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   101
                                                     vhArray, f, VarHandleTestMethodHandleAccess$Type$::testArrayIndexOutOfBounds,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   102
                                                     false));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   103
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   104
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   105
        // Work around issue with jtreg summary reporting which truncates
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   106
        // the String result of Object.toString to 30 characters, hence
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   107
        // the first dummy argument
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   108
        return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   109
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   110
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   111
    @Test(dataProvider = "accessTestCaseProvider")
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   112
    public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   113
        T t = atc.get();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   114
        int iters = atc.requiresLoop() ? ITERS : 1;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   115
        for (int c = 0; c < iters; c++) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   116
            atc.testAccess(t);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   117
        }
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
    static void testInstanceField(VarHandleTestMethodHandleAccess$Type$ recv, Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   122
        // Plain
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   123
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   124
            hs.get(TestAccessMode.SET).invokeExact(recv, $value1$);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   125
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   126
            assertEquals(x, $value1$, "set $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   127
        }
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
        // Volatile
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   131
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   132
            hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, $value2$);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   133
            $type$ x = ($type$) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   134
            assertEquals(x, $value2$, "setVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   135
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   136
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   137
        // Lazy
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   138
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   139
            hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, $value1$);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   140
            $type$ x = ($type$) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   141
            assertEquals(x, $value1$, "setRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   142
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   143
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   144
        // Opaque
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   145
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   146
            hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, $value2$);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   147
            $type$ x = ($type$) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   148
            assertEquals(x, $value2$, "setOpaque $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   149
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   150
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   151
#if[CAS]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   152
        hs.get(TestAccessMode.SET).invokeExact(recv, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   153
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   154
        // Compare
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   155
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   156
            boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, $value1$, $value2$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   157
            assertEquals(r, true, "success compareAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   158
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   159
            assertEquals(x, $value2$, "success compareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   160
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   161
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   162
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   163
            boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, $value1$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   164
            assertEquals(r, false, "failing compareAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   165
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   166
            assertEquals(x, $value2$, "failing compareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   167
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   168
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   169
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   170
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, $value2$, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   171
            assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   172
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   173
            assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   174
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   175
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   176
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   177
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, $value2$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   178
            assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   179
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   180
            assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   181
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   182
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   183
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   184
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, $value1$, $value2$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   185
            assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   186
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   187
            assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   188
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   189
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   190
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   191
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, $value1$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   192
            assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   193
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   194
            assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   195
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   196
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   197
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   198
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, $value2$, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   199
            assertEquals(r, $value2$, "success compareAndExchangeRelease $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   200
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   201
            assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   202
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   203
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   204
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   205
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, $value2$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   206
            assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   207
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   208
            assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   209
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   210
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   211
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   212
            boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, $value1$, $value2$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   213
            assertEquals(r, true, "weakCompareAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   214
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   215
            assertEquals(x, $value2$, "weakCompareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   216
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   217
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   218
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   219
            boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, $value2$, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   220
            assertEquals(r, true, "weakCompareAndSetAcquire $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   221
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   222
            assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   223
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   224
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   225
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   226
            boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, $value1$, $value2$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   227
            assertEquals(r, true, "weakCompareAndSetRelease $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   228
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   229
            assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   230
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   231
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   232
        {
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   233
            boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(recv, $value2$, $value1$);
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   234
            assertEquals(r, true, "weakCompareAndSetVolatile $type$");
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   235
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   236
            assertEquals(x, $value1$, "weakCompareAndSetVolatile $type$ value");
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   237
        }
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   238
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   239
        // Compare set and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   240
        {
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   241
            $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
   242
            assertEquals(o, $value1$, "getAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   243
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   244
            assertEquals(x, $value2$, "getAndSet $type$ value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   245
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   246
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   247
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   248
#if[AtomicAdd]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   249
        hs.get(TestAccessMode.SET).invokeExact(recv, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   250
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   251
        // get and add, add and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   252
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   253
            $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   254
            assertEquals(o, $value1$, "getAndAdd $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   255
            $type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(recv, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   256
            assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   257
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   258
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   259
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   260
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   261
    static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccess$Type$ recv, Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   262
#if[!CAS]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   263
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   264
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   265
                boolean r = (boolean) hs.get(am).invokeExact(recv, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   266
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   267
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   268
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   269
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   270
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   271
                $type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   272
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   273
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   274
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   275
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   276
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   277
                $type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   278
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   279
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   280
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   281
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   282
#if[!AtomicAdd]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   283
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   284
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   285
                $type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   286
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   287
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   288
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   289
    }
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
    static void testStaticField(Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   293
        // Plain
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   294
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   295
            hs.get(TestAccessMode.SET).invokeExact($value1$);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   296
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   297
            assertEquals(x, $value1$, "set $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   298
        }
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
        // Volatile
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   302
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   303
            hs.get(TestAccessMode.SET_VOLATILE).invokeExact($value2$);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   304
            $type$ x = ($type$) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   305
            assertEquals(x, $value2$, "setVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   306
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   307
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   308
        // Lazy
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   309
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   310
            hs.get(TestAccessMode.SET_RELEASE).invokeExact($value1$);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   311
            $type$ x = ($type$) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   312
            assertEquals(x, $value1$, "setRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   313
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   314
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   315
        // Opaque
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   316
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   317
            hs.get(TestAccessMode.SET_OPAQUE).invokeExact($value2$);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   318
            $type$ x = ($type$) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   319
            assertEquals(x, $value2$, "setOpaque $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   320
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   321
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   322
#if[CAS]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   323
        hs.get(TestAccessMode.SET).invokeExact($value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   324
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   325
        // Compare
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   326
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   327
            boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact($value1$, $value2$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   328
            assertEquals(r, true, "success compareAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   329
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   330
            assertEquals(x, $value2$, "success compareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   331
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   332
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   333
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   334
            boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact($value1$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   335
            assertEquals(r, false, "failing compareAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   336
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   337
            assertEquals(x, $value2$, "failing compareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   338
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   339
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   340
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   341
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact($value2$, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   342
            assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   343
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   344
            assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   345
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   346
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   347
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   348
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact($value2$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   349
            assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   350
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   351
            assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   352
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   353
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   354
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   355
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact($value1$, $value2$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   356
            assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   357
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   358
            assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   359
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   360
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   361
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   362
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact($value1$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   363
            assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   364
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   365
            assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   366
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   367
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   368
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   369
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact($value2$, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   370
            assertEquals(r, $value2$, "success compareAndExchangeRelease $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   371
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   372
            assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   373
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   374
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   375
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   376
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact($value2$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   377
            assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   378
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   379
            assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   380
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   381
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   382
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   383
            boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact($value1$, $value2$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   384
            assertEquals(r, true, "weakCompareAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   385
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   386
            assertEquals(x, $value2$, "weakCompareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   387
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   388
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   389
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   390
            boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact($value2$, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   391
            assertEquals(r, true, "weakCompareAndSetAcquire $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   392
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   393
            assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   394
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   395
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   396
        {
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   397
            boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact($value1$, $value2$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   398
            assertEquals(r, true, "weakCompareAndSetRelease $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   399
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   400
            assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   401
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   402
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   403
        {
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   404
            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
   405
            assertEquals(r, true, "weakCompareAndSetVolatile $type$");
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   406
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   407
            assertEquals(x, $value1$, "weakCompareAndSetVolatile $type$ value");
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   408
        }
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   409
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   410
        // Compare set and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   411
        {
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   412
            $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
   413
            assertEquals(o, $value1$, "getAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   414
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   415
            assertEquals(x, $value2$, "getAndSet $type$ value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   416
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   417
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   418
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   419
#if[AtomicAdd]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   420
        hs.get(TestAccessMode.SET).invokeExact($value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   421
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   422
        // get and add, add and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   423
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   424
            $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact( $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   425
            assertEquals(o, $value1$, "getAndAdd $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   426
            $type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact($value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   427
            assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   428
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   429
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   430
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   431
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   432
    static void testStaticFieldUnsupported(Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   433
#if[!CAS]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   434
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   435
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   436
                boolean r = (boolean) hs.get(am).invokeExact($value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   437
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   438
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   439
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   440
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   441
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   442
                $type$ r = ($type$) hs.get(am).invokeExact($value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   443
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   444
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   445
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   446
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   447
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   448
                $type$ r = ($type$) hs.get(am).invokeExact($value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   449
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   450
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   451
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   452
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   453
#if[!AtomicAdd]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   454
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   455
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   456
                $type$ r = ($type$) hs.get(am).invokeExact($value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   457
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   458
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   459
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   460
    }
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
    static void testArray(Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   464
        $type$[] array = new $type$[10];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   465
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   466
        for (int i = 0; i < array.length; i++) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   467
            // Plain
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   468
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   469
                hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   470
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   471
                assertEquals(x, $value1$, "get $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   472
            }
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
            // Volatile
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   476
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   477
                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
   478
                $type$ x = ($type$) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   479
                assertEquals(x, $value2$, "setVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   480
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   481
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   482
            // Lazy
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   483
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   484
                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
   485
                $type$ x = ($type$) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   486
                assertEquals(x, $value1$, "setRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   487
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   488
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   489
            // Opaque
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   490
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   491
                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
   492
                $type$ x = ($type$) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   493
                assertEquals(x, $value2$, "setOpaque $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   494
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   495
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   496
#if[CAS]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   497
            hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   498
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   499
            // Compare
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   500
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   501
                boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, $value1$, $value2$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   502
                assertEquals(r, true, "success compareAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   503
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   504
                assertEquals(x, $value2$, "success compareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   505
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   506
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   507
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   508
                boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, $value1$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   509
                assertEquals(r, false, "failing compareAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   510
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   511
                assertEquals(x, $value2$, "failing compareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   512
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   513
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   514
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   515
                $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, $value2$, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   516
                assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   517
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   518
                assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   519
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   520
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   521
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   522
                $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, $value2$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   523
                assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   524
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   525
                assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   526
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   527
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   528
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   529
                $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, $value1$, $value2$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   530
                assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   531
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   532
                assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   533
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   534
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   535
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   536
                $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, $value1$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   537
                assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   538
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   539
                assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   540
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   541
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   542
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   543
                $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, $value2$, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   544
                assertEquals(r, $value2$, "success compareAndExchangeRelease $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   545
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   546
                assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   547
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   548
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   549
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   550
                $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, $value2$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   551
                assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   552
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   553
                assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   554
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   555
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   556
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   557
                boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, $value1$, $value2$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   558
                assertEquals(r, true, "weakCompareAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   559
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   560
                assertEquals(x, $value2$, "weakCompareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   561
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   562
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   563
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   564
                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
   565
                assertEquals(r, true, "weakCompareAndSetAcquire $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   566
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   567
                assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   568
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   569
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   570
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   571
                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
   572
                assertEquals(r, true, "weakCompareAndSetRelease $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   573
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   574
                assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   575
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   576
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   577
            {
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   578
                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
   579
                assertEquals(r, true, "weakCompareAndSetVolatile $type$");
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   580
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   581
                assertEquals(x, $value1$, "weakCompareAndSetVolatile $type$ value");
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   582
            }
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   583
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   584
            // Compare set and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   585
            {
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37343
diff changeset
   586
                $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
   587
                assertEquals(o, $value1$, "getAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   588
                $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
   589
                assertEquals(x, $value2$, "getAndSet $type$ value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   590
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   591
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   592
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   593
#if[AtomicAdd]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   594
            hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   595
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   596
            // get and add, add and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   597
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   598
                $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   599
                assertEquals(o, $value1$, "getAndAdd $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   600
                $type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(array, i, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   601
                assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   602
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   603
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   604
        }
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
    static void testArrayUnsupported(Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   608
        $type$[] array = new $type$[10];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   609
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   610
        final int i = 0;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   611
#if[!CAS]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   612
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   613
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   614
                boolean r = (boolean) hs.get(am).invokeExact(array, i, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   615
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   616
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   617
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   618
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   619
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   620
                $type$ r = ($type$) hs.get(am).invokeExact(array, i, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   621
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   622
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   623
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   624
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   625
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   626
                $type$ r = ($type$) hs.get(am).invokeExact(array, i, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   627
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   628
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   629
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   630
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   631
#if[!AtomicAdd]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   632
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   633
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   634
                $type$ o = ($type$) hs.get(am).invokeExact(array, i, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   635
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   636
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   637
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   638
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   639
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   640
    static void testArrayIndexOutOfBounds(Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   641
        $type$[] array = new $type$[10];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   642
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   643
        for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   644
            final int ci = i;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   645
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   646
            for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   647
                checkIOOBE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   648
                    $type$ x = ($type$) hs.get(am).invokeExact(array, ci);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   649
                });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   650
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   651
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   652
            for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   653
                checkIOOBE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   654
                    hs.get(am).invokeExact(array, ci, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   655
                });
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
#if[CAS]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   659
            for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   660
                checkIOOBE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   661
                    boolean r = (boolean) hs.get(am).invokeExact(array, ci, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   662
                });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   663
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   664
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   665
            for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   666
                checkIOOBE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   667
                    $type$ r = ($type$) hs.get(am).invokeExact(array, ci, $value2$, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   668
                });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   669
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   670
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   671
            for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   672
                checkIOOBE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   673
                    $type$ o = ($type$) hs.get(am).invokeExact(array, ci, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   674
                });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   675
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   676
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   677
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   678
#if[AtomicAdd]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   679
            for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   680
                checkIOOBE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   681
                    $type$ o = ($type$) hs.get(am).invokeExact(array, ci, $value3$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   682
                });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   683
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   684
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   685
        }
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