test/hotspot/jtreg/compiler/c2/aarch64/TestUnsafeVolatileCAS.java
author adinn
Fri, 29 Nov 2019 15:37:13 +0000
changeset 59326 851a389fc54d
parent 52409 87bc444ca642
permissions -rw-r--r--
8232828: AArch64: compiler/c2/aarch64/TestVolatilesG1.java fails after JDK-8225776 Reviewed-by: aph
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50874
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
     1
/*
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
     2
 * Copyright (c) 2018, Red Hat, Inc. All rights reserved.
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
     4
 *
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
     8
 *
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    13
 * accompanied this code).
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    14
 *
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    18
 *
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    21
 * questions.
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    22
 */
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    23
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    24
package compiler.c2.aarch64;
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    25
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    26
import java.lang.reflect.Field;
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    27
import jdk.internal.misc.Unsafe;
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    28
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    29
class TestUnsafeVolatileCAS
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    30
{
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    31
    public volatile int f_int = 0;
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    32
    public volatile Integer f_obj = Integer.valueOf(0);
52409
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    33
    public volatile long f_long = 0;
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    34
    public volatile byte f_byte = 0;
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    35
    public volatile short f_short = 0;
50874
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    36
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    37
    public static Unsafe unsafe = Unsafe.getUnsafe();
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    38
    public static Field f_int_field;
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    39
    public static Field f_obj_field;
52409
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    40
    public static Field f_long_field;
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    41
    public static Field f_byte_field;
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    42
    public static Field f_short_field;
50874
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    43
    public static long f_int_off;
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    44
    public static long f_obj_off;
52409
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    45
    public static long f_long_off;
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    46
    public static long f_byte_off;
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    47
    public static long f_short_off;
50874
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    48
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    49
    static {
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    50
        try {
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    51
            f_int_field = TestUnsafeVolatileCAS.class.getField("f_int");
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    52
            f_obj_field = TestUnsafeVolatileCAS.class.getField("f_obj");
52409
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    53
            f_long_field = TestUnsafeVolatileCAS.class.getField("f_long");
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    54
            f_byte_field = TestUnsafeVolatileCAS.class.getField("f_byte");
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    55
            f_short_field = TestUnsafeVolatileCAS.class.getField("f_short");
50874
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    56
            f_int_off = unsafe.objectFieldOffset(f_int_field);
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    57
            f_obj_off = unsafe.objectFieldOffset(f_obj_field);
52409
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    58
            f_long_off = unsafe.objectFieldOffset(f_long_field);
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    59
            f_byte_off = unsafe.objectFieldOffset(f_byte_field);
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    60
            f_short_off = unsafe.objectFieldOffset(f_short_field);
50874
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    61
        } catch (Exception e) {
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    62
            System.out.println("reflection failed " + e);
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    63
            e.printStackTrace();
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    64
        }
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    65
    }
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    66
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    67
    public static void main(String[] args)
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    68
    {
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    69
        final TestUnsafeVolatileCAS t = new TestUnsafeVolatileCAS();
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    70
        for (int i = 0; i < 100_000; i++) {
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    71
            t.f_int = -1;
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    72
            t.testInt(-1, i);
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    73
            if (t.f_int != i) {
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    74
                throw new RuntimeException("bad result!");
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    75
            }
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    76
        }
52409
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    77
        for (int i = 0; i < 100_000; i++) {
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    78
            t.f_long = -1;
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    79
            t.testLong(-1, i);
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    80
            if (t.f_long != i) {
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    81
                throw new RuntimeException("bad result!");
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    82
            }
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    83
        }
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    84
        for (int i = 0; i < 100_000; i++) {
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    85
            t.f_byte = -1;
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    86
            byte i_b = (byte)i;
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    87
            t.testByte((byte)-1, i_b);
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    88
            if (t.f_byte != i_b) {
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    89
                throw new RuntimeException("bad result!");
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    90
            }
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    91
        }
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    92
        for (int i = 0; i < 100_000; i++) {
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    93
            t.f_short = -1;
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    94
            short i_s = (short)i;
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    95
            t.testShort((byte)-1, i_s);
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    96
            if (t.f_short != i_s) {
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    97
                throw new RuntimeException("bad result!");
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    98
            }
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
    99
        }
50874
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
   100
        Integer minusOne = Integer.valueOf(-1);
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
   101
        for (int i = 0; i < 100_000; i++) {
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
   102
            t.f_obj = minusOne;
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
   103
            t.testObj(minusOne, Integer.valueOf(i));
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
   104
            if (t.f_obj != i) {
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
   105
                throw new RuntimeException("bad result!");
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
   106
            }
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
   107
        }
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
   108
    }
52409
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
   109
50874
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
   110
    public void testInt(int x, int i)
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
   111
    {
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
   112
        unsafe.compareAndSetInt(this, f_int_off, x, i);
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
   113
    }
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
   114
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
   115
    public void testObj(Object x, Object o)
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
   116
    {
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 50874
diff changeset
   117
        unsafe.compareAndSetReference(this, f_obj_off, x, o);
50874
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
   118
    }
52409
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
   119
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
   120
    public void testLong(long x, long i)
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
   121
    {
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
   122
        unsafe.compareAndSetLong(this, f_long_off, x, i);
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
   123
    }
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
   124
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
   125
    public void testByte(byte x, byte i)
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
   126
    {
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
   127
        unsafe.compareAndSetByte(this, f_byte_off, x, i);
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
   128
    }
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
   129
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
   130
    public void testShort(short x, short i)
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
   131
    {
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
   132
        unsafe.compareAndSetShort(this, f_short_off, x, i);
87bc444ca642 8209835: Aarch64: elide barriers on all volatile operations
roland
parents: 52220
diff changeset
   133
    }
50874
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
   134
}