hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/Main.java
changeset 46344 694c102fd8ed
parent 46327 91576389a517
child 46557 eb30f7891bae
--- a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/Main.java	Mon Dec 12 16:16:27 2016 +0300
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/Main.java	Wed Mar 22 13:42:45 2017 -0700
@@ -60,11 +60,15 @@
 import jdk.tools.jaotc.utils.Timer;
 
 import org.graalvm.compiler.api.runtime.GraalJVMCICompiler;
+import org.graalvm.compiler.hotspot.CompilerConfigurationFactory;
 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
+import org.graalvm.compiler.hotspot.HotSpotGraalCompilerFactory;
+import org.graalvm.compiler.hotspot.HotSpotGraalOptionValues;
 import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider;
 import org.graalvm.compiler.hotspot.HotSpotHostBackend;
 import org.graalvm.compiler.java.GraphBuilderPhase;
 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
+import org.graalvm.compiler.options.OptionValues;
 import org.graalvm.compiler.phases.BasePhase;
 import org.graalvm.compiler.phases.PhaseSuite;
 import org.graalvm.compiler.phases.tiers.HighTierContext;
@@ -76,11 +80,6 @@
 import jdk.vm.ci.runtime.JVMCI;
 
 public class Main implements LogPrinter {
-    static {
-        GeneratePIC.setValue(true);
-        ImmutableCode.setValue(true);
-    }
-
     static class BadArgs extends Exception {
         private static final long serialVersionUID = 1L;
         final String key;
@@ -132,7 +131,7 @@
         abstract void process(Main task, String opt, String arg) throws BadArgs;
     }
 
-    static Option[] recognizedOptions = { new Option("  --output <file>            Output file name", true, "--output") {
+    static Option[] recognizedOptions = {new Option("  --output <file>            Output file name", true, "--output") {
         @Override
         void process(Main task, String opt, String arg) {
             String name = arg;
@@ -172,7 +171,7 @@
     }, new Option("  --compile-for-tiered       Generate profiling code for tiered compilation", false, "--compile-for-tiered") {
         @Override
         void process(Main task, String opt, String arg) {
-            TieredAOT.setValue(true);
+            task.options.tiered = true;
         }
     }, new Option("  --compile-with-assertions  Compile with java assertions", false, "--compile-with-assertions") {
         @Override
@@ -265,6 +264,7 @@
         public boolean help;
         public boolean version;
         public boolean compileWithAssertions;
+        public boolean tiered;
     }
 
     /* package */final Options options = new Options();
@@ -307,7 +307,7 @@
             printlnInfo("Compiling " + options.outputName + "...");
             final long start = System.currentTimeMillis();
             if (!run()) {
-              return EXIT_ABNORMAL;
+                return EXIT_ABNORMAL;
             }
             final long end = System.currentTimeMillis();
             printlnInfo("Total time: " + (end - start) + " ms");
@@ -351,8 +351,7 @@
     }
 
     /**
-     * Visual Studio supported versions
-     * Search Order is:  VS2013, VS2015, VS2012
+     * Visual Studio supported versions Search Order is: VS2013, VS2015, VS2012
      */
     public enum VSVERSIONS {
         VS2013("VS120COMNTOOLS", "C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\bin\\amd64\\link.exe"),
@@ -367,20 +366,23 @@
             this.wkp = wellknownpath;
         }
 
-        String EnvVariable()   { return envvariable; }
-        String WellKnownPath() { return wkp; }
+        String EnvVariable() {
+            return envvariable;
+        }
+
+        String WellKnownPath() {
+            return wkp;
+        }
     }
 
     /**
-     * Search for Visual Studio link.exe
-     * Search Order is:  VS2013, VS2015, VS2012
+     * Search for Visual Studio link.exe Search Order is: VS2013, VS2015, VS2012
      */
     private static String getWindowsLinkPath() {
         String link = "\\VC\\bin\\amd64\\link.exe";
 
         /**
-         * First try searching the paths pointed to by
-         * the VS environment variables.
+         * First try searching the paths pointed to by the VS environment variables.
          */
         for (VSVERSIONS vs : VSVERSIONS.values()) {
             String vspath = System.getenv(vs.EnvVariable());
@@ -388,13 +390,13 @@
                 File commonTools = new File(vspath);
                 File vsRoot = commonTools.getParentFile().getParentFile();
                 File linkPath = new File(vsRoot, link);
-                if (linkPath.exists()) return linkPath.getPath();
+                if (linkPath.exists())
+                    return linkPath.getPath();
             }
         }
 
         /**
-         * If we didn't find via the VS environment variables,
-         * try the well known paths
+         * If we didn't find via the VS environment variables, try the well known paths
          */
         for (VSVERSIONS vs : VSVERSIONS.values()) {
             String wkp = vs.WellKnownPath();
@@ -438,7 +440,13 @@
                 printInfo(classesToCompile.size() + " classes found");
             }
 
-            GraalJVMCICompiler graalCompiler = (GraalJVMCICompiler) JVMCI.getRuntime().getCompiler();
+            OptionValues graalOptions = HotSpotGraalOptionValues.HOTSPOT_OPTIONS;
+            // Setting -Dgraal.TieredAOT overrides --compile-for-tiered
+            if (!TieredAOT.hasBeenSet(graalOptions)) {
+                graalOptions = new OptionValues(graalOptions, TieredAOT, options.tiered);
+            }
+            graalOptions = new OptionValues(HotSpotGraalOptionValues.HOTSPOT_OPTIONS, GeneratePIC, true, ImmutableCode, true);
+            GraalJVMCICompiler graalCompiler = HotSpotGraalCompilerFactory.createCompiler(JVMCI.getRuntime(), graalOptions, CompilerConfigurationFactory.selectFactory(null, graalOptions));
             HotSpotGraalRuntimeProvider runtime = (HotSpotGraalRuntimeProvider) graalCompiler.getGraalRuntime();
             HotSpotHostBackend backend = (HotSpotHostBackend) runtime.getCapability(RuntimeProvider.class).getHostBackend();
             MetaAccessProvider metaAccess = backend.getProviders().getMetaAccess();
@@ -458,8 +466,8 @@
                 System.gc();
             }
 
-            AOTBackend aotBackend = new AOTBackend(this, backend, filters);
-            AOTCompiler compiler = new AOTCompiler(this, aotBackend, options.threads);
+            AOTBackend aotBackend = new AOTBackend(this, graalOptions, backend, filters);
+            AOTCompiler compiler = new AOTCompiler(this, graalOptions, aotBackend, options.threads);
             classes = compiler.compileClasses(classes);
 
             GraalHotSpotVMConfig graalHotSpotVMConfig = runtime.getVMConfig();
@@ -475,7 +483,7 @@
                 System.gc();
             }
 
-            BinaryContainer binaryContainer = new BinaryContainer(graalHotSpotVMConfig, graphBuilderConfig, JVM_VERSION);
+            BinaryContainer binaryContainer = new BinaryContainer(graalOptions, graalHotSpotVMConfig, graphBuilderConfig, JVM_VERSION);
             DataBuilder dataBuilder = new DataBuilder(this, backend, classes, binaryContainer);
             dataBuilder.prepareData();
 
@@ -524,11 +532,9 @@
 
             if (name.endsWith(".so")) {
                 objectFileName = name.substring(0, name.length() - ".so".length());
-            }
-            else if (name.endsWith(".dylib")) {
+            } else if (name.endsWith(".dylib")) {
                 objectFileName = name.substring(0, name.length() - ".dylib".length());
-            }
-            else if (name.endsWith(".dll")) {
+            } else if (name.endsWith(".dll")) {
                 objectFileName = name.substring(0, name.length() - ".dll".length());
             }
 
@@ -536,34 +542,32 @@
                 case "Linux":
                     // libraryFileName = options.outputName + ".so";
                     objectFileName = objectFileName + ".o";
-                    linkerPath = (options.linkerpath != null) ?  options.linkerpath : "ld";
+                    linkerPath = (options.linkerpath != null) ? options.linkerpath : "ld";
                     linkerCmd = linkerPath + " -shared -z noexecstack -o " + libraryFileName + " " + objectFileName;
                     break;
                 case "SunOS":
                     // libraryFileName = options.outputName + ".so";
                     objectFileName = objectFileName + ".o";
-                    linkerPath = (options.linkerpath != null) ?  options.linkerpath : "ld";
+                    linkerPath = (options.linkerpath != null) ? options.linkerpath : "ld";
                     linkerCmd = linkerPath + " -shared -o " + libraryFileName + " " + objectFileName;
                     break;
                 case "Mac OS X":
                     // libraryFileName = options.outputName + ".dylib";
                     objectFileName = objectFileName + ".o";
-                    linkerPath = (options.linkerpath != null) ?  options.linkerpath : "ld";
+                    linkerPath = (options.linkerpath != null) ? options.linkerpath : "ld";
                     linkerCmd = linkerPath + " -dylib -o " + libraryFileName + " " + objectFileName;
                     break;
                 default:
                     if (osName.startsWith("Windows")) {
                         // libraryFileName = options.outputName + ".dll";
                         objectFileName = objectFileName + ".obj";
-                        linkerPath = (options.linkerpath != null) ?
-                            options.linkerpath : getWindowsLinkPath();
+                        linkerPath = (options.linkerpath != null) ? options.linkerpath : getWindowsLinkPath();
                         if (linkerPath == null) {
                             throw new InternalError("Can't locate Microsoft Visual Studio amd64 link.exe");
                         }
                         linkerCmd = linkerPath + " /DLL /OPT:NOREF /NOLOGO /NOENTRY" + " /OUT:" + libraryFileName + " " + objectFileName;
                         break;
-                    }
-                    else
+                    } else
                         throw new InternalError("Unsupported platform: " + osName);
             }