-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathJava_Coherence.java
More file actions
224 lines (204 loc) · 13.1 KB
/
Java_Coherence.java
File metadata and controls
224 lines (204 loc) · 13.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
package io.github.lantalex.mm;
import org.openjdk.jcstress.annotations.Actor;
import org.openjdk.jcstress.annotations.JCStressTest;
import org.openjdk.jcstress.annotations.Outcome;
import org.openjdk.jcstress.annotations.State;
import org.openjdk.jcstress.infra.results.IIII_Result;
import static org.openjdk.jcstress.annotations.Expect.*;
@JCStressTest
@Outcome(expect = ACCEPTABLE, desc = "Expected boring case")
@Outcome(id = "1, 2, 2, 1", expect = ACCEPTABLE_INTERESTING, desc = "Violation of coherence")
@Outcome(id = "2, 1, 1, 2", expect = ACCEPTABLE_INTERESTING, desc = "Violation of coherence")
@State
public class Java_Coherence {
/*
Trick with variable aliases and trap was stolen from: https://github.com/openjdk/jcstress/blob/master/jcstress-samples/src/main/java/org/openjdk/jcstress/samples/jmm/basic/BasicJMM_05_Coherence.java
How to run:
$ ./gradlew jcstress --tests "Java_Coherence"
Results(x86):
----------------------------------------------------------------
RESULT SAMPLES FREQ EXPECT DESCRIPTION
0, 0, 0, 0 125,759,771 12.94% Acceptable Expected boring case
0, 0, 0, 1 61,805 <0.01% Acceptable Expected boring case
0, 0, 0, 2 59,873 <0.01% Acceptable Expected boring case
0, 0, 1, 0 59,929 <0.01% Acceptable Expected boring case
0, 0, 1, 1 109,156,191 11.23% Acceptable Expected boring case
0, 0, 1, 2 122,097 0.01% Acceptable Expected boring case
0, 0, 2, 0 58,895 <0.01% Acceptable Expected boring case
0, 0, 2, 1 117,118 0.01% Acceptable Expected boring case
0, 0, 2, 2 107,081,883 11.01% Acceptable Expected boring case
0, 1, 0, 0 111,201 0.01% Acceptable Expected boring case
0, 1, 0, 1 120 <0.01% Acceptable Expected boring case
0, 1, 0, 2 19 <0.01% Acceptable Expected boring case
0, 1, 1, 0 292 <0.01% Acceptable Expected boring case
0, 1, 1, 1 32,608 <0.01% Acceptable Expected boring case
0, 1, 1, 2 105 <0.01% Acceptable Expected boring case
0, 1, 2, 0 58 <0.01% Acceptable Expected boring case
0, 1, 2, 1 193 <0.01% Acceptable Expected boring case
0, 1, 2, 2 56,442 <0.01% Acceptable Expected boring case
0, 2, 0, 0 108,554 0.01% Acceptable Expected boring case
0, 2, 0, 1 32 <0.01% Acceptable Expected boring case
0, 2, 0, 2 111 <0.01% Acceptable Expected boring case
0, 2, 1, 0 61 <0.01% Acceptable Expected boring case
0, 2, 1, 1 53,846 <0.01% Acceptable Expected boring case
0, 2, 1, 2 202 <0.01% Acceptable Expected boring case
0, 2, 2, 0 276 <0.01% Acceptable Expected boring case
0, 2, 2, 1 105 <0.01% Acceptable Expected boring case
0, 2, 2, 2 30,872 <0.01% Acceptable Expected boring case
1, 0, 0, 0 40,926 <0.01% Acceptable Expected boring case
1, 0, 0, 1 110 <0.01% Acceptable Expected boring case
1, 0, 0, 2 8 <0.01% Acceptable Expected boring case
1, 0, 1, 1 17,506 <0.01% Acceptable Expected boring case
1, 0, 1, 2 62 <0.01% Acceptable Expected boring case
1, 0, 2, 1 6 <0.01% Acceptable Expected boring case
1, 0, 2, 2 28,506 <0.01% Acceptable Expected boring case
1, 1, 0, 0 88,441,435 9.10% Acceptable Expected boring case
1, 1, 0, 1 23,895 <0.01% Acceptable Expected boring case
1, 1, 0, 2 30,825 <0.01% Acceptable Expected boring case
1, 1, 1, 0 20,717 <0.01% Acceptable Expected boring case
1, 1, 1, 1 148,969,113 15.32% Acceptable Expected boring case
1, 1, 1, 2 80,521 <0.01% Acceptable Expected boring case
1, 1, 2, 0 33,481 <0.01% Acceptable Expected boring case
1, 1, 2, 1 76,364 <0.01% Acceptable Expected boring case
1, 1, 2, 2 76,205,555 7.84% Acceptable Expected boring case
1, 2, 0, 0 126,582 0.01% Acceptable Expected boring case
1, 2, 0, 1 74 <0.01% Acceptable Expected boring case
1, 2, 0, 2 88 <0.01% Acceptable Expected boring case
1, 2, 1, 0 258 <0.01% Acceptable Expected boring case
1, 2, 1, 1 90,997 <0.01% Acceptable Expected boring case
1, 2, 1, 2 618 <0.01% Acceptable Expected boring case
1, 2, 2, 0 18 <0.01% Acceptable Expected boring case
----> 1, 2, 2, 1 1,931 <0.01% Interesting Violation of coherence
1, 2, 2, 2 91,294 <0.01% Acceptable Expected boring case
2, 0, 0, 0 40,386 <0.01% Acceptable Expected boring case
2, 0, 0, 1 19 <0.01% Acceptable Expected boring case
2, 0, 0, 2 128 <0.01% Acceptable Expected boring case
2, 0, 1, 1 28,512 <0.01% Acceptable Expected boring case
2, 0, 1, 2 9 <0.01% Acceptable Expected boring case
2, 0, 2, 1 62 <0.01% Acceptable Expected boring case
2, 0, 2, 2 16,473 <0.01% Acceptable Expected boring case
2, 1, 0, 0 127,564 0.01% Acceptable Expected boring case
2, 1, 0, 1 96 <0.01% Acceptable Expected boring case
2, 1, 0, 2 71 <0.01% Acceptable Expected boring case
2, 1, 1, 0 26 <0.01% Acceptable Expected boring case
2, 1, 1, 1 88,662 <0.01% Acceptable Expected boring case
----> 2, 1, 1, 2 1,818 <0.01% Interesting Violation of coherence
2, 1, 2, 0 219 <0.01% Acceptable Expected boring case
2, 1, 2, 1 550 <0.01% Acceptable Expected boring case
2, 1, 2, 2 88,678 <0.01% Acceptable Expected boring case
2, 2, 0, 0 85,848,997 8.83% Acceptable Expected boring case
2, 2, 0, 1 30,653 <0.01% Acceptable Expected boring case
2, 2, 0, 2 22,716 <0.01% Acceptable Expected boring case
2, 2, 1, 0 33,590 <0.01% Acceptable Expected boring case
2, 2, 1, 1 75,234,175 7.74% Acceptable Expected boring case
2, 2, 1, 2 75,607 <0.01% Acceptable Expected boring case
2, 2, 2, 0 19,863 <0.01% Acceptable Expected boring case
2, 2, 2, 1 81,702 <0.01% Acceptable Expected boring case
2, 2, 2, 2 153,275,243 15.77% Acceptable Expected boring case
Results(arm_v8):
----------------------------------------------------------------
RESULT SAMPLES FREQ EXPECT DESCRIPTION
0, 0, 0, 0 79,541 0.16% Acceptable Expected boring case
0, 0, 0, 1 19 <0.01% Acceptable Expected boring case
0, 0, 0, 2 20 <0.01% Acceptable Expected boring case
0, 0, 1, 0 773 <0.01% Acceptable Expected boring case
0, 0, 1, 1 47,437 0.09% Acceptable Expected boring case
0, 0, 1, 2 101 <0.01% Acceptable Expected boring case
0, 0, 2, 0 797 <0.01% Acceptable Expected boring case
0, 0, 2, 1 43 <0.01% Acceptable Expected boring case
0, 0, 2, 2 43,054 0.08% Acceptable Expected boring case
0, 1, 0, 0 445 <0.01% Acceptable Expected boring case
0, 1, 1, 0 50 <0.01% Acceptable Expected boring case
0, 1, 1, 1 965 <0.01% Acceptable Expected boring case
0, 1, 1, 2 6 <0.01% Acceptable Expected boring case
0, 1, 2, 0 31 <0.01% Acceptable Expected boring case
0, 1, 2, 1 3 <0.01% Acceptable Expected boring case
0, 1, 2, 2 513 <0.01% Acceptable Expected boring case
0, 2, 0, 0 337 <0.01% Acceptable Expected boring case
0, 2, 1, 0 20 <0.01% Acceptable Expected boring case
0, 2, 1, 1 566 <0.01% Acceptable Expected boring case
0, 2, 1, 2 6 <0.01% Acceptable Expected boring case
0, 2, 2, 0 50 <0.01% Acceptable Expected boring case
0, 2, 2, 1 1 <0.01% Acceptable Expected boring case
0, 2, 2, 2 827 <0.01% Acceptable Expected boring case
1, 0, 0, 0 194 <0.01% Acceptable Expected boring case
1, 0, 1, 0 6 <0.01% Acceptable Expected boring case
1, 0, 1, 1 329 <0.01% Acceptable Expected boring case
1, 0, 2, 0 7 <0.01% Acceptable Expected boring case
1, 0, 2, 2 159 <0.01% Acceptable Expected boring case
1, 1, 0, 0 46,630 0.09% Acceptable Expected boring case
1, 1, 0, 1 95 <0.01% Acceptable Expected boring case
1, 1, 0, 2 75 <0.01% Acceptable Expected boring case
1, 1, 1, 0 1,467 <0.01% Acceptable Expected boring case
1, 1, 1, 1 27,864,246 54.89% Acceptable Expected boring case
1, 1, 1, 2 700 <0.01% Acceptable Expected boring case
1, 1, 2, 0 842 <0.01% Acceptable Expected boring case
1, 1, 2, 1 345 <0.01% Acceptable Expected boring case
1, 1, 2, 2 134,663 0.27% Acceptable Expected boring case
1, 2, 0, 0 33 <0.01% Acceptable Expected boring case
1, 2, 0, 2 1 <0.01% Acceptable Expected boring case
1, 2, 1, 0 4 <0.01% Acceptable Expected boring case
1, 2, 1, 1 98 <0.01% Acceptable Expected boring case
1, 2, 1, 2 3 <0.01% Acceptable Expected boring case
1, 2, 2, 0 3 <0.01% Acceptable Expected boring case
----> 1, 2, 2, 1 9 <0.01% Interesting Violation of coherence
1, 2, 2, 2 167 <0.01% Acceptable Expected boring case
2, 0, 0, 0 158 <0.01% Acceptable Expected boring case
2, 0, 0, 1 1 <0.01% Acceptable Expected boring case
2, 0, 0, 2 1 <0.01% Acceptable Expected boring case
2, 0, 1, 0 1 <0.01% Acceptable Expected boring case
2, 0, 1, 1 163 <0.01% Acceptable Expected boring case
2, 0, 2, 0 8 <0.01% Acceptable Expected boring case
2, 0, 2, 1 1 <0.01% Acceptable Expected boring case
2, 0, 2, 2 272 <0.01% Acceptable Expected boring case
2, 1, 0, 0 29 <0.01% Acceptable Expected boring case
2, 1, 0, 2 2 <0.01% Acceptable Expected boring case
2, 1, 1, 0 1 <0.01% Acceptable Expected boring case
2, 1, 1, 1 202 <0.01% Acceptable Expected boring case
----> 2, 1, 1, 2 11 <0.01% Interesting Violation of coherence
2, 1, 2, 0 4 <0.01% Acceptable Expected boring case
2, 1, 2, 1 9 <0.01% Acceptable Expected boring case
2, 1, 2, 2 120 <0.01% Acceptable Expected boring case
2, 2, 0, 0 43,568 0.09% Acceptable Expected boring case
2, 2, 0, 1 41 <0.01% Acceptable Expected boring case
2, 2, 0, 2 91 <0.01% Acceptable Expected boring case
2, 2, 1, 0 684 <0.01% Acceptable Expected boring case
2, 2, 1, 1 123,134 0.24% Acceptable Expected boring case
2, 2, 1, 2 388 <0.01% Acceptable Expected boring case
2, 2, 2, 0 1,615 <0.01% Acceptable Expected boring case
2, 2, 2, 1 264 <0.01% Acceptable Expected boring case
2, 2, 2, 2 22,367,479 44.06% Acceptable Expected boring case
*/
private final Holder h1 = new Holder();
private final Holder h2 = h1;
@Actor
public void actorW0() {
h1.x = 1;
}
@Actor
public void actorW1() {
h2.x = 2;
}
@Actor
public void actorR2(IIII_Result r) {
Holder ref1 = this.h1;
Holder ref2 = this.h2;
ref1.trap = 0;
ref2.trap = 0;
r.r1 = ref1.x;
r.r2 = ref2.x;
}
@Actor
public void actorR3(IIII_Result r) {
Holder ref2 = this.h2;
Holder ref1 = this.h1;
ref2.trap = 0;
ref1.trap = 0;
r.r3 = ref1.x;
r.r4 = ref2.x;
}
private static class Holder {
int x;
int trap;
}
}