hotspot/test/compiler/compilercontrol/share/actions/BaseAction.java
author tpivovarova
Tue, 12 Jul 2016 18:24:48 +0300
changeset 40059 c2304140ed64
parent 38089 9e58203ef0e2
child 40631 ed82623d7831
permissions -rw-r--r--
8132919: Put compiler tests in packages Reviewed-by: vlivanov, dpochepk Contributed-by: igor.ignatyev@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33452
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
     1
/*
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
     4
 *
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
     8
 *
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    13
 * accompanied this code).
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    14
 *
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    18
 *
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    21
 * questions.
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    22
 */
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    23
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    24
package compiler.compilercontrol.share.actions;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    25
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38089
diff changeset
    26
import compiler.compilercontrol.share.pool.PoolHelper;
33452
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    27
import compiler.compilercontrol.share.scenario.State;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    28
import jdk.test.lib.Pair;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    29
import jdk.test.lib.ProcessTools;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    30
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    31
import java.io.BufferedReader;
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38089
diff changeset
    32
import java.io.IOException;
33452
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    33
import java.io.InputStreamReader;
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38089
diff changeset
    34
import java.io.OutputStreamWriter;
33452
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    35
import java.io.PrintWriter;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    36
import java.lang.reflect.Executable;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    37
import java.net.InetAddress;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    38
import java.net.Socket;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    39
import java.util.Arrays;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    40
import java.util.HashMap;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    41
import java.util.List;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    42
import java.util.ListIterator;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    43
import java.util.Map;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    44
import java.util.concurrent.Callable;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    45
import java.util.stream.Collectors;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    46
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    47
public class BaseAction {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    48
    private static final List<Pair<Executable, Callable<?>>> METHODS;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    49
    private static final Map<String, Executable> METHODS_NAMES;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    50
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    51
    static {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    52
        METHODS = new PoolHelper().getAllMethods();
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    53
        METHODS_NAMES = METHODS.stream().collect(Collectors.toMap(
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    54
                pair -> pair.first.toGenericString(),
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    55
                pair -> pair.first));
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    56
    }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    57
34226
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34215
diff changeset
    58
    public static void main(String[] args) {
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34215
diff changeset
    59
        new BaseAction().communicate(args);
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34215
diff changeset
    60
    }
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34215
diff changeset
    61
34215
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents: 33452
diff changeset
    62
    /*
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents: 33452
diff changeset
    63
     * args[0] is a port to connect
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents: 33452
diff changeset
    64
     * args[1] is an optional parameter that shows that the state map should be
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents: 33452
diff changeset
    65
     *         passed
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents: 33452
diff changeset
    66
     */
34226
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34215
diff changeset
    67
    protected void communicate(String[] args) {
33452
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    68
        if (args.length < 1) {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    69
            throw new Error("TESTBUG: requires port as parameter: "
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    70
                    + Arrays.toString(args));
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    71
        }
34215
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents: 33452
diff changeset
    72
        boolean getStates = false;
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents: 33452
diff changeset
    73
        if (args.length == 2) {
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents: 33452
diff changeset
    74
            if ("states".equals(args[1])) {
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents: 33452
diff changeset
    75
                getStates = true;
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents: 33452
diff changeset
    76
            } else {
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents: 33452
diff changeset
    77
                throw new Error("TESTBUG: incorrect argument: "+ args[1]);
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents: 33452
diff changeset
    78
            }
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents: 33452
diff changeset
    79
        }
38089
9e58203ef0e2 8153992: Some hotspot tests fail on compact2 due to an unnecessary test library dependency
akulyakh
parents: 34226
diff changeset
    80
        long pid;
33452
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    81
        try {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    82
            pid = ProcessTools.getProcessId();
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    83
        } catch (Exception e) {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    84
            throw new Error("Could not determine own pid", e);
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    85
        }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    86
        int port = Integer.parseInt(args[0]);
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    87
        System.out.println("INFO: Client connection port = " + port);
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    88
        List<String> lines;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    89
        try (
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    90
                Socket socket = new Socket(InetAddress.getLocalHost(), port);
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    91
                BufferedReader in = new BufferedReader(
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    92
                        new InputStreamReader(socket.getInputStream()));
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    93
                PrintWriter out = new PrintWriter(
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    94
                        new OutputStreamWriter(socket.getOutputStream()))) {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    95
            // send own pid to execute jcmd if needed
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    96
            out.println(String.valueOf(pid));
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    97
            out.flush();
34215
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents: 33452
diff changeset
    98
            if (getStates) {
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents: 33452
diff changeset
    99
                lines = in.lines().collect(Collectors.toList());
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents: 33452
diff changeset
   100
                check(decodeMap(lines));
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents: 33452
diff changeset
   101
            } else {
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents: 33452
diff changeset
   102
                in.readLine();
ae6ba67d6420 8066156: JEP-JDK-8046155: Test task: stress by dcmd
ppunegov
parents: 33452
diff changeset
   103
            }
33452
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   104
        } catch (IOException e) {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   105
            throw new Error("Error on performing network operation", e);
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   106
        }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   107
    }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   108
34226
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34215
diff changeset
   109
    private Map<Executable, State> decodeMap(List<String> lines) {
33452
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   110
        if (lines == null || lines.size() == 0) {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   111
            throw new Error("TESTBUG: unexpected lines list");
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   112
        }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   113
        Map<Executable, State> stateMap = new HashMap<>();
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   114
        int startIndex = 0;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   115
        ListIterator<String> iterator = lines.listIterator();
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   116
        while (iterator.hasNext()) {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   117
            int index = iterator.nextIndex();
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   118
            String next = iterator.next();
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   119
            switch (next) {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   120
                case "{" :
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   121
                    startIndex = index;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   122
                    break;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   123
                case "}" :
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   124
                    // method name goes after {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   125
                    Executable executable = METHODS_NAMES.get(lines.get(
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   126
                            ++startIndex));
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   127
                    // state description starts after method
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   128
                    State state = State.fromString(lines.subList(++startIndex,
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   129
                            index).toArray(new String[index - startIndex]));
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   130
                    stateMap.put(executable, state);
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   131
                    break;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   132
            }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   133
        }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   134
        return stateMap;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   135
    }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   136
34226
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34215
diff changeset
   137
    protected void check(Map<Executable, State> methodStates) {
33452
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   138
        // Check each method from the pool
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   139
        METHODS.forEach(pair -> {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   140
            Executable x = pair.first;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   141
            CompileAction.checkCompiled(x, methodStates.get(x));
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   142
        });
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   143
    }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   144
}