Mercurial > hg > truffle
annotate test/gc/g1/TestHumongousShrinkHeap.java @ 21089:bb63a1b5487c
Merge.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Wed, 22 Apr 2015 16:22:53 +0200 |
parents | 7a6313074325 |
children |
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 |
20623
7a6313074325
8064716: TestHumongousShrinkHeap.java can not be run with -XX:+ExplicitGCInvokesConcurrent
azakharov
parents:
20461
diff
changeset
|
27 * @summary Verify that heap shrinks after GC in the presence of fragmentation |
7a6313074325
8064716: TestHumongousShrinkHeap.java can not be run with -XX:+ExplicitGCInvokesConcurrent
azakharov
parents:
20461
diff
changeset
|
28 * due to humongous objects |
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
|
29 * @library /testlibrary |
20623
7a6313074325
8064716: TestHumongousShrinkHeap.java can not be run with -XX:+ExplicitGCInvokesConcurrent
azakharov
parents:
20461
diff
changeset
|
30 * @run main/othervm -XX:-ExplicitGCInvokesConcurrent -XX:MinHeapFreeRatio=10 |
7a6313074325
8064716: TestHumongousShrinkHeap.java can not be run with -XX:+ExplicitGCInvokesConcurrent
azakharov
parents:
20461
diff
changeset
|
31 * -XX:MaxHeapFreeRatio=12 -XX:+UseG1GC -XX:G1HeapRegionSize=1M -verbose:gc |
7a6313074325
8064716: TestHumongousShrinkHeap.java can not be run with -XX:+ExplicitGCInvokesConcurrent
azakharov
parents:
20461
diff
changeset
|
32 * TestHumongousShrinkHeap |
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
|
33 */ |
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 |
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.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
|
36 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
|
37 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
|
38 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
|
39 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
|
40 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
|
41 |
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 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
|
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 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
|
45 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
|
46 |
20461
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
47 private static final List<List<byte[]>> garbage = new ArrayList(); |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
48 private static final int REGION_SIZE = 1024 * 1024; // 1M |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
49 private static final int LISTS_COUNT = 10; |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
50 private static final int HUMON_SIZE = Math.round(.9f * REGION_SIZE); |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
51 private static final long AVAILABLE_MEMORY |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
52 = Runtime.getRuntime().freeMemory(); |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
53 private static final int HUMON_COUNT |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
54 = (int) ((AVAILABLE_MEMORY / HUMON_SIZE) |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
55 / LISTS_COUNT); |
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
|
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 |
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 public static void main(String[] args) { |
20461
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
59 System.out.format("Running with %s max heap size. " |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
60 + "Will allocate humongous object of %s size %d times.%n", |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
61 MemoryUsagePrinter.humanReadableByteCount(AVAILABLE_MEMORY, false), |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
62 MemoryUsagePrinter.humanReadableByteCount(HUMON_SIZE, false), |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
63 HUMON_COUNT |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
64 ); |
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
|
65 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
|
66 } |
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 |
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 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
|
69 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
|
70 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
|
71 |
20461
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
72 allocate(); |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
73 MemoryUsagePrinter.printMemoryUsage("allocated"); |
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
|
74 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
|
75 |
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 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
|
77 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
|
78 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
|
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 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
|
81 "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
|
82 + "%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
|
83 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
|
84 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
|
85 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
|
86 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
|
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 } |
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 |
20461
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
90 private void allocate() { |
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
|
91 |
20461
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
92 for (int i = 0; i < LISTS_COUNT; i++) { |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
93 List<byte[]> stuff = new ArrayList(); |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
94 allocateList(stuff, HUMON_COUNT, HUMON_SIZE); |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
95 MemoryUsagePrinter.printMemoryUsage("allocate #" + (i+1)); |
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
|
96 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
|
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 } |
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 |
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 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
|
101 // 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
|
102 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
|
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 // do not free last one element from last list |
20461
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
105 List stuff = garbage.get(garbage.size() - 1); |
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
|
106 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
|
107 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
|
108 } |
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 |
20461
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
110 private static void allocateList(List garbage, int count, int size) { |
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
|
111 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
|
112 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
|
113 } |
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 } |
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 |
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 /** |
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 * 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
|
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 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
|
121 |
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 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
|
123 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
|
124 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
|
125 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
|
126 } |
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 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
|
128 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
|
129 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
|
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 |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
132 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
|
133 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
|
134 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
|
135 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
|
136 label, |
20461
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
137 humanReadableByteCount(memusage.getInit(), false), |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
138 humanReadableByteCount(memusage.getUsed(), false), |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
139 humanReadableByteCount(memusage.getCommitted(), false), |
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
|
140 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
|
141 ); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
142 } |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
143 } |