Path: blob/master/test/hotspot/jtreg/compiler/compilercontrol/jcmd/ClearDirectivesFileStackTest.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 clear directives added via options28* @modules java.base/jdk.internal.misc29* @library /test/lib /30*31* @build sun.hotspot.WhiteBox32* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox33*34* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions35* -XX:+WhiteBoxAPI36* compiler.compilercontrol.jcmd.ClearDirectivesFileStackTest37*/3839package compiler.compilercontrol.jcmd;4041import compiler.compilercontrol.share.AbstractTestBase;42import compiler.compilercontrol.share.method.MethodDescriptor;43import compiler.compilercontrol.share.scenario.Command;44import compiler.compilercontrol.share.scenario.CommandGenerator;45import compiler.compilercontrol.share.scenario.CompileCommand;46import compiler.compilercontrol.share.scenario.JcmdCommand;47import compiler.compilercontrol.share.scenario.Scenario;48import jdk.test.lib.Utils;49import sun.hotspot.WhiteBox;5051import java.lang.reflect.Executable;5253public class ClearDirectivesFileStackTest extends AbstractTestBase {54private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();55private static final int LIMIT = WHITE_BOX.getIntVMFlag("CompilerDirectivesLimit").intValue();56private static final int AMOUNT = Utils.getRandomInstance().nextInt(LIMIT);57private final CommandGenerator cmdGen = new CommandGenerator();5859public static void main(String[] args) {60new ClearDirectivesFileStackTest().test();61}6263@Override64public void test() {65Scenario.Builder builder = Scenario.getBuilder();66// Add some commands with directives file67for (int i = 0; i < AMOUNT; i++) {68Executable exec = Utils.getRandomElement(METHODS).first;69MethodDescriptor methodDescriptor = getValidMethodDescriptor(exec);70Command command = cmdGen.generateCommand();71if (command == Command.NONEXISTENT) {72// skip invalid command73command = Command.COMPILEONLY;74}75CompileCommand compileCommand = new CompileCommand(command,76methodDescriptor, cmdGen.generateCompiler(),77Scenario.Type.DIRECTIVE);78builder.add(compileCommand);79}80// clear the stack81builder.add(new JcmdCommand(Command.NONEXISTENT, null, null,82Scenario.Type.JCMD, Scenario.JcmdType.CLEAR));83// print all directives after the clear84builder.add(new JcmdCommand(Command.NONEXISTENT, null, null,85Scenario.Type.JCMD, Scenario.JcmdType.PRINT));86Scenario scenario = builder.build();87scenario.execute();88}89}909192