test/hotspot/jtreg/gc/g1/TestHumongousShrinkHeap.java
author phh
Sat, 30 Nov 2019 14:33:05 -0800
changeset 59330 5b96c12f909d
parent 53694 a0a327cae58f
permissions -rw-r--r--
8234541: C1 emits an empty message when it inlines successfully Summary: Use "inline" as the message when successfull Reviewed-by: thartmann, mdoerr Contributed-by: navy.xliu@gmail.com
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
/*
53523
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 51287
diff changeset
     2
 * Copyright (c) 2014, 2019, 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
53523
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 51287
diff changeset
    24
package gc.g1;
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 51287
diff changeset
    25
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
    26
/**
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    27
 * @test TestHumongousShrinkHeap
26321
18d281f5acae 8056043: Heap does not shrink within the heap after JDK-8038423
tschatzl
parents: 24841
diff changeset
    28
 * @bug 8036025 8056043
39414
4adf52148100 8160088: update hotspot tests depending on GC to use @requires vm.gc.X
dfazunen
parents: 38152
diff changeset
    29
 * @requires vm.gc.G1
27605
a162df7acd89 8064716: TestHumongousShrinkHeap.java can not be run with -XX:+ExplicitGCInvokesConcurrent
azakharov
parents: 26695
diff changeset
    30
 * @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
    31
 * due to humongous objects
43403
9a09e7b9f0e1 8170860: Get rid of the humanReadableByteCount() method in openjdk/hotspot
dfazunen
parents: 42022
diff changeset
    32
 * @library /test/lib /
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 32624
diff changeset
    33
 * @modules java.base/jdk.internal.misc
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 27694
diff changeset
    34
 * @modules java.management/sun.management
27605
a162df7acd89 8064716: TestHumongousShrinkHeap.java can not be run with -XX:+ExplicitGCInvokesConcurrent
azakharov
parents: 26695
diff changeset
    35
 * @run main/othervm -XX:-ExplicitGCInvokesConcurrent -XX:MinHeapFreeRatio=10
a162df7acd89 8064716: TestHumongousShrinkHeap.java can not be run with -XX:+ExplicitGCInvokesConcurrent
azakharov
parents: 26695
diff changeset
    36
 * -XX:MaxHeapFreeRatio=12 -XX:+UseG1GC -XX:G1HeapRegionSize=1M -verbose:gc
53523
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 51287
diff changeset
    37
 * gc.g1.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
    38
 */
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
30247
9925b07bba5b 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 29678
diff changeset
    40
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
    41
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
    42
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
    43
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
    44
import java.util.List;
43403
9a09e7b9f0e1 8170860: Get rid of the humanReadableByteCount() method in openjdk/hotspot
dfazunen
parents: 42022
diff changeset
    45
import java.text.NumberFormat;
9a09e7b9f0e1 8170860: Get rid of the humanReadableByteCount() method in openjdk/hotspot
dfazunen
parents: 42022
diff changeset
    46
import gc.testlibrary.Helpers;
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 30247
diff changeset
    47
import static jdk.test.lib.Asserts.*;
51287
7b1ddbafa134 8208655: use JTreg skipped status in hotspot tests
iignatyev
parents: 47216
diff changeset
    48
import jtreg.SkippedException;
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
    49
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 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
    51
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    52
    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
    53
    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
    54
53694
a0a327cae58f 8217332: JTREG: Clean up, use generics instead of raw types
lkorinth
parents: 53523
diff changeset
    55
    private static final List<List<byte[]>> garbage = new ArrayList<>();
26695
18baf1a5a8ce 8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents: 26321
diff changeset
    56
    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
    57
    private static final int LISTS_COUNT = 10;
18baf1a5a8ce 8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents: 26321
diff changeset
    58
    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
    59
42022
3d15294ea920 8166724: gc/g1/TestHumongousShrinkHeap.java fails with OOME
lmesnik
parents: 40631
diff changeset
    60
    private static final long TOTAL_MEMORY = Runtime.getRuntime().totalMemory();
3d15294ea920 8166724: gc/g1/TestHumongousShrinkHeap.java fails with OOME
lmesnik
parents: 40631
diff changeset
    61
    private static final long MAX_MEMORY = Runtime.getRuntime().maxMemory();
3d15294ea920 8166724: gc/g1/TestHumongousShrinkHeap.java fails with OOME
lmesnik
parents: 40631
diff changeset
    62
3d15294ea920 8166724: gc/g1/TestHumongousShrinkHeap.java fails with OOME
lmesnik
parents: 40631
diff changeset
    63
    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
    64
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
    65
    public static void main(String[] args) {
32624
42a9450265ae 8132709: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java might fail on embedded
dfazunen
parents: 30604
diff changeset
    66
        if (HUMON_COUNT == 0) {
51287
7b1ddbafa134 8208655: use JTreg skipped status in hotspot tests
iignatyev
parents: 47216
diff changeset
    67
            throw new SkippedException("Heap is too small");
32624
42a9450265ae 8132709: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java might fail on embedded
dfazunen
parents: 30604
diff changeset
    68
        }
42022
3d15294ea920 8166724: gc/g1/TestHumongousShrinkHeap.java fails with OOME
lmesnik
parents: 40631
diff changeset
    69
3d15294ea920 8166724: gc/g1/TestHumongousShrinkHeap.java fails with OOME
lmesnik
parents: 40631
diff changeset
    70
        if (TOTAL_MEMORY + REGION_SIZE * HUMON_COUNT > MAX_MEMORY) {
51287
7b1ddbafa134 8208655: use JTreg skipped status in hotspot tests
iignatyev
parents: 47216
diff changeset
    71
            throw new SkippedException("Initial heap size is to close to max heap size.");
42022
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
3d15294ea920 8166724: gc/g1/TestHumongousShrinkHeap.java fails with OOME
lmesnik
parents: 40631
diff changeset
    74
        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
    75
                          + "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
    76
                          MemoryUsagePrinter.NF.format(TOTAL_MEMORY),
9a09e7b9f0e1 8170860: Get rid of the humanReadableByteCount() method in openjdk/hotspot
dfazunen
parents: 42022
diff changeset
    77
                          MemoryUsagePrinter.NF.format(MAX_MEMORY),
9a09e7b9f0e1 8170860: Get rid of the humanReadableByteCount() method in openjdk/hotspot
dfazunen
parents: 42022
diff changeset
    78
                          MemoryUsagePrinter.NF.format(HUMON_SIZE),
42022
3d15294ea920 8166724: gc/g1/TestHumongousShrinkHeap.java fails with OOME
lmesnik
parents: 40631
diff changeset
    79
                          HUMON_COUNT
26695
18baf1a5a8ce 8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents: 26321
diff changeset
    80
        );
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
    81
        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
    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
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
    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
    85
        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
    86
        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
    87
26695
18baf1a5a8ce 8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents: 26321
diff changeset
    88
        allocate();
18baf1a5a8ce 8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents: 26321
diff changeset
    89
        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
    90
        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
    91
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
        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
        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
    94
        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
    95
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
        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
    97
                "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
    98
                + "%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
    99
                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
   100
                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
   101
                    .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
   102
                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
   103
                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
   104
                    .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
   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
    }
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   107
26695
18baf1a5a8ce 8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents: 26321
diff changeset
   108
    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
   109
26695
18baf1a5a8ce 8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents: 26321
diff changeset
   110
        for (int i = 0; i < LISTS_COUNT; i++) {
53694
a0a327cae58f 8217332: JTREG: Clean up, use generics instead of raw types
lkorinth
parents: 53523
diff changeset
   111
            List<byte[]> stuff = new ArrayList<>();
26695
18baf1a5a8ce 8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents: 26321
diff changeset
   112
            allocateList(stuff, HUMON_COUNT, HUMON_SIZE);
18baf1a5a8ce 8056237: [TESTBUG] gc/g1/TestHumongousShrinkHeap.java fails due to OOM
jwilhelm
parents: 26321
diff changeset
   113
            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
   114
            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
   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
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
    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
   119
        // 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
   120
        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
   121
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   122
        // do not free last one element from last list
53694
a0a327cae58f 8217332: JTREG: Clean up, use generics instead of raw types
lkorinth
parents: 53523
diff changeset
   123
        List<byte[]> 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
   124
        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
   125
        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
   126
    }
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   127
53694
a0a327cae58f 8217332: JTREG: Clean up, use generics instead of raw types
lkorinth
parents: 53523
diff changeset
   128
    private static void allocateList(List<byte[]> 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
   129
        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
   130
            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
   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
/**
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
 * 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
   137
 */
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
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
   139
43403
9a09e7b9f0e1 8170860: Get rid of the humanReadableByteCount() method in openjdk/hotspot
dfazunen
parents: 42022
diff changeset
   140
    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
   141
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
    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
   143
        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
   144
        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
   145
        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
   146
                label,
43403
9a09e7b9f0e1 8170860: Get rid of the humanReadableByteCount() method in openjdk/hotspot
dfazunen
parents: 42022
diff changeset
   147
                NF.format(memusage.getInit()),
9a09e7b9f0e1 8170860: Get rid of the humanReadableByteCount() method in openjdk/hotspot
dfazunen
parents: 42022
diff changeset
   148
                NF.format(memusage.getUsed()),
9a09e7b9f0e1 8170860: Get rid of the humanReadableByteCount() method in openjdk/hotspot
dfazunen
parents: 42022
diff changeset
   149
                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
   150
                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
   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
    }
99374b567304 8037925: CMM Testing: an allocated humongous object at the end of the heap should not prevents shrinking the heap
jwilhelm
parents:
diff changeset
   153
}