Mercurial > hg > truffle
annotate test/gc/g1/TestHumongousShrinkHeap.java @ 20414:2545e461115b
8044398: Attach code should propagate errors in Diagnostic Commands as errors
Reviewed-by: dcubed, mgronlun
author | sla |
---|---|
date | Fri, 30 May 2014 19:13:07 +0200 |
parents | b1266b08b994 |
children | 9b8bd21b6823 |
rev | line source |
---|---|
20381
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
1 /* |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
4 * |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
8 * |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
13 * accompanied this code). |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
14 * |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
18 * |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
21 * questions. |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
22 */ |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
23 |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
24 /** |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
25 * @test TestHumongousShrinkHeap |
20382
b1266b08b994
8056043: Heap does not shrink within the heap after JDK-8038423
tschatzl
parents:
20381
diff
changeset
|
26 * @bug 8036025 8056043 |
20381
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
27 * @summary Verify that heap shrinks after GC in the presence of fragmentation due to humongous objects |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
28 * @library /testlibrary |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
29 * @run main/othervm -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=50 -XX:+UseG1GC -XX:G1HeapRegionSize=1M -verbose:gc TestHumongousShrinkHeap |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
30 */ |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
31 |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
32 import java.lang.management.ManagementFactory; |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
33 import java.lang.management.MemoryUsage; |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
34 import java.util.ArrayList; |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
35 import java.util.List; |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
36 import sun.management.ManagementFactoryHelper; |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
37 import static com.oracle.java.testlibrary.Asserts.*; |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
38 |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
39 public class TestHumongousShrinkHeap { |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
40 |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
41 public static final String MIN_FREE_RATIO_FLAG_NAME = "MinHeapFreeRatio"; |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
42 public static final String MAX_FREE_RATIO_FLAG_NAME = "MaxHeapFreeRatio"; |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
43 |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
44 private static final ArrayList<ArrayList<byte[]>> garbage = new ArrayList<>(); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
45 private static final int PAGE_SIZE = 1024 * 1024; // 1M |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
46 private static final int PAGES_NUM = 5; |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
47 |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
48 |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
49 public static void main(String[] args) { |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
50 new TestHumongousShrinkHeap().test(); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
51 } |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
52 |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
53 private final void test() { |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
54 System.gc(); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
55 MemoryUsagePrinter.printMemoryUsage("init"); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
56 |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
57 eat(); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
58 MemoryUsagePrinter.printMemoryUsage("eaten"); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
59 MemoryUsage muFull = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
60 |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
61 free(); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
62 MemoryUsagePrinter.printMemoryUsage("free"); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
63 MemoryUsage muFree = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
64 |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
65 assertLessThan(muFree.getCommitted(), muFull.getCommitted(), String.format( |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
66 "committed free heap size is not less than committed full heap size, heap hasn't been shrunk?%n" |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
67 + "%s = %s%n%s = %s", |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
68 MIN_FREE_RATIO_FLAG_NAME, |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
69 ManagementFactoryHelper.getDiagnosticMXBean().getVMOption(MIN_FREE_RATIO_FLAG_NAME).getValue(), |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
70 MAX_FREE_RATIO_FLAG_NAME, |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
71 ManagementFactoryHelper.getDiagnosticMXBean().getVMOption(MAX_FREE_RATIO_FLAG_NAME).getValue() |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
72 )); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
73 } |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
74 |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
75 private void eat() { |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
76 int HumongousObjectSize = Math.round(.9f * PAGE_SIZE); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
77 System.out.println("Will allocate objects of size=" + |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
78 MemoryUsagePrinter.humanReadableByteCount(HumongousObjectSize, true)); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
79 |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
80 for (int i = 0; i < PAGES_NUM; i++) { |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
81 ArrayList<byte[]> stuff = new ArrayList<>(); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
82 eatList(stuff, 100, HumongousObjectSize); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
83 MemoryUsagePrinter.printMemoryUsage("eat #" + i); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
84 garbage.add(stuff); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
85 } |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
86 } |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
87 |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
88 private void free() { |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
89 // do not free last one list |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
90 garbage.subList(0, garbage.size() - 1).clear(); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
91 |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
92 // do not free last one element from last list |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
93 ArrayList stuff = garbage.get(garbage.size() - 1); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
94 stuff.subList(0, stuff.size() - 1).clear(); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
95 System.gc(); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
96 } |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
97 |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
98 private static void eatList(List garbage, int count, int size) { |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
99 for (int i = 0; i < count; i++) { |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
100 garbage.add(new byte[size]); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
101 } |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
102 } |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
103 } |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
104 |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
105 /** |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
106 * Prints memory usage to standard output |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
107 */ |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
108 class MemoryUsagePrinter { |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
109 |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
110 public static String humanReadableByteCount(long bytes, boolean si) { |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
111 int unit = si ? 1000 : 1024; |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
112 if (bytes < unit) { |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
113 return bytes + " B"; |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
114 } |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
115 int exp = (int) (Math.log(bytes) / Math.log(unit)); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
116 String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i"); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
117 return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
118 } |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
119 |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
120 public static void printMemoryUsage(String label) { |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
121 MemoryUsage memusage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
122 float freeratio = 1f - (float) memusage.getUsed() / memusage.getCommitted(); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
123 System.out.format("[%-24s] init: %-7s, used: %-7s, comm: %-7s, freeRatio ~= %.1f%%%n", |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
124 label, |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
125 humanReadableByteCount(memusage.getInit(), true), |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
126 humanReadableByteCount(memusage.getUsed(), true), |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
127 humanReadableByteCount(memusage.getCommitted(), true), |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
128 freeratio * 100 |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
129 ); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
130 } |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
131 } |