Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/gctests/WeakReference/weak007/weak007.java
41161 views
1
/*
2
* Copyright (c) 2007, 2020, 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/WeakReference/weak007.
29
* VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
30
*
31
* @library /vmTestbase
32
* /test/lib
33
* @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.WeakReference.weak007.weak007 -t 1
34
*/
35
36
package gc.gctests.WeakReference.weak007;
37
38
import nsk.share.TestFailure;
39
import nsk.share.gc.*;
40
import java.lang.ref.WeakReference;
41
import java.lang.ref.Reference;
42
43
/**
44
* Test that GC correctly clears weak references.
45
*
46
* This test creates a number of weak references,
47
* each of which points to the next, then provokes
48
* GC with Algorithms.eatMemory(). The test succeeds
49
* if last reference has been cleared and the object
50
* has been finalized.
51
*/
52
public class weak007 extends ThreadedGCTest {
53
54
class Worker implements Runnable {
55
56
private int length = 10000;
57
private int objectSize = 10000;
58
private Reference[] references;
59
60
private void makeReferences() {
61
references[length - 1] = null;
62
FinMemoryObject obj = new FinMemoryObject(objectSize);
63
references[0] = new WeakReference(obj);
64
for (int i = 1; i < length; ++i) {
65
references[i] = new WeakReference(references[i - 1]);
66
}
67
for (int i = 0; i < length - 1; ++i) {
68
references[i] = null;
69
}
70
}
71
72
public void run() {
73
makeReferences();
74
Algorithms.eatMemory(getExecutionController());
75
if (getExecutionController().continueExecution()) {
76
if (references[length - 1].get() != null) {
77
throw new TestFailure("Last weak reference has not been cleared");
78
}
79
} else {
80
log.info("Completed iterations: " + getExecutionController().getIteration());
81
}
82
}
83
84
public Worker() {
85
log.info("Array size: " + length);
86
log.info("Object size: " + objectSize);
87
references = new WeakReference[length];
88
}
89
}
90
91
@Override
92
protected Runnable createRunnable(int i) {
93
return new Worker();
94
}
95
96
public static void main(String[] args) {
97
GC.runTest(new weak007(), args);
98
}
99
}
100
101