hotspot/test/compiler/compilercontrol/jcmd/ClearDirectivesFileStackTest.java
author ppunegov
Tue, 24 Nov 2015 20:55:46 +0300
changeset 34216 2818af1ce748
parent 33481 cef122ff96a1
child 35597 0174e7c4489f
permissions -rw-r--r--
8138993: JEP-JDK-8046155: Test task: add check for Compiler.directives_print diagnostic command Summary: Test Compiler.directive_print command Reviewed-by: iignatyev, neliasso
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33453
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
     1
/*
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
     4
 *
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
     8
 *
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    13
 * accompanied this code).
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    14
 *
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    18
 *
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    21
 * questions.
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    22
 */
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    23
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    24
/*
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    25
 * @test
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    26
 * @bug 8137167
33481
cef122ff96a1 8140668: Quarantine RandomValidCommandsTest
ppunegov
parents: 33453
diff changeset
    27
 * @ignore 8140405
33453
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    28
 * @summary Tests jcmd to be able to clear directives added via options
34216
2818af1ce748 8138993: JEP-JDK-8046155: Test task: add check for Compiler.directives_print diagnostic command
ppunegov
parents: 33481
diff changeset
    29
 * @library /testlibrary /test/lib /compiler/testlibrary ../share /
33453
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    30
 * @build ClearDirectivesFileStackTest pool.sub.* pool.subpack.* sun.hotspot.WhiteBox
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    31
 *        compiler.testlibrary.CompilerUtils compiler.compilercontrol.share.actions.*
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    32
 * @run main ClassFileInstaller sun.hotspot.WhiteBox
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    33
 *                              sun.hotspot.WhiteBox$WhiteBoxPermission
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    34
 * @run main/othervm compiler.compilercontrol.jcmd.ClearDirectivesFileStackTest
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    35
 */
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    36
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    37
package compiler.compilercontrol.jcmd;
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    38
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    39
import compiler.compilercontrol.share.AbstractTestBase;
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    40
import compiler.compilercontrol.share.method.MethodDescriptor;
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    41
import compiler.compilercontrol.share.scenario.Command;
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    42
import compiler.compilercontrol.share.scenario.CommandGenerator;
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    43
import compiler.compilercontrol.share.scenario.CompileCommand;
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    44
import compiler.compilercontrol.share.scenario.JcmdCommand;
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    45
import compiler.compilercontrol.share.scenario.Scenario;
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    46
import jdk.test.lib.Utils;
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    47
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    48
import java.lang.reflect.Executable;
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    49
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    50
public class ClearDirectivesFileStackTest extends AbstractTestBase {
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    51
    private static final int AMOUNT = Utils.getRandomInstance().nextInt(100);
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    52
    private final CommandGenerator cmdGen = new CommandGenerator();
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    53
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    54
    public static void main(String[] args) {
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    55
        new ClearDirectivesFileStackTest().test();
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    56
    }
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    57
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    58
    @Override
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    59
    public void test() {
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    60
        Scenario.Builder builder = Scenario.getBuilder();
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    61
        // Add some commands with directives file
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    62
        for (int i = 0; i < AMOUNT; i++) {
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    63
            Executable exec = Utils.getRandomElement(METHODS).first;
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    64
            MethodDescriptor methodDescriptor = getValidMethodDescriptor(exec);
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    65
            Command command = cmdGen.generateCommand();
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    66
            if (command == Command.NONEXISTENT) {
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    67
                // skip invalid command
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    68
                command = Command.COMPILEONLY;
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    69
            }
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    70
            CompileCommand compileCommand = new CompileCommand(command,
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    71
                    methodDescriptor, cmdGen.generateCompiler(),
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    72
                    Scenario.Type.DIRECTIVE);
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    73
            compileCommand.print();
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    74
            builder.add(compileCommand);
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    75
        }
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    76
        // clear the stack
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    77
        builder.add(new JcmdCommand(Command.NONEXISTENT, null, null,
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    78
                Scenario.Type.JCMD, Scenario.JcmdType.CLEAR));
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    79
        // print all directives after the clear
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    80
        builder.add(new JcmdCommand(Command.NONEXISTENT, null, null,
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    81
                Scenario.Type.JCMD, Scenario.JcmdType.PRINT));
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    82
        Scenario scenario = builder.build();
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    83
        scenario.execute();
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    84
    }
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    85
}