< prev index next >

test/compiler/compilercontrol/jcmd/StressAddJcmdBase.java

Print this page
rev 10239 : imported patch StressAdd

*** 30,107 **** import jdk.test.lib.OutputAnalyzer; import jdk.test.lib.TimeLimitedRunner; import jdk.test.lib.Utils; import pool.PoolHelper; import java.util.List; import java.util.stream.Collectors; - import java.util.stream.Stream; public abstract class StressAddJcmdBase { private static final int DIRECTIVES_AMOUNT = Integer.getInteger( "compiler.compilercontrol.jcmd.StressAddJcmdBase.directivesAmount", ! 1000); ! private static final int DIRECTIVE_FILES = Integer.getInteger( ! "compiler.compilercontrol.jcmd.StressAddJcmdBase.directiveFiles", ! 5); private static final List<MethodDescriptor> DESCRIPTORS = new PoolHelper() .getAllMethods().stream() .map(pair -> AbstractTestBase .getValidMethodDescriptor(pair.first)) .collect(Collectors.toList()); /** * Performs test */ public void test() { ! List<String> commands = prepareCommands(); ! Executor executor = new TimeLimitedExecutor(commands); List<OutputAnalyzer> outputAnalyzers = executor.execute(); outputAnalyzers.get(0).shouldHaveExitValue(0); } /** ! * Makes connection to the test VM * * @param pid a pid of the VM under test - * @param commands a list of jcmd commands to be executed * @return true if the test should continue invocation of this method */ ! protected abstract boolean makeConnection(int pid, List<String> commands); /** * Finish test executions */ protected void finish() { } ! private List<String> prepareCommands() { ! String[] files = new String[DIRECTIVE_FILES]; ! for (int i = 0; i < DIRECTIVE_FILES; i++) { ! files[i] = "directives" + i + ".json"; ! HugeDirectiveUtil.createHugeFile(DESCRIPTORS, files[i], ! DIRECTIVES_AMOUNT); } - return Stream.of(files) - .map(file -> "Compiler.directives_add " + file) - .collect(Collectors.toList()); } ! private class TimeLimitedExecutor extends Executor { ! private final List<String> jcmdCommands; ! public TimeLimitedExecutor(List<String> jcmdCommands) { /* There are no need to check the state */ ! super(true, null, null, jcmdCommands); ! this.jcmdCommands = jcmdCommands; } @Override protected OutputAnalyzer[] executeJCMD(int pid) { TimeLimitedRunner runner = new TimeLimitedRunner( Utils.DEFAULT_TEST_TIMEOUT, Utils.TIMEOUT_FACTOR, ! () -> makeConnection(pid, jcmdCommands)); try { runner.call(); } catch (Exception e) { throw new Error("Exception during the execution: " + e, e); } --- 30,127 ---- import jdk.test.lib.OutputAnalyzer; import jdk.test.lib.TimeLimitedRunner; import jdk.test.lib.Utils; import pool.PoolHelper; + import java.util.ArrayList; import java.util.List; + import java.util.Random; import java.util.stream.Collectors; public abstract class StressAddJcmdBase { private static final int DIRECTIVES_AMOUNT = Integer.getInteger( "compiler.compilercontrol.jcmd.StressAddJcmdBase.directivesAmount", ! 999); private static final List<MethodDescriptor> DESCRIPTORS = new PoolHelper() .getAllMethods().stream() .map(pair -> AbstractTestBase .getValidMethodDescriptor(pair.first)) .collect(Collectors.toList()); + private static final String DIRECTIVE_FILE = "directives.json"; + private static final List<String> VM_OPTIONS = new ArrayList<>(); + private static final Random RANDOM = Utils.getRandomInstance(); + + static { + VM_OPTIONS.add("-XX:+UnlockDiagnosticVMOptions"); + VM_OPTIONS.add("-XX:+LogCompilation"); + VM_OPTIONS.add("-XX:CompilerDirectivesLimit=1000"); + } /** * Performs test */ public void test() { ! HugeDirectiveUtil.createHugeFile(DESCRIPTORS, DIRECTIVE_FILE, ! DIRECTIVES_AMOUNT); ! Executor executor = new TimeLimitedExecutor(); List<OutputAnalyzer> outputAnalyzers = executor.execute(); outputAnalyzers.get(0).shouldHaveExitValue(0); } /** ! * Makes connection to the test VM and performs a diagnostic command * * @param pid a pid of the VM under test * @return true if the test should continue invocation of this method */ ! protected abstract boolean makeConnection(int pid); /** * Finish test executions */ protected void finish() { } ! protected String nextCommand() { ! int i = RANDOM.nextInt(JcmdCommand.values().length); ! JcmdCommand jcmdCommand = JcmdCommand.values()[i]; ! switch (jcmdCommand) { ! case ADD: ! return jcmdCommand.command + " " + DIRECTIVE_FILE; ! case PRINT: ! case CLEAR: ! case REMOVE: ! return jcmdCommand.command; ! default: ! throw new Error("TESTBUG: incorrect command: " + jcmdCommand); } } ! private enum JcmdCommand { ! ADD("Compiler.directives_add"), ! PRINT("Compiler.directives_print"), ! CLEAR("Compiler.directives_clear"), ! REMOVE("Compiler.directives_remove"); ! public final String command; ! ! JcmdCommand(String command) { ! this.command = command; ! } ! } ! ! private class TimeLimitedExecutor extends Executor { ! public TimeLimitedExecutor() { /* There are no need to check the state */ ! super(true, VM_OPTIONS, null, null); } @Override protected OutputAnalyzer[] executeJCMD(int pid) { TimeLimitedRunner runner = new TimeLimitedRunner( Utils.DEFAULT_TEST_TIMEOUT, Utils.TIMEOUT_FACTOR, ! () -> makeConnection(pid)); try { runner.call(); } catch (Exception e) { throw new Error("Exception during the execution: " + e, e); }
< prev index next >