8148563: compiler/compilercontrol/jcmd/StressAddMultiThreadedTest.java timesout
authorppunegov
Tue, 01 Mar 2016 20:17:27 +0300
changeset 36549 d191b3de2ad3
parent 36349 6cc8e6f596b2
child 36550 6d26e3a083cb
8148563: compiler/compilercontrol/jcmd/StressAddMultiThreadedTest.java timesout Summary: decrease amount of directives and threads Reviewed-by: neliasso
hotspot/test/compiler/compilercontrol/jcmd/StressAddJcmdBase.java
hotspot/test/compiler/compilercontrol/jcmd/StressAddMultiThreadedTest.java
hotspot/test/compiler/compilercontrol/jcmd/StressAddSequentiallyTest.java
--- a/hotspot/test/compiler/compilercontrol/jcmd/StressAddJcmdBase.java	Wed Mar 02 15:42:03 2016 +0300
+++ b/hotspot/test/compiler/compilercontrol/jcmd/StressAddJcmdBase.java	Tue Mar 01 20:17:27 2016 +0300
@@ -32,74 +32,99 @@
 import jdk.test.lib.Utils;
 import pool.PoolHelper;
 
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Random;
+import java.util.concurrent.TimeUnit;
 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);
+            200);
+    private static final int TIMEOUT = Integer.getInteger(
+            "compiler.compilercontrol.jcmd.StressAddJcmdBase.timeout",
+            30);
     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("-Xmixed");
+        VM_OPTIONS.add("-XX:+UnlockDiagnosticVMOptions");
+        VM_OPTIONS.add("-XX:+LogCompilation");
+        VM_OPTIONS.add("-XX:CompilerDirectivesLimit=1001");
+    }
 
     /**
      * Performs test
      */
     public void test() {
-        List<String> commands = prepareCommands();
-        Executor executor = new TimeLimitedExecutor(commands);
+        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
+     * Makes connection to the test VM and performs a diagnostic command
      *
-     * @param pid      a pid of the VM under test
-     * @param commands a list of jcmd commands to be executed
+     * @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, List<String> commands);
+    protected abstract boolean makeConnection(int pid);
 
     /**
      * 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);
+    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);
         }
-        return Stream.of(files)
-                .map(file -> "Compiler.directives_add " + file)
-                .collect(Collectors.toList());
+    }
+
+    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 {
-        private final List<String> jcmdCommands;
-
-        public TimeLimitedExecutor(List<String> jcmdCommands) {
+        public TimeLimitedExecutor() {
             /* There are no need to check the state */
-            super(true, null, null, jcmdCommands);
-            this.jcmdCommands = jcmdCommands;
+            super(true, VM_OPTIONS, null, null);
         }
 
         @Override
         protected OutputAnalyzer[] executeJCMD(int pid) {
             TimeLimitedRunner runner = new TimeLimitedRunner(
-                    Utils.DEFAULT_TEST_TIMEOUT,
+                    TimeUnit.SECONDS.toMillis(TIMEOUT),
                     Utils.TIMEOUT_FACTOR,
-                    () -> makeConnection(pid, jcmdCommands));
+                    () -> makeConnection(pid));
             try {
                 runner.call();
             } catch (Exception e) {
--- a/hotspot/test/compiler/compilercontrol/jcmd/StressAddMultiThreadedTest.java	Wed Mar 02 15:42:03 2016 +0300
+++ b/hotspot/test/compiler/compilercontrol/jcmd/StressAddMultiThreadedTest.java	Tue Mar 01 20:17:27 2016 +0300
@@ -27,21 +27,19 @@
  * @summary Tests jcmd to be able to add a lot of huge directive files with
  *          parallel executed jcmds until timeout has reached
  * @library /testlibrary /test/lib /compiler/testlibrary ../share /
- * @ignore 8148563
  * @build compiler.compilercontrol.jcmd.StressAddMultiThreadedTest
  *        pool.sub.* pool.subpack.* sun.hotspot.WhiteBox
  *        compiler.testlibrary.CompilerUtils
  *        compiler.compilercontrol.share.actions.*
  * @run main ClassFileInstaller sun.hotspot.WhiteBox
  *                              sun.hotspot.WhiteBox$WhiteBoxPermission
- * @run main/othervm/timeout=360 compiler.compilercontrol.jcmd.StressAddMultiThreadedTest
+ * @run driver compiler.compilercontrol.jcmd.StressAddMultiThreadedTest
  */
 
 package compiler.compilercontrol.jcmd;
 
 import jdk.test.lib.dcmd.PidJcmdExecutor;
 
-import java.util.List;
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.ExecutorService;
@@ -49,16 +47,15 @@
 import java.util.concurrent.TimeUnit;
 
 public class StressAddMultiThreadedTest extends StressAddJcmdBase {
-    private static final int THREADS;
+    private static final int THREADS = Integer.getInteger(
+            "compiler.compilercontrol.jcmd.StressAddMultiThreadedTest.threads",
+            5);
+    private volatile int commands = Integer.getInteger(
+            "compiler.compilercontrol.jcmd.StressAddMultiThreadedTest.commands",
+            20);
     private final BlockingQueue<Runnable> queue;
     private final ExecutorService executor;
 
-    static {
-        THREADS = Runtime.getRuntime().availableProcessors()
-                * Integer.getInteger("compiler.compilercontrol.jcmd" +
-                        ".StressAddMultiThreadedTest.threadFactor", 10);
-    }
-
     public StressAddMultiThreadedTest() {
         queue = new ArrayBlockingQueue<>(THREADS);
         executor = new ThreadPoolExecutor(THREADS, THREADS, 100,
@@ -71,14 +68,10 @@
     }
 
     @Override
-    protected boolean makeConnection(int pid, List<String> commands) {
-        commands.forEach(command -> {
-            if (!executor.isShutdown()) {
-                executor.submit(() -> new PidJcmdExecutor(String.valueOf(pid))
-                        .execute(command));
-            }
-        });
-        return !executor.isShutdown();
+    protected boolean makeConnection(int pid) {
+        executor.submit(() -> new PidJcmdExecutor(String.valueOf(pid))
+                .execute(nextCommand()));
+        return (--commands != 0);
     }
 
     @Override
--- a/hotspot/test/compiler/compilercontrol/jcmd/StressAddSequentiallyTest.java	Wed Mar 02 15:42:03 2016 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * @test
- * @bug 8137167
- * @summary Tests jcmd to be able to add a lot of huge directives
- * @library /testlibrary /test/lib /compiler/testlibrary ../share /
- * @build compiler.compilercontrol.jcmd.StressAddSequentiallyTest
- *        pool.sub.* pool.subpack.* sun.hotspot.WhiteBox
- *        compiler.testlibrary.CompilerUtils
- *        compiler.compilercontrol.share.actions.*
- * @run main ClassFileInstaller sun.hotspot.WhiteBox
- *                              sun.hotspot.WhiteBox$WhiteBoxPermission
- * @run main/othervm/timeout=300 compiler.compilercontrol.jcmd.StressAddSequentiallyTest
- */
-
-package compiler.compilercontrol.jcmd;
-
-import jdk.test.lib.dcmd.PidJcmdExecutor;
-
-import java.util.List;
-
-public class StressAddSequentiallyTest extends StressAddJcmdBase {
-    public static void main(String[] args) {
-        new StressAddSequentiallyTest().test();
-    }
-
-    @Override
-    protected boolean makeConnection(int pid, List<String> commands) {
-        commands.forEach(command -> new PidJcmdExecutor(String.valueOf(pid))
-                .execute(command));
-        return true;
-    }
-}