Mercurial > hg > graal-compiler
annotate test/gc/g1/TestHumongousShrinkHeap.java @ 20488:9c8439756c05
8052313: Backport CDS tests from JDK-9 to jdk8_u40
Summary: Copied CDS tests from jdk-9 to jdk8u40
Reviewed-by: ccheung, dholmes
author | mseledtsov |
---|---|
date | Fri, 19 Sep 2014 11:12:39 -0400 |
parents | 9b8bd21b6823 |
children | 7a6313074325 |
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 |
20461
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
29 * @run main/othervm -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=12 -XX:+UseG1GC -XX:G1HeapRegionSize=1M -verbose:gc 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
|
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 |
20461
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
44 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
|
45 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
|
46 private static final int LISTS_COUNT = 10; |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
47 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
|
48 private static final long AVAILABLE_MEMORY |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
49 = Runtime.getRuntime().freeMemory(); |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
50 private static final int HUMON_COUNT |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
51 = (int) ((AVAILABLE_MEMORY / HUMON_SIZE) |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
52 / 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
|
53 |
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 |
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 public static void main(String[] args) { |
20461
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
56 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
|
57 + "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
|
58 MemoryUsagePrinter.humanReadableByteCount(AVAILABLE_MEMORY, false), |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
59 MemoryUsagePrinter.humanReadableByteCount(HUMON_SIZE, false), |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
60 HUMON_COUNT |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
61 ); |
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
|
62 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
|
63 } |
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 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
|
66 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
|
67 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
|
68 |
20461
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
69 allocate(); |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
70 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
|
71 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
|
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 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
|
74 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
|
75 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
|
76 |
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 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
|
78 "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
|
79 + "%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
|
80 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
|
81 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
|
82 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
|
83 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
|
84 )); |
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 |
20461
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
87 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
|
88 |
20461
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
89 for (int i = 0; i < LISTS_COUNT; i++) { |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
90 List<byte[]> stuff = new ArrayList(); |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
91 allocateList(stuff, HUMON_COUNT, HUMON_SIZE); |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
92 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
|
93 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
|
94 } |
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 } |
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 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
|
98 // 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
|
99 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
|
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
|
101 // 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
|
102 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
|
103 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
|
104 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
|
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 |
20461
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
107 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
|
108 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
|
109 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
|
110 } |
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 } |
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 } |
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 * 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
|
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 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
|
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 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
|
120 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
|
121 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
|
122 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
|
123 } |
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 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
|
125 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
|
126 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
|
127 } |
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 |
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 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
|
130 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
|
131 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
|
132 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
|
133 label, |
20461
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
134 humanReadableByteCount(memusage.getInit(), false), |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
135 humanReadableByteCount(memusage.getUsed(), false), |
9b8bd21b6823
8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents:
20382
diff
changeset
|
136 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
|
137 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
|
138 ); |
09e9e5240710
8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
139 } |
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 } |