hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotGraalRuntime.java
changeset 46459 7d4e637d3f21
parent 46371 0337d0617e7b
child 46536 79d8dffda212
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotGraalRuntime.java	Fri May 12 13:14:25 2017 -0700
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotGraalRuntime.java	Fri May 12 13:56:13 2017 -0700
@@ -40,6 +40,7 @@
 import java.lang.management.ManagementFactory;
 import java.nio.file.FileVisitResult;
 import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.nio.file.SimpleFileVisitor;
@@ -80,6 +81,7 @@
 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
 import jdk.vm.ci.hotspot.HotSpotVMConfigStore;
 import jdk.vm.ci.meta.JavaKind;
+import jdk.vm.ci.meta.ResolvedJavaMethod;
 import jdk.vm.ci.runtime.JVMCIBackend;
 
 //JaCoCo Exclude
@@ -110,6 +112,7 @@
     private final GraalHotSpotVMConfig config;
 
     private final OptionValues options;
+    private final HotSpotGraalMBean mBean;
 
     /**
      * @param compilerConfigurationFactory factory for the compiler configuration
@@ -127,6 +130,8 @@
             options = initialOptions;
         }
 
+        this.mBean = HotSpotGraalMBean.create();
+
         snippetCounterGroups = GraalOptions.SnippetCounters.getValue(options) ? new ArrayList<>() : null;
         CompilerConfiguration compilerConfiguration = compilerConfigurationFactory.createCompilerConfiguration();
         BackendMap backendMap = compilerConfigurationFactory.createBackendMap();
@@ -224,6 +229,17 @@
 
         runtimeStartTime = System.nanoTime();
         bootstrapJVMCI = config.getFlag("BootstrapJVMCI", Boolean.class);
+
+        assert checkPathIsInvalid(DELETED_OUTPUT_DIRECTORY);
+    }
+
+    private static boolean checkPathIsInvalid(String path) {
+        try {
+            Paths.get(path);
+            return false;
+        } catch (InvalidPathException e) {
+            return true;
+        }
     }
 
     private HotSpotBackend registerBackend(HotSpotBackend backend) {
@@ -245,7 +261,12 @@
 
     @Override
     public OptionValues getOptions() {
-        return options;
+        return mBean == null ? options : mBean.optionsFor(options, null);
+    }
+
+    @Override
+    public OptionValues getOptions(ResolvedJavaMethod forMethod) {
+        return mBean == null ? options : mBean.optionsFor(options, forMethod);
     }
 
     @Override
@@ -363,9 +384,18 @@
 
     private String outputDirectory;
 
+    /**
+     * Use an illegal file name to denote that the output directory has been deleted.
+     */
+    private static final String DELETED_OUTPUT_DIRECTORY = "\u0000";
+
     @Override
     public String getOutputDirectory() {
-        if (outputDirectory == null) {
+        return getOutputDirectory(true);
+    }
+
+    private synchronized String getOutputDirectory(boolean createIfNull) {
+        if (outputDirectory == null && createIfNull) {
             outputDirectory = "graal_output_" + getExecutionID();
             File dir = new File(outputDirectory).getAbsoluteFile();
             if (!dir.exists()) {
@@ -376,22 +406,23 @@
                 }
             }
         }
-        return outputDirectory;
+        return DELETED_OUTPUT_DIRECTORY.equals(outputDirectory) ? null : outputDirectory;
     }
 
     /**
      * Archives and deletes the {@linkplain #getOutputDirectory() output directory} if it exists.
      */
     private void archiveAndDeleteOutputDirectory() {
-        if (outputDirectory != null) {
-            Path dir = Paths.get(outputDirectory);
+        String outDir = getOutputDirectory(false);
+        if (outDir != null) {
+            Path dir = Paths.get(outDir);
             if (dir.toFile().exists()) {
                 try {
                     // Give compiler threads a chance to finishing dumping
                     Thread.sleep(1000);
                 } catch (InterruptedException e1) {
                 }
-                File zip = new File(outputDirectory + ".zip").getAbsoluteFile();
+                File zip = new File(outDir + ".zip").getAbsoluteFile();
                 List<Path> toDelete = new ArrayList<>();
                 try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zip))) {
                     zos.setLevel(Deflater.BEST_COMPRESSION);
@@ -428,6 +459,7 @@
                     }
                 }
             }
+            outputDirectory = DELETED_OUTPUT_DIRECTORY;
         }
     }
 }