author | iignatyev |
Wed, 30 Jan 2019 09:30:40 -0800 | |
changeset 53577 | 7d19ac37d7d1 |
parent 52866 | 4fd8872aebb4 |
child 55270 | 759acbfb9fde |
permissions | -rw-r--r-- |
46383 | 1 |
/* |
49881
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
2 |
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. |
46383 | 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 sun.hotspot.tools.ctw; |
|
25 |
||
46392
d5572756efd6
8178835: CTW Runner should check that all classes have been compiled
iignatyev
parents:
46391
diff
changeset
|
26 |
import jdk.test.lib.Asserts; |
46383 | 27 |
import jdk.test.lib.Utils; |
28 |
import jdk.test.lib.process.ProcessTools; |
|
46385
6b890c9a717f
8178727: CTW should provide class names in error messages
iignatyev
parents:
46383
diff
changeset
|
29 |
import jdk.test.lib.util.Pair; |
46383 | 30 |
|
46391
e33ea5371600
8178913: CTW library does not close all opened resources
iignatyev
parents:
46385
diff
changeset
|
31 |
import java.io.BufferedReader; |
46383 | 32 |
import java.io.IOException; |
33 |
import java.nio.file.Files; |
|
34 |
import java.nio.file.Path; |
|
35 |
import java.nio.file.Paths; |
|
36 |
import java.util.ArrayList; |
|
37 |
import java.util.List; |
|
38 |
import java.util.concurrent.TimeUnit; |
|
39 |
import java.util.function.Predicate; |
|
40 |
import java.util.regex.Pattern; |
|
41 |
import java.util.stream.Collectors; |
|
42 |
||
43 |
/** |
|
44 |
* Runs CompileTheWorld for exact one target. If an error occurs during |
|
45 |
* compilation of class N, this driver class saves error information and |
|
46 |
* restarts CTW from class N + 1. All saved errors are reported at the end. |
|
47 |
* <pre> |
|
48 |
* Usage: <target to compile> |
|
49 |
* </pre> |
|
50 |
*/ |
|
51 |
public class CtwRunner { |
|
52 |
private static final Predicate<String> IS_CLASS_LINE = Pattern.compile( |
|
53 |
"^\\[\\d+\\]\\s*\\S+\\s*$").asPredicate(); |
|
54 |
||
49881
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
55 |
private static final String USAGE = "Usage: CtwRunner <artifact to compile> [start[%] stop[%]]"; |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
56 |
|
46383 | 57 |
public static void main(String[] args) throws Exception { |
49881
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
58 |
CtwRunner runner; |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
59 |
switch (args.length) { |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
60 |
case 1: runner = new CtwRunner(args[0]); break; |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
61 |
case 3: runner = new CtwRunner(args[0], args[1], args[2]); break; |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
62 |
default: throw new Error(USAGE); |
46383 | 63 |
} |
49881
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
64 |
|
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
65 |
runner.run(); |
46383 | 66 |
} |
67 |
||
68 |
private final List<Throwable> errors; |
|
47766
bfba73a06c8c
8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents:
47216
diff
changeset
|
69 |
private final String target; |
46383 | 70 |
private final Path targetPath; |
71 |
private final String targetName; |
|
72 |
||
49881
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
73 |
private final int start, stop; |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
74 |
private final boolean isStartStopPercentage; |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
75 |
|
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
76 |
private CtwRunner(String target, String start, String stop) { |
47766
bfba73a06c8c
8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents:
47216
diff
changeset
|
77 |
if (target.startsWith("modules")) { |
46383 | 78 |
targetPath = Paths |
79 |
.get(Utils.TEST_JDK) |
|
80 |
.resolve("lib") |
|
47766
bfba73a06c8c
8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents:
47216
diff
changeset
|
81 |
.resolve("modules"); |
bfba73a06c8c
8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents:
47216
diff
changeset
|
82 |
if (target.equals("modules")){ |
bfba73a06c8c
8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents:
47216
diff
changeset
|
83 |
target = targetPath.toString(); |
bfba73a06c8c
8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents:
47216
diff
changeset
|
84 |
} |
bfba73a06c8c
8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents:
47216
diff
changeset
|
85 |
targetName = target.replace(':', '_') |
bfba73a06c8c
8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents:
47216
diff
changeset
|
86 |
.replace('.', '_') |
bfba73a06c8c
8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents:
47216
diff
changeset
|
87 |
.replace(',', '_'); |
46383 | 88 |
} else { |
89 |
targetPath = Paths.get(target).toAbsolutePath(); |
|
47766
bfba73a06c8c
8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents:
47216
diff
changeset
|
90 |
targetName = targetPath.getFileName().toString(); |
46383 | 91 |
} |
47766
bfba73a06c8c
8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents:
47216
diff
changeset
|
92 |
this.target = target; |
46383 | 93 |
errors = new ArrayList<>(); |
49881
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
94 |
|
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
95 |
if (start.endsWith("%") && stop.endsWith("%")) { |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
96 |
int startPercentage = Integer.parseInt(start.substring(0, start.length() - 1));; |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
97 |
int stopPercentage = Integer.parseInt(stop.substring(0, stop.length() - 1)); |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
98 |
if (startPercentage < 0 || startPercentage > 100 || |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
99 |
stopPercentage < 0 || stopPercentage > 100) { |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
100 |
throw new Error(USAGE); |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
101 |
} |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
102 |
this.start = startPercentage; |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
103 |
this.stop = stopPercentage; |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
104 |
this.isStartStopPercentage = true; |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
105 |
} else if (!start.endsWith("%") && !stop.endsWith("%")) { |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
106 |
this.start = Integer.parseInt(start); |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
107 |
this.stop = Integer.parseInt(stop); |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
108 |
this.isStartStopPercentage = false; |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
109 |
} else { |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
110 |
throw new Error(USAGE); |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
111 |
} |
46383 | 112 |
} |
113 |
||
49881
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
114 |
private CtwRunner(String target) { |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
115 |
this(target, "0%", "100%"); |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
116 |
} |
46383 | 117 |
|
118 |
private void run() { |
|
119 |
startCtwforAllClasses(); |
|
120 |
if (!errors.isEmpty()) { |
|
121 |
StringBuilder sb = new StringBuilder(); |
|
122 |
sb.append("There were ") |
|
123 |
.append(errors.size()) |
|
124 |
.append(" errors:["); |
|
125 |
System.err.println(sb.toString()); |
|
126 |
for (Throwable e : errors) { |
|
127 |
sb.append("{") |
|
128 |
.append(e.getMessage()) |
|
129 |
.append("}"); |
|
130 |
e.printStackTrace(System.err); |
|
131 |
System.err.println(); |
|
132 |
} |
|
133 |
sb.append("]"); |
|
134 |
throw new AssertionError(sb.toString()); |
|
135 |
} |
|
136 |
} |
|
137 |
||
49881
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
138 |
private long start(long totalClassCount) { |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
139 |
if (isStartStopPercentage) { |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
140 |
return totalClassCount * start / 100; |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
141 |
} else if (start > totalClassCount) { |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
142 |
System.err.println("WARNING: start [" + start + "] > totalClassCount [" + totalClassCount + "]"); |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
143 |
return totalClassCount; |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
144 |
} else { |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
145 |
return start; |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
146 |
} |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
147 |
} |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
148 |
|
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
149 |
private long stop(long totalClassCount) { |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
150 |
if (isStartStopPercentage) { |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
151 |
return totalClassCount * stop / 100; |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
152 |
} else if (stop > totalClassCount) { |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
153 |
System.err.println("WARNING: stop [" + start + "] > totalClassCount [" + totalClassCount + "]"); |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
154 |
return totalClassCount; |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
155 |
} else { |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
156 |
return stop; |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
157 |
} |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
158 |
} |
46383 | 159 |
|
160 |
private void startCtwforAllClasses() { |
|
49881
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
161 |
long totalClassCount = classCount(); |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
162 |
|
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
163 |
long classStart = start(totalClassCount); |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
164 |
long classStop = stop(totalClassCount); |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
165 |
|
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
166 |
long classCount = classStop - classStart; |
46392
d5572756efd6
8178835: CTW Runner should check that all classes have been compiled
iignatyev
parents:
46391
diff
changeset
|
167 |
Asserts.assertGreaterThan(classCount, 0L, |
47766
bfba73a06c8c
8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents:
47216
diff
changeset
|
168 |
target + "(at " + targetPath + ") does not have any classes"); |
49881
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
169 |
|
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
170 |
System.out.printf("Compiling %d classes (of %d total classes) starting at %d and ending at %d\n", |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
171 |
classCount, totalClassCount, classStart, classStop); |
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
172 |
|
46383 | 173 |
boolean done = false; |
174 |
while (!done) { |
|
49881
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
175 |
String[] cmd = cmd(classStart, classStop); |
46383 | 176 |
try { |
177 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( |
|
178 |
/* addTestVmAndJavaOptions = */ true, |
|
179 |
cmd); |
|
180 |
String commandLine = pb.command() |
|
181 |
.stream() |
|
182 |
.collect(Collectors.joining(" ")); |
|
183 |
String phase = phaseName(classStart); |
|
184 |
Path out = Paths.get(".", phase + ".out"); |
|
48192
e5e07e9361ec
8191273: applications/ctw/modules tests fail intermittently
iignatyev
parents:
47766
diff
changeset
|
185 |
Path err = Paths.get(".", phase + ".err"); |
46383 | 186 |
System.out.printf("%s %dms START : [%s]%n" + |
187 |
"cout/cerr are redirected to %s%n", |
|
188 |
phase, TimeUnit.NANOSECONDS.toMillis(System.nanoTime()), |
|
48192
e5e07e9361ec
8191273: applications/ctw/modules tests fail intermittently
iignatyev
parents:
47766
diff
changeset
|
189 |
commandLine, phase); |
e5e07e9361ec
8191273: applications/ctw/modules tests fail intermittently
iignatyev
parents:
47766
diff
changeset
|
190 |
int exitCode = pb.redirectOutput(out.toFile()) |
e5e07e9361ec
8191273: applications/ctw/modules tests fail intermittently
iignatyev
parents:
47766
diff
changeset
|
191 |
.redirectError(err.toFile()) |
e5e07e9361ec
8191273: applications/ctw/modules tests fail intermittently
iignatyev
parents:
47766
diff
changeset
|
192 |
.start() |
e5e07e9361ec
8191273: applications/ctw/modules tests fail intermittently
iignatyev
parents:
47766
diff
changeset
|
193 |
.waitFor(); |
46383 | 194 |
System.out.printf("%s %dms END : exit code = %d%n", |
195 |
phase, TimeUnit.NANOSECONDS.toMillis(System.nanoTime()), |
|
196 |
exitCode); |
|
46385
6b890c9a717f
8178727: CTW should provide class names in error messages
iignatyev
parents:
46383
diff
changeset
|
197 |
Pair<String, Long> lastClass = getLastClass(out); |
46383 | 198 |
if (exitCode == 0) { |
46392
d5572756efd6
8178835: CTW Runner should check that all classes have been compiled
iignatyev
parents:
46391
diff
changeset
|
199 |
long lastIndex = lastClass == null ? -1 : lastClass.second; |
49881
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
200 |
if (lastIndex != classStop) { |
46392
d5572756efd6
8178835: CTW Runner should check that all classes have been compiled
iignatyev
parents:
46391
diff
changeset
|
201 |
errors.add(new Error(phase + ": Unexpected zero exit code" |
d5572756efd6
8178835: CTW Runner should check that all classes have been compiled
iignatyev
parents:
46391
diff
changeset
|
202 |
+ "before finishing all compilations." |
d5572756efd6
8178835: CTW Runner should check that all classes have been compiled
iignatyev
parents:
46391
diff
changeset
|
203 |
+ " lastClass[" + lastIndex |
49881
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
204 |
+ "] != classStop[" + classStop + "]")); |
46392
d5572756efd6
8178835: CTW Runner should check that all classes have been compiled
iignatyev
parents:
46391
diff
changeset
|
205 |
} else { |
d5572756efd6
8178835: CTW Runner should check that all classes have been compiled
iignatyev
parents:
46391
diff
changeset
|
206 |
System.out.println("Executed CTW for all " + classCount |
47766
bfba73a06c8c
8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents:
47216
diff
changeset
|
207 |
+ " classes in " + target + "(at " + targetPath + ")"); |
46392
d5572756efd6
8178835: CTW Runner should check that all classes have been compiled
iignatyev
parents:
46391
diff
changeset
|
208 |
} |
46383 | 209 |
done = true; |
210 |
} else { |
|
46385
6b890c9a717f
8178727: CTW should provide class names in error messages
iignatyev
parents:
46383
diff
changeset
|
211 |
if (lastClass == null) { |
46383 | 212 |
errors.add(new Error(phase + ": failed during preload" |
213 |
+ " with classStart = " + classStart)); |
|
214 |
// skip one class |
|
215 |
++classStart; |
|
216 |
} else { |
|
217 |
errors.add(new Error(phase + ": failed during" |
|
46385
6b890c9a717f
8178727: CTW should provide class names in error messages
iignatyev
parents:
46383
diff
changeset
|
218 |
+ " compilation of class #" + lastClass.second |
6b890c9a717f
8178727: CTW should provide class names in error messages
iignatyev
parents:
46383
diff
changeset
|
219 |
+ " : " + lastClass.first)); |
46383 | 220 |
// continue with the next class |
46385
6b890c9a717f
8178727: CTW should provide class names in error messages
iignatyev
parents:
46383
diff
changeset
|
221 |
classStart = lastClass.second + 1; |
46383 | 222 |
} |
223 |
} |
|
224 |
} catch (Exception e) { |
|
225 |
throw new Error("failed to run from " + classStart, e); |
|
226 |
} |
|
227 |
} |
|
228 |
} |
|
229 |
||
46392
d5572756efd6
8178835: CTW Runner should check that all classes have been compiled
iignatyev
parents:
46391
diff
changeset
|
230 |
private long classCount() { |
47766
bfba73a06c8c
8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents:
47216
diff
changeset
|
231 |
List<PathHandler> phs = PathHandler.create(target); |
46775
d0af9e47df69
8184738: CTW fails with assert(!method->method_holder()->is_not_initialized()) failed: method holder must be initialized
iignatyev
parents:
46392
diff
changeset
|
232 |
long result = phs.stream() |
d0af9e47df69
8184738: CTW fails with assert(!method->method_holder()->is_not_initialized()) failed: method holder must be initialized
iignatyev
parents:
46392
diff
changeset
|
233 |
.mapToLong(PathHandler::classCount) |
d0af9e47df69
8184738: CTW fails with assert(!method->method_holder()->is_not_initialized()) failed: method holder must be initialized
iignatyev
parents:
46392
diff
changeset
|
234 |
.sum(); |
d0af9e47df69
8184738: CTW fails with assert(!method->method_holder()->is_not_initialized()) failed: method holder must be initialized
iignatyev
parents:
46392
diff
changeset
|
235 |
phs.forEach(PathHandler::close); |
d0af9e47df69
8184738: CTW fails with assert(!method->method_holder()->is_not_initialized()) failed: method holder must be initialized
iignatyev
parents:
46392
diff
changeset
|
236 |
return result; |
46392
d5572756efd6
8178835: CTW Runner should check that all classes have been compiled
iignatyev
parents:
46391
diff
changeset
|
237 |
} |
d5572756efd6
8178835: CTW Runner should check that all classes have been compiled
iignatyev
parents:
46391
diff
changeset
|
238 |
|
46385
6b890c9a717f
8178727: CTW should provide class names in error messages
iignatyev
parents:
46383
diff
changeset
|
239 |
private Pair<String, Long> getLastClass(Path errFile) { |
46391
e33ea5371600
8178913: CTW library does not close all opened resources
iignatyev
parents:
46385
diff
changeset
|
240 |
try (BufferedReader reader = Files.newBufferedReader(errFile)) { |
e33ea5371600
8178913: CTW library does not close all opened resources
iignatyev
parents:
46385
diff
changeset
|
241 |
String line = reader.lines() |
46383 | 242 |
.filter(IS_CLASS_LINE) |
46391
e33ea5371600
8178913: CTW library does not close all opened resources
iignatyev
parents:
46385
diff
changeset
|
243 |
.reduce((a, b) -> b) |
e33ea5371600
8178913: CTW library does not close all opened resources
iignatyev
parents:
46385
diff
changeset
|
244 |
.orElse(null); |
46383 | 245 |
if (line != null) { |
246 |
int open = line.indexOf('[') + 1; |
|
247 |
int close = line.indexOf(']'); |
|
46385
6b890c9a717f
8178727: CTW should provide class names in error messages
iignatyev
parents:
46383
diff
changeset
|
248 |
long index = Long.parseLong(line.substring(open, close)); |
6b890c9a717f
8178727: CTW should provide class names in error messages
iignatyev
parents:
46383
diff
changeset
|
249 |
String name = line.substring(close + 1).trim().replace('.', '/'); |
6b890c9a717f
8178727: CTW should provide class names in error messages
iignatyev
parents:
46383
diff
changeset
|
250 |
return new Pair<>(name, index); |
46383 | 251 |
} |
252 |
} catch (IOException ioe) { |
|
253 |
throw new Error("can not read " + errFile + " : " |
|
254 |
+ ioe.getMessage(), ioe); |
|
255 |
} |
|
46385
6b890c9a717f
8178727: CTW should provide class names in error messages
iignatyev
parents:
46383
diff
changeset
|
256 |
return null; |
46383 | 257 |
} |
258 |
||
49881
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
259 |
private String[] cmd(long classStart, long classStop) { |
46383 | 260 |
String phase = phaseName(classStart); |
46392
d5572756efd6
8178835: CTW Runner should check that all classes have been compiled
iignatyev
parents:
46391
diff
changeset
|
261 |
return new String[] { |
46383 | 262 |
"-Xbatch", |
263 |
"-XX:-UseCounterDecay", |
|
264 |
"-XX:-ShowMessageBoxOnError", |
|
265 |
"-XX:+UnlockDiagnosticVMOptions", |
|
53577
7d19ac37d7d1
8207922: ctw of jdk.security.auth failed with "Unexpected zero exit codebefore finishing all compilations"
iignatyev
parents:
52866
diff
changeset
|
266 |
// redirect VM output to cerr so it won't collide w/ ctw output |
7d19ac37d7d1
8207922: ctw of jdk.security.auth failed with "Unexpected zero exit codebefore finishing all compilations"
iignatyev
parents:
52866
diff
changeset
|
267 |
"-XX:+DisplayVMOutputToStderr", |
46383 | 268 |
// define phase start |
269 |
"-DCompileTheWorldStartAt=" + classStart, |
|
49881
29419b836244
8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents:
48192
diff
changeset
|
270 |
"-DCompileTheWorldStopAt=" + classStop, |
46383 | 271 |
// CTW library uses WhiteBox API |
272 |
"-XX:+WhiteBoxAPI", "-Xbootclasspath/a:.", |
|
273 |
// export jdk.internal packages used by CTW library |
|
274 |
"--add-exports", "java.base/jdk.internal.jimage=ALL-UNNAMED", |
|
275 |
"--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED", |
|
276 |
"--add-exports", "java.base/jdk.internal.reflect=ALL-UNNAMED", |
|
52866
4fd8872aebb4
8214915: CtwRunner misses export for jdk.internal.access
iignatyev
parents:
49881
diff
changeset
|
277 |
"--add-exports", "java.base/jdk.internal.access=ALL-UNNAMED", |
46383 | 278 |
// enable diagnostic logging |
279 |
"-XX:+LogCompilation", |
|
46385
6b890c9a717f
8178727: CTW should provide class names in error messages
iignatyev
parents:
46383
diff
changeset
|
280 |
// use phase specific log, hs_err and ciReplay files |
46383 | 281 |
String.format("-XX:LogFile=hotspot_%s_%%p.log", phase), |
282 |
String.format("-XX:ErrorFile=hs_err_%s_%%p.log", phase), |
|
46385
6b890c9a717f
8178727: CTW should provide class names in error messages
iignatyev
parents:
46383
diff
changeset
|
283 |
String.format("-XX:ReplayDataFile=replay_%s_%%p.log", phase), |
46383 | 284 |
// MethodHandle MUST NOT be compiled |
285 |
"-XX:CompileCommand=exclude,java/lang/invoke/MethodHandle.*", |
|
286 |
// CTW entry point |
|
287 |
CompileTheWorld.class.getName(), |
|
47766
bfba73a06c8c
8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents:
47216
diff
changeset
|
288 |
target, |
46383 | 289 |
}; |
290 |
} |
|
291 |
||
292 |
private String phaseName(long classStart) { |
|
293 |
return String.format("%s_%d", targetName, classStart); |
|
294 |
} |
|
295 |
||
296 |
} |