Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/jit/escape/AdaptiveBlocking/AdaptiveBlocking001/AdaptiveBlocking001.java
41160 views
1
/*
2
* Copyright (c) 2010, 2020, Oracle and/or its affiliates. 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
*
27
* @summary converted from VM Testbase jit/escape/AdaptiveBlocking/AdaptiveBlocking001.
28
* VM Testbase keywords: [jit, quick]
29
* VM Testbase readme:
30
* This is a basic JIT compiler adaptive blocking test. The test runs 2 threads
31
* contending for a shared resource. In the first round, the lock is held for
32
* a short period of time, provoking spinlock-style locking. In the second round,
33
* the lock is held for a long period of time, provoking blocked locking. The
34
* described scenario is repeated numRounds (specified by the -numRounds
35
* parameter) times.
36
*
37
* @library /vmTestbase
38
* /test/lib
39
* @build jit.escape.AdaptiveBlocking.AdaptiveBlocking001.AdaptiveBlocking001
40
* @run driver/timeout=300 ExecDriver --java -server -Xcomp -XX:+DoEscapeAnalysis
41
* jit.escape.AdaptiveBlocking.AdaptiveBlocking001.AdaptiveBlocking001 -numRounds 10
42
*/
43
44
package jit.escape.AdaptiveBlocking.AdaptiveBlocking001;
45
46
import nsk.share.TestFailure;
47
48
class AdaptiveBlocking001
49
{
50
public static int numRounds = 10;
51
52
private static Object sharedLock = new Object();
53
private static boolean lockEntered1;
54
private static boolean lockEntered2;
55
56
private static boolean latentLocks;
57
58
private static boolean done;
59
60
private static boolean failed;
61
62
public static void main( String[] args )
63
{
64
System.out.println( "Adaptive blocking test" );
65
66
parseArgs( args );
67
68
for( int i=0; i < numRounds; ++i )
69
{
70
doRound(i, false);
71
doRound(i, true);
72
}
73
74
if( !failed )
75
System.out.println( "TEST PASSED" );
76
else
77
throw new TestFailure( "TEST FAILED" );
78
}
79
80
private static void parseArgs( String[] args )
81
{
82
for( int i=0; i < args.length; ++i )
83
{
84
String arg = args[i];
85
String val;
86
87
if( arg.equals( "-numRounds" ) )
88
{
89
if( ++i < args.length )
90
val = args[i];
91
else
92
throw new TestFailure( "Need value for '" + arg + "' parameter" );
93
94
try {
95
numRounds = Integer.parseInt( val );
96
} catch( NumberFormatException e ) {
97
throw new TestFailure( "Invalid value for '" + arg + "' parameter: " + val );
98
}
99
}
100
else
101
{
102
throw new TestFailure( "Invalid argument: " + args );
103
}
104
}
105
}
106
107
private static void doRound(int ord, boolean latent_locks)
108
{
109
System.out.println( "round #" + ord + ", latent locks: " + (latent_locks ? "yes" : "no") + "..." );
110
111
latentLocks = latent_locks;
112
113
Thread_1 t1 = new Thread_1();
114
Thread_2 t2 = new Thread_2();
115
116
done = false;
117
118
t1.start();
119
t2.start();
120
121
for( int i=0; i < 10; ++i )
122
{
123
try {
124
Thread.sleep( 1000 );
125
} catch( InterruptedException e ) {
126
}
127
128
if( done )
129
break;
130
}
131
132
done = true;
133
134
try {
135
t1.join();
136
t2.join();
137
} catch( InterruptedException e ) {
138
}
139
}
140
141
private static class Thread_1 extends Thread
142
{
143
public void run()
144
{
145
while( !done )
146
{
147
synchronized( sharedLock )
148
{
149
lockEntered1 = true;
150
if( lockEntered2 )
151
{
152
Fail();
153
done = true;
154
break;
155
}
156
157
holdLock();
158
159
lockEntered1 = false;
160
}
161
}
162
}
163
}
164
165
private static class Thread_2 extends Thread
166
{
167
public void run()
168
{
169
while( !done )
170
{
171
synchronized( sharedLock )
172
{
173
lockEntered2 = true;
174
if( lockEntered1 )
175
{
176
Fail();
177
done = true;
178
break;
179
}
180
181
holdLock();
182
183
lockEntered2 = false;
184
}
185
}
186
}
187
}
188
189
private static void holdLock()
190
{
191
if( latentLocks )
192
{
193
try {
194
Thread.sleep( 500 );
195
} catch( InterruptedException e ) {
196
}
197
}
198
}
199
200
private static void Fail()
201
{
202
failed = true;
203
}
204
}
205
206