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