1 /* 2 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test UsageThresholdIncreasedTest 26 * @summary verifying that threshold hasn't been hit after allocation smaller 27 * than threshold value and that threshold value can be changed 28 * @library /test/lib / 29 * @modules java.base/jdk.internal.misc 30 * java.management 31 * @build sun.hotspot.WhiteBox 32 * @run driver ClassFileInstaller sun.hotspot.WhiteBox 33 * sun.hotspot.WhiteBox$WhiteBoxPermission 34 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 35 * -XX:+WhiteBoxAPI -XX:-UseCodeCacheFlushing -XX:-MethodFlushing 36 * -XX:CompileCommand=compileonly,null::* 37 * -XX:-SegmentedCodeCache 38 * compiler.codecache.jmx.UsageThresholdIncreasedTest 39 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 40 * -XX:+WhiteBoxAPI -XX:-UseCodeCacheFlushing -XX:-MethodFlushing 41 * -XX:CompileCommand=compileonly,null::* 42 * -XX:+SegmentedCodeCache 43 * compiler.codecache.jmx.UsageThresholdIncreasedTest 44 */ 45 46 package compiler.codecache.jmx; 47 48 import sun.hotspot.code.BlobType; 49 50 import java.lang.management.MemoryPoolMXBean; 51 52 public class UsageThresholdIncreasedTest { 53 54 private static final int ALLOCATION_STEP = 5; 55 private static final long THRESHOLD_STEP = ALLOCATION_STEP 56 * CodeCacheUtils.MIN_ALLOCATION; 57 private final BlobType btype; 58 59 public UsageThresholdIncreasedTest(BlobType btype) { 60 this.btype = btype; 61 } 62 63 public static void main(String[] args) { 64 for (BlobType btype : BlobType.getAvailable()) { 65 new UsageThresholdIncreasedTest(btype).runTest(); 66 } 67 } 68 69 private void checkUsageThresholdCount(MemoryPoolMXBean bean, long count){ 70 CodeCacheUtils.assertEQorGTE(btype, bean.getUsageThresholdCount(), count, 71 String.format("Usage threshold was hit: %d times for %s " 72 + "Threshold value: %d with current usage: %d", 73 bean.getUsageThresholdCount(), bean.getName(), 74 bean.getUsageThreshold(), bean.getUsage().getUsed())); 75 } 76 77 protected void runTest() { 78 long headerSize = CodeCacheUtils.getHeaderSize(btype); 79 long allocationUnit = Math.max(0, CodeCacheUtils.MIN_ALLOCATION - headerSize); 80 MemoryPoolMXBean bean = btype.getMemoryPool(); 81 long initialCount = bean.getUsageThresholdCount(); 82 long initialSize = bean.getUsage().getUsed(); 83 bean.setUsageThreshold(initialSize + THRESHOLD_STEP); 84 for (int i = 0; i < ALLOCATION_STEP - 1; i++) { 85 CodeCacheUtils.WB.allocateCodeBlob(allocationUnit, btype.id); 86 } 87 // Usage threshold check is triggered by GC cycle, so, call it 88 CodeCacheUtils.WB.fullGC(); 89 checkUsageThresholdCount(bean, initialCount); 90 long filledSize = bean.getUsage().getUsed(); 91 bean.setUsageThreshold(filledSize + THRESHOLD_STEP); 92 for (int i = 0; i < ALLOCATION_STEP - 1; i++) { 93 CodeCacheUtils.WB.allocateCodeBlob(allocationUnit, btype.id); 94 } 95 CodeCacheUtils.WB.fullGC(); 96 checkUsageThresholdCount(bean, initialCount); 97 System.out.println("INFO: Case finished successfully for " + bean.getName()); 98 } 99 }