Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/gc/TestReferenceClearDuringReferenceProcessing.java
40930 views
1
/*
2
* Copyright (c) 2020, 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;
25
26
/* @test
27
* @bug 8256517
28
* @requires vm.gc.Z | vm.gc.Shenandoah
29
* @requires vm.gc != "null"
30
* @library /test/lib
31
* @build sun.hotspot.WhiteBox
32
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
33
* @run main/othervm
34
* -Xbootclasspath/a:.
35
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
36
* gc.TestReferenceClearDuringReferenceProcessing
37
*/
38
39
import java.lang.ref.Reference;
40
import java.lang.ref.ReferenceQueue;
41
import java.lang.ref.WeakReference;
42
import sun.hotspot.WhiteBox;
43
44
public class TestReferenceClearDuringReferenceProcessing {
45
private static final WhiteBox WB = WhiteBox.getWhiteBox();
46
47
private static Object testObject = new Object();
48
private static final ReferenceQueue<Object> queue = new ReferenceQueue<Object>();
49
private static final WeakReference<Object> ref = new WeakReference<Object>(testObject, queue);
50
51
private static final long TIMEOUT = 10000; // 10sec in millis
52
53
private static void test() {
54
while (!WB.isObjectInOldGen(testObject) ||
55
!WB.isObjectInOldGen(ref)) {
56
WB.fullGC();
57
}
58
59
WB.concurrentGCAcquireControl();
60
try {
61
testObject = null;
62
WB.concurrentGCRunTo(WB.AFTER_CONCURRENT_REFERENCE_PROCESSING_STARTED);
63
if (!ref.refersTo(null)) {
64
throw new RuntimeException("ref not apparently cleared");
65
}
66
67
ref.clear();
68
69
WB.concurrentGCRunToIdle();
70
71
Reference<? extends Object> enqueued = null;
72
73
try {
74
enqueued = queue.remove(TIMEOUT);
75
} catch (InterruptedException e) {
76
throw new RuntimeException("queue.remove interrupted");
77
}
78
if (enqueued == null) {
79
throw new RuntimeException("ref not enqueued");
80
} else if (enqueued != ref) {
81
throw new RuntimeException("some other ref enqeueued");
82
}
83
} finally {
84
WB.concurrentGCReleaseControl();
85
}
86
}
87
88
public static void main(String[] args) {
89
if (WB.supportsConcurrentGCBreakpoints()) {
90
// Also requires concurrent reference processing, but we
91
// don't have a predicate for that. For now,
92
// use @requires and CLA to limit the applicable collectors.
93
test();
94
}
95
}
96
}
97
98