Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/gc/TestReferenceClearDuringMarking.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 8240696
28
* @library /test/lib
29
* @build sun.hotspot.WhiteBox
30
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
31
* @run main/othervm
32
* -Xbootclasspath/a:.
33
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
34
* gc.TestReferenceClearDuringMarking
35
*/
36
37
import java.lang.ref.WeakReference;
38
import sun.hotspot.WhiteBox;
39
40
public class TestReferenceClearDuringMarking {
41
private static final WhiteBox WB = WhiteBox.getWhiteBox();
42
43
private static Object testA = new Object();
44
private static Object testB = new Object();
45
46
private static final WeakReference<Object> refA1 = new WeakReference<Object>(testA);
47
private static final WeakReference<Object> refA2 = new WeakReference<Object>(testA);
48
49
private static final WeakReference<Object> refB1 = new WeakReference<Object>(testB);
50
private static final WeakReference<Object> refB2 = new WeakReference<Object>(testB);
51
52
private static void test() {
53
while (!WB.isObjectInOldGen(testA) ||
54
!WB.isObjectInOldGen(testB) ||
55
!WB.isObjectInOldGen(refA1) ||
56
!WB.isObjectInOldGen(refA2) ||
57
!WB.isObjectInOldGen(refB1) ||
58
!WB.isObjectInOldGen(refB2)) {
59
WB.fullGC();
60
}
61
62
WB.concurrentGCAcquireControl();
63
try {
64
testA = null;
65
testB = null;
66
67
WB.concurrentGCRunTo(WB.AFTER_MARKING_STARTED);
68
// Clear A1 early in marking, before reference discovery.
69
refA1.clear();
70
71
WB.concurrentGCRunTo(WB.BEFORE_MARKING_COMPLETED);
72
// Clear B1 late in marking, after reference discovery.
73
refB1.clear();
74
75
WB.concurrentGCRunToIdle();
76
77
// Verify that A2 and B2 still cleared by GC, i.e. the preceding
78
// clear operations did not extend the lifetime of the referents.
79
if (!refA2.refersTo(null)) {
80
throw new RuntimeException("refA2 not cleared");
81
}
82
if (!refB2.refersTo(null)) {
83
throw new RuntimeException("refB2 not cleared");
84
}
85
} finally {
86
WB.concurrentGCReleaseControl();
87
}
88
}
89
90
public static void main(String[] args) {
91
if (WB.supportsConcurrentGCBreakpoints()) {
92
test();
93
}
94
}
95
}
96
97