Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/memory/FillingStation/FillingStation.java
41159 views
1
/*
2
* Copyright (c) 2002, 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/memory/FillingStation.
29
* VM Testbase keywords: [gc, stress, nonconcurrent]
30
*
31
* @library /vmTestbase
32
* /test/lib
33
* @run main/othervm gc.memory.FillingStation.FillingStation
34
*/
35
36
package gc.memory.FillingStation;
37
38
import jdk.test.lib.Utils;
39
import java.util.Random;
40
41
public class FillingStation {
42
43
public static final long minObjectSize = 4;
44
public static final long freeSpaceLimit = 64;
45
public static final long maxObjectSize = 32*1024;
46
47
public static final boolean debug = false;
48
49
public static void main(String[] arg) {
50
prologue();
51
fill();
52
epilogue();
53
}
54
55
public static void prologue() {
56
_beforeMillis = System.currentTimeMillis();
57
}
58
59
public static void epilogue() {
60
_afterMillis = System.currentTimeMillis();
61
if (_overflow) {
62
System.out.println("Overflowed!");
63
}
64
final double deltaSecs = (_afterMillis - _beforeMillis) / 1000.0;
65
final double freeMegs = ((double) _freeBytes) / (1024.0 * 1024.0);
66
final double totalMegs = ((double) _totalBytes) / (1024.0 * 1024.0);
67
final double memRatio = freeMegs / totalMegs;
68
System.out.println("Runtime.freeMemory()/Runtime.totalMemory: " +
69
Long.toString(_freeBytes) +
70
"/" +
71
Long.toString(_totalBytes) +
72
" = " +
73
Double.toString(memRatio));
74
System.out.println("That took: " +
75
Double.toString(deltaSecs) +
76
" seconds");
77
}
78
79
public static void fill() {
80
boolean _overflow = false;
81
Runtime rt = java.lang.Runtime.getRuntime();
82
Random stream = Utils.getRandomInstance();
83
Space next = null;
84
try {
85
for (long available = rt.freeMemory();
86
available > freeSpaceLimit;
87
available = rt.freeMemory()) {
88
long request = (available - freeSpaceLimit) / 2;
89
int maxRequest = (int) Math.min(maxObjectSize, request);
90
int minRequest = (int) Math.max(minObjectSize, maxRequest);
91
int size = stream.nextInt(minRequest);
92
if (debug) {
93
System.err.println("available: " + Long.toString(available) +
94
" maxRequest: " + Integer.toString(maxRequest) +
95
" minRequest: " + Integer.toString(minRequest) +
96
" size: " + Integer.toString(size));
97
}
98
next = new Space(size, next);
99
}
100
} catch (OutOfMemoryError oome) {
101
_overflow = true;
102
}
103
_freeBytes = rt.freeMemory();
104
_totalBytes = rt.totalMemory();
105
}
106
107
static long _beforeMillis = 0L;
108
static long _afterMillis = 0L;
109
static long _freeBytes = 0L;
110
static long _totalBytes = 0L;
111
static boolean _overflow = false;
112
}
113
114
class Space {
115
public Space(int bytes, Space next) {
116
_next = next;
117
_space = new byte[bytes];
118
}
119
private Space _next = null;
120
private byte[] _space = null;
121
}
122
123