hotspot/test/gc/parallelScavenge/TestDynShrinkHeap.java
author duke
Wed, 05 Jul 2017 20:15:13 +0200
changeset 28462 8327024a9955
parent 27692 11c231c781dc
child 29466 06fb7dbdbce7
permissions -rw-r--r--
Merge
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
/**
26573
dca8faae7397 8057918: Update out-dated ignore tags in GC jtreg tests
stefank
parents: 24841
diff changeset
    25
 * @ignore 8019361
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
27692
11c231c781dc 8062537: [TESTBUG] Conflicting GC combinations in hotspot tests
eistepan
parents: 26573
diff changeset
    28
 * @requires vm.gc=="Parallel" | vm.gc=="null"
24095
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    29
 * @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
    30
 * @library /testlibrary
24667
38c5d155aee9 8040250: The test test/gc/parallelScavenge/TestDynShrinkHeap.java fails with OOME
iignatyev
parents: 24473
diff changeset
    31
 * @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
    32
 */
24473
1227042cdc67 8039489: Refactor test framework for dynamic VM options
iignatyev
parents: 24095
diff changeset
    33
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
    34
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
    35
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
    36
import java.util.ArrayList;
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    37
import sun.management.ManagementFactoryHelper;
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    38
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
    39
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    40
public class TestDynShrinkHeap {
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    41
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 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
    43
    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
    44
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    45
    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
    46
    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
    47
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    48
    public TestDynShrinkHeap() {
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
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    51
    private final void test() {
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    52
        System.gc();
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    53
        MemoryUsagePrinter.printMemoryUsage("init");
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    54
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    55
        eat();
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    56
        MemoryUsagePrinter.printMemoryUsage("eaten");
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    57
        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
    58
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    59
        free();
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    60
        MemoryUsagePrinter.printMemoryUsage("free");
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    61
        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
    62
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    63
        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
    64
                "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
    65
                + "%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
    66
                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
    67
                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
    68
                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
    69
                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
    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
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    73
    private void eat() {
24667
38c5d155aee9 8040250: The test test/gc/parallelScavenge/TestDynShrinkHeap.java fails with OOME
iignatyev
parents: 24473
diff changeset
    74
        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
    75
            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
    76
        }
24667
38c5d155aee9 8040250: The test test/gc/parallelScavenge/TestDynShrinkHeap.java fails with OOME
iignatyev
parents: 24473
diff changeset
    77
        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
    78
24667
38c5d155aee9 8040250: The test test/gc/parallelScavenge/TestDynShrinkHeap.java fails with OOME
iignatyev
parents: 24473
diff changeset
    79
        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
    80
        System.gc();
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    81
        MemoryUsagePrinter.printMemoryUsage("array halved");
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
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    84
    private void free() {
24473
1227042cdc67 8039489: Refactor test framework for dynamic VM options
iignatyev
parents: 24095
diff changeset
    85
        int min = DynamicVMOption.getInt(MIN_FREE_RATIO_FLAG_NAME);
1227042cdc67 8039489: Refactor test framework for dynamic VM options
iignatyev
parents: 24095
diff changeset
    86
        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
    87
        System.gc();
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    88
        MemoryUsagePrinter.printMemoryUsage("under pressure");
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
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    91
    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
    92
        new TestDynShrinkHeap().test();
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
/**
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    97
 * 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
    98
 */
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
    99
class MemoryUsagePrinter {
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   100
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   101
    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
   102
        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
   103
        if (bytes < unit) {
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   104
            return bytes + " B";
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   105
        }
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   106
        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
   107
        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
   108
        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
   109
    }
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   110
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   111
    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
   112
        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
   113
        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
   114
        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
   115
                label,
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   116
                humanReadableByteCount(memusage.getInit(), true),
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   117
                humanReadableByteCount(memusage.getUsed(), true),
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   118
                humanReadableByteCount(memusage.getCommitted(), true),
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   119
                freeratio * 100
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
    }
5a5cf6765809 8037924: CMM Testing: Check Min/MaxHeapFreeRatio flags allows to shrink the heap when using ParallelGC
jwilhelm
parents:
diff changeset
   122
}