Path: blob/master/test/hotspot/jtreg/compiler/codecache/jmx/ThresholdNotificationsTest.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 ThresholdNotificationsTest25* @summary testing of getUsageThreshold()26* @library /test/lib /27* @modules java.base/jdk.internal.misc28* java.management29*30* @build sun.hotspot.WhiteBox31* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox32* @run main/othervm -XX:+UnlockDiagnosticVMOptions -Xbootclasspath/a:. -XX:-UseCodeCacheFlushing33* -XX:+WhiteBoxAPI -XX:-MethodFlushing -XX:CompileCommand=compileonly,null::*34* -XX:+SegmentedCodeCache35* compiler.codecache.jmx.ThresholdNotificationsTest36* @run main/othervm -XX:+UnlockDiagnosticVMOptions -Xbootclasspath/a:. -XX:-UseCodeCacheFlushing37* -XX:+WhiteBoxAPI -XX:-MethodFlushing -XX:CompileCommand=compileonly,null::*38* -XX:-SegmentedCodeCache39* compiler.codecache.jmx.ThresholdNotificationsTest40*/4142package compiler.codecache.jmx;4344import jdk.test.lib.Asserts;45import jdk.test.lib.Utils;46import sun.hotspot.code.BlobType;4748import javax.management.ListenerNotFoundException;49import javax.management.Notification;50import javax.management.NotificationEmitter;51import javax.management.NotificationListener;52import java.lang.management.ManagementFactory;53import java.lang.management.MemoryNotificationInfo;54import java.lang.management.MemoryPoolMXBean;5556public class ThresholdNotificationsTest implements NotificationListener {5758private final static long WAIT_TIME = 10000L;59private volatile long counter;60private final BlobType btype;6162public static void main(String[] args) {63for (BlobType bt : BlobType.getAvailable()) {64if (CodeCacheUtils.isCodeHeapPredictable(bt)) {65new ThresholdNotificationsTest(bt).runTest();66}67}68}6970public ThresholdNotificationsTest(BlobType btype) {71this.btype = btype;72counter = 0L;73CodeCacheUtils.disableCollectionUsageThresholds();74}7576@Override77public void handleNotification(Notification notification, Object handback) {78String nType = notification.getType();79String poolName80= CodeCacheUtils.getPoolNameFromNotification(notification);81// consider code cache events only82if (CodeCacheUtils.isAvailableCodeHeapPoolName(poolName)) {83Asserts.assertEQ(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED,84nType, "Unexpected event received: " + nType);85if (poolName.equals(btype.getMemoryPool().getName())) {86counter++;87}88}89}9091protected void runTest() {92int iterationsCount93= Integer.getInteger("jdk.test.lib.iterations", 1);94MemoryPoolMXBean bean = btype.getMemoryPool();95((NotificationEmitter) ManagementFactory.getMemoryMXBean()).96addNotificationListener(this, null, null);97for (int i = 0; i < iterationsCount; i++) {98CodeCacheUtils.hitUsageThreshold(bean, btype);99}100Asserts.assertTrue(101Utils.waitForCondition(102() -> (CodeCacheUtils.isCodeHeapPredictable(btype) ?103(counter == iterationsCount) : (counter >= iterationsCount)),104WAIT_TIME),105"Couldn't receive expected notifications count");106try {107((NotificationEmitter) ManagementFactory.getMemoryMXBean()).108removeNotificationListener(this);109} catch (ListenerNotFoundException ex) {110throw new AssertionError("Can't remove notification listener", ex);111}112System.out.printf("INFO: Scenario finished successfully for %s%n",113bean.getName());114}115}116117118