hotspot/test/compiler/membars/DekkerTest.java
author kvn
Fri, 12 Jul 2013 14:03:10 -0700
changeset 18956 f8fc5dd18a1d
child 23199 239afef157c6
permissions -rw-r--r--
8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier() Summary: generate one "fat" membar instead of set of barriers for volitile store Reviewed-by: roland
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
/*
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
     2
 * Copyright 2013 SAP AG.  All Rights Reserved.
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().
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    28
 * @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:CICompilerCount=1 -XX:+StressGCM -XX:+StressLCM DekkerTest
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    29
 * @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:CICompilerCount=1 -XX:+StressGCM -XX:+StressLCM DekkerTest
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    30
 * @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:CICompilerCount=1 -XX:+StressGCM -XX:+StressLCM DekkerTest
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    31
 * @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
    32
 *
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    33
 * 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
    34
 */
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    35
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    36
public class DekkerTest {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    37
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
      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
    40
      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
    41
        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
    42
        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
    43
     */
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    44
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    45
    static final int ITERATIONS = 1000000;
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
    static class TestData {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    48
        public volatile int a;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    49
        public volatile int b;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    50
    }
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
    static class ResultData {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    53
        public int a;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    54
        public int b;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    55
    }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    56
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    57
    TestData[]   testDataArray;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    58
    ResultData[] results;
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
    volatile boolean start;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    61
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    62
    public DekkerTest() {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    63
        testDataArray = new TestData[ITERATIONS];
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    64
        results = new ResultData[ITERATIONS];
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    65
        for (int i = 0; i < ITERATIONS; ++i) {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    66
            testDataArray[i] = new TestData();
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    67
            results[i] = new ResultData();
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    68
        }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    69
        start = false;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    70
    }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    71
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    72
    public void reset() {
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].a = 0;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    75
            testDataArray[i].b = 0;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    76
            results[i].a = 0;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    77
            results[i].b = 0;
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
        start = false;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    80
    }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    81
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    82
    int actor1(TestData t) {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    83
        t.a = 1;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    84
        return t.b;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    85
    }
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
    int actor2(TestData t) {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    88
        t.b = 1;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    89
        return t.a;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    90
    }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    91
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    92
    class Runner1 extends Thread {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    93
        public void run() {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    94
            do {} while (!start);
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    95
            for (int i = 0; i < ITERATIONS; ++i) {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    96
                results[i].a = actor1(testDataArray[i]);
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
    97
            }
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
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   101
    class Runner2 extends Thread {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   102
        public void run() {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   103
            do {} while (!start);
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   104
            for (int i = 0; i < ITERATIONS; ++i) {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   105
                results[i].b = actor2(testDataArray[i]);
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
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   110
    void testRunner() {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   111
        Thread thread1 = new Runner1();
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   112
        Thread thread2 = new Runner2();
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   113
        thread1.start();
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   114
        thread2.start();
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   115
        do {} while (!thread1.isAlive());
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   116
        do {} while (!thread2.isAlive());
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   117
        start = true;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   118
        Thread.yield();
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   119
        try {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   120
            thread1.join();
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   121
            thread2.join();
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   122
        } catch (InterruptedException e) {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   123
            System.out.println("interrupted!");
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   124
            System.exit(1);
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   125
        }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   126
    }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   127
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   128
    boolean printResult() {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   129
        int[] count = new int[4];
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   130
        for (int i = 0; i < ITERATIONS; ++i) {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   131
            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
   132
            ++count[event_kind];
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
        if (count[0] == 0 && count[3] == 0) {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   135
            System.out.println("[not interesting]");
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   136
            return false; // not interesting
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   137
        }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   138
        String error = (count[0] == 0) ? " ok" : " disallowed!";
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   139
        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
   140
        System.out.println("[0,1] " + count[1]);
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   141
        System.out.println("[1,0] " + count[2]);
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   142
        System.out.println("[1,1] " + count[3]);
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   143
        return (count[0] != 0);
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   144
    }
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
    public static void main(String args[]) {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   147
        DekkerTest test = new DekkerTest();
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   148
        final int runs = 30;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   149
        int failed = 0;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   150
        for (int c = 0; c < runs; ++c) {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   151
            test.testRunner();
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   152
            if (test.printResult()) {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   153
                failed++;
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   154
            }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   155
            test.reset();
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   156
        }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   157
        if (failed > 0) {
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   158
            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
   159
        }
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   160
        System.out.println("PASSED.");
f8fc5dd18a1d 8007898: Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier()
kvn
parents:
diff changeset
   161
    }
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
}