groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: GROOVY-8630: Refine the parameterized type cache(closes #750)
Date Tue, 05 Jun 2018 01:42:14 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X 98cdd7d73 -> 96404d015


GROOVY-8630: Refine the parameterized type cache(closes #750)

(cherry picked from commit 0b77623)

(cherry picked from commit 7785784)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/96404d01
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/96404d01
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/96404d01

Branch: refs/heads/GROOVY_2_5_X
Commit: 96404d0151372357d696f2fb1967aa498a62de4e
Parents: 98cdd7d
Author: sunlan <sunlan@apache.org>
Authored: Tue Jun 5 09:31:59 2018 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Tue Jun 5 09:40:52 2018 +0800

----------------------------------------------------------------------
 .../org/codehaus/groovy/ast/tools/GenericsUtils.java | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/96404d01/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java b/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
index cf3de8c..967db62 100644
--- a/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
+++ b/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
@@ -36,12 +36,13 @@ import org.codehaus.groovy.ast.stmt.EmptyStatement;
 import org.codehaus.groovy.control.CompilationUnit;
 import org.codehaus.groovy.control.ResolveVisitor;
 import org.codehaus.groovy.control.SourceUnit;
-import org.codehaus.groovy.runtime.memoize.ConcurrentCommonCache;
+import org.codehaus.groovy.runtime.memoize.ConcurrentSoftCache;
 import org.codehaus.groovy.runtime.memoize.EvictableCache;
 import org.codehaus.groovy.syntax.ParserException;
 import org.codehaus.groovy.syntax.Reduction;
 
 import java.io.StringReader;
+import java.lang.ref.SoftReference;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -669,12 +670,14 @@ public class GenericsUtils {
      * If no cached item found, cache and return the result of {@link #findParameterizedType(ClassNode,
ClassNode)}
      */
     public static ClassNode findParameterizedTypeFromCache(final ClassNode genericsClass,
final ClassNode actualType) {
-        return PARAMETERIZED_TYPE_CACHE.getAndPut(new ParameterizedTypeCacheKey(genericsClass,
actualType), new EvictableCache.ValueProvider<ParameterizedTypeCacheKey, ClassNode>()
{
+        SoftReference<ClassNode> sr = PARAMETERIZED_TYPE_CACHE.getAndPut(new ParameterizedTypeCacheKey(genericsClass,
actualType), new EvictableCache.ValueProvider<ParameterizedTypeCacheKey, SoftReference<ClassNode>>()
{
             @Override
-            public ClassNode provide(ParameterizedTypeCacheKey key) {
-                return findParameterizedType(key.getGenericsClass(), key.getActualType());
+            public SoftReference<ClassNode> provide(ParameterizedTypeCacheKey key)
{
+                return new SoftReference<>(findParameterizedType(key.getGenericsClass(),
key.getActualType()));
             }
         });
+
+        return null == sr ? null : sr.get();
     }
 
     /**
@@ -742,8 +745,7 @@ public class GenericsUtils {
         return superClassNodeList;
     }
 
-    private static final EvictableCache<ParameterizedTypeCacheKey, ClassNode> PARAMETERIZED_TYPE_CACHE
= new ConcurrentCommonCache<>(128);
-
+    private static final EvictableCache<ParameterizedTypeCacheKey, SoftReference<ClassNode>>
PARAMETERIZED_TYPE_CACHE = new ConcurrentSoftCache<>(64);
 
     /**
      * map declaring generics type to actual generics type, e.g. GROOVY-7204:
@@ -795,7 +797,6 @@ public class GenericsUtils {
         return null;
     }
 
-
     private static class ParameterizedTypeCacheKey {
         private ClassNode genericsClass;
         private ClassNode actualType;


Mime
View raw message