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