annotate test/gc/g1/TestShrinkDefragmentedHeap.java @ 20623:7a6313074325

8064716: TestHumongousShrinkHeap.java can not be run with -XX:+ExplicitGCInvokesConcurrent 8062957: Heap is not shrunk when deallocating under memory pressure Summary: Added explicit -XX:-ExplicitGCInvokesConcurrent to invocations Reviewed-by: brutisso, tschatzl
author azakharov
date Fri, 14 Nov 2014 17:39:07 +0400
parents df66e3a3c4c2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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,
20623
7a6313074325 8064716: TestHumongousShrinkHeap.java can not be run with -XX:+ExplicitGCInvokesConcurrent
azakharov
parents: 20460
diff changeset
62 "-XX:-ExplicitGCInvokesConcurrent",
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
63 "-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
64 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
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
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 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
68 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
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
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 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
72
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 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
74 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
75 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
76
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 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
78
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_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
80 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
81 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
82 // 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
83 // 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
84 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
85 (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
86 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
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
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 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
90
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 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
92 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
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
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 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
96 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
97
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 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
99 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
100 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
101 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
102
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 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
104 //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
105 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
106 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
107
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 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
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
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 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
112 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
113 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
114 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
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
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 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
118 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
119 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
120 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
121
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 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
123 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
124 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
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
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 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
129 // 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
130 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
131
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 // 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
133 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
134 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
135 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
136 }
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 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
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
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 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
141 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
142 "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
143 + "%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
144 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
145 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
146 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
147 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
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
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 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
152 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
153 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
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
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 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
159 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
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 /**
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 * 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
164 */
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 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
166
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 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
168 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
169 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
170 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
171 }
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 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
173 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
174 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
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
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 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
178 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
179 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
180 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
181 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
182 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
183 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
184 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
185 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
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 }
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
189 }