changeset 22414:7015a77b222f

Guarded the auto-reloading of files into FileSource with a TruffleOption (false by default).
author Christian Wirth <christian.wirth@oracle.com>
date Wed, 25 Nov 2015 15:53:11 +0100
parents bc1e026ef5b1
children d158937952b6
files truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleOptions.java truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java
diffstat 2 files changed, 26 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleOptions.java	Tue Nov 24 14:53:48 2015 +0100
+++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleOptions.java	Wed Nov 25 15:53:11 2015 +0100
@@ -24,10 +24,12 @@
  */
 package com.oracle.truffle.api;
 
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
 import com.oracle.truffle.api.nodes.NodeCost;
 import com.oracle.truffle.api.nodes.NodeInfo;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
+import com.oracle.truffle.api.source.Source;
 
 /**
  * Class containing general Truffle options.
@@ -85,6 +87,13 @@
     public static final boolean TraceASTJSON;
 
     /**
+     * Enables auto-reload of file-based {@link Source} when the file is changed on disk.
+     * <p>
+     * Can be set with {@code -Dtruffle.AutoReloadFileSource=true}.
+     */
+    public static final boolean AutoReloadFileSource;
+
+    /**
      * Forces ahead-of-time initialization.
      */
     public static final boolean AOT;
@@ -98,7 +107,7 @@
     }
 
     static {
-        final boolean[] values = new boolean[4];
+        final boolean[] values = new boolean[5];
         AccessController.doPrivileged(new PrivilegedAction<Void>() {
             public Void run() {
                 values[0] = Boolean.getBoolean("truffle.TraceRewrites");
@@ -108,6 +117,7 @@
                 values[1] = Boolean.getBoolean("truffle.DetailedRewriteReasons");
                 values[2] = Boolean.getBoolean("truffle.TraceASTJSON");
                 values[3] = Boolean.getBoolean("com.oracle.truffle.aot");
+                values[4] = Boolean.getBoolean("truffle.AutoReloadFileSource");
                 return null;
             }
         });
@@ -115,5 +125,6 @@
         DetailedRewriteReasons = values[1];
         TraceASTJSON = values[2];
         AOT = values[3];
+        AutoReloadFileSource = values[4];
     }
 }
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java	Tue Nov 24 14:53:48 2015 +0100
+++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java	Wed Nov 25 15:53:11 2015 +0100
@@ -54,6 +54,7 @@
 
 import com.oracle.truffle.api.CompilerAsserts;
 import com.oracle.truffle.api.TruffleLanguage.Registration;
+import com.oracle.truffle.api.TruffleOptions;
 
 /**
  * Representation of a guest language source code unit and its contents. Sources originate in
@@ -832,7 +833,12 @@
         private final String path;  // Normalized path description of an actual file
 
         private String code = null;  // A cache of the file's contents
-        private long timeStamp;      // timestamp of the cache in the file system
+
+        /**
+         * Timestamp of the cache in the file system. Enabled by setting
+         * {@link TruffleOptions.AutoReloadFileSource} to true.
+         */
+        private long timeStamp;
 
         public FileSource(File file, String name, String path) {
             this.file = file.getAbsoluteFile();
@@ -858,10 +864,12 @@
         @Override
         public String getCode() {
             if (fileCacheEnabled) {
-                if (code == null || timeStamp != file.lastModified()) {
+                if (code == null || (TruffleOptions.AutoReloadFileSource && timeStamp != file.lastModified())) {
                     try {
                         code = read(getReader());
-                        timeStamp = file.lastModified();
+                        if (TruffleOptions.AutoReloadFileSource) {
+                            timeStamp = file.lastModified();
+                        }
                     } catch (IOException e) {
                     }
                 }
@@ -886,7 +894,7 @@
 
         @Override
         public Reader getReader() {
-            if (code != null && timeStamp == file.lastModified()) {
+            if (code != null && (TruffleOptions.AutoReloadFileSource && timeStamp == file.lastModified())) {
                 return new StringReader(code);
             }
             try {