UsageThresholdExceededTest.java revision 11707:ad7af1afda7a
138032Speter/*
290792Sgshapiro * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
364562Sgshapiro * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
438032Speter *
538032Speter * This code is free software; you can redistribute it and/or modify it
638032Speter * under the terms of the GNU General Public License version 2 only, as
738032Speter * published by the Free Software Foundation.
838032Speter *
938032Speter * This code is distributed in the hope that it will be useful, but WITHOUT
1038032Speter * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1138032Speter * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1238032Speter * version 2 for more details (a copy is included in the LICENSE file that
1338032Speter * accompanied this code).
1464562Sgshapiro *
1590792Sgshapiro * You should have received a copy of the GNU General Public License version
1690792Sgshapiro * 2 along with this work; if not, write to the Free Software Foundation,
1790792Sgshapiro * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1864562Sgshapiro *
19102528Sgshapiro * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2064562Sgshapiro * or visit www.oracle.com if you need additional information or have any
2190792Sgshapiro * questions.
2290792Sgshapiro */
2390792Sgshapiro
2490792Sgshapiro/*
2590792Sgshapiro * @test UsageThresholdExceededTest
2690792Sgshapiro * @summary verifying that getUsageThresholdCount() returns correct value
2764562Sgshapiro *     after threshold has been hit
2890792Sgshapiro * @library /testlibrary /test/lib /
2990792Sgshapiro * @modules java.base/jdk.internal.misc
3090792Sgshapiro *          java.management
3138032Speter *
3290792Sgshapiro * @build compiler.codecache.jmx.UsageThresholdExceededTest
3390792Sgshapiro * @run driver ClassFileInstaller sun.hotspot.WhiteBox
3438032Speter *                                sun.hotspot.WhiteBox$WhiteBoxPermission
3590792Sgshapiro * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
3690792Sgshapiro *     -XX:+WhiteBoxAPI -XX:-UseCodeCacheFlushing  -XX:-MethodFlushing
3790792Sgshapiro *     -XX:CompileCommand=compileonly,null::*
3890792Sgshapiro *     -XX:+SegmentedCodeCache
3990792Sgshapiro *     compiler.codecache.jmx.UsageThresholdExceededTest
4090792Sgshapiro * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
4190792Sgshapiro *     -XX:+WhiteBoxAPI -XX:-UseCodeCacheFlushing  -XX:-MethodFlushing
4290792Sgshapiro *     -XX:CompileCommand=compileonly,null::*
4390792Sgshapiro *     -XX:-SegmentedCodeCache
4490792Sgshapiro *     compiler.codecache.jmx.UsageThresholdExceededTest
4590792Sgshapiro */
4690792Sgshapiro
4790792Sgshapiropackage compiler.codecache.jmx;
4890792Sgshapiro
4990792Sgshapiroimport sun.hotspot.code.BlobType;
5090792Sgshapiro
5190792Sgshapiroimport java.lang.management.MemoryPoolMXBean;
5290792Sgshapiro
5390792Sgshapiropublic class UsageThresholdExceededTest {
5490792Sgshapiro
5590792Sgshapiro    protected final int iterations;
5690792Sgshapiro    private final BlobType btype;
5790792Sgshapiro
5890792Sgshapiro    public UsageThresholdExceededTest(BlobType btype, int iterations) {
5990792Sgshapiro        this.btype = btype;
6090792Sgshapiro        this.iterations = iterations;
6190792Sgshapiro    }
6290792Sgshapiro
6390792Sgshapiro    public static void main(String[] args) {
6464562Sgshapiro        int iterationsCount = Integer.getInteger("jdk.test.lib.iterations", 1);
6564562Sgshapiro        for (BlobType btype : BlobType.getAvailable()) {
6664562Sgshapiro            new UsageThresholdExceededTest(btype, iterationsCount).runTest();
6764562Sgshapiro        }
6864562Sgshapiro    }
6990792Sgshapiro
7064562Sgshapiro    protected void runTest() {
7138032Speter        MemoryPoolMXBean bean = btype.getMemoryPool();
7290792Sgshapiro        long oldValue = bean.getUsageThresholdCount();
7390792Sgshapiro        for (int i = 0; i < iterations; i++) {
7490792Sgshapiro            CodeCacheUtils.hitUsageThreshold(bean, btype);
7538032Speter        }
7638032Speter        CodeCacheUtils.assertEQorGTE(btype, bean.getUsageThresholdCount(), oldValue + iterations,
7738032Speter                "Unexpected threshold usage count");
7838032Speter        System.out.printf("INFO: Scenario finished successfully for %s%n", bean.getName());
7938032Speter    }
8090792Sgshapiro}
8190792Sgshapiro