test/compiler/membars/DekkerTest.java

Wed, 05 Mar 2014 10:20:30 +0100

author
anoll
date
Wed, 05 Mar 2014 10:20:30 +0100
changeset 7308
e8225dc7c94b
parent 0
f90c822e73f8
permissions
-rw-r--r--

8036091: compiler/membars/DekkerTest.java fails with -XX:CICompilerCount=1
Summary: Start test with -XX:-TieredCompilation so that one compiler thread works
Reviewed-by: kvn, twisti

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

mercurial