From c270234f37f0d9bdb1755f22561cbcba156b6e8c Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Wed, 18 Aug 2010 16:54:59 +0000 Subject: Introduce SoftValuedCache, which evicts more aggressively than SoftValuedHashMap. --- .../amazon/carbonado/qe/JoinedQueryExecutor.java | 6 +++--- .../java/com/amazon/carbonado/qe/OrderingList.java | 8 ++++---- .../com/amazon/carbonado/qe/PropertyFilterList.java | 8 ++++---- .../com/amazon/carbonado/qe/QueryExecutorCache.java | 21 +++++++++++---------- .../amazon/carbonado/qe/StandardQueryFactory.java | 6 ++++-- 5 files changed, 26 insertions(+), 23 deletions(-) (limited to 'src/main/java/com/amazon/carbonado/qe') diff --git a/src/main/java/com/amazon/carbonado/qe/JoinedQueryExecutor.java b/src/main/java/com/amazon/carbonado/qe/JoinedQueryExecutor.java index b370416..9a77f26 100644 --- a/src/main/java/com/amazon/carbonado/qe/JoinedQueryExecutor.java +++ b/src/main/java/com/amazon/carbonado/qe/JoinedQueryExecutor.java @@ -32,7 +32,6 @@ import org.cojen.classfile.Modifiers; import org.cojen.classfile.TypeDesc; import org.cojen.util.ClassInjector; -import org.cojen.util.SoftValuedHashMap; import com.amazon.carbonado.Cursor; import com.amazon.carbonado.FetchException; @@ -52,6 +51,7 @@ import com.amazon.carbonado.info.StorableIntrospector; import com.amazon.carbonado.info.StorableProperty; import com.amazon.carbonado.util.QuickConstructorGenerator; +import com.amazon.carbonado.util.SoftValuedCache; import com.amazon.carbonado.gen.CodeBuilderUtil; @@ -192,10 +192,10 @@ public class JoinedQueryExecutor private static final String INNER_LOOP_FV_FIELD_NAME = "innerLoopFilterValues"; private static final String ACTIVE_SOURCE_FIELD_NAME = "active"; - private static final Map cJoinerCursorClassCache; + private static final SoftValuedCache cJoinerCursorClassCache; static { - cJoinerCursorClassCache = new SoftValuedHashMap(); + cJoinerCursorClassCache = SoftValuedCache.newCache(11); } private static synchronized Joiner.Factory diff --git a/src/main/java/com/amazon/carbonado/qe/OrderingList.java b/src/main/java/com/amazon/carbonado/qe/OrderingList.java index 7feed40..95d8328 100644 --- a/src/main/java/com/amazon/carbonado/qe/OrderingList.java +++ b/src/main/java/com/amazon/carbonado/qe/OrderingList.java @@ -31,14 +31,14 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.cojen.util.SoftValuedHashMap; - import com.amazon.carbonado.Storable; import com.amazon.carbonado.info.ChainedProperty; import com.amazon.carbonado.info.OrderedProperty; import com.amazon.carbonado.info.StorableIntrospector; +import com.amazon.carbonado.util.SoftValuedCache; + /** * Produces unmodifiable lists of {@link OrderedProperty orderings}. Instances * are immutable, canonical and cached. Calls to "equals" and "hashCode" are @@ -53,10 +53,10 @@ public class OrderingList extends AbstractList cCache; + private static final SoftValuedCache cCache; static { - cCache = new SoftValuedHashMap(); + cCache = SoftValuedCache.newCache(11); } /** diff --git a/src/main/java/com/amazon/carbonado/qe/PropertyFilterList.java b/src/main/java/com/amazon/carbonado/qe/PropertyFilterList.java index 7d7966b..cedc05c 100644 --- a/src/main/java/com/amazon/carbonado/qe/PropertyFilterList.java +++ b/src/main/java/com/amazon/carbonado/qe/PropertyFilterList.java @@ -26,8 +26,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.cojen.util.SoftValuedHashMap; - import com.amazon.carbonado.Storable; import com.amazon.carbonado.filter.ExistsFilter; @@ -37,6 +35,8 @@ import com.amazon.carbonado.filter.PropertyFilter; import com.amazon.carbonado.filter.RelOp; import com.amazon.carbonado.filter.Visitor; +import com.amazon.carbonado.util.SoftValuedCache; + /** * Produces unmodifable lists of PropertyFilters which were originally all * 'and'ed together. The filters are ordered such that all '=' operators are @@ -45,10 +45,10 @@ import com.amazon.carbonado.filter.Visitor; * @author Brian S O'Neill */ class PropertyFilterList extends AbstractList> { - private static Map, PropertyFilterList> cCache; + private static SoftValuedCache, PropertyFilterList> cCache; static { - cCache = new SoftValuedHashMap(); + cCache = SoftValuedCache.newCache(11); } /** diff --git a/src/main/java/com/amazon/carbonado/qe/QueryExecutorCache.java b/src/main/java/com/amazon/carbonado/qe/QueryExecutorCache.java index 806365e..e114943 100644 --- a/src/main/java/com/amazon/carbonado/qe/QueryExecutorCache.java +++ b/src/main/java/com/amazon/carbonado/qe/QueryExecutorCache.java @@ -20,7 +20,6 @@ package com.amazon.carbonado.qe; import java.util.Map; -import org.cojen.util.SoftValuedHashMap; import org.cojen.util.WeakIdentityMap; import com.amazon.carbonado.RepositoryException; @@ -28,6 +27,8 @@ import com.amazon.carbonado.Storable; import com.amazon.carbonado.filter.Filter; +import com.amazon.carbonado.util.SoftValuedCache; + /** * QueryExecutors should be cached since expensive analysis is often required * to build them. @@ -38,7 +39,7 @@ public class QueryExecutorCache implements QueryExecutorFact private final QueryExecutorFactory mFactory; // Maps filters to maps which map ordering lists (possibly with hints) to executors. - private final Map, Map>> mFilterToExecutor; + private final Map, SoftValuedCache>> mFilterToExecutor; public QueryExecutorCache(QueryExecutorFactory factory) { if (factory == null) { @@ -62,12 +63,12 @@ public class QueryExecutorCache implements QueryExecutorFact public QueryExecutor executor(Filter filter, OrderingList ordering, QueryHints hints) throws RepositoryException { - Map> map; + SoftValuedCache> cache; synchronized (mFilterToExecutor) { - map = mFilterToExecutor.get(filter); - if (map == null) { - map = new SoftValuedHashMap(7); - mFilterToExecutor.put(filter, map); + cache = mFilterToExecutor.get(filter); + if (cache == null) { + cache = SoftValuedCache.newCache(7); + mFilterToExecutor.put(filter, cache); } } @@ -79,11 +80,11 @@ public class QueryExecutorCache implements QueryExecutorFact } QueryExecutor executor; - synchronized (map) { - executor = map.get(key); + synchronized (cache) { + executor = cache.get(key); if (executor == null) { executor = mFactory.executor(filter, ordering, hints); - map.put(key, executor); + cache.put(key, executor); } } diff --git a/src/main/java/com/amazon/carbonado/qe/StandardQueryFactory.java b/src/main/java/com/amazon/carbonado/qe/StandardQueryFactory.java index 4c80075..d6b99d6 100644 --- a/src/main/java/com/amazon/carbonado/qe/StandardQueryFactory.java +++ b/src/main/java/com/amazon/carbonado/qe/StandardQueryFactory.java @@ -31,6 +31,8 @@ import com.amazon.carbonado.Storable; import com.amazon.carbonado.filter.Filter; import com.amazon.carbonado.filter.FilterValues; +import com.amazon.carbonado.util.SoftValuedCache; + /** * Builds and caches StandardQuery instances. * @@ -40,7 +42,7 @@ public abstract class StandardQueryFactory implements QueryF private final Class mType; private final boolean mLazySetExecutor; - private final Map> mStringToQuery; + private final SoftValuedCache> mStringToQuery; // Maps filters to maps which map ordering lists to queries. private final Map, Map, Query>> mFilterToQuery; @@ -59,7 +61,7 @@ public abstract class StandardQueryFactory implements QueryF } mType = type; mLazySetExecutor = lazySetExecutor; - mStringToQuery = new SoftValuedHashMap(7); + mStringToQuery = SoftValuedCache.newCache(7); mFilterToQuery = new WeakIdentityMap(7); } -- cgit v1.2.3