8066166: JEP-JDK-8046155: Test task: dcmd tests
authorppunegov
Tue, 20 Oct 2015 21:12:25 +0300
changeset 33453 b62df32d4af8
parent 33452 04815c29859c
child 33455 9fbec272c38c
8066166: JEP-JDK-8046155: Test task: dcmd tests Summary: Tests for diagnostic command in CompilerControl Reviewed-by: kvn
hotspot/test/compiler/compilercontrol/jcmd/AddAndRemoveTest.java
hotspot/test/compiler/compilercontrol/jcmd/AddCompileOnlyTest.java
hotspot/test/compiler/compilercontrol/jcmd/AddExcludeTest.java
hotspot/test/compiler/compilercontrol/jcmd/AddLogTest.java
hotspot/test/compiler/compilercontrol/jcmd/AddPrintAssemblyTest.java
hotspot/test/compiler/compilercontrol/jcmd/ClearDirectivesFileStackTest.java
hotspot/test/compiler/compilercontrol/jcmd/ClearDirectivesStackTest.java
hotspot/test/compiler/compilercontrol/share/scenario/CommandGenerator.java
hotspot/test/compiler/compilercontrol/share/scenario/JcmdCommand.java
hotspot/test/compiler/compilercontrol/share/scenario/JcmdStateBuilder.java
hotspot/test/compiler/compilercontrol/share/scenario/Scenario.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/compilercontrol/jcmd/AddAndRemoveTest.java	Tue Oct 20 21:12:25 2015 +0300
@@ -0,0 +1,78 @@
+/*
+ * 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 directives to be able to add and remove directives
+ * @library /testlibrary /../../test/lib /compiler/testlibrary ../share /
+ * @build AddAndRemoveTest 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 compiler.compilercontrol.jcmd.AddAndRemoveTest
+ */
+
+package compiler.compilercontrol.jcmd;
+
+import compiler.compilercontrol.share.AbstractTestBase;
+import compiler.compilercontrol.share.method.MethodDescriptor;
+import compiler.compilercontrol.share.scenario.Command;
+import compiler.compilercontrol.share.scenario.CompileCommand;
+import compiler.compilercontrol.share.scenario.JcmdCommand;
+import compiler.compilercontrol.share.scenario.Scenario;
+import jdk.test.lib.Utils;
+
+import java.lang.reflect.Executable;
+
+public class AddAndRemoveTest extends AbstractTestBase {
+    private static final int AMOUNT = Integer.getInteger(
+            "compiler.compilercontrol.jcmd.AddAndRemoveTest.amount", 10);
+
+    public static void main(String[] args) {
+        new AddAndRemoveTest().test();
+    }
+
+    @Override
+    public void test() {
+        Scenario.Builder builder = Scenario.getBuilder();
+        // Add some commands with JCMD
+        for (int i = 0; i < AMOUNT; i++) {
+            Executable exec = Utils.getRandomElement(METHODS).first;
+            MethodDescriptor md = getValidMethodDescriptor(exec);
+            CompileCommand compileCommand = new JcmdCommand(Command.COMPILEONLY,
+                    md, null, Scenario.Type.JCMD, Scenario.JcmdType.ADD);
+            compileCommand.print();
+            builder.add(compileCommand);
+        }
+        // Remove half of them
+        for (int i = 0; i < AMOUNT / 2; i++) {
+            /* remove jcmd command doesn't need method, compiler etc.
+               command will be ignored */
+            builder.add(new JcmdCommand(Command.NONEXISTENT, null, null,
+                    Scenario.Type.JCMD, Scenario.JcmdType.REMOVE));
+        }
+        Scenario scenario = builder.build();
+        scenario.execute();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/compilercontrol/jcmd/AddCompileOnlyTest.java	Tue Oct 20 21:12:25 2015 +0300
@@ -0,0 +1,47 @@
+/*
+ * 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 directive to compile only specified methods
+ * @library /testlibrary /../../test/lib /compiler/testlibrary ../share /
+ * @build AddCompileOnlyTest 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 compiler.compilercontrol.jcmd.AddCompileOnlyTest
+ */
+
+package compiler.compilercontrol.jcmd;
+
+import compiler.compilercontrol.share.SingleCommand;
+import compiler.compilercontrol.share.scenario.Command;
+import compiler.compilercontrol.share.scenario.Scenario;
+
+public class AddCompileOnlyTest {
+    public static void main(String[] args) {
+        new SingleCommand(Command.COMPILEONLY, Scenario.Type.JCMD)
+                .test();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/compilercontrol/jcmd/AddExcludeTest.java	Tue Oct 20 21:12:25 2015 +0300
@@ -0,0 +1,47 @@
+/*
+ * 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 directive to exclude only specified methods
+ * @library /testlibrary /../../test/lib /compiler/testlibrary ../share /
+ * @build AddExcludeTest 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 compiler.compilercontrol.jcmd.AddExcludeTest
+ */
+
+package compiler.compilercontrol.jcmd;
+
+import compiler.compilercontrol.share.SingleCommand;
+import compiler.compilercontrol.share.scenario.Command;
+import compiler.compilercontrol.share.scenario.Scenario;
+
+public class AddExcludeTest {
+    public static void main(String[] args) {
+        new SingleCommand(Command.EXCLUDE, Scenario.Type.JCMD)
+                .test();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/compilercontrol/jcmd/AddLogTest.java	Tue Oct 20 21:12:25 2015 +0300
@@ -0,0 +1,47 @@
+/*
+ * 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 directive to log only specified methods
+ * @library /testlibrary /../../test/lib /compiler/testlibrary ../share /
+ * @build AddLogTest 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 compiler.compilercontrol.jcmd.AddLogTest
+ */
+
+package compiler.compilercontrol.jcmd;
+
+import compiler.compilercontrol.share.SingleCommand;
+import compiler.compilercontrol.share.scenario.Command;
+import compiler.compilercontrol.share.scenario.Scenario;
+
+public class AddLogTest {
+    public static void main(String[] args) {
+        new SingleCommand(Command.LOG, Scenario.Type.JCMD)
+                .test();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/compilercontrol/jcmd/AddPrintAssemblyTest.java	Tue Oct 20 21:12:25 2015 +0300
@@ -0,0 +1,48 @@
+/*
+ * 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 directive to print assembly
+ *          only for specified methods
+ * @library /testlibrary /../../test/lib /compiler/testlibrary ../share /
+ * @build AddPrintAssemblyTest 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 compiler.compilercontrol.jcmd.AddPrintAssemblyTest
+ */
+
+package compiler.compilercontrol.jcmd;
+
+import compiler.compilercontrol.share.SingleCommand;
+import compiler.compilercontrol.share.scenario.Command;
+import compiler.compilercontrol.share.scenario.Scenario;
+
+public class AddPrintAssemblyTest {
+    public static void main(String[] args) {
+        new SingleCommand(Command.PRINT, Scenario.Type.JCMD)
+                .test();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/compilercontrol/jcmd/ClearDirectivesFileStackTest.java	Tue Oct 20 21:12:25 2015 +0300
@@ -0,0 +1,87 @@
+/*
+ * 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 clear directives added via options
+ * @library /testlibrary /../../test/lib /compiler/testlibrary ../share /
+ * @build ClearDirectivesFileStackTest 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 compiler.compilercontrol.jcmd.ClearDirectivesFileStackTest
+ */
+
+package compiler.compilercontrol.jcmd;
+
+import compiler.compilercontrol.share.AbstractTestBase;
+import compiler.compilercontrol.share.method.MethodDescriptor;
+import compiler.compilercontrol.share.scenario.Command;
+import compiler.compilercontrol.share.scenario.CommandGenerator;
+import compiler.compilercontrol.share.scenario.CompileCommand;
+import compiler.compilercontrol.share.scenario.JcmdCommand;
+import compiler.compilercontrol.share.scenario.Scenario;
+import jdk.test.lib.Utils;
+
+import java.lang.reflect.Executable;
+
+public class ClearDirectivesFileStackTest extends AbstractTestBase {
+    private static final int AMOUNT = Utils.getRandomInstance().nextInt(100);
+    private final CommandGenerator cmdGen = new CommandGenerator();
+
+    public static void main(String[] args) {
+        new ClearDirectivesFileStackTest().test();
+    }
+
+    @Override
+    public void test() {
+        Scenario.Builder builder = Scenario.getBuilder();
+        // Add some commands with directives file
+        for (int i = 0; i < AMOUNT; i++) {
+            Executable exec = Utils.getRandomElement(METHODS).first;
+            MethodDescriptor methodDescriptor = getValidMethodDescriptor(exec);
+            Command command = cmdGen.generateCommand();
+            if (command == Command.NONEXISTENT) {
+                // skip invalid command
+                command = Command.COMPILEONLY;
+            }
+            CompileCommand compileCommand = new CompileCommand(command,
+                    methodDescriptor, cmdGen.generateCompiler(),
+                    Scenario.Type.DIRECTIVE);
+            compileCommand.print();
+            builder.add(compileCommand);
+        }
+        // print all directives before
+        builder.add(new JcmdCommand(Command.NONEXISTENT, null, null,
+                Scenario.Type.JCMD, Scenario.JcmdType.PRINT));
+        // clear the stack
+        builder.add(new JcmdCommand(Command.NONEXISTENT, null, null,
+                Scenario.Type.JCMD, Scenario.JcmdType.CLEAR));
+        // print all directives after the clear
+        builder.add(new JcmdCommand(Command.NONEXISTENT, null, null,
+                Scenario.Type.JCMD, Scenario.JcmdType.PRINT));
+        Scenario scenario = builder.build();
+        scenario.execute();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/compilercontrol/jcmd/ClearDirectivesStackTest.java	Tue Oct 20 21:12:25 2015 +0300
@@ -0,0 +1,83 @@
+/*
+ * 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 clear JCMD command
+ * @library /testlibrary /../../test/lib /compiler/testlibrary ../share /
+ * @build ClearDirectivesStackTest 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 compiler.compilercontrol.jcmd.ClearDirectivesStackTest
+ */
+
+package compiler.compilercontrol.jcmd;
+
+import compiler.compilercontrol.share.AbstractTestBase;
+import compiler.compilercontrol.share.method.MethodDescriptor;
+import compiler.compilercontrol.share.scenario.Command;
+import compiler.compilercontrol.share.scenario.CommandGenerator;
+import compiler.compilercontrol.share.scenario.CompileCommand;
+import compiler.compilercontrol.share.scenario.JcmdCommand;
+import compiler.compilercontrol.share.scenario.Scenario;
+import jdk.test.lib.Utils;
+
+import java.lang.reflect.Executable;
+
+public class ClearDirectivesStackTest extends AbstractTestBase {
+    private static final int AMOUNT = Utils.getRandomInstance().nextInt(100);
+    private final CommandGenerator cmdGen = new CommandGenerator();
+
+    public static void main(String[] args) {
+        new ClearDirectivesStackTest().test();
+    }
+
+    @Override
+    public void test() {
+        Scenario.Builder builder = Scenario.getBuilder();
+        // Add some commands with JCMD
+        for (int i = 0; i < AMOUNT; i++) {
+            Executable exec = Utils.getRandomElement(METHODS).first;
+            MethodDescriptor methodDescriptor = getValidMethodDescriptor(exec);
+            CompileCommand compileCommand = new JcmdCommand(
+                    cmdGen.generateCommand(), methodDescriptor,
+                    cmdGen.generateCompiler(), Scenario.Type.JCMD,
+                    Scenario.JcmdType.ADD);
+            compileCommand.print();
+            builder.add(compileCommand);
+        }
+        // print all directives before
+        builder.add(new JcmdCommand(Command.NONEXISTENT, null, null,
+                Scenario.Type.JCMD, Scenario.JcmdType.PRINT));
+        // clear the stack
+        builder.add(new JcmdCommand(Command.NONEXISTENT, null, null,
+                Scenario.Type.JCMD, Scenario.JcmdType.CLEAR));
+        // print all directives after the clear
+        builder.add(new JcmdCommand(Command.NONEXISTENT, null, null,
+                Scenario.Type.JCMD, Scenario.JcmdType.PRINT));
+        Scenario scenario = builder.build();
+        scenario.execute();
+    }
+}
--- a/hotspot/test/compiler/compilercontrol/share/scenario/CommandGenerator.java	Tue Oct 20 21:09:57 2015 +0300
+++ b/hotspot/test/compiler/compilercontrol/share/scenario/CommandGenerator.java	Tue Oct 20 21:12:25 2015 +0300
@@ -99,4 +99,12 @@
         int compiler = RANDOM.nextInt(compilers.length + 1) - 1;
         return (compiler != -1) ? compilers[compiler] : null;
     }
+
+    /**
+     * Generates random diagnostic command
+     * {@link Scenario.Type}
+     */
+    public Scenario.JcmdType generateJcmdType() {
+        return Utils.getRandomElement(Scenario.JcmdType.values());
+    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/compilercontrol/share/scenario/JcmdCommand.java	Tue Oct 20 21:12:25 2015 +0300
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+
+package compiler.compilercontrol.share.scenario;
+
+import compiler.compilercontrol.share.method.MethodDescriptor;
+
+public class JcmdCommand extends CompileCommand {
+    public final Scenario.JcmdType jcmdType;
+
+    public JcmdCommand(Command command,
+                       MethodDescriptor methodDescriptor,
+                       Scenario.Compiler compiler,
+                       Scenario.Type type,
+                       Scenario.JcmdType jcmdType) {
+        super(command, methodDescriptor, compiler, type);
+        this.jcmdType = jcmdType;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/compilercontrol/share/scenario/JcmdStateBuilder.java	Tue Oct 20 21:12:25 2015 +0300
@@ -0,0 +1,164 @@
+/*
+ * 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.
+ */
+
+package compiler.compilercontrol.share.scenario;
+
+import compiler.compilercontrol.share.method.MethodDescriptor;
+import compiler.compilercontrol.share.method.MethodGenerator;
+import pool.PoolHelper;
+import jdk.test.lib.Pair;
+
+import java.lang.reflect.Executable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
+
+public class JcmdStateBuilder implements StateBuilder<JcmdCommand> {
+    private static final List<Pair<Executable, Callable<?>>> METHODS
+            = new PoolHelper().getAllMethods();
+    private final Map<Executable, State> stateMap = new HashMap<>();
+    private final DirectiveBuilder directiveBuilder;
+    private Map<MethodDescriptor, List<CompileCommand>> matchBlocks
+            = new LinkedHashMap<>();
+    private List<JcmdCommand> commands = new ArrayList<>();
+    private boolean isFileValid = true;
+
+    public JcmdStateBuilder(String fileName) {
+        directiveBuilder = new DirectiveBuilder(fileName);
+    }
+
+    @Override
+    public void add(JcmdCommand compileCommand) {
+        commands.add(compileCommand);
+        switch (compileCommand.jcmdType) {
+            case ADD:
+                directiveBuilder.add(compileCommand);
+                addCommand(compileCommand);
+                break;
+            case PRINT:
+                // doesn't change the state
+                break;
+            case CLEAR:
+                matchBlocks.clear();
+                break;
+            case REMOVE:
+                removeDirective();
+                break;
+        }
+    }
+
+    private void addCommand(JcmdCommand compileCommand) {
+        isFileValid &= compileCommand.isValid();
+        for (MethodDescriptor md: matchBlocks.keySet()) {
+            if (compileCommand.methodDescriptor.getCanonicalString()
+                    .matches(md.getRegexp())) {
+                matchBlocks.get(md).add(compileCommand);
+            }
+        }
+        List<CompileCommand> commands = new ArrayList<>();
+        commands.add(compileCommand);
+        matchBlocks.put(compileCommand.methodDescriptor, commands);
+    }
+
+    private void removeDirective() {
+        Iterator<MethodDescriptor> iterator = matchBlocks.keySet().iterator();
+        if (iterator.hasNext()) {
+            MethodDescriptor md = iterator.next();
+            matchBlocks.remove(md);
+        }
+    }
+
+    @Override
+    public boolean isValid() {
+        // VM skips invalid directive file added via jcmd command
+        return true;
+    }
+
+    @Override
+    public Map<Executable, State> getStates() {
+        directiveBuilder.getStates();
+        // Build states for each method according to match blocks
+        for (Pair<Executable, Callable<?>> pair : METHODS) {
+            State state = getState(pair);
+            if (state != null) {
+                stateMap.put(pair.first, state);
+            }
+        }
+        if (isFileValid) {
+            return stateMap;
+        } else {
+            // return empty map because invalid file doesn't change states
+            return new HashMap<>();
+        }
+    }
+
+    private State getState(Pair<Executable, Callable<?>> pair) {
+        State state = null;
+        MethodDescriptor execDesc = MethodGenerator.commandDescriptor(
+                pair.first);
+        boolean isMatchFound = false;
+
+        if (stateMap.containsKey(pair.first)) {
+            state = stateMap.get(pair.first);
+        }
+        for (MethodDescriptor matchDesc : matchBlocks.keySet()) {
+            if (execDesc.getCanonicalString().matches(matchDesc.getRegexp())) {
+                /*
+                 * if executable matches regex
+                 * then apply commands from this match to the state
+                 */
+                for (CompileCommand cc : matchBlocks.get(matchDesc)) {
+                    state = new State();
+                    if (!isMatchFound) {
+                        // this is a first found match, apply all commands
+                        state.apply(cc);
+                    } else {
+                        // apply only inline directives
+                        switch (cc.command) {
+                            case INLINE:
+                            case DONTINLINE:
+                                state.apply(cc);
+                                break;
+                        }
+                    }
+                }
+                isMatchFound = true;
+            }
+        }
+        return state;
+    }
+
+    @Override
+    public List<String> getOptions() {
+        return new ArrayList<>();
+    }
+
+    @Override
+    public List<JcmdCommand> getCompileCommands() {
+        return commands;
+    }
+}
--- a/hotspot/test/compiler/compilercontrol/share/scenario/Scenario.java	Tue Oct 20 21:09:57 2015 +0300
+++ b/hotspot/test/compiler/compilercontrol/share/scenario/Scenario.java	Tue Oct 20 21:12:25 2015 +0300
@@ -33,6 +33,8 @@
 import jdk.test.lib.OutputAnalyzer;
 import jdk.test.lib.Pair;
 import jdk.test.lib.ProcessTools;
+import jdk.test.lib.dcmd.CommandExecutorException;
+import jdk.test.lib.dcmd.JcmdExecutor;
 import pool.PoolHelper;
 
 import java.io.BufferedReader;
@@ -43,6 +45,7 @@
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedHashSet;
@@ -60,11 +63,13 @@
     private final List<String> vmopts;
     private final Map<Executable, State> states;
     private final List<Consumer<OutputAnalyzer>> processors;
+    private final List<String> jcmdExecCommands;
 
     private Scenario(boolean isValid,
                      List<String> vmopts,
                      Map<Executable, State> states,
-                     List<CompileCommand> compileCommands) {
+                     List<CompileCommand> compileCommands,
+                     List<JcmdCommand> jcmdCommands) {
         this.isValid = isValid;
         this.vmopts = vmopts;
         this.states = states;
@@ -84,6 +89,21 @@
         }
         processors.add(new CommandProcessor(nonQuieted));
         processors.add(new QuietProcessor(quieted));
+        jcmdExecCommands = new ArrayList<>();
+        boolean addCommandMet = false;
+        for (JcmdCommand cmd : jcmdCommands) {
+            switch (cmd.jcmdType) {
+                case ADD:
+                    if (!addCommandMet) {
+                        jcmdExecCommands.add(JcmdType.ADD.command);
+                    }
+                    addCommandMet = true;
+                    break;
+                default:
+                    jcmdExecCommands.add(cmd.jcmdType.command);
+                    break;
+            }
+        }
     }
 
     /**
@@ -128,7 +148,8 @@
     }
 
     /*
-     * Performs connection with a test VM, sends method states
+     * Performs connection with a test VM, sends method states and performs
+     * JCMD operations on a test VM.
      */
     private void connectTestVM(ServerSocket serverSocket) {
         /*
@@ -145,6 +166,7 @@
             // Get pid of the executed process
             int pid = Integer.parseInt(in.readLine());
             Asserts.assertNE(pid, 0, "Got incorrect pid");
+            executeJCMD(pid);
             // serialize and send state map
             for (Executable x : states.keySet()) {
                 pw.println("{");
@@ -157,6 +179,20 @@
         }
     }
 
+    // Executes all diagnostic commands
+    private void executeJCMD(int pid) {
+        for (String command : jcmdExecCommands) {
+            new JcmdExecutor() {
+                @Override
+                protected List<String> createCommandLine(String cmd)
+                        throws CommandExecutorException {
+                    return Arrays.asList(jcmdBinary, Integer.toString(pid),
+                            cmd);
+                }
+            }.execute(command);
+        }
+    }
+
     /**
      * Gets states of methods for this scenario
      *
@@ -178,12 +214,35 @@
     }
 
     /**
+     * Type of diagnostic (jcmd) command
+     */
+    public static enum JcmdType {
+        ADD("Compiler.directives_add " + Type.JCMD.fileName),
+        PRINT("Compiler.directives_print"),
+        CLEAR("Compiler.directives_clear"),
+        REMOVE("Compiler.directives_remove");
+
+        public final String command;
+        private JcmdType(String command) {
+            this.command = command;
+        }
+    }
+
+    /**
      * Type of the compile command
      */
     public static enum Type {
         OPTION(""),
         FILE("command_file"),
-        DIRECTIVE("directives.json");
+        DIRECTIVE("directives.json"),
+        JCMD("jcmd_directives.json") {
+            @Override
+            public CompileCommand createCompileCommand(Command command,
+                    MethodDescriptor md, Compiler compiler) {
+                return new JcmdCommand(command, md, compiler, this,
+                        JcmdType.ADD);
+            }
+        };
 
         public final String fileName;
 
@@ -205,23 +264,30 @@
         private final Set<String> vmopts = new LinkedHashSet<>();
         private final Map<Type, StateBuilder<CompileCommand>> builders
                 = new HashMap<>();
+        private final JcmdStateBuilder jcmdStateBuilder;
 
         public Builder() {
             builders.put(Type.FILE, new CommandFileBuilder(Type.FILE.fileName));
             builders.put(Type.OPTION, new CommandOptionsBuilder());
             builders.put(Type.DIRECTIVE, new DirectiveBuilder(
                     Type.DIRECTIVE.fileName));
+            jcmdStateBuilder = new JcmdStateBuilder(Type.JCMD.fileName);
         }
 
         public void add(CompileCommand compileCommand) {
             String[] vmOptions = compileCommand.command.vmOpts;
             Collections.addAll(vmopts, vmOptions);
-            StateBuilder builder = builders.get(compileCommand.type);
-            if (builder == null) {
-                throw new Error("TESTBUG: Missing builder for the type: "
-                        + compileCommand.type);
+            if (compileCommand.type == Type.JCMD) {
+                jcmdStateBuilder.add((JcmdCommand) compileCommand);
+            } else {
+                StateBuilder<CompileCommand> builder = builders.get(
+                        compileCommand.type);
+                if (builder == null) {
+                    throw new Error("TESTBUG: Missing builder for the type: "
+                            + compileCommand.type);
+                }
+                builder.add(compileCommand);
             }
-            builder.add(compileCommand);
         }
 
         public Scenario build() {
@@ -235,19 +301,33 @@
             Map<Executable, State> directiveFileStates
                     = builders.get(Type.DIRECTIVE).getStates();
 
+            // get all jcmd commands
+            List<JcmdCommand> jcmdCommands = jcmdStateBuilder
+                    .getCompileCommands();
+            boolean isClearedState = false;
+            if (jcmdClearedState(jcmdCommands)) {
+                isClearedState = true;
+            }
+
             // Merge states
             List<Pair<Executable, Callable<?>>> methods = new PoolHelper()
                     .getAllMethods();
             Map<Executable, State> finalStates = new HashMap<>();
+            Map<Executable, State> jcmdStates = jcmdStateBuilder.getStates();
             for (Pair<Executable, Callable<?>> pair : methods) {
                 Executable x = pair.first;
                 State commandOptionState = commandOptionStates.get(x);
                 State commandFileState = commandFileStates.get(x);
                 State st = State.merge(commandOptionState, commandFileState);
-                State directiveState = directiveFileStates.get(x);
-                if (directiveState != null) {
-                    st = directiveState;
+                if (!isClearedState) {
+                    State directiveState = directiveFileStates.get(x);
+                    if (directiveState != null) {
+                        st = directiveState;
+                    }
                 }
+                State jcmdState = jcmdStates.get(x);
+                st = State.merge(st, jcmdState);
+
                 finalStates.put(x, st);
             }
 
@@ -266,7 +346,19 @@
                 options.addAll(builder.getOptions());
                 isValid &= builder.isValid();
             }
-            return new Scenario(isValid, options, finalStates, ccList);
+            options.addAll(jcmdStateBuilder.getOptions());
+            return new Scenario(isValid, options, finalStates, ccList,
+                    jcmdCommands);
+        }
+
+        // shows if jcmd have passed a clear command
+        private boolean jcmdClearedState(List<JcmdCommand> jcmdCommands) {
+            for (JcmdCommand jcmdCommand : jcmdCommands) {
+                if (jcmdCommand.jcmdType == JcmdType.CLEAR) {
+                    return true;
+                }
+            }
+            return false;
         }
     }
 }