hotspot/test/compiler/compilercontrol/jcmd/ClearDirectivesFileStackTest.java
author iignatyev
Tue, 26 Jan 2016 00:25:20 +0300
changeset 35597 0174e7c4489f
parent 34216 2818af1ce748
child 36796 c751f445f5d4
permissions -rw-r--r--
8148136: compile control tests have incorrect @build directives Reviewed-by: kvn
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 /
35597
0174e7c4489f 8148136: compile control tests have incorrect @build directives
iignatyev
parents: 34216
diff changeset
    30
 * @build compiler.compilercontrol.jcmd.ClearDirectivesFileStackTest
0174e7c4489f 8148136: compile control tests have incorrect @build directives
iignatyev
parents: 34216
diff changeset
    31
 *        pool.sub.* pool.subpack.* sun.hotspot.WhiteBox
33453
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    32
 *        compiler.testlibrary.CompilerUtils compiler.compilercontrol.share.actions.*
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    33
 * @run main ClassFileInstaller sun.hotspot.WhiteBox
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    34
 *                              sun.hotspot.WhiteBox$WhiteBoxPermission
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    35
 * @run main/othervm compiler.compilercontrol.jcmd.ClearDirectivesFileStackTest
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
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    38
package compiler.compilercontrol.jcmd;
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    39
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    40
import compiler.compilercontrol.share.AbstractTestBase;
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    41
import compiler.compilercontrol.share.method.MethodDescriptor;
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    42
import compiler.compilercontrol.share.scenario.Command;
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    43
import compiler.compilercontrol.share.scenario.CommandGenerator;
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    44
import compiler.compilercontrol.share.scenario.CompileCommand;
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    45
import compiler.compilercontrol.share.scenario.JcmdCommand;
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    46
import compiler.compilercontrol.share.scenario.Scenario;
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    47
import jdk.test.lib.Utils;
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    48
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    49
import java.lang.reflect.Executable;
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    50
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    51
public class ClearDirectivesFileStackTest extends AbstractTestBase {
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    52
    private static final int AMOUNT = Utils.getRandomInstance().nextInt(100);
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    53
    private final CommandGenerator cmdGen = new CommandGenerator();
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    54
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    55
    public static void main(String[] args) {
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    56
        new ClearDirectivesFileStackTest().test();
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
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    59
    @Override
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    60
    public void test() {
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    61
        Scenario.Builder builder = Scenario.getBuilder();
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    62
        // Add some commands with directives file
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    63
        for (int i = 0; i < AMOUNT; i++) {
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    64
            Executable exec = Utils.getRandomElement(METHODS).first;
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    65
            MethodDescriptor methodDescriptor = getValidMethodDescriptor(exec);
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    66
            Command command = cmdGen.generateCommand();
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    67
            if (command == Command.NONEXISTENT) {
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    68
                // skip invalid command
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    69
                command = Command.COMPILEONLY;
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    70
            }
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    71
            CompileCommand compileCommand = new CompileCommand(command,
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    72
                    methodDescriptor, cmdGen.generateCompiler(),
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    73
                    Scenario.Type.DIRECTIVE);
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    74
            compileCommand.print();
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    75
            builder.add(compileCommand);
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    76
        }
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    77
        // clear the stack
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    78
        builder.add(new JcmdCommand(Command.NONEXISTENT, null, null,
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    79
                Scenario.Type.JCMD, Scenario.JcmdType.CLEAR));
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    80
        // print all directives after the clear
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    81
        builder.add(new JcmdCommand(Command.NONEXISTENT, null, null,
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    82
                Scenario.Type.JCMD, Scenario.JcmdType.PRINT));
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    83
        Scenario scenario = builder.build();
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    84
        scenario.execute();
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    85
    }
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    86
}