hotspot/test/gc/parallelScavenge/TestDynShrinkHeap.java
author pliden
Fri, 30 May 2014 10:37:39 +0200
changeset 24841 5fc47eabda8b
parent 24667 38c5d155aee9
child 26573 dca8faae7397
permissions -rw-r--r--
8044132: Quarantine unstable/broken GC tests Reviewed-by: ehelin, jwilhelm
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24095
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
     1
/*
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
     4
 *
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
     8
 *
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    13
 * accompanied this code).
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    14
 *
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    18
 *
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    21
 * questions.
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    22
 */
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    23
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    24
/**
24841
5fc47eabda8b 8044132: Quarantine unstable/broken GC tests
pliden
parents: 24667
diff changeset
    25
 * @ignore 8042051
24095
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    26
 * @test TestDynShrinkHeap
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    27
 * @bug 8016479
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    28
 * @summary Verify that the heap shrinks after full GC according to the current values of the Min/MaxHeapFreeRatio flags
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    29
 * @library /testlibrary
24667
38c5d155aee9 8040250: The test test/gc/parallelScavenge/TestDynShrinkHeap.java fails with OOME
iignatyev
parents: 24473
diff changeset
    30
 * @run main/othervm -XX:+UseAdaptiveSizePolicyWithSystemGC -XX:+UseParallelGC -XX:MinHeapFreeRatio=0 -XX:MaxHeapFreeRatio=100 -Xmx1g -verbose:gc TestDynShrinkHeap
24095
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    31
 */
24473
1227042cdc67 8039489: Refactor test framework for dynamic VM options
iignatyev
parents: 24095
diff changeset
    32
import com.oracle.java.testlibrary.DynamicVMOption;
24095
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    33
import java.lang.management.ManagementFactory;
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    34
import java.lang.management.MemoryUsage;
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    35
import java.util.ArrayList;
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    36
import sun.management.ManagementFactoryHelper;
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    37
import static com.oracle.java.testlibrary.Asserts.*;
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    38
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    39
public class TestDynShrinkHeap {
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    40
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    41
    public static final String MIN_FREE_RATIO_FLAG_NAME = "MinHeapFreeRatio";
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    42
    public static final String MAX_FREE_RATIO_FLAG_NAME = "MaxHeapFreeRatio";
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    43
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    44
    private static ArrayList<byte[]> list = new ArrayList<>(0);
24667
38c5d155aee9 8040250: The test test/gc/parallelScavenge/TestDynShrinkHeap.java fails with OOME
iignatyev
parents: 24473
diff changeset
    45
    private static final int LEN = 512 * 1024 + 1;
24095
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    46
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    47
    public TestDynShrinkHeap() {
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    48
    }
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    49
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    50
    private final void test() {
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    51
        System.gc();
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    52
        MemoryUsagePrinter.printMemoryUsage("init");
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    53
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    54
        eat();
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    55
        MemoryUsagePrinter.printMemoryUsage("eaten");
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    56
        MemoryUsage muFull = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    57
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    58
        free();
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    59
        MemoryUsagePrinter.printMemoryUsage("free");
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    60
        MemoryUsage muFree = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    61
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    62
        assertLessThan(muFree.getCommitted(), muFull.getCommitted(), String.format(
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    63
                "committed free heap size is not less than committed full heap size, heap hasn't been shrunk?%n"
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    64
                + "%s = %s%n%s = %s",
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    65
                MIN_FREE_RATIO_FLAG_NAME,
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    66
                ManagementFactoryHelper.getDiagnosticMXBean().getVMOption(MIN_FREE_RATIO_FLAG_NAME).getValue(),
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    67
                MAX_FREE_RATIO_FLAG_NAME,
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    68
                ManagementFactoryHelper.getDiagnosticMXBean().getVMOption(MAX_FREE_RATIO_FLAG_NAME).getValue()
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    69
        ));
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    70
    }
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    71
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    72
    private void eat() {
24667
38c5d155aee9 8040250: The test test/gc/parallelScavenge/TestDynShrinkHeap.java fails with OOME
iignatyev
parents: 24473
diff changeset
    73
        for (int i = 0; i < LEN; i++) {
24095
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    74
            list.add(new byte[1024]);
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    75
        }
24667
38c5d155aee9 8040250: The test test/gc/parallelScavenge/TestDynShrinkHeap.java fails with OOME
iignatyev
parents: 24473
diff changeset
    76
        MemoryUsagePrinter.printMemoryUsage("allocated " + LEN + " arrays");
24095
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    77
24667
38c5d155aee9 8040250: The test test/gc/parallelScavenge/TestDynShrinkHeap.java fails with OOME
iignatyev
parents: 24473
diff changeset
    78
        list.subList(0, LEN / 2).clear();
24095
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    79
        System.gc();
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    80
        MemoryUsagePrinter.printMemoryUsage("array halved");
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    81
    }
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    82
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    83
    private void free() {
24473
1227042cdc67 8039489: Refactor test framework for dynamic VM options
iignatyev
parents: 24095
diff changeset
    84
        int min = DynamicVMOption.getInt(MIN_FREE_RATIO_FLAG_NAME);
1227042cdc67 8039489: Refactor test framework for dynamic VM options
iignatyev
parents: 24095
diff changeset
    85
        DynamicVMOption.setInt(MAX_FREE_RATIO_FLAG_NAME, min);
24095
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    86
        System.gc();
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    87
        MemoryUsagePrinter.printMemoryUsage("under pressure");
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    88
    }
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    89
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    90
    public static void main(String[] args) {
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    91
        new TestDynShrinkHeap().test();
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    92
    }
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    93
}
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    94
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    95
/**
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    96
 * Prints memory usage to standard output
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    97
 */
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    98
class MemoryUsagePrinter {
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    99
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   100
    public static String humanReadableByteCount(long bytes, boolean si) {
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   101
        int unit = si ? 1000 : 1024;
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   102
        if (bytes < unit) {
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   103
            return bytes + " B";
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   104
        }
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   105
        int exp = (int) (Math.log(bytes) / Math.log(unit));
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   106
        String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i");
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   107
        return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   108
    }
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   109
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   110
    public static void printMemoryUsage(String label) {
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   111
        MemoryUsage memusage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   112
        float freeratio = 1f - (float) memusage.getUsed() / memusage.getCommitted();
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   113
        System.out.format("[%-24s] init: %-7s, used: %-7s, comm: %-7s, freeRatio ~= %.1f%%%n",
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   114
                label,
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   115
                humanReadableByteCount(memusage.getInit(), true),
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   116
                humanReadableByteCount(memusage.getUsed(), true),
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   117
                humanReadableByteCount(memusage.getCommitted(), true),
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   118
                freeratio * 100
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   119
        );
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   120
    }
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   121
}