Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/gc/g1/TestPeriodicCollectionJNI.java
40942 views
1
/*
2
* Copyright (c) 2019, 2021, 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.g1;
25
26
/* @test
27
* @bug 8218880
28
* @summary Test that issuing a periodic collection while the GC locker is
29
* held does not crash the VM.
30
* @requires vm.gc.G1
31
* @run main/othervm/native
32
* -Xbootclasspath/a:.
33
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
34
* -XX:+UseG1GC -XX:G1PeriodicGCInterval=100
35
* -XX:+G1PeriodicGCInvokesConcurrent
36
* -Xlog:gc*,gc+periodic=debug
37
* gc.g1.TestPeriodicCollectionJNI
38
* @run main/othervm/native
39
* -Xbootclasspath/a:.
40
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
41
* -XX:+UseG1GC -XX:G1PeriodicGCInterval=100
42
* -XX:-G1PeriodicGCInvokesConcurrent
43
* -Xlog:gc*,gc+periodic=debug
44
* gc.g1.TestPeriodicCollectionJNI
45
*/
46
47
public class TestPeriodicCollectionJNI {
48
static { System.loadLibrary("TestPeriodicCollectionJNI"); }
49
50
private static native boolean blockInNative(byte[] array);
51
private static native void unblock();
52
53
public static void block() {
54
if (!blockInNative(new byte[0])) {
55
throw new RuntimeException("failed to acquire lock to dummy object");
56
}
57
}
58
59
public static void main(String[] args) throws InterruptedException {
60
long timeout = 2000;
61
long startTime = System.currentTimeMillis();
62
63
// Start thread doing JNI call
64
BlockInNative blocker = new BlockInNative();
65
blocker.start();
66
67
try {
68
// Wait for periodic GC timeout to trigger
69
while (System.currentTimeMillis() < startTime + timeout) {
70
System.out.println("Sleeping to let periodic GC trigger...");
71
Thread.sleep(200);
72
}
73
} finally {
74
unblock();
75
}
76
}
77
}
78
79
class BlockInNative extends Thread {
80
81
public void run() {
82
TestPeriodicCollectionJNI.block();
83
}
84
85
native void unlock();
86
}
87
88