Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/ref/SoftReference/Bash.java
38828 views
1
/*
2
* Copyright (c) 1997, 1998, 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
/* @test
25
* @bug 4076283
26
* @summary java.lang.ref.SoftReference should reliably prevent
27
* OutOfMemoryErrors
28
* @author Peter Jones
29
* @author Mark Reinhold
30
*/
31
32
/* If this test fails, an OutOfMemoryError will be thrown */
33
34
import java.lang.ref.SoftReference;
35
36
37
public class Bash {
38
39
static class TestReference extends SoftReference {
40
41
public static TestReference head;
42
public TestReference next;
43
44
public TestReference(Object referent) {
45
super(referent);
46
next = head;
47
head = this;
48
}
49
}
50
51
52
final static int NUM_BLOCKS = 2048;
53
final static int BLOCK_SIZE = 32768;
54
55
56
public static void main(String[] args) throws Exception {
57
58
for (int i = 0; i < NUM_BLOCKS; ++ i) {
59
TestReference ref = new TestReference(new byte[BLOCK_SIZE]);
60
}
61
62
int emptyCount = 0;
63
int fullCount = 0;
64
for (TestReference r = TestReference.head; r != null; r = r.next) {
65
if (r.get() == null) emptyCount++;
66
else fullCount++;
67
}
68
69
System.err.println(fullCount + " full, " + emptyCount + " empty ");
70
71
}
72
73
}
74
75