author | twisti |
Mon, 27 Apr 2015 09:02:41 -0700 | |
changeset 30288 | 476c276de939 |
parent 30247 | 9925b07bba5b |
child 30604 | b8d532cb6420 |
permissions | -rw-r--r-- |
24095
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
1 |
/* |
29466 | 2 |
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
24095
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
4 |
* |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
8 |
* |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
13 |
* accompanied this code). |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
14 |
* |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
18 |
* |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
21 |
* questions. |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
22 |
*/ |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
23 |
|
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
24 |
/** |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
25 |
* @test TestDynShrinkHeap |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
26 |
* @bug 8016479 |
27692
11c231c781dc
8062537: [TESTBUG] Conflicting GC combinations in hotspot tests
eistepan
parents:
26573
diff
changeset
|
27 |
* @requires vm.gc=="Parallel" | vm.gc=="null" |
24095
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
28 |
* @summary Verify that the heap shrinks after full GC according to the current values of the Min/MaxHeapFreeRatio flags |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
29 |
* @library /testlibrary |
24667
38c5d155aee9
8040250: The test test/gc/parallelScavenge/TestDynShrinkHeap.java fails with OOME
iignatyev
parents:
24473
diff
changeset
|
30 |
* @run main/othervm -XX:+UseAdaptiveSizePolicyWithSystemGC -XX:+UseParallelGC -XX:MinHeapFreeRatio=0 -XX:MaxHeapFreeRatio=100 -Xmx1g -verbose:gc TestDynShrinkHeap |
24095
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
31 |
*/ |
24473
1227042cdc67
8039489: Refactor test framework for dynamic VM options
iignatyev
parents:
24095
diff
changeset
|
32 |
import com.oracle.java.testlibrary.DynamicVMOption; |
24095
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
33 |
import java.lang.management.ManagementFactory; |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
34 |
import java.lang.management.MemoryUsage; |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
35 |
import java.util.ArrayList; |
29466 | 36 |
import static com.oracle.java.testlibrary.Asserts.assertLessThan; |
30247
9925b07bba5b
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
29466
diff
changeset
|
37 |
import com.sun.management.HotSpotDiagnosticMXBean; |
24095
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
38 |
|
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
39 |
public class TestDynShrinkHeap { |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
40 |
|
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
41 |
public static final String MIN_FREE_RATIO_FLAG_NAME = "MinHeapFreeRatio"; |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
42 |
public static final String MAX_FREE_RATIO_FLAG_NAME = "MaxHeapFreeRatio"; |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
43 |
|
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
44 |
private static ArrayList<byte[]> list = new ArrayList<>(0); |
24667
38c5d155aee9
8040250: The test test/gc/parallelScavenge/TestDynShrinkHeap.java fails with OOME
iignatyev
parents:
24473
diff
changeset
|
45 |
private static final int LEN = 512 * 1024 + 1; |
24095
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
46 |
|
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
47 |
public TestDynShrinkHeap() { |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
48 |
} |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
49 |
|
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
50 |
private final void test() { |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
51 |
System.gc(); |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
52 |
MemoryUsagePrinter.printMemoryUsage("init"); |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
53 |
|
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
54 |
eat(); |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
55 |
MemoryUsagePrinter.printMemoryUsage("eaten"); |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
56 |
MemoryUsage muFull = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
57 |
|
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
58 |
free(); |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
59 |
MemoryUsagePrinter.printMemoryUsage("free"); |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
60 |
MemoryUsage muFree = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
61 |
|
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
62 |
assertLessThan(muFree.getCommitted(), muFull.getCommitted(), String.format( |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
63 |
"committed free heap size is not less than committed full heap size, heap hasn't been shrunk?%n" |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
64 |
+ "%s = %s%n%s = %s", |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
65 |
MIN_FREE_RATIO_FLAG_NAME, |
30247
9925b07bba5b
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
29466
diff
changeset
|
66 |
ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class) |
9925b07bba5b
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
29466
diff
changeset
|
67 |
.getVMOption(MIN_FREE_RATIO_FLAG_NAME).getValue(), |
24095
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
68 |
MAX_FREE_RATIO_FLAG_NAME, |
30247
9925b07bba5b
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
29466
diff
changeset
|
69 |
ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class) |
9925b07bba5b
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
29466
diff
changeset
|
70 |
.getVMOption(MAX_FREE_RATIO_FLAG_NAME).getValue() |
24095
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
71 |
)); |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
72 |
} |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
73 |
|
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
74 |
private void eat() { |
24667
38c5d155aee9
8040250: The test test/gc/parallelScavenge/TestDynShrinkHeap.java fails with OOME
iignatyev
parents:
24473
diff
changeset
|
75 |
for (int i = 0; i < LEN; i++) { |
24095
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
76 |
list.add(new byte[1024]); |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
77 |
} |
24667
38c5d155aee9
8040250: The test test/gc/parallelScavenge/TestDynShrinkHeap.java fails with OOME
iignatyev
parents:
24473
diff
changeset
|
78 |
MemoryUsagePrinter.printMemoryUsage("allocated " + LEN + " arrays"); |
24095
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
79 |
|
24667
38c5d155aee9
8040250: The test test/gc/parallelScavenge/TestDynShrinkHeap.java fails with OOME
iignatyev
parents:
24473
diff
changeset
|
80 |
list.subList(0, LEN / 2).clear(); |
24095
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
81 |
System.gc(); |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
82 |
MemoryUsagePrinter.printMemoryUsage("array halved"); |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
83 |
} |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
84 |
|
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
85 |
private void free() { |
24473
1227042cdc67
8039489: Refactor test framework for dynamic VM options
iignatyev
parents:
24095
diff
changeset
|
86 |
int min = DynamicVMOption.getInt(MIN_FREE_RATIO_FLAG_NAME); |
1227042cdc67
8039489: Refactor test framework for dynamic VM options
iignatyev
parents:
24095
diff
changeset
|
87 |
DynamicVMOption.setInt(MAX_FREE_RATIO_FLAG_NAME, min); |
24095
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
88 |
System.gc(); |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
89 |
MemoryUsagePrinter.printMemoryUsage("under pressure"); |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
90 |
} |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
91 |
|
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
92 |
public static void main(String[] args) { |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
93 |
new TestDynShrinkHeap().test(); |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
94 |
} |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
95 |
} |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
96 |
|
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
97 |
/** |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
98 |
* Prints memory usage to standard output |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
99 |
*/ |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
100 |
class MemoryUsagePrinter { |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
101 |
|
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
102 |
public static String humanReadableByteCount(long bytes, boolean si) { |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
103 |
int unit = si ? 1000 : 1024; |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
104 |
if (bytes < unit) { |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
105 |
return bytes + " B"; |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
106 |
} |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
107 |
int exp = (int) (Math.log(bytes) / Math.log(unit)); |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
108 |
String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i"); |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
109 |
return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre); |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
110 |
} |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
111 |
|
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
112 |
public static void printMemoryUsage(String label) { |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
113 |
MemoryUsage memusage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
114 |
float freeratio = 1f - (float) memusage.getUsed() / memusage.getCommitted(); |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
115 |
System.out.format("[%-24s] init: %-7s, used: %-7s, comm: %-7s, freeRatio ~= %.1f%%%n", |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
116 |
label, |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
117 |
humanReadableByteCount(memusage.getInit(), true), |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
118 |
humanReadableByteCount(memusage.getUsed(), true), |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
119 |
humanReadableByteCount(memusage.getCommitted(), true), |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
120 |
freeratio * 100 |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
121 |
); |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
122 |
} |
5a5cf6765809
8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff
changeset
|
123 |
} |