hotspot/test/compiler/compilercontrol/jcmd/AddAndRemoveTest.java
author dcubed
Tue, 05 Jul 2016 14:00:21 -0700
changeset 39696 80c9894e18f9
parent 39438 206a712f8f16
child 40059 c2304140ed64
permissions -rw-r--r--
8160739: quarantine tests failing due to -XX:TieredStopAtLevel=1 8160743: quarantine tests that can't attach symbolicator to the process on MacOS X Reviewed-by: sspitsyn, dholmes, 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
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    27
 * @summary Tests directives to be able to add and remove directives
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 36796
diff changeset
    28
 * @modules java.base/jdk.internal.misc
39438
206a712f8f16 8132920: use package in compiler testlibraries
iignatyev
parents: 38152
diff changeset
    29
 * @library /testlibrary /test/lib ../share /
35597
0174e7c4489f 8148136: compile control tests have incorrect @build directives
iignatyev
parents: 33453
diff changeset
    30
 * @build compiler.compilercontrol.jcmd.AddAndRemoveTest
0174e7c4489f 8148136: compile control tests have incorrect @build directives
iignatyev
parents: 33453
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.*
36796
c751f445f5d4 8150054: Make compilercontrol test ignore xcomp
neliasso
parents: 35753
diff changeset
    33
 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
39438
206a712f8f16 8132920: use package in compiler testlibraries
iignatyev
parents: 38152
diff changeset
    34
 *                                sun.hotspot.WhiteBox$WhiteBoxPermission
36796
c751f445f5d4 8150054: Make compilercontrol test ignore xcomp
neliasso
parents: 35753
diff changeset
    35
 * @run driver compiler.compilercontrol.jcmd.AddAndRemoveTest
33453
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.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 AddAndRemoveTest extends AbstractTestBase {
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    51
    private static final int AMOUNT = Integer.getInteger(
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    52
            "compiler.compilercontrol.jcmd.AddAndRemoveTest.amount", 10);
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 AddAndRemoveTest().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 JCMD
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 md = getValidMethodDescriptor(exec);
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    65
            CompileCommand compileCommand = new JcmdCommand(Command.COMPILEONLY,
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    66
                    md, null, Scenario.Type.JCMD, Scenario.JcmdType.ADD);
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    67
            compileCommand.print();
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    68
            builder.add(compileCommand);
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
        // Remove half of them
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    71
        for (int i = 0; i < AMOUNT / 2; i++) {
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    72
            /* remove jcmd command doesn't need method, compiler etc.
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    73
               command will be ignored */
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    74
            builder.add(new JcmdCommand(Command.NONEXISTENT, null, null,
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    75
                    Scenario.Type.JCMD, Scenario.JcmdType.REMOVE));
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
        Scenario scenario = builder.build();
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    78
        scenario.execute();
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    79
    }
b62df32d4af8 8066166: JEP-JDK-8046155: Test task: dcmd tests
ppunegov
parents:
diff changeset
    80
}