Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/gc/TestReferenceRefersToDuringConcMark.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
* @requires vm.gc != "Shenandoah" | vm.opt.ShenandoahGCMode != "iu"
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.TestReferenceRefersToDuringConcMark
35
*/
36
37
import java.lang.ref.Reference;
38
import java.lang.ref.WeakReference;
39
import sun.hotspot.WhiteBox;
40
41
public class TestReferenceRefersToDuringConcMark {
42
private static final WhiteBox WB = WhiteBox.getWhiteBox();
43
44
private static volatile Object testObject = null;
45
46
private static WeakReference<Object> testWeak = null;
47
48
private static void setup() {
49
testObject = new Object();
50
testWeak = new WeakReference<Object>(testObject);
51
}
52
53
private static void gcUntilOld(Object o) throws Exception {
54
if (!WB.isObjectInOldGen(o)) {
55
WB.fullGC();
56
if (!WB.isObjectInOldGen(o)) {
57
fail("object not promoted by full gc");
58
}
59
}
60
}
61
62
private static void gcUntilOld() throws Exception {
63
gcUntilOld(testObject);
64
gcUntilOld(testWeak);
65
}
66
67
private static void fail(String msg) throws Exception {
68
throw new RuntimeException(msg);
69
}
70
71
private static void expectNotCleared(Reference<Object> ref,
72
String which) throws Exception {
73
if (ref.refersTo(null)) {
74
fail("expected " + which + " to not be cleared");
75
}
76
}
77
78
private static void expectValue(Reference<Object> ref,
79
Object value,
80
String which) throws Exception {
81
expectNotCleared(ref, which);
82
if (!ref.refersTo(value)) {
83
fail(which + " doesn't refer to expected value");
84
}
85
}
86
87
private static void checkInitialStates() throws Exception {
88
expectValue(testWeak, testObject, "testWeak");
89
}
90
91
private static void discardStrongReferences() {
92
testObject = null;
93
}
94
95
private static void testConcurrentCollection() throws Exception {
96
setup();
97
gcUntilOld();
98
99
WB.concurrentGCAcquireControl();
100
try {
101
checkInitialStates();
102
103
discardStrongReferences();
104
105
WB.concurrentGCRunTo(WB.BEFORE_MARKING_COMPLETED);
106
107
// For most collectors - the configurations tested here -,
108
// calling get() will keep testObject alive.
109
if (testWeak.get() == null) {
110
fail("testWeak unexpectedly == null");
111
}
112
113
WB.concurrentGCRunToIdle();
114
115
expectNotCleared(testWeak, "testWeak");
116
} finally {
117
WB.concurrentGCReleaseControl();
118
}
119
}
120
121
public static void main(String[] args) throws Exception {
122
if (WB.supportsConcurrentGCBreakpoints()) {
123
testConcurrentCollection();
124
}
125
}
126
}
127
128