test/hotspot/jtreg/compiler/membars/DekkerTest.java
author iignatyev
Mon, 18 Feb 2019 09:31:07 -0800
changeset 53791 bec6c8739833
parent 47216 71c04702a3d5
permissions -rw-r--r--
8219157: vm/mlvm/mixed/stress/java/findDeadlock should be problem-listed only on mac Reviewed-by: thartmann
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18956
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
     1
/*
35594
cc13089c6327 8147937: Adapt SAP copyrights to new company name.
goetz
parents: 33616
diff changeset
     2
 * Copyright (c) 2013 SAP SE. All rights reserved.
18956
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
     4
 *
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
     8
 *
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    13
 * accompanied this code).
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    14
 *
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    18
 *
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    21
 * questions.
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    22
 */
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    23
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    24
/**
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    25
 * @test
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    26
 * @bug 8007898
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    27
 * @summary Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier().
40062
3b21b3295f19 8160761: [TESTBUG] Several compiler tests fail with product bits
ppunegov
parents: 40059
diff changeset
    28
 * @run main/othervm -Xbatch -XX:+UnlockDiagnosticVMOptions -XX:+IgnoreUnrecognizedVMOptions
3b21b3295f19 8160761: [TESTBUG] Several compiler tests fail with product bits
ppunegov
parents: 40059
diff changeset
    29
 *      -XX:-TieredCompilation -XX:CICompilerCount=1 -XX:+StressGCM -XX:+StressLCM
3b21b3295f19 8160761: [TESTBUG] Several compiler tests fail with product bits
ppunegov
parents: 40059
diff changeset
    30
 *      compiler.membars.DekkerTest
3b21b3295f19 8160761: [TESTBUG] Several compiler tests fail with product bits
ppunegov
parents: 40059
diff changeset
    31
 * @run main/othervm -Xbatch -XX:+UnlockDiagnosticVMOptions -XX:+IgnoreUnrecognizedVMOptions
3b21b3295f19 8160761: [TESTBUG] Several compiler tests fail with product bits
ppunegov
parents: 40059
diff changeset
    32
 *      -XX:-TieredCompilation -XX:CICompilerCount=1 -XX:+StressGCM -XX:+StressLCM
3b21b3295f19 8160761: [TESTBUG] Several compiler tests fail with product bits
ppunegov
parents: 40059
diff changeset
    33
 *      compiler.membars.DekkerTest
3b21b3295f19 8160761: [TESTBUG] Several compiler tests fail with product bits
ppunegov
parents: 40059
diff changeset
    34
 * @run main/othervm -Xbatch -XX:+UnlockDiagnosticVMOptions -XX:+IgnoreUnrecognizedVMOptions
3b21b3295f19 8160761: [TESTBUG] Several compiler tests fail with product bits
ppunegov
parents: 40059
diff changeset
    35
 *      -XX:-TieredCompilation -XX:CICompilerCount=1 -XX:+StressGCM -XX:+StressLCM
3b21b3295f19 8160761: [TESTBUG] Several compiler tests fail with product bits
ppunegov
parents: 40059
diff changeset
    36
 *      compiler.membars.DekkerTest
18956
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    37
 * @author Martin Doerr martin DOT doerr AT sap DOT com
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    38
 *
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    39
 * Run 3 times since the failure is intermittent.
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    40
 */
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    41
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35594
diff changeset
    42
package compiler.membars;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 35594
diff changeset
    43
18956
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    44
public class DekkerTest {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    45
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    46
    /*
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    47
      Read After Write Test (basically a simple Dekker test with volatile variables)
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    48
      Derived from the original jcstress test, available at:
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    49
        http://hg.openjdk.java.net/code-tools/jcstress/file/6c339a5aa00d/
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    50
        tests-custom/src/main/java/org/openjdk/jcstress/tests/volatiles/DekkerTest.java
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    51
     */
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    52
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    53
    static final int ITERATIONS = 1000000;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    54
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    55
    static class TestData {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    56
        public volatile int a;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    57
        public volatile int b;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    58
    }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    59
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    60
    static class ResultData {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    61
        public int a;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    62
        public int b;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    63
    }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    64
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    65
    TestData[]   testDataArray;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    66
    ResultData[] results;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    67
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    68
    volatile boolean start;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    69
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    70
    public DekkerTest() {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    71
        testDataArray = new TestData[ITERATIONS];
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    72
        results = new ResultData[ITERATIONS];
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    73
        for (int i = 0; i < ITERATIONS; ++i) {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    74
            testDataArray[i] = new TestData();
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    75
            results[i] = new ResultData();
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    76
        }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    77
        start = false;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    78
    }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    79
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    80
    public void reset() {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    81
        for (int i = 0; i < ITERATIONS; ++i) {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    82
            testDataArray[i].a = 0;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    83
            testDataArray[i].b = 0;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    84
            results[i].a = 0;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    85
            results[i].b = 0;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    86
        }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    87
        start = false;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    88
    }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    89
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    90
    int actor1(TestData t) {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    91
        t.a = 1;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    92
        return t.b;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    93
    }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    94
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    95
    int actor2(TestData t) {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    96
        t.b = 1;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    97
        return t.a;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    98
    }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    99
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   100
    class Runner1 extends Thread {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   101
        public void run() {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   102
            do {} while (!start);
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   103
            for (int i = 0; i < ITERATIONS; ++i) {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   104
                results[i].a = actor1(testDataArray[i]);
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   105
            }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   106
        }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   107
    }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   108
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   109
    class Runner2 extends Thread {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   110
        public void run() {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   111
            do {} while (!start);
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   112
            for (int i = 0; i < ITERATIONS; ++i) {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   113
                results[i].b = actor2(testDataArray[i]);
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   114
            }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   115
        }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   116
    }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   117
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   118
    void testRunner() {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   119
        Thread thread1 = new Runner1();
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   120
        Thread thread2 = new Runner2();
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   121
        thread1.start();
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   122
        thread2.start();
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   123
        do {} while (!thread1.isAlive());
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   124
        do {} while (!thread2.isAlive());
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   125
        start = true;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   126
        Thread.yield();
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   127
        try {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   128
            thread1.join();
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   129
            thread2.join();
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   130
        } catch (InterruptedException e) {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   131
            System.out.println("interrupted!");
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   132
            System.exit(1);
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   133
        }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   134
    }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   135
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   136
    boolean printResult() {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   137
        int[] count = new int[4];
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   138
        for (int i = 0; i < ITERATIONS; ++i) {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   139
            int event_kind = (results[i].a << 1) + results[i].b;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   140
            ++count[event_kind];
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   141
        }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   142
        if (count[0] == 0 && count[3] == 0) {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   143
            System.out.println("[not interesting]");
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   144
            return false; // not interesting
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   145
        }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   146
        String error = (count[0] == 0) ? " ok" : " disallowed!";
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   147
        System.out.println("[0,0] " + count[0] + error);
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   148
        System.out.println("[0,1] " + count[1]);
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   149
        System.out.println("[1,0] " + count[2]);
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   150
        System.out.println("[1,1] " + count[3]);
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   151
        return (count[0] != 0);
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   152
    }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   153
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   154
    public static void main(String args[]) {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   155
        DekkerTest test = new DekkerTest();
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   156
        final int runs = 30;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   157
        int failed = 0;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   158
        for (int c = 0; c < runs; ++c) {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   159
            test.testRunner();
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   160
            if (test.printResult()) {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   161
                failed++;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   162
            }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   163
            test.reset();
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   164
        }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   165
        if (failed > 0) {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   166
            throw new InternalError("FAILED. Got " + failed + " failed ITERATIONS");
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   167
        }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   168
        System.out.println("PASSED.");
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   169
    }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   170
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   171
}