Mercurial > hg > graal-compiler
diff graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java @ 20022:eebf140fa6e4
syncronize the access to Source.allSources. Should fix random crashes we experienced before.
author | Christian Wirth <christian.wirth@oracle.com> |
---|---|
date | Tue, 24 Mar 2015 17:19:23 +0100 |
parents | 191c55f08ed2 |
children | bbf53b35292e |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java Tue Mar 24 14:36:57 2015 +0100 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java Tue Mar 24 17:19:23 2015 +0100 @@ -81,7 +81,7 @@ /** * All Sources that have been created. */ - private static final List<WeakReference<Source>> allSources = new ArrayList<>(); + private static final List<WeakReference<Source>> allSources = Collections.synchronizedList(new ArrayList<WeakReference<Source>>()); // Files and pseudo files are indexed. private static final Map<String, WeakReference<Source>> filePathToSource = new Hashtable<>(); @@ -273,11 +273,13 @@ */ public static Collection<Source> findSourcesTaggedAs(SourceTag tag) { final List<Source> taggedSources = new ArrayList<>(); - for (WeakReference<Source> ref : allSources) { - Source source = ref.get(); - if (source != null) { - if (tag == null || source.isTaggedAs(tag)) { - taggedSources.add(ref.get()); + synchronized (allSources) { + for (WeakReference<Source> ref : allSources) { + Source source = ref.get(); + if (source != null) { + if (tag == null || source.isTaggedAs(tag)) { + taggedSources.add(ref.get()); + } } } }