UsageThresholdExceededTest.java revision 11801:46bf19165c57
1193323Sed/* 2193323Sed * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. 3193323Sed * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4193323Sed * 5193323Sed * This code is free software; you can redistribute it and/or modify it 6193323Sed * under the terms of the GNU General Public License version 2 only, as 7193323Sed * published by the Free Software Foundation. 8193323Sed * 9193323Sed * This code is distributed in the hope that it will be useful, but WITHOUT 10193323Sed * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11193323Sed * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12193323Sed * version 2 for more details (a copy is included in the LICENSE file that 13193323Sed * accompanied this code). 14193323Sed * 15193323Sed * You should have received a copy of the GNU General Public License version 16193323Sed * 2 along with this work; if not, write to the Free Software Foundation, 17193323Sed * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18218893Sdim * 19193323Sed * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20218893Sdim * or visit www.oracle.com if you need additional information or have any 21193323Sed * questions. 22193323Sed */ 23193323Sed 24198892Srdivacky/* 25218893Sdim * @test UsageThresholdExceededTest 26193323Sed * @summary verifying that getUsageThresholdCount() returns correct value 27193323Sed * after threshold has been hit 28193323Sed * @library /testlibrary /test/lib / 29193323Sed * @modules java.base/jdk.internal.misc 30193323Sed * java.management 31193323Sed * 32193323Sed * @build compiler.codecache.jmx.UsageThresholdExceededTest 33193323Sed * @run driver ClassFileInstaller sun.hotspot.WhiteBox 34193323Sed * sun.hotspot.WhiteBox$WhiteBoxPermission 35198090Srdivacky * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 36193323Sed * -XX:+WhiteBoxAPI -XX:-UseCodeCacheFlushing -XX:-MethodFlushing 37193323Sed * -XX:CompileCommand=compileonly,null::* 38218893Sdim * -XX:+SegmentedCodeCache 39218893Sdim * compiler.codecache.jmx.UsageThresholdExceededTest 40218893Sdim * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 41193323Sed * -XX:+WhiteBoxAPI -XX:-UseCodeCacheFlushing -XX:-MethodFlushing 42193323Sed * -XX:CompileCommand=compileonly,null::* 43193323Sed * -XX:-SegmentedCodeCache 44212904Sdim * compiler.codecache.jmx.UsageThresholdExceededTest 45212904Sdim */ 46212904Sdim 47193323Sedpackage compiler.codecache.jmx; 48193323Sed 49193323Sedimport sun.hotspot.code.BlobType; 50193323Sed 51193323Sedimport java.lang.management.MemoryPoolMXBean; 52193323Sed 53193323Sedpublic class UsageThresholdExceededTest { 54218893Sdim 55218893Sdim protected final int iterations; 56193323Sed private final BlobType btype; 57193323Sed 58218893Sdim public UsageThresholdExceededTest(BlobType btype, int iterations) { 59193323Sed this.btype = btype; 60193323Sed this.iterations = iterations; 61193323Sed } 62193323Sed 63218893Sdim public static void main(String[] args) { 64218893Sdim int iterationsCount = Integer.getInteger("jdk.test.lib.iterations", 1); 65218893Sdim for (BlobType btype : BlobType.getAvailable()) { 66218893Sdim if (CodeCacheUtils.isCodeHeapPredictable(btype)) { 67218893Sdim new UsageThresholdExceededTest(btype, iterationsCount).runTest(); 68193323Sed } 69193323Sed } 70193323Sed } 71193323Sed 72195098Sed protected void runTest() { 73218893Sdim MemoryPoolMXBean bean = btype.getMemoryPool(); 74218893Sdim long oldValue = bean.getUsageThresholdCount(); 75193323Sed for (int i = 0; i < iterations; i++) { 76193323Sed CodeCacheUtils.hitUsageThreshold(bean, btype); 77218893Sdim } 78218893Sdim CodeCacheUtils.assertEQorGTE(btype, bean.getUsageThresholdCount(), oldValue + iterations, 79218893Sdim "Unexpected threshold usage count"); 80193323Sed System.out.printf("INFO: Scenario finished successfully for %s%n", bean.getName()); 81218893Sdim } 82193323Sed} 83193323Sed