Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java @ 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 | 78f014d57b4b |
children | 1c39c96a1703 |
comparison
equal
deleted
inserted
replaced
22413:bc1e026ef5b1 | 22414:7015a77b222f |
---|---|
52 import java.util.logging.Level; | 52 import java.util.logging.Level; |
53 import java.util.logging.Logger; | 53 import java.util.logging.Logger; |
54 | 54 |
55 import com.oracle.truffle.api.CompilerAsserts; | 55 import com.oracle.truffle.api.CompilerAsserts; |
56 import com.oracle.truffle.api.TruffleLanguage.Registration; | 56 import com.oracle.truffle.api.TruffleLanguage.Registration; |
57 import com.oracle.truffle.api.TruffleOptions; | |
57 | 58 |
58 /** | 59 /** |
59 * Representation of a guest language source code unit and its contents. Sources originate in | 60 * Representation of a guest language source code unit and its contents. Sources originate in |
60 * several ways: | 61 * several ways: |
61 * <ul> | 62 * <ul> |
830 private final File file; | 831 private final File file; |
831 private final String name; // Name used originally to describe the source | 832 private final String name; // Name used originally to describe the source |
832 private final String path; // Normalized path description of an actual file | 833 private final String path; // Normalized path description of an actual file |
833 | 834 |
834 private String code = null; // A cache of the file's contents | 835 private String code = null; // A cache of the file's contents |
835 private long timeStamp; // timestamp of the cache in the file system | 836 |
837 /** | |
838 * Timestamp of the cache in the file system. Enabled by setting | |
839 * {@link TruffleOptions.AutoReloadFileSource} to true. | |
840 */ | |
841 private long timeStamp; | |
836 | 842 |
837 public FileSource(File file, String name, String path) { | 843 public FileSource(File file, String name, String path) { |
838 this.file = file.getAbsoluteFile(); | 844 this.file = file.getAbsoluteFile(); |
839 this.name = name; | 845 this.name = name; |
840 this.path = path; | 846 this.path = path; |
856 } | 862 } |
857 | 863 |
858 @Override | 864 @Override |
859 public String getCode() { | 865 public String getCode() { |
860 if (fileCacheEnabled) { | 866 if (fileCacheEnabled) { |
861 if (code == null || timeStamp != file.lastModified()) { | 867 if (code == null || (TruffleOptions.AutoReloadFileSource && timeStamp != file.lastModified())) { |
862 try { | 868 try { |
863 code = read(getReader()); | 869 code = read(getReader()); |
864 timeStamp = file.lastModified(); | 870 if (TruffleOptions.AutoReloadFileSource) { |
871 timeStamp = file.lastModified(); | |
872 } | |
865 } catch (IOException e) { | 873 } catch (IOException e) { |
866 } | 874 } |
867 } | 875 } |
868 return code; | 876 return code; |
869 } | 877 } |
884 return null; | 892 return null; |
885 } | 893 } |
886 | 894 |
887 @Override | 895 @Override |
888 public Reader getReader() { | 896 public Reader getReader() { |
889 if (code != null && timeStamp == file.lastModified()) { | 897 if (code != null && (TruffleOptions.AutoReloadFileSource && timeStamp == file.lastModified())) { |
890 return new StringReader(code); | 898 return new StringReader(code); |
891 } | 899 } |
892 try { | 900 try { |
893 return new InputStreamReader(new FileInputStream(file), "UTF-8"); | 901 return new InputStreamReader(new FileInputStream(file), "UTF-8"); |
894 } catch (FileNotFoundException e) { | 902 } catch (FileNotFoundException e) { |