jdk/test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessByte.java
author psandoz
Mon, 20 Jun 2016 17:57:19 +0200
changeset 39471 6622892a347a
parent 39470 d6f8b4a85fb0
child 39472 6df82f4c63ac
permissions -rw-r--r--
8158039: VarHandle float/double field/array access should support CAS/set/add atomics Reviewed-by: shade, vlivanov, darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     1
/*
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     4
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     7
 * published by the Free Software Foundation.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     8
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    13
 * accompanied this code).
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    14
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    18
 *
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    21
 * questions.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    22
 */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    23
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    24
/*
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    25
 * @test
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    26
 * @run testng/othervm -Diters=20000 VarHandleTestMethodHandleAccessByte
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    27
 */
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    28
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    29
import org.testng.annotations.BeforeClass;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    30
import org.testng.annotations.DataProvider;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    31
import org.testng.annotations.Test;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    32
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    33
import java.lang.invoke.MethodHandles;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    34
import java.lang.invoke.VarHandle;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    35
import java.util.ArrayList;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    36
import java.util.Arrays;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    37
import java.util.List;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    38
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    39
import static org.testng.Assert.*;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    40
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    41
public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
    42
    static final byte static_final_v = (byte)0x01;
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    43
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    44
    static byte static_v;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    45
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
    46
    final byte final_v = (byte)0x01;
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    47
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    48
    byte v;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    49
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    50
    VarHandle vhFinalField;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    51
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    52
    VarHandle vhField;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    53
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    54
    VarHandle vhStaticField;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    55
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    56
    VarHandle vhStaticFinalField;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    57
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    58
    VarHandle vhArray;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    59
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    60
    @BeforeClass
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    61
    public void setup() throws Exception {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    62
        vhFinalField = MethodHandles.lookup().findVarHandle(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    63
                VarHandleTestMethodHandleAccessByte.class, "final_v", byte.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    64
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    65
        vhField = MethodHandles.lookup().findVarHandle(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    66
                VarHandleTestMethodHandleAccessByte.class, "v", byte.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    67
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    68
        vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    69
            VarHandleTestMethodHandleAccessByte.class, "static_final_v", byte.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    70
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    71
        vhStaticField = MethodHandles.lookup().findStaticVarHandle(
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    72
            VarHandleTestMethodHandleAccessByte.class, "static_v", byte.class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    73
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    74
        vhArray = MethodHandles.arrayElementVarHandle(byte[].class);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    75
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    76
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    77
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    78
    @DataProvider
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    79
    public Object[][] accessTestCaseProvider() throws Exception {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    80
        List<AccessTestCase<?>> cases = new ArrayList<>();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    81
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    82
        for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    83
            cases.add(new MethodHandleAccessTestCase("Instance field",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    84
                                                     vhField, f, hs -> testInstanceField(this, hs)));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    85
            cases.add(new MethodHandleAccessTestCase("Instance field unsupported",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    86
                                                     vhField, f, hs -> testInstanceFieldUnsupported(this, hs),
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    87
                                                     false));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    88
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    89
            cases.add(new MethodHandleAccessTestCase("Static field",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    90
                                                     vhStaticField, f, VarHandleTestMethodHandleAccessByte::testStaticField));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    91
            cases.add(new MethodHandleAccessTestCase("Static field unsupported",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    92
                                                     vhStaticField, f, VarHandleTestMethodHandleAccessByte::testStaticFieldUnsupported,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    93
                                                     false));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    94
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    95
            cases.add(new MethodHandleAccessTestCase("Array",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    96
                                                     vhArray, f, VarHandleTestMethodHandleAccessByte::testArray));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    97
            cases.add(new MethodHandleAccessTestCase("Array unsupported",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    98
                                                     vhArray, f, VarHandleTestMethodHandleAccessByte::testArrayUnsupported,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
    99
                                                     false));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   100
            cases.add(new MethodHandleAccessTestCase("Array index out of bounds",
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   101
                                                     vhArray, f, VarHandleTestMethodHandleAccessByte::testArrayIndexOutOfBounds,
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   102
                                                     false));
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   103
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   104
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   105
        // Work around issue with jtreg summary reporting which truncates
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   106
        // the String result of Object.toString to 30 characters, hence
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   107
        // the first dummy argument
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   108
        return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   109
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   110
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   111
    @Test(dataProvider = "accessTestCaseProvider")
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   112
    public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   113
        T t = atc.get();
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   114
        int iters = atc.requiresLoop() ? ITERS : 1;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   115
        for (int c = 0; c < iters; c++) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   116
            atc.testAccess(t);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   117
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   118
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   119
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   120
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   121
    static void testInstanceField(VarHandleTestMethodHandleAccessByte recv, Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   122
        // Plain
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   123
        {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   124
            hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   125
            byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   126
            assertEquals(x, (byte)0x01, "set byte value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   127
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   128
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   129
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   130
        // Volatile
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   131
        {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   132
            hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, (byte)0x23);
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   133
            byte x = (byte) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   134
            assertEquals(x, (byte)0x23, "setVolatile byte value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   135
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   136
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   137
        // Lazy
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   138
        {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   139
            hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, (byte)0x01);
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   140
            byte x = (byte) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   141
            assertEquals(x, (byte)0x01, "setRelease byte value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   142
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   143
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   144
        // Opaque
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   145
        {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   146
            hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, (byte)0x23);
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   147
            byte x = (byte) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   148
            assertEquals(x, (byte)0x23, "setOpaque byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   149
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   150
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   151
        hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   152
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   153
        // Compare
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   154
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   155
            boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, (byte)0x01, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   156
            assertEquals(r, true, "success compareAndSet byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   157
            byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   158
            assertEquals(x, (byte)0x23, "success compareAndSet byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   159
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   160
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   161
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   162
            boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, (byte)0x01, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   163
            assertEquals(r, false, "failing compareAndSet byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   164
            byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   165
            assertEquals(x, (byte)0x23, "failing compareAndSet byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   166
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   167
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   168
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   169
            byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, (byte)0x23, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   170
            assertEquals(r, (byte)0x23, "success compareAndExchangeVolatile byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   171
            byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   172
            assertEquals(x, (byte)0x01, "success compareAndExchangeVolatile byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   173
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   174
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   175
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   176
            byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, (byte)0x23, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   177
            assertEquals(r, (byte)0x01, "failing compareAndExchangeVolatile byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   178
            byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   179
            assertEquals(x, (byte)0x01, "failing compareAndExchangeVolatile byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   180
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   181
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   182
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   183
            byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, (byte)0x01, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   184
            assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   185
            byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   186
            assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   187
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   188
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   189
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   190
            byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, (byte)0x01, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   191
            assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   192
            byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   193
            assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   194
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   195
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   196
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   197
            byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, (byte)0x23, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   198
            assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   199
            byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   200
            assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   201
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   202
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   203
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   204
            byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, (byte)0x23, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   205
            assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   206
            byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   207
            assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   208
        }
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   209
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   210
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   211
            boolean success = false;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   212
            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   213
                success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, (byte)0x01, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   214
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   215
            assertEquals(success, true, "weakCompareAndSet byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   216
            byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   217
            assertEquals(x, (byte)0x23, "weakCompareAndSet byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   218
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   219
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   220
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   221
            boolean success = false;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   222
            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   223
                success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, (byte)0x23, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   224
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   225
            assertEquals(success, true, "weakCompareAndSetAcquire byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   226
            byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   227
            assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   228
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   229
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   230
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   231
            boolean success = false;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   232
            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   233
                success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, (byte)0x01, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   234
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   235
            assertEquals(success, true, "weakCompareAndSetRelease byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   236
            byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   237
            assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   238
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   239
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   240
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   241
            boolean success = false;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   242
            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   243
                success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(recv, (byte)0x23, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   244
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   245
            assertEquals(success, true, "weakCompareAndSetVolatile byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   246
            byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   247
            assertEquals(x, (byte)0x01, "weakCompareAndSetVolatile byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   248
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   249
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   250
        // Compare set and get
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   251
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   252
            byte o = (byte) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   253
            assertEquals(o, (byte)0x01, "getAndSet byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   254
            byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   255
            assertEquals(x, (byte)0x23, "getAndSet byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   256
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   257
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   258
        hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   259
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   260
        // get and add, add and get
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   261
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   262
            byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   263
            assertEquals(o, (byte)0x01, "getAndAdd byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   264
            byte c = (byte) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(recv, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   265
            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
   266
        }
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   267
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   268
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   269
    static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessByte recv, Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   270
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   271
    }
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
    static void testStaticField(Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   275
        // Plain
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   276
        {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   277
            hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   278
            byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   279
            assertEquals(x, (byte)0x01, "set byte value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   280
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   281
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   282
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   283
        // Volatile
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   284
        {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   285
            hs.get(TestAccessMode.SET_VOLATILE).invokeExact((byte)0x23);
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   286
            byte x = (byte) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   287
            assertEquals(x, (byte)0x23, "setVolatile byte value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   288
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   289
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   290
        // Lazy
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   291
        {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   292
            hs.get(TestAccessMode.SET_RELEASE).invokeExact((byte)0x01);
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   293
            byte x = (byte) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   294
            assertEquals(x, (byte)0x01, "setRelease byte value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   295
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   296
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   297
        // Opaque
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   298
        {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   299
            hs.get(TestAccessMode.SET_OPAQUE).invokeExact((byte)0x23);
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   300
            byte x = (byte) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   301
            assertEquals(x, (byte)0x23, "setOpaque byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   302
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   303
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   304
        hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   305
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   306
        // Compare
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   307
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   308
            boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact((byte)0x01, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   309
            assertEquals(r, true, "success compareAndSet byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   310
            byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   311
            assertEquals(x, (byte)0x23, "success compareAndSet byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   312
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   313
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   314
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   315
            boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact((byte)0x01, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   316
            assertEquals(r, false, "failing compareAndSet byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   317
            byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   318
            assertEquals(x, (byte)0x23, "failing compareAndSet byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   319
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   320
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   321
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   322
            byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact((byte)0x23, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   323
            assertEquals(r, (byte)0x23, "success compareAndExchangeVolatile byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   324
            byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   325
            assertEquals(x, (byte)0x01, "success compareAndExchangeVolatile byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   326
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   327
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   328
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   329
            byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact((byte)0x23, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   330
            assertEquals(r, (byte)0x01, "failing compareAndExchangeVolatile byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   331
            byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   332
            assertEquals(x, (byte)0x01, "failing compareAndExchangeVolatile byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   333
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   334
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   335
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   336
            byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact((byte)0x01, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   337
            assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   338
            byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   339
            assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   340
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   341
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   342
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   343
            byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact((byte)0x01, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   344
            assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   345
            byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   346
            assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   347
        }
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
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   350
            byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact((byte)0x23, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   351
            assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   352
            byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   353
            assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   354
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   355
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   356
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   357
            byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact((byte)0x23, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   358
            assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   359
            byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   360
            assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   361
        }
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   362
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   363
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   364
            boolean success = false;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   365
            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   366
                success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact((byte)0x01, (byte)0x23);
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
            assertEquals(success, true, "weakCompareAndSet byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   369
            byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   370
            assertEquals(x, (byte)0x23, "weakCompareAndSet byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   371
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   372
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   373
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   374
            boolean success = false;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   375
            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   376
                success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact((byte)0x23, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   377
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   378
            assertEquals(success, true, "weakCompareAndSetAcquire byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   379
            byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   380
            assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte");
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
            boolean success = false;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   385
            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   386
                success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact((byte)0x01, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   387
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   388
            assertEquals(success, true, "weakCompareAndSetRelease byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   389
            byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   390
            assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   391
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   392
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   393
        {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   394
            boolean success = false;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   395
            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   396
                success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact((byte)0x23, (byte)0x01);
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
            assertEquals(success, true, "weakCompareAndSetVolatile byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   399
            byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   400
            assertEquals(x, (byte)0x01, "weakCompareAndSetVolatile byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   401
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   402
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   403
        // Compare set and get
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
            byte o = (byte) hs.get(TestAccessMode.GET_AND_SET).invokeExact( (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   406
            assertEquals(o, (byte)0x01, "getAndSet byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   407
            byte x = (byte) hs.get(TestAccessMode.GET).invokeExact();
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   408
            assertEquals(x, (byte)0x23, "getAndSet byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   409
        }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   410
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   411
        hs.get(TestAccessMode.SET).invokeExact((byte)0x01);
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
        // get and add, add and get
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
            byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD).invokeExact( (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   416
            assertEquals(o, (byte)0x01, "getAndAdd byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   417
            byte c = (byte) hs.get(TestAccessMode.ADD_AND_GET).invokeExact((byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   418
            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
   419
        }
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   420
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   421
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   422
    static void testStaticFieldUnsupported(Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   423
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   424
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   425
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   426
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   427
    static void testArray(Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   428
        byte[] array = new byte[10];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   429
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   430
        for (int i = 0; i < array.length; i++) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   431
            // Plain
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   432
            {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   433
                hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   434
                byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   435
                assertEquals(x, (byte)0x01, "get byte value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   436
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   437
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   438
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   439
            // Volatile
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   440
            {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   441
                hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, (byte)0x23);
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   442
                byte x = (byte) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   443
                assertEquals(x, (byte)0x23, "setVolatile byte value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   444
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   445
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   446
            // Lazy
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   447
            {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   448
                hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, (byte)0x01);
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   449
                byte x = (byte) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   450
                assertEquals(x, (byte)0x01, "setRelease byte value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   451
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   452
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   453
            // Opaque
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   454
            {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   455
                hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, (byte)0x23);
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   456
                byte x = (byte) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   457
                assertEquals(x, (byte)0x23, "setOpaque byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   458
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   459
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   460
            hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   461
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   462
            // Compare
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   463
            {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   464
                boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, (byte)0x01, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   465
                assertEquals(r, true, "success compareAndSet byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   466
                byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   467
                assertEquals(x, (byte)0x23, "success compareAndSet byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   468
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   469
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   470
            {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   471
                boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, (byte)0x01, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   472
                assertEquals(r, false, "failing compareAndSet byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   473
                byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   474
                assertEquals(x, (byte)0x23, "failing compareAndSet byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   475
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   476
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   477
            {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   478
                byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, (byte)0x23, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   479
                assertEquals(r, (byte)0x23, "success compareAndExchangeVolatile byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   480
                byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   481
                assertEquals(x, (byte)0x01, "success compareAndExchangeVolatile byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   482
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   483
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   484
            {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   485
                byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, (byte)0x23, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   486
                assertEquals(r, (byte)0x01, "failing compareAndExchangeVolatile byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   487
                byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   488
                assertEquals(x, (byte)0x01, "failing compareAndExchangeVolatile byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   489
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   490
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   491
            {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   492
                byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, (byte)0x01, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   493
                assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   494
                byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   495
                assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire 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
            {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   499
                byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, (byte)0x01, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   500
                assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   501
                byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   502
                assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   503
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   504
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   505
            {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   506
                byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, (byte)0x23, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   507
                assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   508
                byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   509
                assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value");
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   510
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   511
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   512
            {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   513
                byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, (byte)0x23, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   514
                assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   515
                byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   516
                assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   517
            }
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   518
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   519
            {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   520
                boolean success = false;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   521
                for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   522
                    success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, (byte)0x01, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   523
                }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   524
                assertEquals(success, true, "weakCompareAndSet byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   525
                byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   526
                assertEquals(x, (byte)0x23, "weakCompareAndSet 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
                boolean success = false;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   531
                for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   532
                    success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, (byte)0x23, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   533
                }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   534
                assertEquals(success, true, "weakCompareAndSetAcquire byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   535
                byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   536
                assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   537
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   538
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   539
            {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   540
                boolean success = false;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   541
                for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   542
                    success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, (byte)0x01, (byte)0x23);
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
                assertEquals(success, true, "weakCompareAndSetRelease byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   545
                byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   546
                assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   547
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   548
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   549
            {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   550
                boolean success = false;
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   551
                for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   552
                    success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(array, i, (byte)0x23, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   553
                }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   554
                assertEquals(success, true, "weakCompareAndSetVolatile byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   555
                byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   556
                assertEquals(x, (byte)0x01, "weakCompareAndSetVolatile byte");
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
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   559
            // Compare set and get
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   560
            {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   561
                byte o = (byte) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, (byte)0x23);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   562
                assertEquals(o, (byte)0x01, "getAndSet byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   563
                byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   564
                assertEquals(x, (byte)0x23, "getAndSet 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
            hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   568
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   569
            // get and add, add and get
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   570
            {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   571
                byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   572
                assertEquals(o, (byte)0x01, "getAndAdd byte");
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   573
                byte c = (byte) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(array, i, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   574
                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
   575
            }
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   576
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   577
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   578
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   579
    static void testArrayUnsupported(Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   580
        byte[] array = new byte[10];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   581
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   582
        final int i = 0;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   583
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   584
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   585
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   586
    static void testArrayIndexOutOfBounds(Handles hs) throws Throwable {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   587
        byte[] array = new byte[10];
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   588
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   589
        for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   590
            final int ci = i;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   591
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   592
            for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   593
                checkIOOBE(am, () -> {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   594
                    byte x = (byte) hs.get(am).invokeExact(array, ci);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   595
                });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   596
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   597
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36934
diff changeset
   598
            for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   599
                checkIOOBE(am, () -> {
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   600
                    hs.get(am).invokeExact(array, ci, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   601
                });
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   602
            }
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
            for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   605
                checkIOOBE(am, () -> {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   606
                    boolean r = (boolean) hs.get(am).invokeExact(array, ci, (byte)0x01, (byte)0x23);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   607
                });
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   608
            }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   609
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   610
            for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   611
                checkIOOBE(am, () -> {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   612
                    byte r = (byte) hs.get(am).invokeExact(array, ci, (byte)0x23, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   613
                });
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   614
            }
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   615
39470
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   616
            for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   617
                checkIOOBE(am, () -> {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   618
                    byte o = (byte) hs.get(am).invokeExact(array, ci, (byte)0x01);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   619
                });
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   620
            }
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   621
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   622
            for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   623
                checkIOOBE(am, () -> {
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   624
                    byte o = (byte) hs.get(am).invokeExact(array, ci, (byte)0x45);
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   625
                });
d6f8b4a85fb0 8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents: 38429
diff changeset
   626
            }
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   627
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   628
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   629
}
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents:
diff changeset
   630