Path: blob/master/test/hotspot/jtreg/serviceability/dcmd/compiler/CompilerQueueTest.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 CompilerQueueTest25* @bug 805488926* @key intermittent27* @library /test/lib /28* @modules java.base/jdk.internal.misc29* java.compiler30* java.management31* jdk.internal.jvmstat/sun.jvmstat.monitor32* @summary Test of diagnostic command Compiler.queue33* @build sun.hotspot.WhiteBox34* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox35* @run testng/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -Xmixed -XX:+WhiteBoxAPI CompilerQueueTest36* @run testng/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -Xmixed -XX:-TieredCompilation -XX:+WhiteBoxAPI CompilerQueueTest37* @run testng/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -Xint -XX:+WhiteBoxAPI CompilerQueueTest38*/3940import compiler.testlibrary.CompilerUtils;41import jdk.test.lib.process.OutputAnalyzer;42import jdk.test.lib.dcmd.CommandExecutor;43import jdk.test.lib.dcmd.JMXExecutor;44import org.testng.annotations.Test;45import org.testng.Assert;46import sun.hotspot.WhiteBox;4748import java.lang.reflect.Executable;49import java.lang.reflect.Method;50import java.util.Iterator;5152public class CompilerQueueTest {5354/**55* This test calls Jcmd (diagnostic command tool) Compiler.queue and56* then parses the output, making sure that the output look ok.57*58*59* Output example:60*61* Current compiles:62* C1 CompilerThread14 267 3 java.net.URLStreamHandler::parseURL (1166 bytes)63* C1 CompilerThread13 760 3 javax.management.StandardMBean::getDescription (11 bytes)64* C1 CompilerThread12 757 s 3 com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory::getMapping (27 bytes)65* C1 CompilerThread11 756 s! 3 com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory::mappingForType (110 bytes)66* C1 CompilerThread10 761 3 java.lang.StringLatin1::indexOf (121 bytes)67* C2 CompilerThread7 769 4 CompilerQueueTest::testcaseMethod4 (1 bytes)68*69* C1 compile queue:70* 762 3 java.lang.invoke.MethodType::basicType (8 bytes)71* 763 3 java.util.ArrayList::rangeCheck (22 bytes)72* 764 3 java.util.ArrayList::elementData (7 bytes)73* 765 3 jdk.internal.org.objectweb.asm.MethodVisitor::<init> (35 bytes)74* 766 1 CompilerQueueTest::testcaseMethod1 (1 bytes)75* 767 2 CompilerQueueTest::testcaseMethod2 (1 bytes)76* 768 3 CompilerQueueTest::testcaseMethod3 (1 bytes)77* 770 3 java.util.Properties::getProperty (46 bytes)78*79* C2 compile queue:80* Empty81*82**/8384protected static final WhiteBox WB = WhiteBox.getWhiteBox();8586public void run(CommandExecutor executor) {8788TestCase[] testcases = {89new TestCase(1, "testcaseMethod1"),90new TestCase(2, "testcaseMethod2"),91new TestCase(3, "testcaseMethod3"),92new TestCase(4, "testcaseMethod4"),93};9495// Lock compilation makes all compiles stay in queue or compile thread before completion96WB.lockCompilation();9798// Enqueue one test method for each available level99int[] complevels = CompilerUtils.getAvailableCompilationLevels();100for (int level : complevels) {101TestCase testcase = testcases[level - 1];102103boolean added = WB.enqueueMethodForCompilation(testcase.method, testcase.level);104// Set results to false for those methods we must to find105// We will also assert if we find any test method we don't expect106Assert.assertEquals(added, WB.isMethodQueuedForCompilation(testcase.method));107testcase.check = false;108}109110// Get output from dcmd (diagnostic command)111OutputAnalyzer output = executor.execute("Compiler.queue");112Iterator<String> lines = output.asLines().iterator();113114// Loop over output set result for all found methods115while (lines.hasNext()) {116String str = lines.next();117// Fast check for common part of method name118if (str.contains("testcaseMethod")) {119for (TestCase testcase : testcases) {120if (str.contains(testcase.methodName)) {121Assert.assertFalse(testcase.check, "Must not be found or already found.");122testcase.check = true;123}124}125}126}127128for (TestCase testcase : testcases) {129if (!testcase.check) {130// If this method wasn't found it must have been removed by policy,131// verify that it is now removed from the queue132Assert.assertFalse(WB.isMethodQueuedForCompilation(testcase.method), "Must be found or not in queue");133}134// Otherwise all good.135}136137// Enable compilations again138WB.unlockCompilation();139}140141@Test142public void jmx() {143run(new JMXExecutor());144}145146public void testcaseMethod1() {147}148149public void testcaseMethod2() {150}151152public void testcaseMethod3() {153}154155public void testcaseMethod4() {156}157158public static Method getMethod(Class klass, String name, Class<?>... parameterTypes) {159try {160return klass.getDeclaredMethod(name, parameterTypes);161} catch (NoSuchMethodException | SecurityException e) {162throw new RuntimeException("exception on getting method Helper." + name, e);163}164}165166class TestCase {167Method method;168int level;169String methodName;170Boolean check;171172public TestCase(int level, String methodName) {173this.method = getMethod(CompilerQueueTest.class, methodName);174this.level = level;175this.methodName = methodName;176this.check = true;177}178}179180}181182183