jdk/test/java/lang/invoke/VarHandles/X-VarHandleTestAccess.java.template
author psandoz
Wed, 13 Apr 2016 15:05:48 +0200
changeset 37343 35a2231828a7
parent 36934 590fc47a0aeb
child 37719 add11bc0e6e2
child 38355 674cfd9b90cf
permissions -rw-r--r--
8151705: VarHandle.AccessMode enum names should conform to code style Reviewed-by: mhaupt, shade, redestad
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, 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=10    -Xint                   VarHandleTestAccess$Type$
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    27
 * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestAccess$Type$
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    28
 * @run testng/othervm -Diters=20000                         VarHandleTestAccess$Type$
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    29
 * @run testng/othervm -Diters=20000 -XX:-TieredCompilation  VarHandleTestAccess$Type$
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    30
 */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    31
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    32
import org.testng.annotations.BeforeClass;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    33
import org.testng.annotations.DataProvider;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    34
import org.testng.annotations.Test;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    35
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    36
import java.lang.invoke.MethodHandles;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    37
import java.lang.invoke.VarHandle;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    38
import java.util.ArrayList;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    39
import java.util.Arrays;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    40
import java.util.List;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    41
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    42
import static org.testng.Assert.*;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    43
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    44
public class VarHandleTestAccess$Type$ extends VarHandleBaseTest {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    45
    static final $type$ static_final_v = $value1$;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    46
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    47
    static $type$ static_v;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    48
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    49
    final $type$ final_v = $value1$;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    50
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    51
    $type$ v;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    52
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    53
    VarHandle vhFinalField;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    54
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    55
    VarHandle vhField;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    56
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    57
    VarHandle vhStaticField;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    58
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    59
    VarHandle vhStaticFinalField;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    60
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    61
    VarHandle vhArray;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    62
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    63
    @BeforeClass
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    64
    public void setup() throws Exception {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    65
        vhFinalField = MethodHandles.lookup().findVarHandle(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    66
                VarHandleTestAccess$Type$.class, "final_v", $type$.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    67
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    68
        vhField = MethodHandles.lookup().findVarHandle(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    69
                VarHandleTestAccess$Type$.class, "v", $type$.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    70
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    71
        vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    72
            VarHandleTestAccess$Type$.class, "static_final_v", $type$.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    73
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    74
        vhStaticField = MethodHandles.lookup().findStaticVarHandle(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    75
            VarHandleTestAccess$Type$.class, "static_v", $type$.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    76
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    77
        vhArray = MethodHandles.arrayElementVarHandle($type$[].class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    78
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    79
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    80
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    81
    @DataProvider
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    82
    public Object[][] varHandlesProvider() throws Exception {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    83
        List<VarHandle> vhs = new ArrayList<>();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    84
        vhs.add(vhField);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    85
        vhs.add(vhStaticField);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    86
        vhs.add(vhArray);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    87
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    88
        return vhs.stream().map(tc -> new Object[]{tc}).toArray(Object[][]::new);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    89
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    90
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    91
    @Test(dataProvider = "varHandlesProvider")
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    92
    public void testIsAccessModeSupported(VarHandle vh) {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
    93
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
    94
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
    95
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
    96
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
    97
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
    98
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
    99
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   100
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   101
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   102
#if[CAS]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   103
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   104
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE));
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   105
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   106
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   107
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   108
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   109
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   110
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   111
#else[CAS]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   112
        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   113
        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE));
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   114
        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   115
        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   116
        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   117
        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   118
        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   119
        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   120
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   121
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   122
#if[AtomicAdd]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   123
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   124
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.ADD_AND_GET));
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   125
#else[AtomicAdd]
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   126
        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   127
        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.ADD_AND_GET));
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   128
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   129
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   130
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   131
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   132
    @DataProvider
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   133
    public Object[][] typesProvider() throws Exception {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   134
        List<Object[]> types = new ArrayList<>();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   135
        types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccess$Type$.class)});
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   136
        types.add(new Object[] {vhStaticField, Arrays.asList()});
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   137
        types.add(new Object[] {vhArray, Arrays.asList($type$[].class, int.class)});
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   138
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   139
        return types.stream().toArray(Object[][]::new);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   140
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   141
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   142
    @Test(dataProvider = "typesProvider")
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   143
    public void testTypes(VarHandle vh, List<Class<?>> pts) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   144
        assertEquals(vh.varType(), $type$.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   145
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   146
        assertEquals(vh.coordinateTypes(), pts);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   147
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   148
        testTypes(vh);
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
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   152
    @Test
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   153
    public void testLookupInstanceToStatic() {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   154
        checkIAE("Lookup of static final field to instance final field", () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   155
            MethodHandles.lookup().findStaticVarHandle(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   156
                    VarHandleTestAccess$Type$.class, "final_v", $type$.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   157
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   158
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   159
        checkIAE("Lookup of static field to instance field", () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   160
            MethodHandles.lookup().findStaticVarHandle(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   161
                    VarHandleTestAccess$Type$.class, "v", $type$.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   162
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   163
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   164
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   165
    @Test
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   166
    public void testLookupStaticToInstance() {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   167
        checkIAE("Lookup of instance final field to static final field", () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   168
            MethodHandles.lookup().findVarHandle(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   169
                VarHandleTestAccess$Type$.class, "static_final_v", $type$.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   170
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   171
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   172
        checkIAE("Lookup of instance field to static field", () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   173
            vhStaticField = MethodHandles.lookup().findVarHandle(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   174
                VarHandleTestAccess$Type$.class, "static_v", $type$.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   175
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   176
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   177
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   178
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   179
    @DataProvider
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   180
    public Object[][] accessTestCaseProvider() throws Exception {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   181
        List<AccessTestCase<?>> cases = new ArrayList<>();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   182
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   183
        cases.add(new VarHandleAccessTestCase("Instance final field",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   184
                                              vhFinalField, vh -> testInstanceFinalField(this, vh)));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   185
        cases.add(new VarHandleAccessTestCase("Instance final field unsupported",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   186
                                              vhFinalField, vh -> testInstanceFinalFieldUnsupported(this, vh),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   187
                                              false));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   188
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   189
        cases.add(new VarHandleAccessTestCase("Static final field",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   190
                                              vhStaticFinalField, VarHandleTestAccess$Type$::testStaticFinalField));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   191
        cases.add(new VarHandleAccessTestCase("Static final field unsupported",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   192
                                              vhStaticFinalField, VarHandleTestAccess$Type$::testStaticFinalFieldUnsupported,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   193
                                              false));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   194
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   195
        cases.add(new VarHandleAccessTestCase("Instance field",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   196
                                              vhField, vh -> testInstanceField(this, vh)));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   197
        cases.add(new VarHandleAccessTestCase("Instance field unsupported",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   198
                                              vhField, vh -> testInstanceFieldUnsupported(this, vh),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   199
                                              false));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   200
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   201
        cases.add(new VarHandleAccessTestCase("Static field",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   202
                                              vhStaticField, VarHandleTestAccess$Type$::testStaticField));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   203
        cases.add(new VarHandleAccessTestCase("Static field unsupported",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   204
                                              vhStaticField, VarHandleTestAccess$Type$::testStaticFieldUnsupported,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   205
                                              false));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   206
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   207
        cases.add(new VarHandleAccessTestCase("Array",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   208
                                              vhArray, VarHandleTestAccess$Type$::testArray));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   209
        cases.add(new VarHandleAccessTestCase("Array unsupported",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   210
                                              vhArray, VarHandleTestAccess$Type$::testArrayUnsupported,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   211
                                              false));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   212
        cases.add(new VarHandleAccessTestCase("Array index out of bounds",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   213
                                              vhArray, VarHandleTestAccess$Type$::testArrayIndexOutOfBounds,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   214
                                              false));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   215
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   216
        // Work around issue with jtreg summary reporting which truncates
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   217
        // the String result of Object.toString to 30 characters, hence
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   218
        // the first dummy argument
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   219
        return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   220
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   221
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   222
    @Test(dataProvider = "accessTestCaseProvider")
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   223
    public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   224
        T t = atc.get();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   225
        int iters = atc.requiresLoop() ? ITERS : 1;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   226
        for (int c = 0; c < iters; c++) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   227
            atc.testAccess(t);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   228
        }
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
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   232
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   233
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   234
    static void testInstanceFinalField(VarHandleTestAccess$Type$ recv, VarHandle vh) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   235
        // Plain
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   236
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   237
            $type$ x = ($type$) vh.get(recv);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   238
            assertEquals(x, $value1$, "get $type$ value");
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
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   242
        // Volatile
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   243
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   244
            $type$ x = ($type$) vh.getVolatile(recv);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   245
            assertEquals(x, $value1$, "getVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   246
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   247
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   248
        // Lazy
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   249
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   250
            $type$ x = ($type$) vh.getAcquire(recv);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   251
            assertEquals(x, $value1$, "getRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   252
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   253
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   254
        // Opaque
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   255
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   256
            $type$ x = ($type$) vh.getOpaque(recv);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   257
            assertEquals(x, $value1$, "getOpaque $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   258
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   259
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   260
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   261
    static void testInstanceFinalFieldUnsupported(VarHandleTestAccess$Type$ recv, VarHandle vh) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   262
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   263
            vh.set(recv, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   264
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   265
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   266
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   267
            vh.setVolatile(recv, $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
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   271
            vh.setRelease(recv, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   272
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   273
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   274
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   275
            vh.setOpaque(recv, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   276
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   277
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   278
#if[!CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   279
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   280
            boolean r = vh.compareAndSet(recv, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   281
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   282
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   283
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   284
            $type$ r = ($type$) vh.compareAndExchangeVolatile(recv, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   285
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   286
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   287
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   288
            $type$ r = ($type$) vh.compareAndExchangeAcquire(recv, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   289
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   290
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   291
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   292
            $type$ r = ($type$) vh.compareAndExchangeRelease(recv, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   293
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   294
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   295
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   296
            boolean r = vh.weakCompareAndSet(recv, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   297
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   298
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   299
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   300
            boolean r = vh.weakCompareAndSetAcquire(recv, $value1$, $value2$);
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
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   304
            boolean r = vh.weakCompareAndSetRelease(recv, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   305
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   306
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   307
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   308
#if[!AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   309
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   310
            $type$ o = ($type$) vh.getAndAdd(recv, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   311
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   312
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   313
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   314
            $type$ o = ($type$) vh.addAndGet(recv, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   315
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   316
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   317
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   318
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   319
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   320
    static void testStaticFinalField(VarHandle vh) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   321
        // Plain
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   322
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   323
            $type$ x = ($type$) vh.get();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   324
            assertEquals(x, $value1$, "get $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   325
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   326
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   327
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   328
        // Volatile
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   329
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   330
            $type$ x = ($type$) vh.getVolatile();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   331
            assertEquals(x, $value1$, "getVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   332
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   333
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   334
        // Lazy
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   335
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   336
            $type$ x = ($type$) vh.getAcquire();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   337
            assertEquals(x, $value1$, "getRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   338
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   339
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   340
        // Opaque
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   341
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   342
            $type$ x = ($type$) vh.getOpaque();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   343
            assertEquals(x, $value1$, "getOpaque $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   344
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   345
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   346
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   347
    static void testStaticFinalFieldUnsupported(VarHandle vh) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   348
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   349
            vh.set($value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   350
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   351
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   352
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   353
            vh.setVolatile($value2$);
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
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   357
            vh.setRelease($value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   358
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   359
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   360
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   361
            vh.setOpaque($value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   362
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   363
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   364
#if[!CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   365
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   366
            boolean r = vh.compareAndSet($value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   367
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   368
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   369
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   370
            $type$ r = ($type$) vh.compareAndExchangeVolatile($value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   371
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   372
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   373
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   374
            $type$ r = ($type$) vh.compareAndExchangeAcquire($value1$, $value2$);
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
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   378
            $type$ r = ($type$) vh.compareAndExchangeRelease($value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   379
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   380
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   381
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   382
            boolean r = vh.weakCompareAndSet($value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   383
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   384
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   385
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   386
            boolean r = vh.weakCompareAndSetAcquire($value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   387
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   388
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   389
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   390
            boolean r = vh.weakCompareAndSetRelease($value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   391
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   392
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   393
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   394
#if[!AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   395
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   396
            $type$ o = ($type$) vh.getAndAdd($value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   397
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   398
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   399
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   400
            $type$ o = ($type$) vh.addAndGet($value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   401
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   402
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   403
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   404
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   405
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   406
    static void testInstanceField(VarHandleTestAccess$Type$ recv, VarHandle vh) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   407
        // Plain
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   408
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   409
            vh.set(recv, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   410
            $type$ x = ($type$) vh.get(recv);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   411
            assertEquals(x, $value1$, "set $type$ value");
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
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   415
        // Volatile
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   416
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   417
            vh.setVolatile(recv, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   418
            $type$ x = ($type$) vh.getVolatile(recv);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   419
            assertEquals(x, $value2$, "setVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   420
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   421
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   422
        // Lazy
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   423
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   424
            vh.setRelease(recv, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   425
            $type$ x = ($type$) vh.getAcquire(recv);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   426
            assertEquals(x, $value1$, "setRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   427
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   428
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   429
        // Opaque
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   430
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   431
            vh.setOpaque(recv, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   432
            $type$ x = ($type$) vh.getOpaque(recv);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   433
            assertEquals(x, $value2$, "setOpaque $type$ value");
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
#if[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   437
        vh.set(recv, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   438
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   439
        // Compare
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   440
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   441
            boolean r = vh.compareAndSet(recv, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   442
            assertEquals(r, true, "success compareAndSet $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   443
            $type$ x = ($type$) vh.get(recv);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   444
            assertEquals(x, $value2$, "success compareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   445
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   446
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   447
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   448
            boolean r = vh.compareAndSet(recv, $value1$, $value3$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   449
            assertEquals(r, false, "failing compareAndSet $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   450
            $type$ x = ($type$) vh.get(recv);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   451
            assertEquals(x, $value2$, "failing compareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   452
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   453
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   454
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   455
            $type$ r = ($type$) vh.compareAndExchangeVolatile(recv, $value2$, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   456
            assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   457
            $type$ x = ($type$) vh.get(recv);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   458
            assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   459
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   460
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   461
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   462
            $type$ r = ($type$) vh.compareAndExchangeVolatile(recv, $value2$, $value3$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   463
            assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   464
            $type$ x = ($type$) vh.get(recv);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   465
            assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   466
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   467
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   468
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   469
            $type$ r = ($type$) vh.compareAndExchangeAcquire(recv, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   470
            assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   471
            $type$ x = ($type$) vh.get(recv);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   472
            assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   473
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   474
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   475
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   476
            $type$ r = ($type$) vh.compareAndExchangeAcquire(recv, $value1$, $value3$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   477
            assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   478
            $type$ x = ($type$) vh.get(recv);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   479
            assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   480
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   481
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   482
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   483
            $type$ r = ($type$) vh.compareAndExchangeRelease(recv, $value2$, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   484
            assertEquals(r, $value2$, "success compareAndExchangeRelease $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   485
            $type$ x = ($type$) vh.get(recv);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   486
            assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   487
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   488
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   489
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   490
            $type$ r = ($type$) vh.compareAndExchangeRelease(recv, $value2$, $value3$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   491
            assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   492
            $type$ x = ($type$) vh.get(recv);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   493
            assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   494
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   495
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   496
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   497
            boolean r = vh.weakCompareAndSet(recv, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   498
            assertEquals(r, true, "weakCompareAndSet $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   499
            $type$ x = ($type$) vh.get(recv);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   500
            assertEquals(x, $value2$, "weakCompareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   501
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   502
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   503
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   504
            boolean r = vh.weakCompareAndSetAcquire(recv, $value2$, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   505
            assertEquals(r, true, "weakCompareAndSetAcquire $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   506
            $type$ x = ($type$) vh.get(recv);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   507
            assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   508
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   509
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   510
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   511
            boolean r = vh.weakCompareAndSetRelease(recv, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   512
            assertEquals(r, true, "weakCompareAndSetRelease $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   513
            $type$ x = ($type$) vh.get(recv);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   514
            assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   515
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   516
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   517
        // Compare set and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   518
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   519
            $type$ o = ($type$) vh.getAndSet(recv, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   520
            assertEquals(o, $value2$, "getAndSet $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   521
            $type$ x = ($type$) vh.get(recv);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   522
            assertEquals(x, $value1$, "getAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   523
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   524
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   525
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   526
#if[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   527
        vh.set(recv, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   528
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   529
        // get and add, add and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   530
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   531
            $type$ o = ($type$) vh.getAndAdd(recv, $value3$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   532
            assertEquals(o, $value1$, "getAndAdd $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   533
            $type$ c = ($type$) vh.addAndGet(recv, $value3$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   534
            assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   535
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   536
#end[AtomicAdd]
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
    static void testInstanceFieldUnsupported(VarHandleTestAccess$Type$ recv, VarHandle vh) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   540
#if[!CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   541
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   542
            boolean r = vh.compareAndSet(recv, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   543
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   544
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   545
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   546
            $type$ r = ($type$) vh.compareAndExchangeVolatile(recv, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   547
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   548
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   549
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   550
            $type$ r = ($type$) vh.compareAndExchangeAcquire(recv, $value1$, $value2$);
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
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   554
            $type$ r = ($type$) vh.compareAndExchangeRelease(recv, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   555
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   556
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   557
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   558
            boolean r = vh.weakCompareAndSet(recv, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   559
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   560
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   561
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   562
            boolean r = vh.weakCompareAndSetAcquire(recv, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   563
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   564
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   565
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   566
            boolean r = vh.weakCompareAndSetRelease(recv, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   567
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   568
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   569
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   570
#if[!AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   571
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   572
            $type$ o = ($type$) vh.getAndAdd(recv, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   573
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   574
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   575
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   576
            $type$ o = ($type$) vh.addAndGet(recv, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   577
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   578
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   579
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   580
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   581
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   582
    static void testStaticField(VarHandle vh) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   583
        // Plain
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   584
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   585
            vh.set($value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   586
            $type$ x = ($type$) vh.get();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   587
            assertEquals(x, $value1$, "set $type$ value");
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
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   591
        // Volatile
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   592
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   593
            vh.setVolatile($value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   594
            $type$ x = ($type$) vh.getVolatile();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   595
            assertEquals(x, $value2$, "setVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   596
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   597
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   598
        // Lazy
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   599
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   600
            vh.setRelease($value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   601
            $type$ x = ($type$) vh.getAcquire();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   602
            assertEquals(x, $value1$, "setRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   603
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   604
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   605
        // Opaque
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   606
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   607
            vh.setOpaque($value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   608
            $type$ x = ($type$) vh.getOpaque();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   609
            assertEquals(x, $value2$, "setOpaque $type$ value");
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
#if[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   613
        vh.set($value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   614
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   615
        // Compare
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   616
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   617
            boolean r = vh.compareAndSet($value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   618
            assertEquals(r, true, "success compareAndSet $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   619
            $type$ x = ($type$) vh.get();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   620
            assertEquals(x, $value2$, "success compareAndSet $type$ value");
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
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   624
            boolean r = vh.compareAndSet($value1$, $value3$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   625
            assertEquals(r, false, "failing compareAndSet $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   626
            $type$ x = ($type$) vh.get();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   627
            assertEquals(x, $value2$, "failing compareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   628
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   629
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   630
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   631
            $type$ r = ($type$) vh.compareAndExchangeVolatile($value2$, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   632
            assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   633
            $type$ x = ($type$) vh.get();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   634
            assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   635
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   636
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   637
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   638
            $type$ r = ($type$) vh.compareAndExchangeVolatile($value2$, $value3$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   639
            assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   640
            $type$ x = ($type$) vh.get();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   641
            assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   642
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   643
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   644
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   645
            $type$ r = ($type$) vh.compareAndExchangeAcquire($value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   646
            assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   647
            $type$ x = ($type$) vh.get();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   648
            assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   649
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   650
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   651
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   652
            $type$ r = ($type$) vh.compareAndExchangeAcquire($value1$, $value3$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   653
            assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   654
            $type$ x = ($type$) vh.get();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   655
            assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   656
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   657
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   658
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   659
            $type$ r = ($type$) vh.compareAndExchangeRelease($value2$, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   660
            assertEquals(r, $value2$, "success compareAndExchangeRelease $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   661
            $type$ x = ($type$) vh.get();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   662
            assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   663
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   664
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   665
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   666
            $type$ r = ($type$) vh.compareAndExchangeRelease($value2$, $value3$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   667
            assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   668
            $type$ x = ($type$) vh.get();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   669
            assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   670
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   671
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   672
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   673
            boolean r = (boolean) vh.weakCompareAndSet($value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   674
            assertEquals(r, true, "weakCompareAndSet $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   675
            $type$ x = ($type$) vh.get();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   676
            assertEquals(x, $value2$, "weakCompareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   677
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   678
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   679
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   680
            boolean r = (boolean) vh.weakCompareAndSetAcquire($value2$, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   681
            assertEquals(r, true, "weakCompareAndSetAcquire $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   682
            $type$ x = ($type$) vh.get();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   683
            assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   684
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   685
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   686
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   687
            boolean r = (boolean) vh.weakCompareAndSetRelease( $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   688
            assertEquals(r, true, "weakCompareAndSetRelease $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   689
            $type$ x = ($type$) vh.get();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   690
            assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
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
        // Compare set and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   694
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   695
            $type$ o = ($type$) vh.getAndSet( $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   696
            assertEquals(o, $value2$, "getAndSet $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   697
            $type$ x = ($type$) vh.get();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   698
            assertEquals(x, $value1$, "getAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   699
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   700
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   701
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   702
#if[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   703
        vh.set($value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   704
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   705
        // get and add, add and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   706
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   707
            $type$ o = ($type$) vh.getAndAdd( $value3$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   708
            assertEquals(o, $value1$, "getAndAdd $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   709
            $type$ c = ($type$) vh.addAndGet($value3$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   710
            assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   711
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   712
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   713
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   714
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   715
    static void testStaticFieldUnsupported(VarHandle vh) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   716
#if[!CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   717
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   718
            boolean r = vh.compareAndSet($value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   719
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   720
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   721
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   722
            $type$ r = ($type$) vh.compareAndExchangeVolatile($value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   723
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   724
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   725
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   726
            $type$ r = ($type$) vh.compareAndExchangeAcquire($value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   727
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   728
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   729
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   730
            $type$ r = ($type$) vh.compareAndExchangeRelease($value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   731
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   732
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   733
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   734
            boolean r = vh.weakCompareAndSet($value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   735
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   736
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   737
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   738
            boolean r = vh.weakCompareAndSetAcquire($value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   739
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   740
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   741
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   742
            boolean r = vh.weakCompareAndSetRelease($value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   743
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   744
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   745
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   746
#if[!AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   747
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   748
            $type$ o = ($type$) vh.getAndAdd($value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   749
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   750
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   751
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   752
            $type$ o = ($type$) vh.addAndGet($value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   753
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   754
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   755
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   756
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   757
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   758
    static void testArray(VarHandle vh) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   759
        $type$[] array = new $type$[10];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   760
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   761
        for (int i = 0; i < array.length; i++) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   762
            // Plain
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   763
            {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   764
                vh.set(array, i, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   765
                $type$ x = ($type$) vh.get(array, i);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   766
                assertEquals(x, $value1$, "get $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   767
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   768
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   769
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   770
            // Volatile
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   771
            {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   772
                vh.setVolatile(array, i, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   773
                $type$ x = ($type$) vh.getVolatile(array, i);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   774
                assertEquals(x, $value2$, "setVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   775
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   776
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   777
            // Lazy
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   778
            {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   779
                vh.setRelease(array, i, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   780
                $type$ x = ($type$) vh.getAcquire(array, i);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   781
                assertEquals(x, $value1$, "setRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   782
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   783
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   784
            // Opaque
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   785
            {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   786
                vh.setOpaque(array, i, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   787
                $type$ x = ($type$) vh.getOpaque(array, i);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   788
                assertEquals(x, $value2$, "setOpaque $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   789
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   790
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   791
#if[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   792
            vh.set(array, i, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   793
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   794
            // Compare
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   795
            {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   796
                boolean r = vh.compareAndSet(array, i, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   797
                assertEquals(r, true, "success compareAndSet $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   798
                $type$ x = ($type$) vh.get(array, i);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   799
                assertEquals(x, $value2$, "success compareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   800
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   801
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   802
            {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   803
                boolean r = vh.compareAndSet(array, i, $value1$, $value3$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   804
                assertEquals(r, false, "failing compareAndSet $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   805
                $type$ x = ($type$) vh.get(array, i);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   806
                assertEquals(x, $value2$, "failing compareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   807
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   808
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   809
            {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   810
                $type$ r = ($type$) vh.compareAndExchangeVolatile(array, i, $value2$, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   811
                assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   812
                $type$ x = ($type$) vh.get(array, i);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   813
                assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   814
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   815
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   816
            {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   817
                $type$ r = ($type$) vh.compareAndExchangeVolatile(array, i, $value2$, $value3$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   818
                assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   819
                $type$ x = ($type$) vh.get(array, i);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   820
                assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   821
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   822
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   823
            {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   824
                $type$ r = ($type$) vh.compareAndExchangeAcquire(array, i, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   825
                assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   826
                $type$ x = ($type$) vh.get(array, i);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   827
                assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   828
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   829
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   830
            {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   831
                $type$ r = ($type$) vh.compareAndExchangeAcquire(array, i, $value1$, $value3$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   832
                assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   833
                $type$ x = ($type$) vh.get(array, i);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   834
                assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   835
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   836
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   837
            {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   838
                $type$ r = ($type$) vh.compareAndExchangeRelease(array, i, $value2$, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   839
                assertEquals(r, $value2$, "success compareAndExchangeRelease $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   840
                $type$ x = ($type$) vh.get(array, i);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   841
                assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   842
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   843
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   844
            {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   845
                $type$ r = ($type$) vh.compareAndExchangeRelease(array, i, $value2$, $value3$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   846
                assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   847
                $type$ x = ($type$) vh.get(array, i);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   848
                assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   849
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   850
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   851
            {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   852
                boolean r = vh.weakCompareAndSet(array, i, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   853
                assertEquals(r, true, "weakCompareAndSet $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   854
                $type$ x = ($type$) vh.get(array, i);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   855
                assertEquals(x, $value2$, "weakCompareAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   856
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   857
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   858
            {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   859
                boolean r = vh.weakCompareAndSetAcquire(array, i, $value2$, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   860
                assertEquals(r, true, "weakCompareAndSetAcquire $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   861
                $type$ x = ($type$) vh.get(array, i);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   862
                assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   863
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   864
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   865
            {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   866
                boolean r = vh.weakCompareAndSetRelease(array, i, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   867
                assertEquals(r, true, "weakCompareAndSetRelease $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   868
                $type$ x = ($type$) vh.get(array, i);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   869
                assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   870
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   871
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   872
            // Compare set and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   873
            {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   874
                $type$ o = ($type$) vh.getAndSet(array, i, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   875
                assertEquals(o, $value2$, "getAndSet $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   876
                $type$ x = ($type$) vh.get(array, i);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   877
                assertEquals(x, $value1$, "getAndSet $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   878
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   879
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   880
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   881
#if[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   882
            vh.set(array, i, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   883
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   884
            // get and add, add and get
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   885
            {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   886
                $type$ o = ($type$) vh.getAndAdd(array, i, $value3$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   887
                assertEquals(o, $value1$, "getAndAdd $type$");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   888
                $type$ c = ($type$) vh.addAndGet(array, i, $value3$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   889
                assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value");
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   890
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   891
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   892
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   893
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   894
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   895
    static void testArrayUnsupported(VarHandle vh) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   896
        $type$[] array = new $type$[10];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   897
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   898
        int i = 0;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   899
#if[!CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   900
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   901
            boolean r = vh.compareAndSet(array, i, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   902
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   903
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   904
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   905
            $type$ r = ($type$) vh.compareAndExchangeVolatile(array, i, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   906
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   907
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   908
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   909
            $type$ r = ($type$) vh.compareAndExchangeAcquire(array, i, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   910
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   911
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   912
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   913
            $type$ r = ($type$) vh.compareAndExchangeRelease(array, i, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   914
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   915
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   916
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   917
            boolean r = vh.weakCompareAndSet(array, i, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   918
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   919
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   920
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   921
            boolean r = vh.weakCompareAndSetAcquire(array, i, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   922
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   923
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   924
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   925
            boolean r = vh.weakCompareAndSetRelease(array, i, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   926
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   927
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   928
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   929
#if[!AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   930
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   931
            $type$ o = ($type$) vh.getAndAdd(array, i, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   932
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   933
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   934
        checkUOE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   935
            $type$ o = ($type$) vh.addAndGet(array, i, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   936
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   937
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   938
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   939
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   940
    static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   941
        $type$[] array = new $type$[10];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   942
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   943
        for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   944
            final int ci = i;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   945
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   946
            checkIOOBE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   947
                $type$ x = ($type$) vh.get(array, ci);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   948
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   949
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   950
            checkIOOBE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   951
                vh.set(array, ci, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   952
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   953
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   954
            checkIOOBE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   955
                $type$ x = ($type$) vh.getVolatile(array, ci);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   956
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   957
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   958
            checkIOOBE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   959
                vh.setVolatile(array, ci, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   960
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   961
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   962
            checkIOOBE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   963
                $type$ x = ($type$) vh.getAcquire(array, ci);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   964
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   965
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   966
            checkIOOBE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   967
                vh.setRelease(array, ci, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   968
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   969
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   970
            checkIOOBE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   971
                $type$ x = ($type$) vh.getOpaque(array, ci);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   972
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   973
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   974
            checkIOOBE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   975
                vh.setOpaque(array, ci, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   976
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   977
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   978
#if[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   979
            checkIOOBE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   980
                boolean r = vh.compareAndSet(array, ci, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   981
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   982
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   983
            checkIOOBE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   984
                $type$ r = ($type$) vh.compareAndExchangeVolatile(array, ci, $value2$, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   985
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   986
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   987
            checkIOOBE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   988
                $type$ r = ($type$) vh.compareAndExchangeAcquire(array, ci, $value2$, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   989
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   990
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   991
            checkIOOBE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   992
                $type$ r = ($type$) vh.compareAndExchangeRelease(array, ci, $value2$, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   993
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   994
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   995
            checkIOOBE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   996
                boolean r = vh.weakCompareAndSet(array, ci, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   997
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   998
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   999
            checkIOOBE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1000
                boolean r = vh.weakCompareAndSetAcquire(array, ci, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1001
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1002
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1003
            checkIOOBE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1004
                boolean r = vh.weakCompareAndSetRelease(array, ci, $value1$, $value2$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1005
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1006
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1007
            checkIOOBE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1008
                $type$ o = ($type$) vh.getAndSet(array, ci, $value1$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1009
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1010
#end[CAS]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1011
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1012
#if[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1013
            checkIOOBE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1014
                $type$ o = ($type$) vh.getAndAdd(array, ci, $value3$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1015
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1016
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1017
            checkIOOBE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1018
                $type$ o = ($type$) vh.addAndGet(array, ci, $value3$);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1019
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1020
#end[AtomicAdd]
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1021
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1022
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1023
}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
  1024