Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/gc/shenandoah/TestVerifyJCStress.java
40942 views
1
/*
2
* Copyright (c) 2017, 2020, Red Hat, Inc. 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
/*
26
* @test TestVerifyJCStress
27
* @summary Tests that we pass at least one jcstress-like test with all verification turned on
28
* @requires vm.gc.Shenandoah
29
* @modules java.base/jdk.internal.misc
30
* java.management
31
*
32
* @run main/othervm -Xmx1g -Xms1g -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions
33
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
34
* -XX:+ShenandoahDegeneratedGC -XX:+ShenandoahVerify
35
* TestVerifyJCStress
36
*
37
* @run main/othervm -Xmx1g -Xms1g -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions
38
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
39
* -XX:-ShenandoahDegeneratedGC -XX:+ShenandoahVerify
40
* TestVerifyJCStress
41
*/
42
43
/*
44
* @test TestVerifyJCStress
45
* @summary Tests that we pass at least one jcstress-like test with all verification turned on
46
* @requires vm.gc.Shenandoah
47
* @modules java.base/jdk.internal.misc
48
* java.management
49
*
50
* @run main/othervm -Xmx1g -Xms1g -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions
51
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive
52
* -XX:+ShenandoahVerify -XX:+IgnoreUnrecognizedVMOptions -XX:+ShenandoahVerifyOptoBarriers
53
* TestVerifyJCStress
54
*
55
* @run main/othervm -Xmx1g -Xms1g -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions
56
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact
57
* -XX:+ShenandoahVerify -XX:+IgnoreUnrecognizedVMOptions -XX:+ShenandoahVerifyOptoBarriers
58
* TestVerifyJCStress
59
*/
60
61
/*
62
* @test TestVerifyJCStress
63
* @summary Tests that we pass at least one jcstress-like test with all verification turned on
64
* @requires vm.gc.Shenandoah
65
* @modules java.base/jdk.internal.misc
66
* java.management
67
*
68
* @run main/othervm -Xmx1g -Xms1g -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions
69
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu
70
* -XX:+ShenandoahVerify -XX:+IgnoreUnrecognizedVMOptions -XX:+ShenandoahVerifyOptoBarriers
71
* TestVerifyJCStress
72
*
73
* @run main/othervm -Xmx1g -Xms1g -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions
74
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu
75
* -XX:+ShenandoahVerify -XX:+IgnoreUnrecognizedVMOptions -XX:TieredStopAtLevel=1
76
* TestVerifyJCStress
77
*/
78
79
import java.util.*;
80
import java.util.concurrent.*;
81
import java.util.concurrent.locks.*;
82
83
public class TestVerifyJCStress {
84
85
public static void main(String[] args) throws Exception {
86
ExecutorService service = Executors.newFixedThreadPool(
87
2,
88
r -> {
89
Thread t = new Thread(r);
90
t.setDaemon(true);
91
return t;
92
}
93
);
94
95
for (int c = 0; c < 10000; c++) {
96
final Test[] tests = new Test[10000];
97
for (int t = 0; t < tests.length; t++) {
98
tests[t] = new Test();
99
}
100
101
Future<?> f1 = service.submit(() -> {
102
IntResult2 r = new IntResult2();
103
for (Test test : tests) {
104
test.RL_Us(r);
105
}
106
});
107
Future<?> f2 = service.submit(() -> {
108
for (Test test : tests) {
109
test.WLI_Us();
110
}
111
});
112
113
f1.get();
114
f2.get();
115
}
116
}
117
118
public static class IntResult2 {
119
int r1, r2;
120
}
121
122
public static class Test {
123
final StampedLock lock = new StampedLock();
124
125
int x, y;
126
127
public void RL_Us(IntResult2 r) {
128
StampedLock lock = this.lock;
129
long stamp = lock.readLock();
130
r.r1 = x;
131
r.r2 = y;
132
lock.unlock(stamp);
133
}
134
135
public void WLI_Us() {
136
try {
137
StampedLock lock = this.lock;
138
long stamp = lock.writeLockInterruptibly();
139
x = 1;
140
y = 2;
141
lock.unlock(stamp);
142
} catch (InterruptedException e) {
143
throw new RuntimeException(e);
144
}
145
}
146
}
147
148
}
149
150