Mercurial > hg > graal-compiler
changeset 13997:5f2c0ad0501a
Merge.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Fri, 21 Feb 2014 02:30:03 +0100 |
parents | c7ac129e17e9 (current diff) 643cb1fc9497 (diff) |
children | aabdacb9555c |
files | graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java |
diffstat | 2 files changed, 28 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCache.java Fri Feb 21 02:29:16 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCache.java Fri Feb 21 02:30:03 2014 +0100 @@ -26,6 +26,7 @@ import java.lang.reflect.*; import java.util.*; +import java.util.Map.Entry; import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; @@ -60,8 +61,10 @@ private final OptimisticOptimizations optimisticOptimizations; private final HashMap<List<Object>, StructuredGraph> cache = new HashMap<>(); + private final HashMap<List<Object>, Long> lastUsed = new HashMap<>(); private final StructuredGraph markerGraph = new StructuredGraph(); private final ResolvedJavaType stringBuilderClass; + private long counter; public TruffleCache(Providers providers, GraphBuilderConfiguration config, OptimisticOptimizations optimisticOptimizations) { this.providers = providers; @@ -82,6 +85,7 @@ } StructuredGraph resultGraph = cache.get(key); if (resultGraph != null) { + lastUsed.put(key, counter++); return resultGraph; } @@ -90,6 +94,28 @@ return null; } + if (lastUsed.values().size() >= TruffleCompilerOptions.TruffleMaxCompilationCacheSize.getValue()) { + List<Long> lastUsedList = new ArrayList<>(); + for (long l : lastUsed.values()) { + lastUsedList.add(l); + } + Collections.sort(lastUsedList); + long mid = lastUsedList.get(lastUsedList.size() / 2); + + List<List<Object>> toRemoveList = new ArrayList<>(); + for (Entry<List<Object>, Long> entry : lastUsed.entrySet()) { + if (entry.getValue() < mid) { + toRemoveList.add(entry.getKey()); + } + } + + for (List<Object> entry : toRemoveList) { + cache.remove(entry); + lastUsed.remove(entry); + } + } + + lastUsed.put(key, counter++); cache.put(key, markerGraph); try (Scope s = Debug.scope("TruffleCache", new Object[]{providers.getMetaAccess(), method})) {
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java Fri Feb 21 02:29:16 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java Fri Feb 21 02:30:03 2014 +0100 @@ -76,6 +76,8 @@ @Option(help = "") public static final OptionValue<Integer> TruffleCompilationDecisionTime = new OptionValue<>(100); @Option(help = "") + public static final OptionValue<Integer> TruffleMaxCompilationCacheSize = new OptionValue<>(512); + @Option(help = "") public static final OptionValue<Boolean> TruffleCompilationDecisionTimePrintFail = new OptionValue<>(false); @Option(help = "") public static final OptionValue<Boolean> TruffleBackgroundCompilation = new OptionValue<>(true);