test/hotspot/jtreg/gc/g1/TestHumongousShrinkHeap.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 43403 hotspot/test/gc/g1/TestHumongousShrinkHeap.java@9a09e7b9f0e1
child 51287 7b1ddbafa134
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24097
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
     1
/*
39414
4adf52148100 8160088: update hotspot tests depending on GC to use @requires vm.gc.X
dfazunen
parents: 38152
diff changeset
     2
 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
24097
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
     4
 *
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
     8
 *
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    13
 * accompanied this code).
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    14
 *
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    18
 *
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    21
 * questions.
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    22
 */
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    23
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    24
/**
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    25
 * @test TestHumongousShrinkHeap
26321
18d281f5acae 8056043: Heap does not shrink within the heap after JDK-8038423
tschatzl
parents: 24841
diff changeset
    26
 * @bug 8036025 8056043
39414
4adf52148100 8160088: update hotspot tests depending on GC to use @requires vm.gc.X
dfazunen
parents: 38152
diff changeset
    27
 * @requires vm.gc.G1
27605
a162df7acd89 8064716: TestHumongousShrinkHeap.java can not be run with -XX:+ExplicitGCInvokesConcurrent
azakharov
parents: 26695
diff changeset
    28
 * @summary Verify that heap shrinks after GC in the presence of fragmentation
a162df7acd89 8064716: TestHumongousShrinkHeap.java can not be run with -XX:+ExplicitGCInvokesConcurrent
azakharov
parents: 26695
diff changeset
    29
 * due to humongous objects
43403
9a09e7b9f0e1 8170860: Get rid of the humanReadableByteCount() method in openjdk/hotspot
dfazunen
parents: 42022
diff changeset
    30
 * @library /test/lib /
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 32624
diff changeset
    31
 * @modules java.base/jdk.internal.misc
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 27694
diff changeset
    32
 * @modules java.management/sun.management
27605
a162df7acd89 8064716: TestHumongousShrinkHeap.java can not be run with -XX:+ExplicitGCInvokesConcurrent
azakharov
parents: 26695
diff changeset
    33
 * @run main/othervm -XX:-ExplicitGCInvokesConcurrent -XX:MinHeapFreeRatio=10
a162df7acd89 8064716: TestHumongousShrinkHeap.java can not be run with -XX:+ExplicitGCInvokesConcurrent
azakharov
parents: 26695
diff changeset
    34
 * -XX:MaxHeapFreeRatio=12 -XX:+UseG1GC -XX:G1HeapRegionSize=1M -verbose:gc
a162df7acd89 8064716: TestHumongousShrinkHeap.java can not be run with -XX:+ExplicitGCInvokesConcurrent
azakharov
parents: 26695
diff changeset
    35
 * TestHumongousShrinkHeap
24097
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    36
 */
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    37
30247
9925b07bba5b 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 29678
diff changeset
    38
import com.sun.management.HotSpotDiagnosticMXBean;
24097
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    39
import java.lang.management.ManagementFactory;
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    40
import java.lang.management.MemoryUsage;
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    41
import java.util.ArrayList;
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    42
import java.util.List;
43403
9a09e7b9f0e1 8170860: Get rid of the humanReadableByteCount() method in openjdk/hotspot
dfazunen
parents: 42022
diff changeset
    43
import java.text.NumberFormat;
9a09e7b9f0e1 8170860: Get rid of the humanReadableByteCount() method in openjdk/hotspot
dfazunen
parents: 42022
diff changeset
    44
import gc.testlibrary.Helpers;
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 30247
diff changeset
    45
import static jdk.test.lib.Asserts.*;
24097
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    46
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    47
public class TestHumongousShrinkHeap {
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    48
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    49
    public static final String MIN_FREE_RATIO_FLAG_NAME = "MinHeapFreeRatio";
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    50
    public static final String MAX_FREE_RATIO_FLAG_NAME = "MaxHeapFreeRatio";
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    51
26695
18baf1a5a8ce 8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents: 26321
diff changeset
    52
    private static final List<List<byte[]>> garbage = new ArrayList();
18baf1a5a8ce 8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents: 26321
diff changeset
    53
    private static final int REGION_SIZE = 1024 * 1024; // 1M
18baf1a5a8ce 8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents: 26321
diff changeset
    54
    private static final int LISTS_COUNT = 10;
18baf1a5a8ce 8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents: 26321
diff changeset
    55
    private static final int HUMON_SIZE = Math.round(.9f * REGION_SIZE);
24097
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    56
42022
3d15294ea920 8166724: gc/g1/TestHumongousShrinkHeap.java fails with OOME
lmesnik
parents: 40631
diff changeset
    57
    private static final long TOTAL_MEMORY = Runtime.getRuntime().totalMemory();
3d15294ea920 8166724: gc/g1/TestHumongousShrinkHeap.java fails with OOME
lmesnik
parents: 40631
diff changeset
    58
    private static final long MAX_MEMORY = Runtime.getRuntime().maxMemory();
3d15294ea920 8166724: gc/g1/TestHumongousShrinkHeap.java fails with OOME
lmesnik
parents: 40631
diff changeset
    59
3d15294ea920 8166724: gc/g1/TestHumongousShrinkHeap.java fails with OOME
lmesnik
parents: 40631
diff changeset
    60
    private static final int HUMON_COUNT = (int) ((TOTAL_MEMORY / HUMON_SIZE) / LISTS_COUNT);
24097
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    61
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    62
    public static void main(String[] args) {
32624
42a9450265ae 8132709: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java might fail on embedded
dfazunen
parents: 30604
diff changeset
    63
        if (HUMON_COUNT == 0) {
42a9450265ae 8132709: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java might fail on embedded
dfazunen
parents: 30604
diff changeset
    64
            System.out.println("Skipped. Heap is too small");
42a9450265ae 8132709: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java might fail on embedded
dfazunen
parents: 30604
diff changeset
    65
            return;
42a9450265ae 8132709: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java might fail on embedded
dfazunen
parents: 30604
diff changeset
    66
        }
42022
3d15294ea920 8166724: gc/g1/TestHumongousShrinkHeap.java fails with OOME
lmesnik
parents: 40631
diff changeset
    67
3d15294ea920 8166724: gc/g1/TestHumongousShrinkHeap.java fails with OOME
lmesnik
parents: 40631
diff changeset
    68
        if (TOTAL_MEMORY + REGION_SIZE * HUMON_COUNT > MAX_MEMORY) {
3d15294ea920 8166724: gc/g1/TestHumongousShrinkHeap.java fails with OOME
lmesnik
parents: 40631
diff changeset
    69
            System.out.println("Skipped. Initial heap size is to close to max heap size.");
3d15294ea920 8166724: gc/g1/TestHumongousShrinkHeap.java fails with OOME
lmesnik
parents: 40631
diff changeset
    70
            return;
3d15294ea920 8166724: gc/g1/TestHumongousShrinkHeap.java fails with OOME
lmesnik
parents: 40631
diff changeset
    71
        }
3d15294ea920 8166724: gc/g1/TestHumongousShrinkHeap.java fails with OOME
lmesnik
parents: 40631
diff changeset
    72
3d15294ea920 8166724: gc/g1/TestHumongousShrinkHeap.java fails with OOME
lmesnik
parents: 40631
diff changeset
    73
        System.out.format("Running with %s initial heap size of %s maximum heap size. "
3d15294ea920 8166724: gc/g1/TestHumongousShrinkHeap.java fails with OOME
lmesnik
parents: 40631
diff changeset
    74
                          + "Will allocate humongous object of %s size %d times.%n",
43403
9a09e7b9f0e1 8170860: Get rid of the humanReadableByteCount() method in openjdk/hotspot
dfazunen
parents: 42022
diff changeset
    75
                          MemoryUsagePrinter.NF.format(TOTAL_MEMORY),
9a09e7b9f0e1 8170860: Get rid of the humanReadableByteCount() method in openjdk/hotspot
dfazunen
parents: 42022
diff changeset
    76
                          MemoryUsagePrinter.NF.format(MAX_MEMORY),
9a09e7b9f0e1 8170860: Get rid of the humanReadableByteCount() method in openjdk/hotspot
dfazunen
parents: 42022
diff changeset
    77
                          MemoryUsagePrinter.NF.format(HUMON_SIZE),
42022
3d15294ea920 8166724: gc/g1/TestHumongousShrinkHeap.java fails with OOME
lmesnik
parents: 40631
diff changeset
    78
                          HUMON_COUNT
26695
18baf1a5a8ce 8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents: 26321
diff changeset
    79
        );
24097
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    80
        new TestHumongousShrinkHeap().test();
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    81
    }
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    82
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    83
    private final void test() {
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    84
        System.gc();
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    85
        MemoryUsagePrinter.printMemoryUsage("init");
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    86
26695
18baf1a5a8ce 8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents: 26321
diff changeset
    87
        allocate();
18baf1a5a8ce 8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents: 26321
diff changeset
    88
        MemoryUsagePrinter.printMemoryUsage("allocated");
24097
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    89
        MemoryUsage muFull = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    90
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    91
        free();
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    92
        MemoryUsagePrinter.printMemoryUsage("free");
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    93
        MemoryUsage muFree = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    94
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    95
        assertLessThan(muFree.getCommitted(), muFull.getCommitted(), String.format(
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    96
                "committed free heap size is not less than committed full heap size, heap hasn't been shrunk?%n"
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    97
                + "%s = %s%n%s = %s",
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    98
                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
    99
                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
   100
                    .getVMOption(MIN_FREE_RATIO_FLAG_NAME).getValue(),
24097
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   101
                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
   102
                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
   103
                    .getVMOption(MAX_FREE_RATIO_FLAG_NAME).getValue()
24097
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   104
        ));
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   105
    }
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   106
26695
18baf1a5a8ce 8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents: 26321
diff changeset
   107
    private void allocate() {
24097
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   108
26695
18baf1a5a8ce 8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents: 26321
diff changeset
   109
        for (int i = 0; i < LISTS_COUNT; i++) {
18baf1a5a8ce 8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents: 26321
diff changeset
   110
            List<byte[]> stuff = new ArrayList();
18baf1a5a8ce 8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents: 26321
diff changeset
   111
            allocateList(stuff, HUMON_COUNT, HUMON_SIZE);
18baf1a5a8ce 8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents: 26321
diff changeset
   112
            MemoryUsagePrinter.printMemoryUsage("allocate #" + (i+1));
24097
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   113
            garbage.add(stuff);
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   114
        }
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   115
    }
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   116
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   117
    private void free() {
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   118
        // do not free last one list
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   119
        garbage.subList(0, garbage.size() - 1).clear();
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   120
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   121
        // do not free last one element from last list
26695
18baf1a5a8ce 8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents: 26321
diff changeset
   122
        List stuff = garbage.get(garbage.size() - 1);
24097
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   123
        stuff.subList(0, stuff.size() - 1).clear();
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   124
        System.gc();
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   125
    }
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   126
26695
18baf1a5a8ce 8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents: 26321
diff changeset
   127
    private static void allocateList(List garbage, int count, int size) {
24097
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   128
        for (int i = 0; i < count; i++) {
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   129
            garbage.add(new byte[size]);
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   130
        }
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   131
    }
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   132
}
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   133
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   134
/**
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   135
 * Prints memory usage to standard output
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   136
 */
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   137
class MemoryUsagePrinter {
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   138
43403
9a09e7b9f0e1 8170860: Get rid of the humanReadableByteCount() method in openjdk/hotspot
dfazunen
parents: 42022
diff changeset
   139
    public static final NumberFormat NF = Helpers.numberFormatter();
24097
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   140
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   141
    public static void printMemoryUsage(String label) {
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   142
        MemoryUsage memusage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   143
        float freeratio = 1f - (float) memusage.getUsed() / memusage.getCommitted();
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   144
        System.out.format("[%-24s] init: %-7s, used: %-7s, comm: %-7s, freeRatio ~= %.1f%%%n",
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   145
                label,
43403
9a09e7b9f0e1 8170860: Get rid of the humanReadableByteCount() method in openjdk/hotspot
dfazunen
parents: 42022
diff changeset
   146
                NF.format(memusage.getInit()),
9a09e7b9f0e1 8170860: Get rid of the humanReadableByteCount() method in openjdk/hotspot
dfazunen
parents: 42022
diff changeset
   147
                NF.format(memusage.getUsed()),
9a09e7b9f0e1 8170860: Get rid of the humanReadableByteCount() method in openjdk/hotspot
dfazunen
parents: 42022
diff changeset
   148
                NF.format(memusage.getCommitted()),
24097
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   149
                freeratio * 100
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   150
        );
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   151
    }
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   152
}