jdk/test/java/lang/invoke/VarHandles/X-VarHandleTestMethodHandleAccess.java.template
author shade
Wed, 04 May 2016 17:17:28 +0300
changeset 38355 674cfd9b90cf
parent 37343 35a2231828a7
child 38358 cb99c6d2af1b
permissions -rw-r--r--
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures Reviewed-by: psandoz, vlivanov, simonis
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
        {
38355
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   212
            boolean success = false;
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   213
            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   214
                success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, $value1$, $value2$);
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   215
            }
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   216
            assertEquals(success, true, "weakCompareAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   217
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   218
            assertEquals(x, $value2$, "weakCompareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   219
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   220
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   221
        {
38355
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   222
            boolean success = false;
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   223
            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   224
                success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, $value2$, $value1$);
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   225
            }
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   226
            assertEquals(success, true, "weakCompareAndSetAcquire $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   227
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   228
            assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   229
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   230
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   231
        {
38355
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   232
            boolean success = false;
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   233
            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   234
                success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, $value1$, $value2$);
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   235
            }
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   236
            assertEquals(success, true, "weakCompareAndSetRelease $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   237
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   238
            assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   239
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   240
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   241
        // Compare set and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   242
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   243
            $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   244
            assertEquals(o, $value2$, "getAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   245
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   246
            assertEquals(x, $value1$, "getAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   247
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   248
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   249
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   250
#if[AtomicAdd]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   251
        hs.get(TestAccessMode.SET).invokeExact(recv, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   252
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   253
        // get and add, add and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   254
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   255
            $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   256
            assertEquals(o, $value1$, "getAndAdd $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   257
            $type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(recv, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   258
            assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   259
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   260
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   261
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   262
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   263
    static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccess$Type$ recv, Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   264
#if[!CAS]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   265
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   266
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   267
                boolean r = (boolean) hs.get(am).invokeExact(recv, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   268
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   269
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   270
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   271
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   272
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   273
                $type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   274
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   275
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   276
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   277
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   278
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   279
                $type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   280
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   281
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   282
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   283
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   284
#if[!AtomicAdd]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   285
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   286
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   287
                $type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   288
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   289
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   290
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   291
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   292
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   293
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   294
    static void testStaticField(Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   295
        // Plain
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   296
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   297
            hs.get(TestAccessMode.SET).invokeExact($value1$);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   298
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   299
            assertEquals(x, $value1$, "set $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   300
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   301
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   302
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   303
        // Volatile
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   304
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   305
            hs.get(TestAccessMode.SET_VOLATILE).invokeExact($value2$);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   306
            $type$ x = ($type$) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   307
            assertEquals(x, $value2$, "setVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   308
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   309
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   310
        // Lazy
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   311
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   312
            hs.get(TestAccessMode.SET_RELEASE).invokeExact($value1$);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   313
            $type$ x = ($type$) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   314
            assertEquals(x, $value1$, "setRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   315
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   316
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   317
        // Opaque
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   318
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   319
            hs.get(TestAccessMode.SET_OPAQUE).invokeExact($value2$);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   320
            $type$ x = ($type$) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   321
            assertEquals(x, $value2$, "setOpaque $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   322
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   323
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   324
#if[CAS]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   325
        hs.get(TestAccessMode.SET).invokeExact($value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   326
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   327
        // Compare
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   328
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   329
            boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact($value1$, $value2$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   330
            assertEquals(r, true, "success compareAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   331
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   332
            assertEquals(x, $value2$, "success compareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   333
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   334
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   335
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   336
            boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact($value1$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   337
            assertEquals(r, false, "failing compareAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   338
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   339
            assertEquals(x, $value2$, "failing compareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   340
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   341
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   342
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   343
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact($value2$, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   344
            assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   345
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   346
            assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   347
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   348
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   349
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   350
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact($value2$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   351
            assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   352
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   353
            assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   354
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   355
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   356
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   357
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact($value1$, $value2$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   358
            assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   359
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   360
            assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   361
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   362
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   363
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   364
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact($value1$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   365
            assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   366
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   367
            assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   368
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   369
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   370
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   371
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact($value2$, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   372
            assertEquals(r, $value2$, "success compareAndExchangeRelease $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   373
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   374
            assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   375
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   376
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   377
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   378
            $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact($value2$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   379
            assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   380
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   381
            assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   382
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   383
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   384
        {
38355
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   385
            boolean success = false;
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   386
            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   387
                success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact($value1$, $value2$);
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   388
            }
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   389
            assertEquals(success, true, "weakCompareAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   390
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   391
            assertEquals(x, $value2$, "weakCompareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   392
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   393
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   394
        {
38355
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   395
            boolean success = false;
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   396
            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   397
                success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact($value2$, $value1$);
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   398
            }
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   399
            assertEquals(success, true, "weakCompareAndSetAcquire $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   400
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   401
            assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   402
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   403
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   404
        {
38355
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   405
            boolean success = false;
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   406
            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   407
                success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact($value1$, $value2$);
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   408
            }
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   409
            assertEquals(success, true, "weakCompareAndSetRelease $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   410
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   411
            assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   412
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   413
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   414
        // Compare set and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   415
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   416
            $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact( $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   417
            assertEquals(o, $value2$, "getAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   418
            $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   419
            assertEquals(x, $value1$, "getAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   420
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   421
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   422
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   423
#if[AtomicAdd]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   424
        hs.get(TestAccessMode.SET).invokeExact($value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   425
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   426
        // get and add, add and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   427
        {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   428
            $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact( $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   429
            assertEquals(o, $value1$, "getAndAdd $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   430
            $type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact($value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   431
            assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   432
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   433
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   434
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   435
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   436
    static void testStaticFieldUnsupported(Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   437
#if[!CAS]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   438
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   439
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   440
                boolean r = (boolean) hs.get(am).invokeExact($value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   441
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   442
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   443
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   444
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   445
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   446
                $type$ r = ($type$) hs.get(am).invokeExact($value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   447
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   448
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   449
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   450
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   451
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   452
                $type$ r = ($type$) hs.get(am).invokeExact($value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   453
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   454
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   455
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   456
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   457
#if[!AtomicAdd]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   458
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   459
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   460
                $type$ r = ($type$) hs.get(am).invokeExact($value1$);
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
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   464
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   465
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   466
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   467
    static void testArray(Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   468
        $type$[] array = new $type$[10];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   469
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   470
        for (int i = 0; i < array.length; i++) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   471
            // Plain
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   472
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   473
                hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   474
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   475
                assertEquals(x, $value1$, "get $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   476
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   477
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   478
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   479
            // Volatile
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   480
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   481
                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
   482
                $type$ x = ($type$) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   483
                assertEquals(x, $value2$, "setVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   484
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   485
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   486
            // Lazy
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   487
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   488
                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
   489
                $type$ x = ($type$) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   490
                assertEquals(x, $value1$, "setRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   491
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   492
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   493
            // Opaque
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   494
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   495
                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
   496
                $type$ x = ($type$) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   497
                assertEquals(x, $value2$, "setOpaque $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   498
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   499
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   500
#if[CAS]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   501
            hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   502
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   503
            // Compare
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   504
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   505
                boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, $value1$, $value2$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   506
                assertEquals(r, true, "success compareAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   507
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   508
                assertEquals(x, $value2$, "success compareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   509
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   510
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   511
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   512
                boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, $value1$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   513
                assertEquals(r, false, "failing compareAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   514
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   515
                assertEquals(x, $value2$, "failing compareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   516
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   517
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   518
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   519
                $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, $value2$, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   520
                assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   521
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   522
                assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   523
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   524
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   525
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   526
                $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, $value2$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   527
                assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   528
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   529
                assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   530
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   531
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   532
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   533
                $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, $value1$, $value2$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   534
                assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   535
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   536
                assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   537
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   538
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   539
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   540
                $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, $value1$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   541
                assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   542
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   543
                assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   544
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   545
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   546
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   547
                $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, $value2$, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   548
                assertEquals(r, $value2$, "success compareAndExchangeRelease $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   549
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   550
                assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   551
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   552
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   553
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   554
                $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, $value2$, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   555
                assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   556
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   557
                assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   558
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   559
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   560
            {
38355
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   561
                boolean success = false;
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   562
                for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   563
                    success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, $value1$, $value2$);
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   564
                }
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   565
                assertEquals(success, true, "weakCompareAndSet $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, $value2$, "weakCompareAndSet $type$ value");
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
            {
38355
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   571
                boolean success = false;
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   572
                for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   573
                    success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, $value2$, $value1$);
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   574
                }
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   575
                assertEquals(success, true, "weakCompareAndSetAcquire $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   576
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   577
                assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   578
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   579
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   580
            {
38355
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   581
                boolean success = false;
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   582
                for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   583
                    success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, $value1$, $value2$);
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   584
                }
674cfd9b90cf 8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents: 37343
diff changeset
   585
                assertEquals(success, true, "weakCompareAndSetRelease $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   586
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   587
                assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   588
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   589
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   590
            // Compare set and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   591
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   592
                $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   593
                assertEquals(o, $value2$, "getAndSet $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   594
                $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   595
                assertEquals(x, $value1$, "getAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   596
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   597
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   598
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   599
#if[AtomicAdd]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   600
            hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   601
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   602
            // get and add, add and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   603
            {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   604
                $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   605
                assertEquals(o, $value1$, "getAndAdd $type$");
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   606
                $type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(array, i, $value3$);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   607
                assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   608
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   609
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   610
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   611
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   612
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   613
    static void testArrayUnsupported(Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   614
        $type$[] array = new $type$[10];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   615
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   616
        final int i = 0;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   617
#if[!CAS]
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_SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   619
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   620
                boolean r = (boolean) 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.COMPARE_AND_EXCHANGE)) {
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$, $value2$);
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
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   630
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   631
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   632
                $type$ r = ($type$) hs.get(am).invokeExact(array, i, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   633
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   634
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   635
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   636
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   637
#if[!AtomicAdd]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   638
        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   639
            checkUOE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   640
                $type$ o = ($type$) hs.get(am).invokeExact(array, i, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   641
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   642
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   643
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   644
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   645
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   646
    static void testArrayIndexOutOfBounds(Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   647
        $type$[] array = new $type$[10];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   648
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   649
        for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   650
            final int ci = i;
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.GET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   653
                checkIOOBE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   654
                    $type$ x = ($type$) hs.get(am).invokeExact(array, ci);
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
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   658
            for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   659
                checkIOOBE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   660
                    hs.get(am).invokeExact(array, ci, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   661
                });
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
#if[CAS]
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_SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   666
                checkIOOBE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   667
                    boolean r = (boolean) hs.get(am).invokeExact(array, ci, $value1$, $value2$);
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.COMPARE_AND_EXCHANGE)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   672
                checkIOOBE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   673
                    $type$ r = ($type$) hs.get(am).invokeExact(array, ci, $value2$, $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
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   677
            for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   678
                checkIOOBE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   679
                    $type$ o = ($type$) hs.get(am).invokeExact(array, ci, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   680
                });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   681
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   682
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   683
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   684
#if[AtomicAdd]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   685
            for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   686
                checkIOOBE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   687
                    $type$ o = ($type$) hs.get(am).invokeExact(array, ci, $value3$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   688
                });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   689
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   690
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   691
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   692
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   693
}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   694