Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/gc/cslocker/TestCSLocker.java
40942 views
1
/*
2
* Copyright (c) 2007, 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
package gc.cslocker;
25
26
import static gc.testlibrary.Allocation.blackHole;
27
28
/*
29
* @test TestCSLocker
30
* @bug 6186200
31
* @library /
32
* @summary This short test check RFE 6186200 changes. One thread locked
33
* @summary completely in JNI CS, while other is trying to allocate memory
34
* @summary provoking GC. OOM means FAIL, deadlock means PASS.
35
* @run main/native/othervm -Xmx256m gc.cslocker.TestCSLocker
36
*/
37
38
public class TestCSLocker extends Thread
39
{
40
static int timeout = 5000;
41
public static void main(String args[]) throws Exception {
42
long startTime = System.currentTimeMillis();
43
44
// start garbage producer thread
45
GarbageProducer garbageProducer = new GarbageProducer(1000000, 10);
46
garbageProducer.start();
47
48
// start CS locker thread
49
CSLocker csLocker = new CSLocker();
50
csLocker.start();
51
52
// check timeout to success deadlocking
53
while(System.currentTimeMillis() < startTime + timeout) {
54
System.out.println("sleeping...");
55
sleep(1000);
56
}
57
58
csLocker.unlock();
59
garbageProducer.interrupt();
60
}
61
}
62
63
class GarbageProducer extends Thread
64
{
65
private int size;
66
private int sleepTime;
67
68
GarbageProducer(int size, int sleepTime) {
69
this.size = size;
70
this.sleepTime = sleepTime;
71
}
72
73
public void run() {
74
boolean isRunning = true;
75
76
while (isRunning) {
77
try {
78
blackHole(new int[size]);
79
sleep(sleepTime);
80
} catch (InterruptedException e) {
81
isRunning = false;
82
}
83
}
84
}
85
}
86
87
class CSLocker extends Thread
88
{
89
static { System.loadLibrary("TestCSLocker"); }
90
91
public void run() {
92
int[] a = new int[10];
93
a[0] = 1;
94
if (!lock(a)) {
95
throw new RuntimeException("failed to acquire CSLock");
96
}
97
}
98
99
native boolean lock(int[] array);
100
native void unlock();
101
}
102
103