Path: blob/master/test/hotspot/jtreg/compiler/compilercontrol/jcmd/PrintDirectivesTest.java
41153 views
/*1* Copyright (c) 2015, 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* @test25* @key randomness26* @bug 813716727* @summary Tests jcmd to be able to add a directive to compile only specified methods28* @modules java.base/jdk.internal.misc29* @library /test/lib /30* @requires vm.flavor != "minimal" & !vm.graal.enabled31*32* @build sun.hotspot.WhiteBox33* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox34* @run driver compiler.compilercontrol.jcmd.PrintDirectivesTest35*/3637package compiler.compilercontrol.jcmd;3839import compiler.compilercontrol.share.AbstractTestBase;40import compiler.compilercontrol.share.method.MethodDescriptor;41import compiler.compilercontrol.share.scenario.Command;42import compiler.compilercontrol.share.scenario.CommandGenerator;43import compiler.compilercontrol.share.scenario.CompileCommand;44import compiler.compilercontrol.share.scenario.JcmdCommand;45import compiler.compilercontrol.share.scenario.Scenario;46import jdk.test.lib.Utils;4748import java.lang.reflect.Executable;4950import static compiler.compilercontrol.share.IntrinsicCommand.VALID_INTRINSIC_SAMPLES;5152public class PrintDirectivesTest extends AbstractTestBase {53private static final int AMOUNT = Utils.getRandomInstance().nextInt(54Integer.getInteger("compiler.compilercontrol.jcmd."55+ "PrintDirectivesTest.amount", 20));56private final CommandGenerator cmdGen = new CommandGenerator();5758public static void main(String[] args) {59new PrintDirectivesTest().test();60}6162@Override63public void test() {64Scenario.Builder builder = Scenario.getBuilder();65// Add some commands with directives file66for (int i = 0; i < AMOUNT; i++) {67String argument = null;6869Executable exec = Utils.getRandomElement(METHODS).first;70MethodDescriptor methodDescriptor = getValidMethodDescriptor(exec);71Command command = cmdGen.generateCommand();72if (command == Command.NONEXISTENT) {73// skip invalid command74command = Command.COMPILEONLY;75}76if (command == Command.INTRINSIC) {77argument = Utils.getRandomElement(VALID_INTRINSIC_SAMPLES);78}79CompileCommand compileCommand = new CompileCommand(command,80methodDescriptor, cmdGen.generateCompiler(),81Scenario.Type.DIRECTIVE, argument);82builder.add(compileCommand);83}84// print all directives85builder.add(new JcmdCommand(Command.NONEXISTENT, null, null,86Scenario.Type.JCMD, Scenario.JcmdType.PRINT));87Scenario scenario = builder.build();88scenario.execute();89}90}919293