jdk/test/java/lang/invoke/VarHandles/VarHandleTestAccessByte.java
author shade
Wed, 15 Jun 2016 11:20:15 +0300
changeset 39470 d6f8b4a85fb0
parent 38429 0fd11baf20c3
child 39472 6df82f4c63ac
permissions -rw-r--r--
8157726: VarHandles/Unsafe should support sub-word atomic ops Reviewed-by: psandoz, vlivanov, lagergren
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                   VarHandleTestAccessByte
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    27
 * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestAccessByte
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    28
 * @run testng/othervm -Diters=20000                         VarHandleTestAccessByte
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    29
 * @run testng/othervm -Diters=20000 -XX:-TieredCompilation  VarHandleTestAccessByte
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 VarHandleTestAccessByte extends VarHandleBaseTest {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
    45
    static final byte static_final_v = (byte)0x01;
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    46
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    47
    static byte static_v;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    48
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
    49
    final byte final_v = (byte)0x01;
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    50
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    51
    byte 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
                VarHandleTestAccessByte.class, "final_v", byte.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
                VarHandleTestAccessByte.class, "v", byte.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
            VarHandleTestAccessByte.class, "static_final_v", byte.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
            VarHandleTestAccessByte.class, "static_v", byte.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    76
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    77
        vhArray = MethodHandles.arrayElementVarHandle(byte[].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
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   102
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   103
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE));
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   104
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   105
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   106
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   107
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_VOLATILE));
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   108
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   109
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   110
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   111
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   112
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   113
        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.ADD_AND_GET));
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   114
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   115
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   116
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   117
    @DataProvider
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   118
    public Object[][] typesProvider() throws Exception {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   119
        List<Object[]> types = new ArrayList<>();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   120
        types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessByte.class)});
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   121
        types.add(new Object[] {vhStaticField, Arrays.asList()});
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   122
        types.add(new Object[] {vhArray, Arrays.asList(byte[].class, int.class)});
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   123
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   124
        return types.stream().toArray(Object[][]::new);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   125
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   126
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   127
    @Test(dataProvider = "typesProvider")
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   128
    public void testTypes(VarHandle vh, List<Class<?>> pts) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   129
        assertEquals(vh.varType(), byte.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   130
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   131
        assertEquals(vh.coordinateTypes(), pts);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   132
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   133
        testTypes(vh);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   134
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   135
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   136
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   137
    @Test
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   138
    public void testLookupInstanceToStatic() {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   139
        checkIAE("Lookup of static final field to instance final field", () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   140
            MethodHandles.lookup().findStaticVarHandle(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   141
                    VarHandleTestAccessByte.class, "final_v", byte.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   142
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   143
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   144
        checkIAE("Lookup of static field to instance field", () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   145
            MethodHandles.lookup().findStaticVarHandle(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   146
                    VarHandleTestAccessByte.class, "v", byte.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   147
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   148
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   149
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   150
    @Test
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   151
    public void testLookupStaticToInstance() {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   152
        checkIAE("Lookup of instance final field to static final field", () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   153
            MethodHandles.lookup().findVarHandle(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   154
                VarHandleTestAccessByte.class, "static_final_v", byte.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   155
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   156
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   157
        checkIAE("Lookup of instance field to static field", () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   158
            vhStaticField = MethodHandles.lookup().findVarHandle(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   159
                VarHandleTestAccessByte.class, "static_v", byte.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   160
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   161
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   162
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   163
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   164
    @DataProvider
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   165
    public Object[][] accessTestCaseProvider() throws Exception {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   166
        List<AccessTestCase<?>> cases = new ArrayList<>();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   167
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   168
        cases.add(new VarHandleAccessTestCase("Instance final field",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   169
                                              vhFinalField, vh -> testInstanceFinalField(this, vh)));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   170
        cases.add(new VarHandleAccessTestCase("Instance final field unsupported",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   171
                                              vhFinalField, vh -> testInstanceFinalFieldUnsupported(this, vh),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   172
                                              false));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   173
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   174
        cases.add(new VarHandleAccessTestCase("Static final field",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   175
                                              vhStaticFinalField, VarHandleTestAccessByte::testStaticFinalField));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   176
        cases.add(new VarHandleAccessTestCase("Static final field unsupported",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   177
                                              vhStaticFinalField, VarHandleTestAccessByte::testStaticFinalFieldUnsupported,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   178
                                              false));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   179
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   180
        cases.add(new VarHandleAccessTestCase("Instance field",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   181
                                              vhField, vh -> testInstanceField(this, vh)));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   182
        cases.add(new VarHandleAccessTestCase("Instance field unsupported",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   183
                                              vhField, vh -> testInstanceFieldUnsupported(this, vh),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   184
                                              false));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   185
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   186
        cases.add(new VarHandleAccessTestCase("Static field",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   187
                                              vhStaticField, VarHandleTestAccessByte::testStaticField));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   188
        cases.add(new VarHandleAccessTestCase("Static field unsupported",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   189
                                              vhStaticField, VarHandleTestAccessByte::testStaticFieldUnsupported,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   190
                                              false));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   191
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   192
        cases.add(new VarHandleAccessTestCase("Array",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   193
                                              vhArray, VarHandleTestAccessByte::testArray));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   194
        cases.add(new VarHandleAccessTestCase("Array unsupported",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   195
                                              vhArray, VarHandleTestAccessByte::testArrayUnsupported,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   196
                                              false));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   197
        cases.add(new VarHandleAccessTestCase("Array index out of bounds",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   198
                                              vhArray, VarHandleTestAccessByte::testArrayIndexOutOfBounds,
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
        // Work around issue with jtreg summary reporting which truncates
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   202
        // the String result of Object.toString to 30 characters, hence
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   203
        // the first dummy argument
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   204
        return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   205
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   206
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   207
    @Test(dataProvider = "accessTestCaseProvider")
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   208
    public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   209
        T t = atc.get();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   210
        int iters = atc.requiresLoop() ? ITERS : 1;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   211
        for (int c = 0; c < iters; c++) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   212
            atc.testAccess(t);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   213
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   214
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   215
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   216
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   217
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   218
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   219
    static void testInstanceFinalField(VarHandleTestAccessByte recv, VarHandle vh) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   220
        // Plain
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   221
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   222
            byte x = (byte) vh.get(recv);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   223
            assertEquals(x, (byte)0x01, "get byte value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   224
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   225
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   226
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   227
        // Volatile
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   228
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   229
            byte x = (byte) vh.getVolatile(recv);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   230
            assertEquals(x, (byte)0x01, "getVolatile byte value");
36934
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
        // Lazy
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   234
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   235
            byte x = (byte) vh.getAcquire(recv);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   236
            assertEquals(x, (byte)0x01, "getRelease byte value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   237
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   238
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   239
        // Opaque
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   240
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   241
            byte x = (byte) vh.getOpaque(recv);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   242
            assertEquals(x, (byte)0x01, "getOpaque byte value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   243
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   244
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   245
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   246
    static void testInstanceFinalFieldUnsupported(VarHandleTestAccessByte recv, VarHandle vh) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   247
        checkUOE(() -> {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   248
            vh.set(recv, (byte)0x23);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   249
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   250
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   251
        checkUOE(() -> {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   252
            vh.setVolatile(recv, (byte)0x23);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   253
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   254
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   255
        checkUOE(() -> {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   256
            vh.setRelease(recv, (byte)0x23);
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37668
diff changeset
   257
        });
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37668
diff changeset
   258
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37668
diff changeset
   259
        checkUOE(() -> {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   260
            vh.setOpaque(recv, (byte)0x23);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   261
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   262
38328
40435a469d25 8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents: 37719
diff changeset
   263
36934
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
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   267
    static void testStaticFinalField(VarHandle vh) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   268
        // Plain
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   269
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   270
            byte x = (byte) vh.get();
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   271
            assertEquals(x, (byte)0x01, "get byte value");
36934
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
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   275
        // Volatile
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   276
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   277
            byte x = (byte) vh.getVolatile();
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   278
            assertEquals(x, (byte)0x01, "getVolatile byte value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   279
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   280
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   281
        // Lazy
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   282
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   283
            byte x = (byte) vh.getAcquire();
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   284
            assertEquals(x, (byte)0x01, "getRelease byte value");
36934
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
        // Opaque
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   288
        {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   289
            byte x = (byte) vh.getOpaque();
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   290
            assertEquals(x, (byte)0x01, "getOpaque byte value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   291
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   292
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   293
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   294
    static void testStaticFinalFieldUnsupported(VarHandle vh) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   295
        checkUOE(() -> {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   296
            vh.set((byte)0x23);
36934
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(() -> {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   300
            vh.setVolatile((byte)0x23);
36934
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(() -> {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   304
            vh.setRelease((byte)0x23);
37719
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37668
diff changeset
   305
        });
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37668
diff changeset
   306
add11bc0e6e2 8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents: 37668
diff changeset
   307
        checkUOE(() -> {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   308
            vh.setOpaque((byte)0x23);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   309
        });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   310
38328
40435a469d25 8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents: 37719
diff changeset
   311
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   312
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   313
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   314
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   315
    static void testInstanceField(VarHandleTestAccessByte recv, VarHandle vh) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   316
        // Plain
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   317
        {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   318
            vh.set(recv, (byte)0x01);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   319
            byte x = (byte) vh.get(recv);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   320
            assertEquals(x, (byte)0x01, "set byte value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   321
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   322
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   323
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   324
        // Volatile
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   325
        {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   326
            vh.setVolatile(recv, (byte)0x23);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   327
            byte x = (byte) vh.getVolatile(recv);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   328
            assertEquals(x, (byte)0x23, "setVolatile byte value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   329
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   330
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   331
        // Lazy
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   332
        {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   333
            vh.setRelease(recv, (byte)0x01);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   334
            byte x = (byte) vh.getAcquire(recv);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   335
            assertEquals(x, (byte)0x01, "setRelease byte value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   336
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   337
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   338
        // Opaque
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   339
        {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   340
            vh.setOpaque(recv, (byte)0x23);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   341
            byte x = (byte) vh.getOpaque(recv);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   342
            assertEquals(x, (byte)0x23, "setOpaque byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   343
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   344
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   345
        vh.set(recv, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   346
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   347
        // Compare
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   348
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   349
            boolean r = vh.compareAndSet(recv, (byte)0x01, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   350
            assertEquals(r, true, "success compareAndSet byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   351
            byte x = (byte) vh.get(recv);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   352
            assertEquals(x, (byte)0x23, "success compareAndSet byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   353
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   354
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   355
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   356
            boolean r = vh.compareAndSet(recv, (byte)0x01, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   357
            assertEquals(r, false, "failing compareAndSet byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   358
            byte x = (byte) vh.get(recv);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   359
            assertEquals(x, (byte)0x23, "failing compareAndSet byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   360
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   361
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   362
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   363
            byte r = (byte) vh.compareAndExchangeVolatile(recv, (byte)0x23, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   364
            assertEquals(r, (byte)0x23, "success compareAndExchangeVolatile byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   365
            byte x = (byte) vh.get(recv);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   366
            assertEquals(x, (byte)0x01, "success compareAndExchangeVolatile byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   367
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   368
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   369
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   370
            byte r = (byte) vh.compareAndExchangeVolatile(recv, (byte)0x23, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   371
            assertEquals(r, (byte)0x01, "failing compareAndExchangeVolatile byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   372
            byte x = (byte) vh.get(recv);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   373
            assertEquals(x, (byte)0x01, "failing compareAndExchangeVolatile byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   374
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   375
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   376
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   377
            byte r = (byte) vh.compareAndExchangeAcquire(recv, (byte)0x01, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   378
            assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   379
            byte x = (byte) vh.get(recv);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   380
            assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   381
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   382
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   383
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   384
            byte r = (byte) vh.compareAndExchangeAcquire(recv, (byte)0x01, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   385
            assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   386
            byte x = (byte) vh.get(recv);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   387
            assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   388
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   389
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   390
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   391
            byte r = (byte) vh.compareAndExchangeRelease(recv, (byte)0x23, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   392
            assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   393
            byte x = (byte) vh.get(recv);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   394
            assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   395
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   396
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   397
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   398
            byte r = (byte) vh.compareAndExchangeRelease(recv, (byte)0x23, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   399
            assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   400
            byte x = (byte) vh.get(recv);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   401
            assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   402
        }
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   403
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   404
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   405
            boolean success = false;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   406
            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   407
                success = vh.weakCompareAndSet(recv, (byte)0x01, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   408
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   409
            assertEquals(success, true, "weakCompareAndSet byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   410
            byte x = (byte) vh.get(recv);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   411
            assertEquals(x, (byte)0x23, "weakCompareAndSet byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   412
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   413
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   414
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   415
            boolean success = false;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   416
            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   417
                success = vh.weakCompareAndSetAcquire(recv, (byte)0x23, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   418
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   419
            assertEquals(success, true, "weakCompareAndSetAcquire byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   420
            byte x = (byte) vh.get(recv);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   421
            assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   422
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   423
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   424
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   425
            boolean success = false;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   426
            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   427
                success = vh.weakCompareAndSetRelease(recv, (byte)0x01, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   428
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   429
            assertEquals(success, true, "weakCompareAndSetRelease byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   430
            byte x = (byte) vh.get(recv);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   431
            assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   432
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   433
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   434
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   435
            boolean success = false;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   436
            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   437
                success = vh.weakCompareAndSetVolatile(recv, (byte)0x23, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   438
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   439
            assertEquals(success, true, "weakCompareAndSetVolatile byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   440
            byte x = (byte) vh.get(recv);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   441
            assertEquals(x, (byte)0x01, "weakCompareAndSetVolatile byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   442
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   443
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   444
        // Compare set and get
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   445
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   446
            byte o = (byte) vh.getAndSet(recv, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   447
            assertEquals(o, (byte)0x01, "getAndSet byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   448
            byte x = (byte) vh.get(recv);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   449
            assertEquals(x, (byte)0x23, "getAndSet byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   450
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   451
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   452
        vh.set(recv, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   453
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   454
        // get and add, add and get
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   455
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   456
            byte o = (byte) vh.getAndAdd(recv, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   457
            assertEquals(o, (byte)0x01, "getAndAdd byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   458
            byte c = (byte) vh.addAndGet(recv, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   459
            assertEquals(c, (byte)((byte)0x01 + (byte)0x45 + (byte)0x45), "getAndAdd byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   460
        }
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   461
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   462
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   463
    static void testInstanceFieldUnsupported(VarHandleTestAccessByte recv, VarHandle vh) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   464
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   465
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   466
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   467
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   468
    static void testStaticField(VarHandle vh) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   469
        // Plain
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   470
        {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   471
            vh.set((byte)0x01);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   472
            byte x = (byte) vh.get();
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   473
            assertEquals(x, (byte)0x01, "set byte value");
36934
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
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   477
        // Volatile
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   478
        {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   479
            vh.setVolatile((byte)0x23);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   480
            byte x = (byte) vh.getVolatile();
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   481
            assertEquals(x, (byte)0x23, "setVolatile byte value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   482
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   483
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   484
        // Lazy
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   485
        {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   486
            vh.setRelease((byte)0x01);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   487
            byte x = (byte) vh.getAcquire();
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   488
            assertEquals(x, (byte)0x01, "setRelease byte value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   489
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   490
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   491
        // Opaque
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   492
        {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   493
            vh.setOpaque((byte)0x23);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   494
            byte x = (byte) vh.getOpaque();
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   495
            assertEquals(x, (byte)0x23, "setOpaque byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   496
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   497
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   498
        vh.set((byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   499
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   500
        // Compare
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   501
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   502
            boolean r = vh.compareAndSet((byte)0x01, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   503
            assertEquals(r, true, "success compareAndSet byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   504
            byte x = (byte) vh.get();
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   505
            assertEquals(x, (byte)0x23, "success compareAndSet byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   506
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   507
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   508
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   509
            boolean r = vh.compareAndSet((byte)0x01, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   510
            assertEquals(r, false, "failing compareAndSet byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   511
            byte x = (byte) vh.get();
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   512
            assertEquals(x, (byte)0x23, "failing compareAndSet byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   513
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   514
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   515
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   516
            byte r = (byte) vh.compareAndExchangeVolatile((byte)0x23, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   517
            assertEquals(r, (byte)0x23, "success compareAndExchangeVolatile byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   518
            byte x = (byte) vh.get();
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   519
            assertEquals(x, (byte)0x01, "success compareAndExchangeVolatile byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   520
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   521
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   522
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   523
            byte r = (byte) vh.compareAndExchangeVolatile((byte)0x23, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   524
            assertEquals(r, (byte)0x01, "failing compareAndExchangeVolatile byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   525
            byte x = (byte) vh.get();
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   526
            assertEquals(x, (byte)0x01, "failing compareAndExchangeVolatile byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   527
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   528
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   529
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   530
            byte r = (byte) vh.compareAndExchangeAcquire((byte)0x01, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   531
            assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   532
            byte x = (byte) vh.get();
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   533
            assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   534
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   535
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   536
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   537
            byte r = (byte) vh.compareAndExchangeAcquire((byte)0x01, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   538
            assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   539
            byte x = (byte) vh.get();
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   540
            assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   541
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   542
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   543
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   544
            byte r = (byte) vh.compareAndExchangeRelease((byte)0x23, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   545
            assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   546
            byte x = (byte) vh.get();
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   547
            assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   548
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   549
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   550
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   551
            byte r = (byte) vh.compareAndExchangeRelease((byte)0x23, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   552
            assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   553
            byte x = (byte) vh.get();
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   554
            assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   555
        }
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   556
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   557
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   558
            boolean success = false;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   559
            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   560
                success = vh.weakCompareAndSet((byte)0x01, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   561
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   562
            assertEquals(success, true, "weakCompareAndSet byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   563
            byte x = (byte) vh.get();
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   564
            assertEquals(x, (byte)0x23, "weakCompareAndSet byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   565
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   566
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   567
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   568
            boolean success = false;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   569
            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   570
                success = vh.weakCompareAndSetAcquire((byte)0x23, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   571
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   572
            assertEquals(success, true, "weakCompareAndSetAcquire byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   573
            byte x = (byte) vh.get();
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   574
            assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   575
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   576
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   577
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   578
            boolean success = false;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   579
            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   580
                success = vh.weakCompareAndSetRelease((byte)0x01, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   581
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   582
            assertEquals(success, true, "weakCompareAndSetRelease byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   583
            byte x = (byte) vh.get();
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   584
            assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   585
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   586
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   587
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   588
            boolean success = false;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   589
            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   590
                success = vh.weakCompareAndSetRelease((byte)0x23, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   591
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   592
            assertEquals(success, true, "weakCompareAndSetVolatile byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   593
            byte x = (byte) vh.get();
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   594
            assertEquals(x, (byte)0x01, "weakCompareAndSetVolatile byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   595
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   596
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   597
        // Compare set and get
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   598
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   599
            byte o = (byte) vh.getAndSet((byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   600
            assertEquals(o, (byte)0x01, "getAndSet byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   601
            byte x = (byte) vh.get();
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   602
            assertEquals(x, (byte)0x23, "getAndSet byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   603
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   604
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   605
        vh.set((byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   606
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   607
        // get and add, add and get
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   608
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   609
            byte o = (byte) vh.getAndAdd( (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   610
            assertEquals(o, (byte)0x01, "getAndAdd byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   611
            byte c = (byte) vh.addAndGet((byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   612
            assertEquals(c, (byte)((byte)0x01 + (byte)0x45 + (byte)0x45), "getAndAdd byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   613
        }
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   614
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   615
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   616
    static void testStaticFieldUnsupported(VarHandle vh) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   617
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   618
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   619
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   620
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   621
    static void testArray(VarHandle vh) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   622
        byte[] array = new byte[10];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   623
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   624
        for (int i = 0; i < array.length; i++) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   625
            // Plain
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   626
            {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   627
                vh.set(array, i, (byte)0x01);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   628
                byte x = (byte) vh.get(array, i);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   629
                assertEquals(x, (byte)0x01, "get byte value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   630
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   631
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   632
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   633
            // Volatile
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   634
            {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   635
                vh.setVolatile(array, i, (byte)0x23);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   636
                byte x = (byte) vh.getVolatile(array, i);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   637
                assertEquals(x, (byte)0x23, "setVolatile byte value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   638
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   639
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   640
            // Lazy
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   641
            {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   642
                vh.setRelease(array, i, (byte)0x01);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   643
                byte x = (byte) vh.getAcquire(array, i);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   644
                assertEquals(x, (byte)0x01, "setRelease byte value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   645
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   646
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   647
            // Opaque
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   648
            {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   649
                vh.setOpaque(array, i, (byte)0x23);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   650
                byte x = (byte) vh.getOpaque(array, i);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   651
                assertEquals(x, (byte)0x23, "setOpaque byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   652
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   653
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   654
            vh.set(array, i, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   655
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   656
            // Compare
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   657
            {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   658
                boolean r = vh.compareAndSet(array, i, (byte)0x01, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   659
                assertEquals(r, true, "success compareAndSet byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   660
                byte x = (byte) vh.get(array, i);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   661
                assertEquals(x, (byte)0x23, "success compareAndSet byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   662
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   663
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   664
            {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   665
                boolean r = vh.compareAndSet(array, i, (byte)0x01, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   666
                assertEquals(r, false, "failing compareAndSet byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   667
                byte x = (byte) vh.get(array, i);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   668
                assertEquals(x, (byte)0x23, "failing compareAndSet byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   669
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   670
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   671
            {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   672
                byte r = (byte) vh.compareAndExchangeVolatile(array, i, (byte)0x23, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   673
                assertEquals(r, (byte)0x23, "success compareAndExchangeVolatile byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   674
                byte x = (byte) vh.get(array, i);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   675
                assertEquals(x, (byte)0x01, "success compareAndExchangeVolatile byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   676
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   677
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   678
            {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   679
                byte r = (byte) vh.compareAndExchangeVolatile(array, i, (byte)0x23, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   680
                assertEquals(r, (byte)0x01, "failing compareAndExchangeVolatile byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   681
                byte x = (byte) vh.get(array, i);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   682
                assertEquals(x, (byte)0x01, "failing compareAndExchangeVolatile byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   683
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   684
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   685
            {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   686
                byte r = (byte) vh.compareAndExchangeAcquire(array, i, (byte)0x01, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   687
                assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   688
                byte x = (byte) vh.get(array, i);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   689
                assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   690
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   691
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   692
            {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   693
                byte r = (byte) vh.compareAndExchangeAcquire(array, i, (byte)0x01, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   694
                assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   695
                byte x = (byte) vh.get(array, i);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   696
                assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   697
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   698
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   699
            {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   700
                byte r = (byte) vh.compareAndExchangeRelease(array, i, (byte)0x23, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   701
                assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   702
                byte x = (byte) vh.get(array, i);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   703
                assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   704
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   705
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   706
            {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   707
                byte r = (byte) vh.compareAndExchangeRelease(array, i, (byte)0x23, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   708
                assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   709
                byte x = (byte) vh.get(array, i);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   710
                assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   711
            }
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   712
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   713
            {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   714
                boolean success = false;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   715
                for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   716
                    success = vh.weakCompareAndSet(array, i, (byte)0x01, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   717
                }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   718
                assertEquals(success, true, "weakCompareAndSet byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   719
                byte x = (byte) vh.get(array, i);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   720
                assertEquals(x, (byte)0x23, "weakCompareAndSet byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   721
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   722
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   723
            {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   724
                boolean success = false;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   725
                for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   726
                    success = vh.weakCompareAndSetAcquire(array, i, (byte)0x23, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   727
                }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   728
                assertEquals(success, true, "weakCompareAndSetAcquire byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   729
                byte x = (byte) vh.get(array, i);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   730
                assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   731
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   732
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   733
            {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   734
                boolean success = false;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   735
                for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   736
                    success = vh.weakCompareAndSetRelease(array, i, (byte)0x01, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   737
                }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   738
                assertEquals(success, true, "weakCompareAndSetRelease byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   739
                byte x = (byte) vh.get(array, i);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   740
                assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   741
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   742
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   743
            {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   744
                boolean success = false;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   745
                for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   746
                    success = vh.weakCompareAndSetVolatile(array, i, (byte)0x23, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   747
                }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   748
                assertEquals(success, true, "weakCompareAndSetVolatile byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   749
                byte x = (byte) vh.get(array, i);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   750
                assertEquals(x, (byte)0x01, "weakCompareAndSetVolatile byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   751
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   752
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   753
            // Compare set and get
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   754
            {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   755
                byte o = (byte) vh.getAndSet(array, i, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   756
                assertEquals(o, (byte)0x01, "getAndSet byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   757
                byte x = (byte) vh.get(array, i);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   758
                assertEquals(x, (byte)0x23, "getAndSet byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   759
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   760
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   761
            vh.set(array, i, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   762
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   763
            // get and add, add and get
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   764
            {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   765
                byte o = (byte) vh.getAndAdd(array, i, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   766
                assertEquals(o, (byte)0x01, "getAndAdd byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   767
                byte c = (byte) vh.addAndGet(array, i, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   768
                assertEquals(c, (byte)((byte)0x01 + (byte)0x45 + (byte)0x45), "getAndAdd byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   769
            }
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   770
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   771
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   772
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   773
    static void testArrayUnsupported(VarHandle vh) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   774
        byte[] array = new byte[10];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   775
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   776
        int i = 0;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   777
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   778
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   779
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   780
    static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   781
        byte[] array = new byte[10];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   782
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   783
        for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   784
            final int ci = i;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   785
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   786
            checkIOOBE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   787
                byte x = (byte) vh.get(array, ci);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   788
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   789
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   790
            checkIOOBE(() -> {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   791
                vh.set(array, ci, (byte)0x01);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   792
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   793
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   794
            checkIOOBE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   795
                byte x = (byte) vh.getVolatile(array, ci);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   796
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   797
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   798
            checkIOOBE(() -> {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   799
                vh.setVolatile(array, ci, (byte)0x01);
36934
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
            checkIOOBE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   803
                byte x = (byte) vh.getAcquire(array, ci);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   804
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   805
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   806
            checkIOOBE(() -> {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   807
                vh.setRelease(array, ci, (byte)0x01);
36934
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
            checkIOOBE(() -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   811
                byte x = (byte) vh.getOpaque(array, ci);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   812
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   813
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   814
            checkIOOBE(() -> {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   815
                vh.setOpaque(array, ci, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   816
            });
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   817
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   818
            checkIOOBE(() -> {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   819
                boolean r = vh.compareAndSet(array, ci, (byte)0x01, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   820
            });
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   821
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   822
            checkIOOBE(() -> {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   823
                byte r = (byte) vh.compareAndExchangeVolatile(array, ci, (byte)0x23, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   824
            });
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   825
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   826
            checkIOOBE(() -> {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   827
                byte r = (byte) vh.compareAndExchangeAcquire(array, ci, (byte)0x23, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   828
            });
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   829
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   830
            checkIOOBE(() -> {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   831
                byte r = (byte) vh.compareAndExchangeRelease(array, ci, (byte)0x23, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   832
            });
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   833
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   834
            checkIOOBE(() -> {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   835
                boolean r = vh.weakCompareAndSet(array, ci, (byte)0x01, (byte)0x23);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   836
            });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   837
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   838
            checkIOOBE(() -> {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   839
                boolean r = vh.weakCompareAndSetVolatile(array, ci, (byte)0x01, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   840
            });
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   841
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   842
            checkIOOBE(() -> {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   843
                boolean r = vh.weakCompareAndSetAcquire(array, ci, (byte)0x01, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   844
            });
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   845
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   846
            checkIOOBE(() -> {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   847
                boolean r = vh.weakCompareAndSetRelease(array, ci, (byte)0x01, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   848
            });
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   849
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   850
            checkIOOBE(() -> {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   851
                byte o = (byte) vh.getAndSet(array, ci, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   852
            });
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   853
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   854
            checkIOOBE(() -> {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   855
                byte o = (byte) vh.getAndAdd(array, ci, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   856
            });
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   857
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   858
            checkIOOBE(() -> {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   859
                byte o = (byte) vh.addAndGet(array, ci, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   860
            });
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   861
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   862
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   863
}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   864