Path: blob/master/test/hotspot/jtreg/compiler/codecache/jmx/UsageThresholdIncreasedTest.java
41153 views
/*1* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test UsageThresholdIncreasedTest25* @summary verifying that threshold hasn't been hit after allocation smaller26* than threshold value and that threshold value can be changed27* @library /test/lib /28* @modules java.base/jdk.internal.misc29* java.management30* @build sun.hotspot.WhiteBox31* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox32* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions33* -XX:+WhiteBoxAPI -XX:-UseCodeCacheFlushing -XX:-MethodFlushing34* -XX:CompileCommand=compileonly,null::*35* -XX:-SegmentedCodeCache36* compiler.codecache.jmx.UsageThresholdIncreasedTest37* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions38* -XX:+WhiteBoxAPI -XX:-UseCodeCacheFlushing -XX:-MethodFlushing39* -XX:CompileCommand=compileonly,null::*40* -XX:+SegmentedCodeCache41* compiler.codecache.jmx.UsageThresholdIncreasedTest42*/4344package compiler.codecache.jmx;4546import sun.hotspot.code.BlobType;4748import java.lang.management.MemoryPoolMXBean;4950public class UsageThresholdIncreasedTest {5152private static final int ALLOCATION_STEP = 5;53private static final long THRESHOLD_STEP = ALLOCATION_STEP54* CodeCacheUtils.MIN_ALLOCATION;55private final BlobType btype;5657public UsageThresholdIncreasedTest(BlobType btype) {58this.btype = btype;59}6061public static void main(String[] args) {62for (BlobType btype : BlobType.getAvailable()) {63new UsageThresholdIncreasedTest(btype).runTest();64}65}6667private void checkUsageThresholdCount(MemoryPoolMXBean bean, long count){68CodeCacheUtils.assertEQorGTE(btype, bean.getUsageThresholdCount(), count,69String.format("Usage threshold was hit: %d times for %s "70+ "Threshold value: %d with current usage: %d",71bean.getUsageThresholdCount(), bean.getName(),72bean.getUsageThreshold(), bean.getUsage().getUsed()));73}7475protected void runTest() {76long headerSize = CodeCacheUtils.getHeaderSize(btype);77long allocationUnit = Math.max(0, CodeCacheUtils.MIN_ALLOCATION - headerSize);78MemoryPoolMXBean bean = btype.getMemoryPool();79long initialCount = bean.getUsageThresholdCount();80long initialSize = bean.getUsage().getUsed();81bean.setUsageThreshold(initialSize + THRESHOLD_STEP);82for (int i = 0; i < ALLOCATION_STEP - 1; i++) {83CodeCacheUtils.WB.allocateCodeBlob(allocationUnit, btype.id);84}85// Usage threshold check is triggered by GC cycle, so, call it86CodeCacheUtils.WB.fullGC();87checkUsageThresholdCount(bean, initialCount);88long filledSize = bean.getUsage().getUsed();89bean.setUsageThreshold(filledSize + THRESHOLD_STEP);90for (int i = 0; i < ALLOCATION_STEP - 1; i++) {91CodeCacheUtils.WB.allocateCodeBlob(allocationUnit, btype.id);92}93CodeCacheUtils.WB.fullGC();94checkUsageThresholdCount(bean, initialCount);95System.out.println("INFO: Case finished successfully for " + bean.getName());96}97}9899100