test/hotspot/jtreg/compiler/c2/aarch64/TestUnsafeVolatileLoad.java
author mchung
Mon, 22 Oct 2018 17:00:04 -0700
changeset 52220 9c260a6b6471
parent 50874 551c340ca01a
permissions -rw-r--r--
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference Reviewed-by: dholmes, thartmann
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
package compiler.c2.aarch64;
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
     2
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
     3
import java.lang.reflect.Field;
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
     4
import jdk.internal.misc.Unsafe;
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
     5
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
     6
class TestUnsafeVolatileLoad
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
     7
{
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
     8
    public volatile int f_int = 0;
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
     9
    public volatile Integer f_obj = Integer.valueOf(0);
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    10
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    11
    public static Unsafe unsafe = Unsafe.getUnsafe();
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    12
    public static Field f_int_field;
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    13
    public static Field f_obj_field;
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    14
    public static long f_int_off;
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    15
    public static long f_obj_off;
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    16
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    17
    static {
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    18
        try {
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    19
            f_int_field = TestUnsafeVolatileLoad.class.getField("f_int");
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    20
            f_obj_field = TestUnsafeVolatileLoad.class.getField("f_obj");
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    21
            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
    22
            f_obj_off = unsafe.objectFieldOffset(f_obj_field);
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    23
        } catch (Exception e) {
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    24
            System.out.println("reflection failed " + e);
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    25
            e.printStackTrace();
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    26
        }
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    27
    }
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
    public static void main(String[] args)
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
        final TestUnsafeVolatileLoad t = new TestUnsafeVolatileLoad();
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    32
        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
    33
            t.f_int = i;
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    34
            int r = t.testInt();
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    35
            if (r != i) {
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    36
                throw new RuntimeException("bad result!");
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    37
            }
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    38
        }
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    39
        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
    40
            t.f_obj = Integer.valueOf(i);
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    41
            int r = t.testObj();
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    42
            if (r != i) {
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    43
                throw new RuntimeException("bad result!");
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    44
            }
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    45
        }
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    46
    }
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    47
    public int testInt()
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
        return unsafe.getIntVolatile(this, f_int_off);
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    50
    }
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    51
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    52
    public int testObj()
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    53
    {
52220
9c260a6b6471 8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents: 50874
diff changeset
    54
        return ((Integer)unsafe.getReferenceVolatile(this, f_obj_off));
50874
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    55
    }
551c340ca01a 8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff changeset
    56
}