hotspot/test/compiler/codecache/jmx/InitialAndMaxUsageTest.java
author tpivovarova
Sat, 19 Sep 2015 12:03:36 +0300
changeset 33072 71f9b0782023
parent 30604 b8d532cb6420
child 33730 30e064828045
permissions -rw-r--r--
8136693: add package statement 'compiler.testlibrary' to CompilerUtils Reviewed-by: iignatyev
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28384
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
     1
/*
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 28922
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
28384
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
     4
 *
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
     8
 *
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    13
 * accompanied this code).
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    14
 *
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    18
 *
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    21
 * questions.
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    22
 */
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    23
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 29678
diff changeset
    24
import jdk.test.lib.Asserts;
28384
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    25
import java.lang.management.MemoryPoolMXBean;
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    26
import java.util.ArrayList;
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    27
import java.util.List;
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    28
import sun.hotspot.code.BlobType;
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    29
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    30
/*
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    31
 * @test InitialAndMaxUsageTest
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    32
 * @library /testlibrary /../../test/lib
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 28922
diff changeset
    33
 * @modules java.base/sun.misc
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 28922
diff changeset
    34
 *          java.management
28384
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    35
 * @build InitialAndMaxUsageTest
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    36
 * @run main ClassFileInstaller sun.hotspot.WhiteBox
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    37
 *     sun.hotspot.WhiteBox$WhiteBoxPermission
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    38
 * @run main/othervm -Xbootclasspath/a:. -XX:-UseCodeCacheFlushing
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    39
 *     -XX:-MethodFlushing -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    40
 *     -XX:+SegmentedCodeCache -XX:CompileCommand=compileonly,null::*
28922
bff1596d4b44 8071995: compiler/codecache/jmx/InitialAndMaxUsageTest.java fails with large pages
thartmann
parents: 28384
diff changeset
    41
 *     -XX:-UseLargePages InitialAndMaxUsageTest
28384
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    42
 * @summary testing of initial and max usage
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    43
 */
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    44
public class InitialAndMaxUsageTest {
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    45
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    46
    private static final double CACHE_USAGE_COEF = 0.95d;
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    47
    private final BlobType btype;
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    48
    private final boolean lowerBoundIsZero;
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    49
    private final long maxSize;
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    50
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    51
    public InitialAndMaxUsageTest(BlobType btype) {
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    52
        this.btype = btype;
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    53
        this.maxSize = btype.getSize();
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    54
        /* Only profiled code cache initial size should be 0, because of
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    55
         -XX:CompileCommand=compileonly,null::* non-methods might be not empty,
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    56
         as well as non-profiled methods, because it's used as fallback in
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    57
         case non-methods is full */
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    58
        lowerBoundIsZero = btype == BlobType.MethodProfiled;
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    59
    }
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    60
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    61
    public static void main(String[] args) {
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    62
        for (BlobType btype : BlobType.getAvailable()) {
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    63
            new InitialAndMaxUsageTest(btype).runTest();
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    64
        }
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    65
    }
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    66
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    67
    private void fillWithSize(long size, List<Long> blobs) {
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    68
        long blob;
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    69
        while ((blob = CodeCacheUtils.WB.allocateCodeBlob(size, btype.id))
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    70
                != 0L) {
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    71
            blobs.add(blob);
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    72
        }
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    73
    }
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    74
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    75
    protected void runTest() {
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    76
        long headerSize = CodeCacheUtils.getHeaderSize(btype);
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    77
        MemoryPoolMXBean bean = btype.getMemoryPool();
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    78
        long initialUsage = btype.getMemoryPool().getUsage().getUsed();
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    79
        System.out.printf("INFO: trying to test %s of max size %d and initial"
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    80
                + " usage %d%n", bean.getName(), maxSize, initialUsage);
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    81
        Asserts.assertLT(initialUsage + headerSize + 1L, maxSize,
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    82
                "Initial usage is close to total size for " + bean.getName());
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    83
        if (lowerBoundIsZero) {
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    84
            Asserts.assertEQ(initialUsage, 0L, "Unexpected initial usage");
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    85
        }
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    86
        ArrayList<Long> blobs = new ArrayList<>();
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    87
        long minAllocationUnit = CodeCacheUtils.MIN_ALLOCATION - headerSize;
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    88
        /* now filling code cache with large-sized allocation first, since
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    89
         lots of small allocations takes too much time, so, just a small
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    90
         optimization */
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    91
        try {
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    92
            for (int coef = 1000000; coef > 0; coef /= 10) {
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    93
                fillWithSize(coef * minAllocationUnit, blobs);
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    94
            }
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    95
            Asserts.assertGT((double) bean.getUsage().getUsed(),
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    96
                    CACHE_USAGE_COEF * maxSize, String.format("Unable to fill "
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    97
                            + "more than %f of %s. Reported usage is %d ",
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    98
                            CACHE_USAGE_COEF, bean.getName(),
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    99
                            bean.getUsage().getUsed()));
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
   100
        } finally {
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
   101
            for (long entry : blobs) {
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
   102
                CodeCacheUtils.WB.freeCodeBlob(entry);
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
   103
            }
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
   104
        }
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
   105
        System.out.printf("INFO: Scenario finished successfully for %s%n",
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
   106
                bean.getName());
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
   107
    }
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
   108
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
   109
}