hotspot/test/compiler/c1/UnsafeVolatileGuardTest.java
author thartmann
Fri, 14 Jul 2017 11:55:58 +0200
changeset 46663 715d5f268f62
parent 44091 dcca5d534437
permissions -rw-r--r--
8184271: Time related C1 intrinsics produce inconsistent results when floating around Summary: C1 intrinsics for System.nanoTime(), System.currentTimeMillis() and JVM.counterTime() should be pinned. Reviewed-by: kvn, vlivanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44091
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
     1
/*
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
     2
 * Copyright (c) 2017, Red Hat Inc. All rights reserved.
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
     4
 *
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
     7
 * published by the Free Software Foundation.
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
     8
 *
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    13
 * accompanied this code).
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    14
 *
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    18
 *
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    21
 * questions.
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    22
 */
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    23
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    24
import java.lang.reflect.Field;
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    25
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    26
/**
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    27
 * @test
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    28
 * @bug 8175887
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    29
 * @summary C1 value numbering handling of Unsafe.get*Volatile is incorrect
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    30
 * @modules java.base/jdk.internal.misc
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    31
 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:TieredStopAtLevel=1 UnsafeVolatileGuardTest
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    32
 */
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    33
public class UnsafeVolatileGuardTest {
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    34
    volatile static private int a;
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    35
    static private int b;
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    36
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    37
    static final jdk.internal.misc.Unsafe UNSAFE = jdk.internal.misc.Unsafe.getUnsafe();
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    38
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    39
    static final Object BASE;
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    40
    static final long OFFSET;
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    41
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    42
    static {
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    43
        try {
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    44
            Field f = UnsafeVolatileGuardTest.class.getDeclaredField("a");
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    45
            BASE = UNSAFE.staticFieldBase(f);
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    46
            OFFSET = UNSAFE.staticFieldOffset(f);
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    47
        } catch (Exception e) {
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    48
            throw new RuntimeException(e);
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    49
        }
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    50
    }
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    51
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    52
    static void test() {
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    53
        int tt = b; // makes the JVM CSE the value of b
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    54
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    55
        while (UNSAFE.getIntVolatile(BASE, OFFSET) == 0) {} // burn
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    56
        if (b == 0) {
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    57
            System.err.println("wrong value of b");
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    58
            System.exit(1); // fail hard to report the error
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    59
        }
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    60
    }
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    61
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    62
    public static void main(String [] args) throws Exception {
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    63
        for (int i = 0; i < 10; i++) {
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    64
            new Thread(UnsafeVolatileGuardTest::test).start();
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    65
        }
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    66
        b = 1;
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    67
        a = 1;
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    68
    }
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    69
}