Mercurial > hg > truffle
annotate test/gc/g1/TestShrinkDefragmentedHeap.java @ 20460:df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
Summary: New test added
Reviewed-by: jwilhelm, tschatzl
Contributed-by: andrey.x.zakharov@oracle.com
author | jwilhelm |
---|---|
date | Thu, 11 Sep 2014 14:21:13 +0200 |
parents | |
children | 7a6313074325 |
rev | line source |
---|---|
20460
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
1 /* |
df66e3a3c4c2
8041946: CMM Testing: 8u40 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. |
df66e3a3c4c2
8041946: CMM Testing: 8u40 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. |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
4 * |
df66e3a3c4c2
8041946: CMM Testing: 8u40 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 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 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 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 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. |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
8 * |
df66e3a3c4c2
8041946: CMM Testing: 8u40 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 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 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 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 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 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 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 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
13 * accompanied this code). |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
14 * |
df66e3a3c4c2
8041946: CMM Testing: 8u40 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 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 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, |
df66e3a3c4c2
8041946: CMM Testing: 8u40 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. |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
18 * |
df66e3a3c4c2
8041946: CMM Testing: 8u40 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 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 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 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
21 * questions. |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
22 */ |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
23 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
24 /** |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
25 * @test TestShrinkDefragmentedHeap |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
26 * @bug 8038423 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 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 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
28 * 1. allocate small objects mixed with humongous ones |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
29 * "ssssHssssHssssHssssHssssHssssHssssH" |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
30 * 2. release all allocated object except the last humongous one |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
31 * "..................................H" |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
32 * 3. invoke gc and check that memory returned to the system (amount of committed memory got down) |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
33 * |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
34 * @library /testlibrary |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
35 */ |
df66e3a3c4c2
8041946: CMM Testing: 8u40 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.ManagementFactory; |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
37 import java.lang.management.MemoryUsage; |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
38 import java.util.ArrayList; |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
39 import java.util.List; |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
40 import sun.management.ManagementFactoryHelper; |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
41 import static com.oracle.java.testlibrary.Asserts.*; |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
42 import com.oracle.java.testlibrary.ProcessTools; |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
43 import com.oracle.java.testlibrary.OutputAnalyzer; |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
44 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
45 public class TestShrinkDefragmentedHeap { |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
46 // Since we store all the small objects, they become old and old regions are also allocated at the bottom of the heap |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
47 // together with humongous regions. So if there are a lot of old regions in the lower part of the heap, |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
48 // the humongous regions will be allocated in the upper part of the heap anyway. |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
49 // To avoid this the Eden needs to be big enough to fit all the small objects. |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
50 private static final int INITIAL_HEAP_SIZE = 200 * 1024 * 1024; |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
51 private static final int MINIMAL_YOUNG_SIZE = 190 * 1024 * 1024; |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
52 private static final int REGION_SIZE = 1 * 1024 * 1024; |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
53 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
54 public static void main(String[] args) throws Exception, Throwable { |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
55 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
56 "-XX:InitialHeapSize=" + INITIAL_HEAP_SIZE, |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
57 "-Xmn" + MINIMAL_YOUNG_SIZE, |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
58 "-XX:MinHeapFreeRatio=10", |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
59 "-XX:MaxHeapFreeRatio=11", |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
60 "-XX:+UseG1GC", |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
61 "-XX:G1HeapRegionSize=" + REGION_SIZE, |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
62 "-verbose:gc", |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
63 GCTest.class.getName() |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
64 ); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
65 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
66 OutputAnalyzer output = ProcessTools.executeProcess(pb); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
67 output.shouldHaveExitValue(0); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
68 } |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
69 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
70 static class GCTest { |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
71 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
72 private static final String MIN_FREE_RATIO_FLAG_NAME = "MinHeapFreeRatio"; |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
73 private static final String MAX_FREE_RATIO_FLAG_NAME = "MaxHeapFreeRatio"; |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
74 private static final String NEW_SIZE_FLAG_NAME = "NewSize"; |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
75 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
76 private static final ArrayList<ArrayList<byte[]>> garbage = new ArrayList<>(); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
77 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
78 private static final int SMALL_OBJS_SIZE = 10 * 1024; // 10kB |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
79 private static final int SMALL_OBJS_COUNT = MINIMAL_YOUNG_SIZE / (SMALL_OBJS_SIZE-1); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
80 private static final int ALLOCATE_COUNT = 3; |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
81 // try to put all humongous object into gap between min young size and initial heap size |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
82 // to avoid implicit GCs |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
83 private static final int HUMONG_OBJS_SIZE = (int) Math.max( |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
84 (INITIAL_HEAP_SIZE - MINIMAL_YOUNG_SIZE) / ALLOCATE_COUNT / 4, |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
85 REGION_SIZE * 1.1 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
86 ); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
87 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
88 private static final long initialHeapSize = getHeapMemoryUsage().getUsed(); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
89 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
90 public static void main(String[] args) throws InterruptedException { |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
91 new GCTest().test(); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
92 } |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
93 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
94 private void test() throws InterruptedException { |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
95 MemoryUsagePrinter.printMemoryUsage("init"); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
96 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
97 allocate(); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
98 System.gc(); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
99 MemoryUsage muFull = getHeapMemoryUsage(); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
100 MemoryUsagePrinter.printMemoryUsage("allocated"); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
101 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
102 free(); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
103 //Thread.sleep(1000); // sleep before measures due lags in JMX |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
104 MemoryUsage muFree = getHeapMemoryUsage(); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
105 MemoryUsagePrinter.printMemoryUsage("free"); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
106 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
107 assertLessThan(muFree.getCommitted(), muFull.getCommitted(), prepareMessageCommittedIsNotLess() ); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
108 } |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
109 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
110 private void allocate() { |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
111 System.out.format("Will allocate objects of small size = %s and humongous size = %s", |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
112 MemoryUsagePrinter.humanReadableByteCount(SMALL_OBJS_SIZE, false), |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
113 MemoryUsagePrinter.humanReadableByteCount(HUMONG_OBJS_SIZE, false) |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
114 ); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
115 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
116 for (int i = 0; i < ALLOCATE_COUNT; i++) { |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
117 ArrayList<byte[]> stuff = new ArrayList<>(); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
118 allocateList(stuff, SMALL_OBJS_COUNT / ALLOCATE_COUNT, SMALL_OBJS_SIZE); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
119 garbage.add(stuff); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
120 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
121 ArrayList<byte[]> humongousStuff = new ArrayList<>(); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
122 allocateList(humongousStuff, 4, HUMONG_OBJS_SIZE); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
123 garbage.add(humongousStuff); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
124 } |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
125 } |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
126 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
127 private void free() { |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
128 // do not free last one list |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
129 garbage.subList(0, garbage.size() - 1).clear(); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
130 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
131 // do not free last one element from last list |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
132 ArrayList stuff = garbage.get(garbage.size() - 1); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
133 if (stuff.size() > 1) { |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
134 stuff.subList(0, stuff.size() - 1).clear(); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
135 } |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
136 System.gc(); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
137 } |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
138 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
139 private String prepareMessageCommittedIsNotLess() { |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
140 return String.format( |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
141 "committed free heap size is not less than committed full heap size, heap hasn't been shrunk?%n" |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
142 + "%s = %s%n%s = %s", |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
143 MIN_FREE_RATIO_FLAG_NAME, |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
144 ManagementFactoryHelper.getDiagnosticMXBean().getVMOption(MIN_FREE_RATIO_FLAG_NAME).getValue(), |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
145 MAX_FREE_RATIO_FLAG_NAME, |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
146 ManagementFactoryHelper.getDiagnosticMXBean().getVMOption(MAX_FREE_RATIO_FLAG_NAME).getValue() |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
147 ); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
148 } |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
149 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
150 private static void allocateList(List garbage, int count, int size) { |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
151 for (int i = 0; i < count; i++) { |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
152 garbage.add(new byte[size]); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
153 } |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
154 } |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
155 } |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
156 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
157 static MemoryUsage getHeapMemoryUsage() { |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
158 return ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
159 } |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
160 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
161 /** |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
162 * Prints memory usage to standard output |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
163 */ |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
164 static class MemoryUsagePrinter { |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
165 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
166 public static String humanReadableByteCount(long bytes, boolean si) { |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
167 int unit = si ? 1000 : 1024; |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
168 if (bytes < unit) { |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
169 return bytes + " B"; |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
170 } |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
171 int exp = (int) (Math.log(bytes) / Math.log(unit)); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
172 String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i"); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
173 return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
174 } |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
175 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
176 public static void printMemoryUsage(String label) { |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
177 MemoryUsage memusage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
178 float freeratio = 1f - (float) memusage.getUsed() / memusage.getCommitted(); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
179 System.out.format("[%-24s] init: %-7s, used: %-7s, comm: %-7s, freeRatio ~= %.1f%%%n", |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
180 label, |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
181 humanReadableByteCount(memusage.getInit(), false), |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
182 humanReadableByteCount(memusage.getUsed(), false), |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
183 humanReadableByteCount(memusage.getCommitted(), false), |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
184 freeratio * 100 |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
185 ); |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
186 } |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
187 } |
df66e3a3c4c2
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
188 } |