hotspot/test/compiler/compilercontrol/share/scenario/Executor.java
author iignatyev
Wed, 12 Apr 2017 19:28:47 -0700
changeset 44584 8cd22f56bfca
parent 40631 ed82623d7831
permissions -rw-r--r--
8164944: Refactor ProcessTools to get rid of dependency on java.management Reviewed-by: kvn, gtriantafill, dfazunen, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34215
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
     1
/*
44584
8cd22f56bfca 8164944: Refactor ProcessTools to get rid of dependency on java.management
iignatyev
parents: 40631
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
34215
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
     4
 *
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
     8
 *
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    13
 * accompanied this code).
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    14
 *
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    18
 *
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    21
 * questions.
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    22
 */
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    23
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    24
package compiler.compilercontrol.share.scenario;
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    25
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    26
import compiler.compilercontrol.share.actions.BaseAction;
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    27
import jdk.test.lib.Asserts;
44584
8cd22f56bfca 8164944: Refactor ProcessTools to get rid of dependency on java.management
iignatyev
parents: 40631
diff changeset
    28
import jdk.test.lib.management.InputArguments;
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 34226
diff changeset
    29
import jdk.test.lib.process.OutputAnalyzer;
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 34226
diff changeset
    30
import jdk.test.lib.process.ProcessTools;
34215
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    31
import jdk.test.lib.dcmd.CommandExecutor;
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    32
import jdk.test.lib.dcmd.PidJcmdExecutor;
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    33
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    34
import java.io.BufferedReader;
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    35
import java.io.IOException;
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    36
import java.io.InputStreamReader;
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    37
import java.io.PrintWriter;
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    38
import java.lang.reflect.Executable;
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    39
import java.net.ServerSocket;
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    40
import java.net.Socket;
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    41
import java.util.ArrayList;
44584
8cd22f56bfca 8164944: Refactor ProcessTools to get rid of dependency on java.management
iignatyev
parents: 40631
diff changeset
    42
import java.util.Arrays;
34216
2818af1ce748 8138993: JEP-JDK-8046155: Test task: add check for Compiler.directives_print diagnostic command
ppunegov
parents: 34215
diff changeset
    43
import java.util.Collections;
34215
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    44
import java.util.List;
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    45
import java.util.Map;
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    46
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    47
public class Executor {
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    48
    private final boolean isValid;
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    49
    private final List<String> vmOptions;
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    50
    private final Map<Executable, State> states;
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    51
    private final List<String> jcmdCommands;
34226
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
    52
    private final String execClass = System.getProperty("compiler."
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
    53
            + "compilercontrol.share.executor.executeClass",
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
    54
            BaseAction.class.getName());
34216
2818af1ce748 8138993: JEP-JDK-8046155: Test task: add check for Compiler.directives_print diagnostic command
ppunegov
parents: 34215
diff changeset
    55
    private OutputAnalyzer[] jcmdOutputAnalyzers;
34215
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    56
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    57
    /**
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    58
     * Constructor
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    59
     *
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    60
     * @param isValid      shows that the input given to the VM is valid and
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    61
     *                     VM shouldn't fail
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    62
     * @param vmOptions    a list of VM input options
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    63
     * @param states       a state map, or null for the non-checking execution
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    64
     * @param jcmdCommands a list of diagnostic commands to be preformed
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    65
     *                     on test VM
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    66
     */
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    67
    public Executor(boolean isValid, List<String> vmOptions,
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    68
            Map<Executable, State> states, List<String> jcmdCommands) {
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    69
        this.isValid = isValid;
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    70
        if (vmOptions == null) {
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    71
            this.vmOptions = new ArrayList<>();
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    72
        } else {
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    73
            this.vmOptions = vmOptions;
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    74
        }
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    75
        this.states = states;
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    76
        this.jcmdCommands = jcmdCommands;
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    77
    }
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    78
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    79
    /**
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    80
     * Executes separate VM a gets an OutputAnalyzer instance with the results
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    81
     * of execution
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    82
     */
34216
2818af1ce748 8138993: JEP-JDK-8046155: Test task: add check for Compiler.directives_print diagnostic command
ppunegov
parents: 34215
diff changeset
    83
    public List<OutputAnalyzer> execute() {
34215
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    84
        // Add class name that would be executed in a separate VM
34226
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
    85
        vmOptions.add(execClass);
34215
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    86
        OutputAnalyzer output;
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    87
        try (ServerSocket serverSocket = new ServerSocket(0)) {
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    88
            if (isValid) {
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    89
                // Get port test VM will connect to
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    90
                int port = serverSocket.getLocalPort();
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    91
                if (port == -1) {
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    92
                    throw new Error("Socket is not bound: " + port);
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    93
                }
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    94
                vmOptions.add(String.valueOf(port));
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    95
                if (states != null) {
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    96
                    // add flag to show that there should be state map passed
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    97
                    vmOptions.add("states");
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    98
                }
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
    99
                // Start separate thread to connect with test VM
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   100
                new Thread(() -> connectTestVM(serverSocket)).start();
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   101
            }
44584
8cd22f56bfca 8164944: Refactor ProcessTools to get rid of dependency on java.management
iignatyev
parents: 40631
diff changeset
   102
            // Start a test VM using vm flags from @run and from vm options
8cd22f56bfca 8164944: Refactor ProcessTools to get rid of dependency on java.management
iignatyev
parents: 40631
diff changeset
   103
            String[] vmInputArgs = InputArguments.getVmInputArgs();
8cd22f56bfca 8164944: Refactor ProcessTools to get rid of dependency on java.management
iignatyev
parents: 40631
diff changeset
   104
            String[] cmds = Arrays.copyOf(vmInputArgs,
8cd22f56bfca 8164944: Refactor ProcessTools to get rid of dependency on java.management
iignatyev
parents: 40631
diff changeset
   105
                    vmInputArgs.length + vmOptions.size());
8cd22f56bfca 8164944: Refactor ProcessTools to get rid of dependency on java.management
iignatyev
parents: 40631
diff changeset
   106
            System.arraycopy(vmOptions.toArray(), 0, cmds, vmInputArgs.length,
8cd22f56bfca 8164944: Refactor ProcessTools to get rid of dependency on java.management
iignatyev
parents: 40631
diff changeset
   107
                    vmOptions.size());
8cd22f56bfca 8164944: Refactor ProcessTools to get rid of dependency on java.management
iignatyev
parents: 40631
diff changeset
   108
            output = ProcessTools.executeTestJvm(cmds);
34215
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   109
        } catch (Throwable thr) {
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   110
            throw new Error("Execution failed: " + thr.getMessage(), thr);
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   111
        }
34216
2818af1ce748 8138993: JEP-JDK-8046155: Test task: add check for Compiler.directives_print diagnostic command
ppunegov
parents: 34215
diff changeset
   112
2818af1ce748 8138993: JEP-JDK-8046155: Test task: add check for Compiler.directives_print diagnostic command
ppunegov
parents: 34215
diff changeset
   113
        List<OutputAnalyzer> outputList = new ArrayList<>();
2818af1ce748 8138993: JEP-JDK-8046155: Test task: add check for Compiler.directives_print diagnostic command
ppunegov
parents: 34215
diff changeset
   114
        outputList.add(output);
2818af1ce748 8138993: JEP-JDK-8046155: Test task: add check for Compiler.directives_print diagnostic command
ppunegov
parents: 34215
diff changeset
   115
        if (jcmdOutputAnalyzers != null) {
2818af1ce748 8138993: JEP-JDK-8046155: Test task: add check for Compiler.directives_print diagnostic command
ppunegov
parents: 34215
diff changeset
   116
            Collections.addAll(outputList, jcmdOutputAnalyzers);
2818af1ce748 8138993: JEP-JDK-8046155: Test task: add check for Compiler.directives_print diagnostic command
ppunegov
parents: 34215
diff changeset
   117
        }
2818af1ce748 8138993: JEP-JDK-8046155: Test task: add check for Compiler.directives_print diagnostic command
ppunegov
parents: 34215
diff changeset
   118
        return outputList;
34215
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   119
    }
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   120
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   121
    /*
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   122
     * Performs connection with a test VM, sends method states and performs
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   123
     * JCMD operations on a test VM.
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   124
     */
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   125
    private void connectTestVM(ServerSocket serverSocket) {
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   126
        /*
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   127
         * There are no way to prove that accept was invoked before we started
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   128
         * test VM that connects to this serverSocket. Connection timeout is
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   129
         * enough
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   130
         */
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   131
        try (
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   132
                Socket socket = serverSocket.accept();
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   133
                PrintWriter pw = new PrintWriter(socket.getOutputStream(),
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   134
                        true);
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   135
                BufferedReader in = new BufferedReader(new InputStreamReader(
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   136
                        socket.getInputStream()))) {
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   137
            // Get pid of the executed process
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   138
            int pid = Integer.parseInt(in.readLine());
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   139
            Asserts.assertNE(pid, 0, "Got incorrect pid");
34216
2818af1ce748 8138993: JEP-JDK-8046155: Test task: add check for Compiler.directives_print diagnostic command
ppunegov
parents: 34215
diff changeset
   140
            jcmdOutputAnalyzers = executeJCMD(pid);
34215
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   141
            if (states != null) {
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   142
                // serialize and send state map
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   143
                states.forEach((executable, state) -> {
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   144
                    pw.println("{");
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   145
                    pw.println(executable.toGenericString());
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   146
                    pw.println(state.toString());
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   147
                    pw.println("}");
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   148
                });
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   149
            } else {
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   150
                pw.println();
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   151
            }
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   152
        } catch (IOException e) {
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   153
            throw new Error("Failed to write data: " + e.getMessage(), e);
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   154
        }
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   155
    }
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   156
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   157
    // Executes all diagnostic commands
34216
2818af1ce748 8138993: JEP-JDK-8046155: Test task: add check for Compiler.directives_print diagnostic command
ppunegov
parents: 34215
diff changeset
   158
    protected OutputAnalyzer[] executeJCMD(int pid) {
2818af1ce748 8138993: JEP-JDK-8046155: Test task: add check for Compiler.directives_print diagnostic command
ppunegov
parents: 34215
diff changeset
   159
        int size = jcmdCommands.size();
2818af1ce748 8138993: JEP-JDK-8046155: Test task: add check for Compiler.directives_print diagnostic command
ppunegov
parents: 34215
diff changeset
   160
        OutputAnalyzer[] outputArray = new OutputAnalyzer[size];
34215
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   161
        CommandExecutor jcmdExecutor = new PidJcmdExecutor(String.valueOf(pid));
34216
2818af1ce748 8138993: JEP-JDK-8046155: Test task: add check for Compiler.directives_print diagnostic command
ppunegov
parents: 34215
diff changeset
   162
        for (int i = 0; i < size; i++) {
2818af1ce748 8138993: JEP-JDK-8046155: Test task: add check for Compiler.directives_print diagnostic command
ppunegov
parents: 34215
diff changeset
   163
            outputArray[i] = jcmdExecutor.execute(jcmdCommands.get(i));
34215
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   164
        }
34216
2818af1ce748 8138993: JEP-JDK-8046155: Test task: add check for Compiler.directives_print diagnostic command
ppunegov
parents: 34215
diff changeset
   165
        return outputArray;
34215
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   166
    }
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents:
diff changeset
   167
}