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 gc
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 driver jdk.test.lib.FileInstaller . .
34 * @run main/othervm gc.memory.FillingStation.FillingStation
35 */
36
37 package gc.memory.FillingStation;
38
39 public class FillingStation {
40
41 public static final long minObjectSize = 4;
42 public static final long freeSpaceLimit = 64;
43 public static final long maxObjectSize = 32*1024;
44
45 public static final boolean debug = false;
46
47 public static void main(String[] arg) {
48 prologue();
49 fill();
50 epilogue();
51 }
52
53 public static void prologue() {
54 _beforeMillis = System.currentTimeMillis();
55 }
56
57 public static void epilogue() {
58 _afterMillis = System.currentTimeMillis();
60 System.out.println("Overflowed!");
61 }
62 final double deltaSecs = (_afterMillis - _beforeMillis) / 1000.0;
63 final double freeMegs = ((double) _freeBytes) / (1024.0 * 1024.0);
64 final double totalMegs = ((double) _totalBytes) / (1024.0 * 1024.0);
65 final double memRatio = freeMegs / totalMegs;
66 System.out.println("Runtime.freeMemory()/Runtime.totalMemory: " +
67 Long.toString(_freeBytes) +
68 "/" +
69 Long.toString(_totalBytes) +
70 " = " +
71 Double.toString(memRatio));
72 System.out.println("That took: " +
73 Double.toString(deltaSecs) +
74 " seconds");
75 }
76
77 public static void fill() {
78 boolean _overflow = false;
79 Runtime rt = java.lang.Runtime.getRuntime();
80 java.util.Random stream = new java.util.Random();
81 Space next = null;
82 try {
83 for (long available = rt.freeMemory();
84 available > freeSpaceLimit;
85 available = rt.freeMemory()) {
86 long request = (available - freeSpaceLimit) / 2;
87 int maxRequest = (int) Math.min(maxObjectSize, request);
88 int minRequest = (int) Math.max(minObjectSize, maxRequest);
89 int size = stream.nextInt(minRequest);
90 if (debug) {
91 System.err.println("available: " + Long.toString(available) +
92 " maxRequest: " + Integer.toString(maxRequest) +
93 " minRequest: " + Integer.toString(minRequest) +
94 " size: " + Integer.toString(size));
95 }
96 next = new Space(size, next);
97 }
98 } catch (OutOfMemoryError oome) {
99 _overflow = true;
100 }
|
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 gc
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 driver jdk.test.lib.FileInstaller . .
34 * @run main/othervm gc.memory.FillingStation.FillingStation
35 */
36
37 package gc.memory.FillingStation;
38
39 import jdk.test.lib.Utils;
40 import java.util.Random;
41
42 public class FillingStation {
43
44 public static final long minObjectSize = 4;
45 public static final long freeSpaceLimit = 64;
46 public static final long maxObjectSize = 32*1024;
47
48 public static final boolean debug = false;
49
50 public static void main(String[] arg) {
51 prologue();
52 fill();
53 epilogue();
54 }
55
56 public static void prologue() {
57 _beforeMillis = System.currentTimeMillis();
58 }
59
60 public static void epilogue() {
61 _afterMillis = System.currentTimeMillis();
63 System.out.println("Overflowed!");
64 }
65 final double deltaSecs = (_afterMillis - _beforeMillis) / 1000.0;
66 final double freeMegs = ((double) _freeBytes) / (1024.0 * 1024.0);
67 final double totalMegs = ((double) _totalBytes) / (1024.0 * 1024.0);
68 final double memRatio = freeMegs / totalMegs;
69 System.out.println("Runtime.freeMemory()/Runtime.totalMemory: " +
70 Long.toString(_freeBytes) +
71 "/" +
72 Long.toString(_totalBytes) +
73 " = " +
74 Double.toString(memRatio));
75 System.out.println("That took: " +
76 Double.toString(deltaSecs) +
77 " seconds");
78 }
79
80 public static void fill() {
81 boolean _overflow = false;
82 Runtime rt = java.lang.Runtime.getRuntime();
83 Random stream = Utils.getRandomInstance();
84 Space next = null;
85 try {
86 for (long available = rt.freeMemory();
87 available > freeSpaceLimit;
88 available = rt.freeMemory()) {
89 long request = (available - freeSpaceLimit) / 2;
90 int maxRequest = (int) Math.min(maxObjectSize, request);
91 int minRequest = (int) Math.max(minObjectSize, maxRequest);
92 int size = stream.nextInt(minRequest);
93 if (debug) {
94 System.err.println("available: " + Long.toString(available) +
95 " maxRequest: " + Integer.toString(maxRequest) +
96 " minRequest: " + Integer.toString(minRequest) +
97 " size: " + Integer.toString(size));
98 }
99 next = new Space(size, next);
100 }
101 } catch (OutOfMemoryError oome) {
102 _overflow = true;
103 }
|