author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 55509 | d58442b8abc1 |
permissions | -rw-r--r-- |
42650 | 1 |
/* |
55094
80dd2b549354
8224931: disable JAOTC invokedynamic support until 8223533 is fixed
dlong
parents:
54084
diff
changeset
|
2 |
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. |
42650 | 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 |
||
51436 | 24 |
|
25 |
||
42650 | 26 |
package jdk.tools.jaotc; |
27 |
||
28 |
import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC; |
|
29 |
import static org.graalvm.compiler.core.common.GraalOptions.ImmutableCode; |
|
30 |
import static org.graalvm.compiler.hotspot.meta.HotSpotAOTProfilingPlugin.Options.TieredAOT; |
|
31 |
||
53071 | 32 |
import java.io.IOException; |
42650 | 33 |
import java.io.PrintWriter; |
34 |
import java.text.MessageFormat; |
|
53071 | 35 |
import java.util.ArrayList; |
36 |
import java.util.Collections; |
|
42650 | 37 |
import java.util.List; |
43405
1fab8e6866d7
8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents:
42650
diff
changeset
|
38 |
import java.util.ListIterator; |
42650 | 39 |
import java.util.Set; |
53071 | 40 |
import java.util.StringTokenizer; |
41 |
import java.util.stream.Stream; |
|
42 |
import java.nio.file.Files; |
|
43 |
import java.nio.file.Paths; |
|
42650 | 44 |
|
46640 | 45 |
import org.graalvm.compiler.api.replacements.SnippetReflectionProvider; |
42650 | 46 |
import org.graalvm.compiler.api.runtime.GraalJVMCICompiler; |
46640 | 47 |
import org.graalvm.compiler.debug.DebugContext; |
48 |
import org.graalvm.compiler.debug.DebugContext.Activation; |
|
46344 | 49 |
import org.graalvm.compiler.hotspot.CompilerConfigurationFactory; |
43405
1fab8e6866d7
8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents:
42650
diff
changeset
|
50 |
import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig; |
46344 | 51 |
import org.graalvm.compiler.hotspot.HotSpotGraalCompilerFactory; |
52 |
import org.graalvm.compiler.hotspot.HotSpotGraalOptionValues; |
|
51206
14b870bda24f
8207069: [AOT] we should check that VM uses the same GC as one used for AOT library generation.
kvn
parents:
49873
diff
changeset
|
53 |
import org.graalvm.compiler.hotspot.HotSpotGraalRuntime; |
42650 | 54 |
import org.graalvm.compiler.hotspot.HotSpotHostBackend; |
47668 | 55 |
import org.graalvm.compiler.hotspot.meta.HotSpotInvokeDynamicPlugin; |
43405
1fab8e6866d7
8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents:
42650
diff
changeset
|
56 |
import org.graalvm.compiler.java.GraphBuilderPhase; |
1fab8e6866d7
8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents:
42650
diff
changeset
|
57 |
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration; |
55094
80dd2b549354
8224931: disable JAOTC invokedynamic support until 8223533 is fixed
dlong
parents:
54084
diff
changeset
|
58 |
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext; |
46344 | 59 |
import org.graalvm.compiler.options.OptionValues; |
43405
1fab8e6866d7
8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents:
42650
diff
changeset
|
60 |
import org.graalvm.compiler.phases.BasePhase; |
1fab8e6866d7
8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents:
42650
diff
changeset
|
61 |
import org.graalvm.compiler.phases.PhaseSuite; |
1fab8e6866d7
8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents:
42650
diff
changeset
|
62 |
import org.graalvm.compiler.phases.tiers.HighTierContext; |
46640 | 63 |
import org.graalvm.compiler.printer.GraalDebugHandlersFactory; |
42650 | 64 |
import org.graalvm.compiler.runtime.RuntimeProvider; |
65 |
||
51436 | 66 |
import jdk.tools.jaotc.Options.Option; |
67 |
import jdk.tools.jaotc.binformat.BinaryContainer; |
|
42650 | 68 |
import jdk.vm.ci.meta.MetaAccessProvider; |
69 |
import jdk.vm.ci.meta.ResolvedJavaMethod; |
|
70 |
import jdk.vm.ci.runtime.JVMCI; |
|
71 |
||
46949 | 72 |
public final class Main { |
42650 | 73 |
|
46949 | 74 |
final Options options = new Options(); |
75 |
private PrintWriter log; |
|
76 |
LogPrinter printer; |
|
77 |
GraalFilters filters; |
|
42650 | 78 |
|
79 |
private static final int EXIT_OK = 0; // No errors. |
|
80 |
private static final int EXIT_CMDERR = 2; // Bad command-line arguments and/or switches. |
|
81 |
private static final int EXIT_ABNORMAL = 4; // Terminated abnormally. |
|
82 |
||
83 |
private static final String PROGNAME = "jaotc"; |
|
84 |
||
85 |
private static final String JVM_VERSION = System.getProperty("java.runtime.version"); |
|
86 |
||
87 |
public static void main(String[] args) throws Exception { |
|
88 |
Main t = new Main(); |
|
53071 | 89 |
final int exitCode = t.run(parse(args)); |
42650 | 90 |
System.exit(exitCode); |
91 |
} |
|
92 |
||
53071 | 93 |
/** |
94 |
* Expands '@file' in command line arguments by replacing '@file' with the content of 'file' |
|
95 |
* parsed by StringTokenizer. '@' character can be quoted as '@@'. |
|
96 |
*/ |
|
97 |
private static String[] parse(String[] args) throws IOException { |
|
98 |
List<String> result = new ArrayList<>(); |
|
99 |
for (String arg : args) { |
|
100 |
if (arg.length() > 1 && arg.charAt(0) == '@') { |
|
101 |
String v = arg.substring(1); |
|
102 |
if (v.charAt(0) == '@') { |
|
103 |
result.add(v); |
|
104 |
} else { |
|
105 |
try (Stream<String> file = Files.lines(Paths.get(v))) { |
|
106 |
file.map(StringTokenizer::new).map(Collections::list).flatMap(l -> l.stream().map(o -> (String) o)).forEachOrdered(result::add); |
|
107 |
} |
|
108 |
} |
|
109 |
} else { |
|
110 |
result.add(arg); |
|
111 |
} |
|
112 |
} |
|
113 |
return result.toArray(String[]::new); |
|
114 |
} |
|
115 |
||
42650 | 116 |
private int run(String[] args) { |
46949 | 117 |
log = new PrintWriter(System.out); |
118 |
printer = new LogPrinter(this, log); |
|
42650 | 119 |
|
120 |
try { |
|
46949 | 121 |
Options.handleOptions(this, args); |
42650 | 122 |
if (options.help) { |
123 |
showHelp(); |
|
124 |
return EXIT_OK; |
|
125 |
} |
|
126 |
if (options.version) { |
|
127 |
showVersion(); |
|
128 |
return EXIT_OK; |
|
129 |
} |
|
130 |
||
46949 | 131 |
printer.printlnInfo("Compiling " + options.outputName + "..."); |
42650 | 132 |
final long start = System.currentTimeMillis(); |
43464
f38fde4a6b52
8169588: [AOT] jaotc --classpath option is confusing
rbackman
parents:
43405
diff
changeset
|
133 |
if (!run()) { |
46344 | 134 |
return EXIT_ABNORMAL; |
43464
f38fde4a6b52
8169588: [AOT] jaotc --classpath option is confusing
rbackman
parents:
43405
diff
changeset
|
135 |
} |
42650 | 136 |
final long end = System.currentTimeMillis(); |
46949 | 137 |
printer.printlnInfo("Total time: " + (end - start) + " ms"); |
42650 | 138 |
|
139 |
return EXIT_OK; |
|
46949 | 140 |
} catch (Options.BadArgs e) { |
141 |
printer.reportError(e.key, e.args); |
|
42650 | 142 |
if (e.showUsage) { |
143 |
showUsage(); |
|
144 |
} |
|
145 |
return EXIT_CMDERR; |
|
146 |
} catch (Exception e) { |
|
147 |
e.printStackTrace(); |
|
148 |
return EXIT_ABNORMAL; |
|
149 |
} finally { |
|
150 |
log.flush(); |
|
151 |
} |
|
152 |
} |
|
153 |
||
154 |
@SuppressWarnings("try") |
|
43464
f38fde4a6b52
8169588: [AOT] jaotc --classpath option is confusing
rbackman
parents:
43405
diff
changeset
|
155 |
private boolean run() throws Exception { |
46949 | 156 |
LogPrinter.openLog(); |
42650 | 157 |
|
158 |
try { |
|
159 |
||
46949 | 160 |
final Linker linker = new Linker(this); |
161 |
final String objectFileName = linker.objFile(); |
|
162 |
final Collector collector = new Collector(this); |
|
163 |
Set<Class<?>> classesToCompile; |
|
42650 | 164 |
|
165 |
try (Timer t = new Timer(this, "")) { |
|
46949 | 166 |
classesToCompile = collector.collectClassesToCompile(); |
167 |
printer.printInfo(classesToCompile.size() + " classes found"); |
|
42650 | 168 |
} |
169 |
||
54084 | 170 |
OptionValues graalOptions = HotSpotGraalOptionValues.defaultOptions(); |
46344 | 171 |
// Setting -Dgraal.TieredAOT overrides --compile-for-tiered |
172 |
if (!TieredAOT.hasBeenSet(graalOptions)) { |
|
173 |
graalOptions = new OptionValues(graalOptions, TieredAOT, options.tiered); |
|
174 |
} |
|
46557 | 175 |
graalOptions = new OptionValues(graalOptions, GeneratePIC, true, ImmutableCode, true); |
49873 | 176 |
GraalJVMCICompiler graalCompiler = HotSpotGraalCompilerFactory.createCompiler("JAOTC", JVMCI.getRuntime(), graalOptions, CompilerConfigurationFactory.selectFactory(null, graalOptions)); |
51206
14b870bda24f
8207069: [AOT] we should check that VM uses the same GC as one used for AOT library generation.
kvn
parents:
49873
diff
changeset
|
177 |
HotSpotGraalRuntime runtime = (HotSpotGraalRuntime) graalCompiler.getGraalRuntime(); |
42650 | 178 |
HotSpotHostBackend backend = (HotSpotHostBackend) runtime.getCapability(RuntimeProvider.class).getHostBackend(); |
179 |
MetaAccessProvider metaAccess = backend.getProviders().getMetaAccess(); |
|
46949 | 180 |
filters = new GraalFilters(metaAccess); |
42650 | 181 |
|
182 |
List<AOTCompiledClass> classes; |
|
183 |
||
184 |
try (Timer t = new Timer(this, "")) { |
|
46949 | 185 |
classes = collector.collectMethodsToCompile(classesToCompile, metaAccess); |
42650 | 186 |
} |
187 |
||
188 |
// Free memory! |
|
189 |
try (Timer t = options.verbose ? new Timer(this, "Freeing memory") : null) { |
|
46949 | 190 |
printer.printMemoryUsage(); |
42650 | 191 |
classesToCompile = null; |
192 |
System.gc(); |
|
193 |
} |
|
194 |
||
47668 | 195 |
AOTDynamicTypeStore dynoStore = new AOTDynamicTypeStore(); |
196 |
AOTCompiledClass.setDynamicTypeStore(dynoStore); |
|
197 |
||
55509 | 198 |
// AOTBackend aotBackend = new AOTBackend(this, graalOptions, backend, new |
199 |
// HotSpotInvokeDynamicPlugin(dynoStore)); |
|
55094
80dd2b549354
8224931: disable JAOTC invokedynamic support until 8223533 is fixed
dlong
parents:
54084
diff
changeset
|
200 |
// Temporary workaround until JDK-8223533 is fixed. |
80dd2b549354
8224931: disable JAOTC invokedynamic support until 8223533 is fixed
dlong
parents:
54084
diff
changeset
|
201 |
// Disable invokedynamic support. |
80dd2b549354
8224931: disable JAOTC invokedynamic support until 8223533 is fixed
dlong
parents:
54084
diff
changeset
|
202 |
var indyPlugin = new HotSpotInvokeDynamicPlugin(dynoStore) { |
80dd2b549354
8224931: disable JAOTC invokedynamic support until 8223533 is fixed
dlong
parents:
54084
diff
changeset
|
203 |
@Override |
80dd2b549354
8224931: disable JAOTC invokedynamic support until 8223533 is fixed
dlong
parents:
54084
diff
changeset
|
204 |
public boolean supportsDynamicInvoke(GraphBuilderContext builder, int index, int opcode) { |
80dd2b549354
8224931: disable JAOTC invokedynamic support until 8223533 is fixed
dlong
parents:
54084
diff
changeset
|
205 |
return false; |
80dd2b549354
8224931: disable JAOTC invokedynamic support until 8223533 is fixed
dlong
parents:
54084
diff
changeset
|
206 |
} |
80dd2b549354
8224931: disable JAOTC invokedynamic support until 8223533 is fixed
dlong
parents:
54084
diff
changeset
|
207 |
}; |
80dd2b549354
8224931: disable JAOTC invokedynamic support until 8223533 is fixed
dlong
parents:
54084
diff
changeset
|
208 |
AOTBackend aotBackend = new AOTBackend(this, graalOptions, backend, indyPlugin); |
46640 | 209 |
SnippetReflectionProvider snippetReflection = aotBackend.getProviders().getSnippetReflection(); |
46344 | 210 |
AOTCompiler compiler = new AOTCompiler(this, graalOptions, aotBackend, options.threads); |
42650 | 211 |
classes = compiler.compileClasses(classes); |
212 |
||
43405
1fab8e6866d7
8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents:
42650
diff
changeset
|
213 |
GraalHotSpotVMConfig graalHotSpotVMConfig = runtime.getVMConfig(); |
1fab8e6866d7
8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents:
42650
diff
changeset
|
214 |
PhaseSuite<HighTierContext> graphBuilderSuite = aotBackend.getGraphBuilderSuite(); |
1fab8e6866d7
8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents:
42650
diff
changeset
|
215 |
ListIterator<BasePhase<? super HighTierContext>> iterator = graphBuilderSuite.findPhase(GraphBuilderPhase.class); |
1fab8e6866d7
8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents:
42650
diff
changeset
|
216 |
GraphBuilderConfiguration graphBuilderConfig = ((GraphBuilderPhase) iterator.previous()).getGraphBuilderConfig(); |
1fab8e6866d7
8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents:
42650
diff
changeset
|
217 |
|
42650 | 218 |
// Free memory! |
219 |
try (Timer t = options.verbose ? new Timer(this, "Freeing memory") : null) { |
|
46949 | 220 |
printer.printMemoryUsage(); |
42650 | 221 |
aotBackend = null; |
222 |
compiler = null; |
|
223 |
System.gc(); |
|
224 |
} |
|
225 |
||
51436 | 226 |
int gc = runtime.getGarbageCollector().ordinal() + 1; |
51206
14b870bda24f
8207069: [AOT] we should check that VM uses the same GC as one used for AOT library generation.
kvn
parents:
49873
diff
changeset
|
227 |
BinaryContainer binaryContainer = new BinaryContainer(graalOptions, graalHotSpotVMConfig, graphBuilderConfig, gc, JVM_VERSION); |
42650 | 228 |
DataBuilder dataBuilder = new DataBuilder(this, backend, classes, binaryContainer); |
46640 | 229 |
|
230 |
try (DebugContext debug = DebugContext.create(graalOptions, new GraalDebugHandlersFactory(snippetReflection)); Activation a = debug.activate()) { |
|
231 |
dataBuilder.prepareData(debug); |
|
232 |
} |
|
42650 | 233 |
|
234 |
// Print information about section sizes |
|
46949 | 235 |
printer.containersInfo(binaryContainer); |
42650 | 236 |
|
237 |
// Free memory! |
|
238 |
try (Timer t = options.verbose ? new Timer(this, "Freeing memory") : null) { |
|
46949 | 239 |
printer.printMemoryUsage(); |
42650 | 240 |
backend = null; |
241 |
for (AOTCompiledClass aotCompClass : classes) { |
|
242 |
aotCompClass.clear(); |
|
243 |
} |
|
244 |
classes.clear(); |
|
245 |
classes = null; |
|
246 |
dataBuilder = null; |
|
247 |
binaryContainer.freeMemory(); |
|
248 |
System.gc(); |
|
249 |
} |
|
250 |
||
251 |
try (Timer t = new Timer(this, "Creating binary: " + objectFileName)) { |
|
46949 | 252 |
binaryContainer.createBinary(objectFileName); |
42650 | 253 |
} |
254 |
||
255 |
// Free memory! |
|
256 |
try (Timer t = options.verbose ? new Timer(this, "Freeing memory") : null) { |
|
46949 | 257 |
printer.printMemoryUsage(); |
42650 | 258 |
binaryContainer = null; |
259 |
System.gc(); |
|
260 |
} |
|
261 |
||
46949 | 262 |
try (Timer t = new Timer(this, "Creating shared library: " + linker.libFile())) { |
263 |
linker.link(); |
|
42650 | 264 |
} |
265 |
||
46949 | 266 |
printer.printVerbose("Final memory "); |
267 |
printer.printMemoryUsage(); |
|
268 |
printer.printlnVerbose(""); |
|
42650 | 269 |
|
270 |
} finally { |
|
46949 | 271 |
LogPrinter.closeLog(); |
42650 | 272 |
} |
43464
f38fde4a6b52
8169588: [AOT] jaotc --classpath option is confusing
rbackman
parents:
43405
diff
changeset
|
273 |
return true; |
42650 | 274 |
} |
275 |
||
46949 | 276 |
void handleError(ResolvedJavaMethod resolvedMethod, Throwable e, String message) { |
277 |
String methodName = JavaMethodInfo.uniqueMethodName(resolvedMethod); |
|
42650 | 278 |
|
46949 | 279 |
if (options.debug) { |
280 |
printer.printError("Failed compilation: " + methodName + ": " + e); |
|
42650 | 281 |
} |
46949 | 282 |
|
283 |
// Ignore some exceptions when meta-compiling Graal. |
|
284 |
if (GraalFilters.shouldIgnoreException(e)) { |
|
42650 | 285 |
return; |
286 |
} |
|
287 |
||
46949 | 288 |
LogPrinter.writeLog("Failed compilation of method " + methodName + message); |
42650 | 289 |
|
46949 | 290 |
if (!options.debug) { |
291 |
printer.printError("Failed compilation: " + methodName + ": " + e); |
|
42650 | 292 |
} |
293 |
||
46949 | 294 |
if (options.verbose) { |
295 |
e.printStackTrace(log); |
|
296 |
} |
|
42650 | 297 |
|
46949 | 298 |
if (options.exitOnError) { |
299 |
System.exit(1); |
|
42650 | 300 |
} |
301 |
} |
|
302 |
||
46949 | 303 |
void warning(String key, Object... args) { |
42650 | 304 |
log.println("Warning: " + MessageFormat.format(key, args)); |
305 |
log.flush(); |
|
306 |
} |
|
307 |
||
308 |
private void showUsage() { |
|
43479 | 309 |
log.println("Usage: " + PROGNAME + " <options> list"); |
42650 | 310 |
log.println("use --help for a list of possible options"); |
46949 | 311 |
log.flush(); |
42650 | 312 |
} |
313 |
||
314 |
private void showHelp() { |
|
43479 | 315 |
log.println("Usage: " + PROGNAME + " <options> list"); |
42650 | 316 |
log.println(); |
43479 | 317 |
log.println(" list A : separated list of class names, modules, jar files"); |
318 |
log.println(" or directories which contain class files."); |
|
42650 | 319 |
log.println(); |
43479 | 320 |
log.println("where options include:"); |
46949 | 321 |
for (Option o : Options.recognizedOptions) { |
42650 | 322 |
String name = o.aliases[0].substring(1); // there must always be at least one name |
323 |
name = name.charAt(0) == '-' ? name.substring(1) : name; |
|
324 |
if (o.isHidden() || name.equals("h")) { |
|
325 |
continue; |
|
326 |
} |
|
327 |
log.println(o.help); |
|
328 |
} |
|
46949 | 329 |
log.flush(); |
42650 | 330 |
} |
331 |
||
332 |
private void showVersion() { |
|
333 |
log.println(PROGNAME + " " + JVM_VERSION); |
|
334 |
} |
|
335 |
} |