test/hotspot/jtreg/compiler/c1/VolatileGuardTest.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 44091 hotspot/test/compiler/c1/VolatileGuardTest.java@dcca5d534437
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
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
/**
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    25
 * @test
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    26
 * @bug 8175887
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    27
 * @summary C1 doesn't respect the JMM with volatile field loads
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    28
 *
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    29
 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:TieredStopAtLevel=1 VolatileGuardTest
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    30
 */
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    31
public class VolatileGuardTest {
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    32
    volatile static private int a;
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    33
    static private int b;
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    34
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    35
    static void test() {
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    36
        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
    37
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    38
        while (a == 0) {} // burn
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    39
        if (b == 0) {
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    40
            System.err.println("wrong value of b");
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    41
            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
    42
        }
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    43
    }
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    44
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    45
    public static void main(String [] args) throws Exception {
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    46
        for (int i = 0; i < 10; i++) {
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    47
            new Thread(VolatileGuardTest::test).start();
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    48
        }
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    49
        b = 1;
dcca5d534437 8175887: C1 value numbering handling of Unsafe.get*Volatile is incorrect
shade
parents:
diff changeset
    50
        a = 1;
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
}