hotspot/test/compiler/codecache/jmx/GetUsageTest.java
author cjplummer
Thu, 29 Oct 2015 12:04:04 -0700
changeset 33730 30e064828045
parent 31522 2d29f2e927fc
child 36851 03e2f4d0a421
permissions -rw-r--r--
8140189: [TESTBUG] Get rid of "@library /../../test/lib" in jtreg tests Summary: Use new external.lib.roots property in TEST.ROOT so /../../test/lib is not needed. Reviewed-by: mseledtsov, sla, iklam
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: 28384
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.HashMap;
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    27
import java.util.Map;
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 GetUsageTest
33730
30e064828045 8140189: [TESTBUG] Get rid of "@library /../../test/lib" in jtreg tests
cjplummer
parents: 31522
diff changeset
    32
 * @library /testlibrary /test/lib
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 28384
diff changeset
    33
 * @modules java.base/sun.misc
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 28384
diff changeset
    34
 *          java.management
28384
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    35
 * @build GetUsageTest
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:CompileCommand=compileonly,null::*
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    39
 *     -XX:-UseCodeCacheFlushing -XX:-MethodFlushing -XX:+SegmentedCodeCache
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    40
 *     -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI GetUsageTest
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    41
 * @summary testing of getUsage() for segmented code cache
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    42
 */
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    43
public class GetUsageTest {
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    44
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    45
    private final BlobType btype;
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    46
    private final int allocateSize;
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    47
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    48
    public GetUsageTest(BlobType btype, int allocSize) {
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    49
        this.btype = btype;
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    50
        this.allocateSize = allocSize;
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    51
    }
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    52
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    53
    public static void main(String[] args) throws Exception {
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    54
        for (BlobType btype : BlobType.getAvailable()) {
31522
2d29f2e927fc 8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents: 30604
diff changeset
    55
            for (int allocSize = 10; allocSize < 100000; allocSize *= 10) {
2d29f2e927fc 8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents: 30604
diff changeset
    56
                new GetUsageTest(btype, allocSize).runTest();
28384
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    57
            }
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    58
        }
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
    protected final Map<MemoryPoolMXBean, Long> getBeanUsages() {
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    62
        Map<MemoryPoolMXBean, Long> beanUsages = new HashMap<>();
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    63
        for (BlobType bt : BlobType.getAvailable()) {
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    64
            beanUsages.put(bt.getMemoryPool(),
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    65
                    bt.getMemoryPool().getUsage().getUsed());
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
        return beanUsages;
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    68
    }
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    69
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    70
    protected void runTest() {
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    71
        MemoryPoolMXBean[] predictableBeans = BlobType.getAvailable().stream()
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    72
                .filter(CodeCacheUtils::isCodeHeapPredictable)
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    73
                .map(BlobType::getMemoryPool)
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    74
                .toArray(MemoryPoolMXBean[]::new);
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    75
        Map<MemoryPoolMXBean, Long> initial = getBeanUsages();
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    76
        long addr = 0;
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    77
        try {
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    78
            addr = CodeCacheUtils.WB.allocateCodeBlob(allocateSize, btype.id);
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    79
            Map<MemoryPoolMXBean, Long> current = getBeanUsages();
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    80
            long blockCount = Math.floorDiv(allocateSize
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    81
                    + CodeCacheUtils.getHeaderSize(btype)
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    82
                    + CodeCacheUtils.SEGMENT_SIZE - 1, CodeCacheUtils.SEGMENT_SIZE);
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    83
            long usageUpperEstimate = Math.max(blockCount,
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    84
                    CodeCacheUtils.MIN_BLOCK_LENGTH) * CodeCacheUtils.SEGMENT_SIZE;
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    85
            for (MemoryPoolMXBean entry : predictableBeans) {
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    86
                long diff = current.get(entry) - initial.get(entry);
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    87
                if (entry.equals(btype.getMemoryPool())) {
31522
2d29f2e927fc 8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents: 30604
diff changeset
    88
                    if (CodeCacheUtils.isCodeHeapPredictable(btype)) {
2d29f2e927fc 8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents: 30604
diff changeset
    89
                        Asserts.assertFalse(diff <= 0L || diff > usageUpperEstimate,
2d29f2e927fc 8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents: 30604
diff changeset
    90
                                String.format("Pool %s usage increase was reported "
2d29f2e927fc 8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents: 30604
diff changeset
    91
                                        + "unexpectedly as increased by %d using "
2d29f2e927fc 8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents: 30604
diff changeset
    92
                                        + "allocation size %d", entry.getName(),
2d29f2e927fc 8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents: 30604
diff changeset
    93
                                        diff, allocateSize));
2d29f2e927fc 8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents: 30604
diff changeset
    94
                    }
28384
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    95
                } else {
31522
2d29f2e927fc 8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents: 30604
diff changeset
    96
                    CodeCacheUtils.assertEQorGTE(btype, diff, 0L,
28384
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    97
                            String.format("Pool %s usage changed unexpectedly while"
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    98
                                    + " trying to increase: %s using allocation "
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
    99
                                    + "size %d", entry.getName(),
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
   100
                                    btype.getMemoryPool().getName(), allocateSize));
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
   101
                }
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
   102
            }
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
   103
        } finally {
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
   104
            if (addr != 0) {
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
   105
                CodeCacheUtils.WB.freeCodeBlob(addr);
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
   106
            }
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
        System.out.printf("INFO: Scenario finished successfully for %s%n",
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
   109
                btype.getMemoryPool().getName());
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
   110
    }
918bbbe51796 8059613: JEP-JDK-8043304: Test task: JMX- tests
iignatyev
parents:
diff changeset
   111
}