< prev index next >

src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/Main.java

Print this page
rev 53024 : [mq]: 8215322


   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 
  25 
  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 

  32 import java.io.PrintWriter;
  33 import java.text.MessageFormat;


  34 import java.util.List;
  35 import java.util.ListIterator;
  36 import java.util.Set;




  37 
  38 import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
  39 import org.graalvm.compiler.api.runtime.GraalJVMCICompiler;
  40 import org.graalvm.compiler.debug.DebugContext;
  41 import org.graalvm.compiler.debug.DebugContext.Activation;
  42 import org.graalvm.compiler.hotspot.CompilerConfigurationFactory;
  43 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
  44 import org.graalvm.compiler.hotspot.HotSpotGraalCompilerFactory;
  45 import org.graalvm.compiler.hotspot.HotSpotGraalOptionValues;
  46 import org.graalvm.compiler.hotspot.HotSpotGraalRuntime;
  47 import org.graalvm.compiler.hotspot.HotSpotHostBackend;
  48 import org.graalvm.compiler.hotspot.meta.HotSpotInvokeDynamicPlugin;
  49 import org.graalvm.compiler.java.GraphBuilderPhase;
  50 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
  51 import org.graalvm.compiler.options.OptionValues;
  52 import org.graalvm.compiler.phases.BasePhase;
  53 import org.graalvm.compiler.phases.PhaseSuite;
  54 import org.graalvm.compiler.phases.tiers.HighTierContext;
  55 import org.graalvm.compiler.printer.GraalDebugHandlersFactory;
  56 import org.graalvm.compiler.runtime.RuntimeProvider;


  61 import jdk.vm.ci.meta.ResolvedJavaMethod;
  62 import jdk.vm.ci.runtime.JVMCI;
  63 
  64 public final class Main {
  65 
  66     final Options options = new Options();
  67     private PrintWriter log;
  68     LogPrinter printer;
  69     GraalFilters filters;
  70 
  71     private static final int EXIT_OK = 0;        // No errors.
  72     private static final int EXIT_CMDERR = 2;    // Bad command-line arguments and/or switches.
  73     private static final int EXIT_ABNORMAL = 4;  // Terminated abnormally.
  74 
  75     private static final String PROGNAME = "jaotc";
  76 
  77     private static final String JVM_VERSION = System.getProperty("java.runtime.version");
  78 
  79     public static void main(String[] args) throws Exception {
  80         Main t = new Main();
  81         final int exitCode = t.run(args);
  82         System.exit(exitCode);
  83     }
  84 























  85     private int run(String[] args) {
  86         log = new PrintWriter(System.out);
  87         printer = new LogPrinter(this, log);
  88 
  89         try {
  90             Options.handleOptions(this, args);
  91             if (options.help) {
  92                 showHelp();
  93                 return EXIT_OK;
  94             }
  95             if (options.version) {
  96                 showVersion();
  97                 return EXIT_OK;
  98             }
  99 
 100             printer.printlnInfo("Compiling " + options.outputName + "...");
 101             final long start = System.currentTimeMillis();
 102             if (!run()) {
 103                 return EXIT_ABNORMAL;
 104             }




   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 jdk.tools.jaotc;
  25 
  26 import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC;
  27 import static org.graalvm.compiler.core.common.GraalOptions.ImmutableCode;
  28 import static org.graalvm.compiler.hotspot.meta.HotSpotAOTProfilingPlugin.Options.TieredAOT;
  29 
  30 import java.io.IOException;
  31 import java.io.PrintWriter;
  32 import java.text.MessageFormat;
  33 import java.util.ArrayList;
  34 import java.util.Collections;
  35 import java.util.List;
  36 import java.util.ListIterator;
  37 import java.util.Set;
  38 import java.util.StringTokenizer;
  39 import java.util.stream.Stream;
  40 import java.nio.file.Files;
  41 import java.nio.file.Paths;
  42 
  43 import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
  44 import org.graalvm.compiler.api.runtime.GraalJVMCICompiler;
  45 import org.graalvm.compiler.debug.DebugContext;
  46 import org.graalvm.compiler.debug.DebugContext.Activation;
  47 import org.graalvm.compiler.hotspot.CompilerConfigurationFactory;
  48 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
  49 import org.graalvm.compiler.hotspot.HotSpotGraalCompilerFactory;
  50 import org.graalvm.compiler.hotspot.HotSpotGraalOptionValues;
  51 import org.graalvm.compiler.hotspot.HotSpotGraalRuntime;
  52 import org.graalvm.compiler.hotspot.HotSpotHostBackend;
  53 import org.graalvm.compiler.hotspot.meta.HotSpotInvokeDynamicPlugin;
  54 import org.graalvm.compiler.java.GraphBuilderPhase;
  55 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
  56 import org.graalvm.compiler.options.OptionValues;
  57 import org.graalvm.compiler.phases.BasePhase;
  58 import org.graalvm.compiler.phases.PhaseSuite;
  59 import org.graalvm.compiler.phases.tiers.HighTierContext;
  60 import org.graalvm.compiler.printer.GraalDebugHandlersFactory;
  61 import org.graalvm.compiler.runtime.RuntimeProvider;


  66 import jdk.vm.ci.meta.ResolvedJavaMethod;
  67 import jdk.vm.ci.runtime.JVMCI;
  68 
  69 public final class Main {
  70 
  71     final Options options = new Options();
  72     private PrintWriter log;
  73     LogPrinter printer;
  74     GraalFilters filters;
  75 
  76     private static final int EXIT_OK = 0;        // No errors.
  77     private static final int EXIT_CMDERR = 2;    // Bad command-line arguments and/or switches.
  78     private static final int EXIT_ABNORMAL = 4;  // Terminated abnormally.
  79 
  80     private static final String PROGNAME = "jaotc";
  81 
  82     private static final String JVM_VERSION = System.getProperty("java.runtime.version");
  83 
  84     public static void main(String[] args) throws Exception {
  85         Main t = new Main();
  86         final int exitCode = t.run(parse(args));
  87         System.exit(exitCode);
  88     }
  89 
  90     /**
  91      * Expands '@file' in command line arguments by replacing '@file' with the content of 'file'
  92      * parsed by StringTokenizer. '@' character can be quoted as '@@'.
  93      */
  94     private static String[] parse(String[] args) throws IOException {
  95         List<String> result = new ArrayList<>();
  96         for (String arg : args) {
  97             if (arg.length() > 1 && arg.charAt(0) == '@') {
  98                 String v = arg.substring(1);
  99                 if (v.charAt(0) == '@') {
 100                     result.add(v);
 101                 } else {
 102                     try (Stream<String> file = Files.lines(Paths.get(v))) {
 103                         file.map(StringTokenizer::new).map(Collections::list).flatMap(l -> l.stream().map(o -> (String) o)).forEachOrdered(result::add);
 104                     }
 105                 }
 106             } else {
 107                 result.add(arg);
 108             }
 109         }
 110         return result.toArray(String[]::new);
 111     }
 112 
 113     private int run(String[] args) {
 114         log = new PrintWriter(System.out);
 115         printer = new LogPrinter(this, log);
 116 
 117         try {
 118             Options.handleOptions(this, args);
 119             if (options.help) {
 120                 showHelp();
 121                 return EXIT_OK;
 122             }
 123             if (options.version) {
 124                 showVersion();
 125                 return EXIT_OK;
 126             }
 127 
 128             printer.printlnInfo("Compiling " + options.outputName + "...");
 129             final long start = System.currentTimeMillis();
 130             if (!run()) {
 131                 return EXIT_ABNORMAL;
 132             }


< prev index next >