Path: blob/master/test/hotspot/jtreg/compiler/compilercontrol/jcmd/StressAddJcmdBase.java
41153 views
/*1* Copyright (c) 2015, 2016, 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*/2223package compiler.compilercontrol.jcmd;2425import compiler.compilercontrol.parser.HugeDirectiveUtil;26import compiler.compilercontrol.share.AbstractTestBase;27import compiler.compilercontrol.share.method.MethodDescriptor;28import compiler.compilercontrol.share.pool.PoolHelper;29import compiler.compilercontrol.share.scenario.Executor;30import jdk.test.lib.process.OutputAnalyzer;31import jdk.test.lib.TimeLimitedRunner;32import jdk.test.lib.Utils;3334import java.util.ArrayList;35import java.util.List;36import java.util.Random;37import java.util.concurrent.TimeUnit;38import java.util.stream.Collectors;3940public abstract class StressAddJcmdBase {41private static final int DIRECTIVES_AMOUNT = Integer.getInteger(42"compiler.compilercontrol.jcmd.StressAddJcmdBase.directivesAmount",43200);44private static final int TIMEOUT = Integer.getInteger(45"compiler.compilercontrol.jcmd.StressAddJcmdBase.timeout",4630);47private static final List<MethodDescriptor> DESCRIPTORS = new PoolHelper()48.getAllMethods().stream()49.map(pair -> AbstractTestBase50.getValidMethodDescriptor(pair.first))51.collect(Collectors.toList());52private static final String DIRECTIVE_FILE = "directives.json";53private static final List<String> VM_OPTIONS = new ArrayList<>();54private static final Random RANDOM = Utils.getRandomInstance();5556static {57VM_OPTIONS.add("-Xmixed");58VM_OPTIONS.add("-XX:+UnlockDiagnosticVMOptions");59VM_OPTIONS.add("-XX:+LogCompilation");60VM_OPTIONS.add("-XX:CompilerDirectivesLimit=1001");61}6263/**64* Performs test65*/66public void test() {67HugeDirectiveUtil.createHugeFile(DESCRIPTORS, DIRECTIVE_FILE,68DIRECTIVES_AMOUNT);69Executor executor = new TimeLimitedExecutor();70List<OutputAnalyzer> outputAnalyzers = executor.execute();71outputAnalyzers.get(0).shouldHaveExitValue(0);72}7374/**75* Makes connection to the test VM and performs a diagnostic command76*77* @param pid a pid of the VM under test78* @return true if the test should continue invocation of this method79*/80protected abstract boolean makeConnection(int pid);8182/**83* Finish test executions84*/85protected void finish() { }8687protected String nextCommand() {88int i = RANDOM.nextInt(JcmdCommand.values().length);89JcmdCommand jcmdCommand = JcmdCommand.values()[i];90switch (jcmdCommand) {91case ADD:92return jcmdCommand.command + " " + DIRECTIVE_FILE;93case PRINT:94case CLEAR:95case REMOVE:96return jcmdCommand.command;97default:98throw new Error("TESTBUG: incorrect command: " + jcmdCommand);99}100}101102private enum JcmdCommand {103ADD("Compiler.directives_add"),104PRINT("Compiler.directives_print"),105CLEAR("Compiler.directives_clear"),106REMOVE("Compiler.directives_remove");107108public final String command;109110JcmdCommand(String command) {111this.command = command;112}113}114115private class TimeLimitedExecutor extends Executor {116public TimeLimitedExecutor() {117/* There are no need to check the state */118super(true, VM_OPTIONS, null, null);119}120121@Override122protected OutputAnalyzer[] executeJCMD(int pid) {123TimeLimitedRunner runner = new TimeLimitedRunner(124TimeUnit.SECONDS.toMillis(TIMEOUT),125Utils.TIMEOUT_FACTOR,126() -> makeConnection(pid));127try {128runner.call();129} catch (Exception e) {130throw new Error("Exception during the execution: " + e, e);131}132finish();133return new OutputAnalyzer[0];134}135}136}137138139