author | tschatzl |
Tue, 19 Jul 2016 10:31:41 +0200 | |
changeset 39979 | b17e445924da |
parent 36851 | 03e2f4d0a421 |
child 40631 | ed82623d7831 |
permissions | -rw-r--r-- |
26694
37ba4a5a3f9c
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 |
/* |
29678
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
27605
diff
changeset
|
2 |
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
26694
37ba4a5a3f9c
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. |
37ba4a5a3f9c
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 |
* |
37ba4a5a3f9c
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 |
37ba4a5a3f9c
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 |
37ba4a5a3f9c
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. |
37ba4a5a3f9c
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 |
* |
37ba4a5a3f9c
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 |
37ba4a5a3f9c
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 |
37ba4a5a3f9c
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 |
37ba4a5a3f9c
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 |
37ba4a5a3f9c
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). |
37ba4a5a3f9c
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 |
* |
37ba4a5a3f9c
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 |
37ba4a5a3f9c
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, |
37ba4a5a3f9c
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. |
37ba4a5a3f9c
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 |
* |
37ba4a5a3f9c
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 |
37ba4a5a3f9c
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 |
37ba4a5a3f9c
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. |
37ba4a5a3f9c
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 |
*/ |
37ba4a5a3f9c
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 |
|
37ba4a5a3f9c
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 |
/** |
37ba4a5a3f9c
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 |
31622
65674ad91414
8129590: TestShrinkDefragmentedHeap.java runs out of memory
sjohanss
parents:
30604
diff
changeset
|
26 |
* @bug 8038423 8129590 |
26694
37ba4a5a3f9c
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 |
37ba4a5a3f9c
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 |
37ba4a5a3f9c
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" |
37ba4a5a3f9c
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 |
37ba4a5a3f9c
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" |
37ba4a5a3f9c
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) |
37ba4a5a3f9c
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 |
* |
37ba4a5a3f9c
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 |
36851 | 35 |
* @modules java.base/jdk.internal.misc |
29678
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
27605
diff
changeset
|
36 |
* java.management/sun.management |
26694
37ba4a5a3f9c
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 |
*/ |
37ba4a5a3f9c
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.lang.management.ManagementFactory; |
37ba4a5a3f9c
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.lang.management.MemoryUsage; |
37ba4a5a3f9c
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 java.util.ArrayList; |
37ba4a5a3f9c
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 java.util.List; |
30604
b8d532cb6420
8067013: Rename the com.oracle.java.testlibary package
ykantser
parents:
30247
diff
changeset
|
42 |
import static jdk.test.lib.Asserts.*; |
b8d532cb6420
8067013: Rename the com.oracle.java.testlibary package
ykantser
parents:
30247
diff
changeset
|
43 |
import jdk.test.lib.ProcessTools; |
b8d532cb6420
8067013: Rename the com.oracle.java.testlibary package
ykantser
parents:
30247
diff
changeset
|
44 |
import jdk.test.lib.OutputAnalyzer; |
30247
9925b07bba5b
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
29678
diff
changeset
|
45 |
import com.sun.management.HotSpotDiagnosticMXBean; |
26694
37ba4a5a3f9c
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 |
|
37ba4a5a3f9c
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 |
public class TestShrinkDefragmentedHeap { |
37ba4a5a3f9c
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 |
// Since we store all the small objects, they become old and old regions are also allocated at the bottom of the heap |
37ba4a5a3f9c
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 |
// together with humongous regions. So if there are a lot of old regions in the lower part of the heap, |
37ba4a5a3f9c
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 |
// the humongous regions will be allocated in the upper part of the heap anyway. |
37ba4a5a3f9c
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 |
// To avoid this the Eden needs to be big enough to fit all the small objects. |
37ba4a5a3f9c
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 INITIAL_HEAP_SIZE = 200 * 1024 * 1024; |
37ba4a5a3f9c
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 |
private static final int MINIMAL_YOUNG_SIZE = 190 * 1024 * 1024; |
31622
65674ad91414
8129590: TestShrinkDefragmentedHeap.java runs out of memory
sjohanss
parents:
30604
diff
changeset
|
54 |
private static final int MAXIMUM_HEAP_SIZE = 256 * 1024 * 1024; |
26694
37ba4a5a3f9c
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 |
private static final int REGION_SIZE = 1 * 1024 * 1024; |
37ba4a5a3f9c
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 |
|
37ba4a5a3f9c
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 |
public static void main(String[] args) throws Exception, Throwable { |
37ba4a5a3f9c
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 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( |
37ba4a5a3f9c
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:InitialHeapSize=" + INITIAL_HEAP_SIZE, |
37ba4a5a3f9c
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 |
"-Xmn" + MINIMAL_YOUNG_SIZE, |
31622
65674ad91414
8129590: TestShrinkDefragmentedHeap.java runs out of memory
sjohanss
parents:
30604
diff
changeset
|
61 |
"-Xmx" + MAXIMUM_HEAP_SIZE, |
26694
37ba4a5a3f9c
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 |
"-XX:MinHeapFreeRatio=10", |
37ba4a5a3f9c
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 |
"-XX:MaxHeapFreeRatio=11", |
37ba4a5a3f9c
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 |
"-XX:+UseG1GC", |
37ba4a5a3f9c
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 |
"-XX:G1HeapRegionSize=" + REGION_SIZE, |
27605
a162df7acd89
8064716: TestHumongousShrinkHeap.java can not be run with -XX:+ExplicitGCInvokesConcurrent
azakharov
parents:
26694
diff
changeset
|
66 |
"-XX:-ExplicitGCInvokesConcurrent", |
26694
37ba4a5a3f9c
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 |
"-verbose:gc", |
37ba4a5a3f9c
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 |
GCTest.class.getName() |
37ba4a5a3f9c
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 |
); |
37ba4a5a3f9c
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 |
|
37ba4a5a3f9c
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 |
OutputAnalyzer output = ProcessTools.executeProcess(pb); |
37ba4a5a3f9c
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 |
output.shouldHaveExitValue(0); |
37ba4a5a3f9c
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 |
} |
37ba4a5a3f9c
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 |
|
37ba4a5a3f9c
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 |
static class GCTest { |
37ba4a5a3f9c
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 |
|
37ba4a5a3f9c
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 String MIN_FREE_RATIO_FLAG_NAME = "MinHeapFreeRatio"; |
37ba4a5a3f9c
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 String MAX_FREE_RATIO_FLAG_NAME = "MaxHeapFreeRatio"; |
37ba4a5a3f9c
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 String NEW_SIZE_FLAG_NAME = "NewSize"; |
37ba4a5a3f9c
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 |
|
37ba4a5a3f9c
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 ArrayList<ArrayList<byte[]>> garbage = new ArrayList<>(); |
37ba4a5a3f9c
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 |
|
37ba4a5a3f9c
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 SMALL_OBJS_SIZE = 10 * 1024; // 10kB |
37ba4a5a3f9c
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 SMALL_OBJS_COUNT = MINIMAL_YOUNG_SIZE / (SMALL_OBJS_SIZE-1); |
37ba4a5a3f9c
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 |
private static final int ALLOCATE_COUNT = 3; |
37ba4a5a3f9c
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 |
// try to put all humongous object into gap between min young size and initial heap size |
37ba4a5a3f9c
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 |
// to avoid implicit GCs |
37ba4a5a3f9c
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 int HUMONG_OBJS_SIZE = (int) Math.max( |
37ba4a5a3f9c
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 |
(INITIAL_HEAP_SIZE - MINIMAL_YOUNG_SIZE) / ALLOCATE_COUNT / 4, |
37ba4a5a3f9c
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 |
REGION_SIZE * 1.1 |
37ba4a5a3f9c
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 |
); |
37ba4a5a3f9c
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 |
|
37ba4a5a3f9c
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 |
private static final long initialHeapSize = getHeapMemoryUsage().getUsed(); |
37ba4a5a3f9c
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 |
|
37ba4a5a3f9c
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 |
public static void main(String[] args) throws InterruptedException { |
37ba4a5a3f9c
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 |
new GCTest().test(); |
37ba4a5a3f9c
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 |
} |
37ba4a5a3f9c
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 |
|
37ba4a5a3f9c
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 |
private void test() throws InterruptedException { |
37ba4a5a3f9c
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("init"); |
37ba4a5a3f9c
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 |
|
37ba4a5a3f9c
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 |
allocate(); |
37ba4a5a3f9c
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 |
System.gc(); |
37ba4a5a3f9c
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 muFull = getHeapMemoryUsage(); |
37ba4a5a3f9c
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("allocated"); |
37ba4a5a3f9c
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 |
|
37ba4a5a3f9c
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 |
free(); |
37ba4a5a3f9c
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 |
//Thread.sleep(1000); // sleep before measures due lags in JMX |
37ba4a5a3f9c
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 |
MemoryUsage muFree = getHeapMemoryUsage(); |
37ba4a5a3f9c
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 |
MemoryUsagePrinter.printMemoryUsage("free"); |
37ba4a5a3f9c
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 |
|
37ba4a5a3f9c
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 |
assertLessThan(muFree.getCommitted(), muFull.getCommitted(), prepareMessageCommittedIsNotLess() ); |
37ba4a5a3f9c
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 |
} |
37ba4a5a3f9c
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 |
|
37ba4a5a3f9c
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 |
private void allocate() { |
37ba4a5a3f9c
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 |
System.out.format("Will allocate objects of small size = %s and humongous size = %s", |
37ba4a5a3f9c
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 |
MemoryUsagePrinter.humanReadableByteCount(SMALL_OBJS_SIZE, false), |
37ba4a5a3f9c
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 |
MemoryUsagePrinter.humanReadableByteCount(HUMONG_OBJS_SIZE, false) |
37ba4a5a3f9c
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 |
); |
37ba4a5a3f9c
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 |
|
37ba4a5a3f9c
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 |
for (int i = 0; i < ALLOCATE_COUNT; i++) { |
37ba4a5a3f9c
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[]> stuff = new ArrayList<>(); |
37ba4a5a3f9c
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(stuff, SMALL_OBJS_COUNT / ALLOCATE_COUNT, SMALL_OBJS_SIZE); |
37ba4a5a3f9c
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(stuff); |
37ba4a5a3f9c
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 |
|
37ba4a5a3f9c
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 |
ArrayList<byte[]> humongousStuff = new ArrayList<>(); |
37ba4a5a3f9c
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 |
allocateList(humongousStuff, 4, HUMONG_OBJS_SIZE); |
37ba4a5a3f9c
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 |
garbage.add(humongousStuff); |
37ba4a5a3f9c
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 |
} |
37ba4a5a3f9c
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 |
} |
37ba4a5a3f9c
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 |
|
37ba4a5a3f9c
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 |
private void free() { |
37ba4a5a3f9c
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 |
// do not free last one list |
37ba4a5a3f9c
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 |
garbage.subList(0, garbage.size() - 1).clear(); |
37ba4a5a3f9c
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 |
|
37ba4a5a3f9c
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 |
// do not free last one element from last list |
37ba4a5a3f9c
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 |
ArrayList stuff = garbage.get(garbage.size() - 1); |
37ba4a5a3f9c
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 |
if (stuff.size() > 1) { |
37ba4a5a3f9c
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 |
stuff.subList(0, stuff.size() - 1).clear(); |
37ba4a5a3f9c
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 |
} |
37ba4a5a3f9c
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 |
System.gc(); |
37ba4a5a3f9c
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 |
} |
37ba4a5a3f9c
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 |
|
37ba4a5a3f9c
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 |
private String prepareMessageCommittedIsNotLess() { |
37ba4a5a3f9c
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 |
return String.format( |
37ba4a5a3f9c
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 |
"committed free heap size is not less than committed full heap size, heap hasn't been shrunk?%n" |
37ba4a5a3f9c
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 |
+ "%s = %s%n%s = %s", |
37ba4a5a3f9c
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 |
MIN_FREE_RATIO_FLAG_NAME, |
30247
9925b07bba5b
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
29678
diff
changeset
|
149 |
ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class) |
9925b07bba5b
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
29678
diff
changeset
|
150 |
.getVMOption(MIN_FREE_RATIO_FLAG_NAME).getValue(), |
26694
37ba4a5a3f9c
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 |
MAX_FREE_RATIO_FLAG_NAME, |
30247
9925b07bba5b
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
29678
diff
changeset
|
152 |
ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class) |
9925b07bba5b
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
29678
diff
changeset
|
153 |
.getVMOption(MAX_FREE_RATIO_FLAG_NAME).getValue() |
26694
37ba4a5a3f9c
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 |
); |
37ba4a5a3f9c
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 |
} |
37ba4a5a3f9c
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 |
|
37ba4a5a3f9c
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 |
private static void allocateList(List garbage, int count, int size) { |
37ba4a5a3f9c
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 |
for (int i = 0; i < count; i++) { |
37ba4a5a3f9c
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 |
garbage.add(new byte[size]); |
37ba4a5a3f9c
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 |
} |
37ba4a5a3f9c
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 |
} |
37ba4a5a3f9c
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 |
} |
37ba4a5a3f9c
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 |
|
37ba4a5a3f9c
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 MemoryUsage getHeapMemoryUsage() { |
37ba4a5a3f9c
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 |
return ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); |
37ba4a5a3f9c
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 |
} |
37ba4a5a3f9c
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 |
|
37ba4a5a3f9c
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 |
/** |
37ba4a5a3f9c
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 |
* Prints memory usage to standard output |
37ba4a5a3f9c
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 |
*/ |
37ba4a5a3f9c
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 |
static class MemoryUsagePrinter { |
37ba4a5a3f9c
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 |
|
37ba4a5a3f9c
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 |
public static String humanReadableByteCount(long bytes, boolean si) { |
37ba4a5a3f9c
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 |
int unit = si ? 1000 : 1024; |
37ba4a5a3f9c
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 |
if (bytes < unit) { |
37ba4a5a3f9c
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 |
return bytes + " B"; |
37ba4a5a3f9c
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 |
} |
37ba4a5a3f9c
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 |
int exp = (int) (Math.log(bytes) / Math.log(unit)); |
37ba4a5a3f9c
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 |
String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i"); |
37ba4a5a3f9c
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 |
return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre); |
37ba4a5a3f9c
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 |
} |
37ba4a5a3f9c
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 |
|
37ba4a5a3f9c
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 |
public static void printMemoryUsage(String label) { |
37ba4a5a3f9c
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 |
MemoryUsage memusage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); |
37ba4a5a3f9c
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 |
float freeratio = 1f - (float) memusage.getUsed() / memusage.getCommitted(); |
37ba4a5a3f9c
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 |
System.out.format("[%-24s] init: %-7s, used: %-7s, comm: %-7s, freeRatio ~= %.1f%%%n", |
37ba4a5a3f9c
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 |
label, |
37ba4a5a3f9c
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 |
humanReadableByteCount(memusage.getInit(), false), |
37ba4a5a3f9c
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 |
humanReadableByteCount(memusage.getUsed(), false), |
37ba4a5a3f9c
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
190 |
humanReadableByteCount(memusage.getCommitted(), false), |
37ba4a5a3f9c
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
191 |
freeratio * 100 |
37ba4a5a3f9c
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
192 |
); |
37ba4a5a3f9c
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
193 |
} |
37ba4a5a3f9c
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
194 |
} |
37ba4a5a3f9c
8041946: CMM Testing: 8u40 an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff
changeset
|
195 |
} |