Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/gctests/PhantomReference/PhantomReferenceTest/PhantomReferenceTest.java
41161 views
1
/*
2
* Copyright (c) 2004, 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
/*
25
* @test
26
* @key stress randomness
27
*
28
* @summary converted from VM Testbase gc/gctests/PhantomReference/PhantomReferenceTest.
29
* VM Testbase keywords: [gc, stress, stressopt, nonconcurrent, jrockit]
30
* VM Testbase readme:
31
* DESCRIPTION
32
* Test that verifies the PhantomReference handling in JRockit.
33
*
34
* COMMENTS
35
* This test was ported from JRockit test suite.
36
*
37
* @library /vmTestbase
38
* /test/lib
39
* @run main/othervm
40
* -XX:-UseGCOverheadLimit
41
* gc.gctests.PhantomReference.PhantomReferenceTest.PhantomReferenceTest
42
*/
43
44
package gc.gctests.PhantomReference.PhantomReferenceTest;
45
46
import gc.gctests.PhantomReference.PRHelper;
47
import gc.gctests.PhantomReference.PhantomHelper;
48
import java.lang.ref.ReferenceQueue;
49
import java.util.ArrayList;
50
import java.util.HashMap;
51
import java.util.Random;
52
import nsk.share.TestFailure;
53
import nsk.share.gc.GC;
54
import nsk.share.gc.GCTestBase;
55
import nsk.share.gc.gp.GarbageUtils;
56
import nsk.share.test.Stresser;
57
58
/**
59
* Tests for the PhantomReference handling in JRockit.
60
*/
61
public class PhantomReferenceTest extends GCTestBase {
62
63
/**
64
* Test that verifies the PhantomReference handling in JRockit.
65
*
66
* @return success if all phantom references were enqueued
67
*/
68
public final void run() {
69
long seed;
70
int minSize;
71
int maxSize;
72
int nrOfObjs;
73
int sleepTime;
74
long maxWaitTime;
75
76
77
seed = runParams.getSeed();
78
minSize = 2048;
79
maxSize = 32768;
80
nrOfObjs = 1000;
81
sleepTime = 10000;
82
maxWaitTime = 30000;
83
84
Random rndGenerator = new Random(seed);
85
long multiplier = maxSize - minSize;
86
ReferenceQueue rq = new ReferenceQueue();
87
HashMap hmHelper = new HashMap();
88
ArrayList alPhantomRefs = new ArrayList();
89
90
for (int i = 0; i < nrOfObjs; i++) {
91
int allocationSize = ((int) (rndGenerator.nextDouble()
92
* multiplier)) + minSize;
93
byte[] tmp = new byte[allocationSize];
94
Integer ik = Integer.valueOf(tmp.hashCode());
95
if (hmHelper.containsKey(ik)) {
96
PhantomHelper ph = (PhantomHelper) hmHelper.get(ik);
97
ph.increaseHashCounter();
98
hmHelper.put(ik, ph);
99
} else {
100
hmHelper.put(ik, new PhantomHelper(tmp.hashCode()));
101
}
102
103
PRHelper prh = new PRHelper(tmp, rq);
104
prh.setReferentHashCode(tmp.hashCode());
105
alPhantomRefs.add(prh);
106
prh = null;
107
tmp = null;
108
}
109
110
Stresser stresser = new Stresser(runParams.getStressOptions());
111
stresser.start(0);
112
GarbageUtils.eatMemory(stresser);
113
if (!stresser.continueExecution()) {
114
return; //we couldn't be sure that FullGC is triggered
115
}
116
String retInfo = PhantomHelper.checkAllHashCodes(
117
rq, hmHelper, maxWaitTime);
118
if (retInfo != null) {
119
alPhantomRefs.clear();
120
hmHelper.clear();
121
throw new TestFailure(retInfo);
122
}
123
124
// Make sure the ArrayList:s are live at the end of the test
125
// to make sure that the references gets enqueued.
126
alPhantomRefs.clear();
127
hmHelper.clear();
128
129
alPhantomRefs = null;
130
hmHelper = null;
131
}
132
133
public static void main(String[] args) {
134
GC.runTest(new PhantomReferenceTest(), args);
135
}
136
}
137
138