You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2018/03/01 16:26:25 UTC

[1/2] groovy git commit: Fix property name of cache

Repository: groovy
Updated Branches:
  refs/heads/master 7ab1bd2bc -> 3a3b32c3b


Fix property name of cache


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

Branch: refs/heads/master
Commit: d1fc95c18ed38fe26d6b066c70b905b6b77f74c3
Parents: 7ab1bd2
Author: danielsun1106 <re...@hotmail.com>
Authored: Fri Mar 2 00:12:02 2018 +0800
Committer: danielsun1106 <re...@hotmail.com>
Committed: Fri Mar 2 00:12:02 2018 +0800

----------------------------------------------------------------------
 .../groovy/runtime/memoize/CacheCleanupTest.groovy      | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/d1fc95c1/src/test/org/codehaus/groovy/runtime/memoize/CacheCleanupTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/runtime/memoize/CacheCleanupTest.groovy b/src/test/org/codehaus/groovy/runtime/memoize/CacheCleanupTest.groovy
index e6b2255..f4d48d9 100644
--- a/src/test/org/codehaus/groovy/runtime/memoize/CacheCleanupTest.groovy
+++ b/src/test/org/codehaus/groovy/runtime/memoize/CacheCleanupTest.groovy
@@ -34,14 +34,14 @@ public class CacheCleanupTest extends GroovyTestCase {
     }
 
     private def checkCache(MemoizeCache cache) {
-        assert cache.cache.size() == 0
+        assert cache.map.size() == 0
         cache.put('key1', new SoftReference(ANCHOR))
         cache.put('key2', new SoftReference(ANCHOR))
-        assert cache.cache.size() == 2
+        assert cache.map.size() == 2
         cache.put('key3', new SoftReference(null))  //Simulating evicted objects
         cache.put('key4', new SoftReference(null))
         cache.cleanUpNullReferences()
-        assert cache.cache.size() == 2
+        assert cache.map.size() == 2
     }
 
     public void testUnlimitedCacheConcurrently() {
@@ -51,10 +51,10 @@ public class CacheCleanupTest extends GroovyTestCase {
     }
 
     private def checkCacheConcurrently(MemoizeCache cache) {
-        assert cache.cache.size() == 0
+        assert cache.map.size() == 0
         cache.put('key1', new SoftReference(ANCHOR))
         cache.put('key2', new SoftReference(ANCHOR))
-        assert cache.cache.size() == 2
+        assert cache.map.size() == 2
         for (i in (3..1000)) {
             cache.put("key${i}", new SoftReference(null))  //Simulating evicted objects
             cache.get('key1')  //touch the non-null cache entries to keep them hot to prevent a potential LRU algorithm from evicting them
@@ -72,6 +72,6 @@ public class CacheCleanupTest extends GroovyTestCase {
         barrier.await(30, TimeUnit.SECONDS)  //start threads
         barrier.await(30, TimeUnit.SECONDS)  //wait for threads to finish
 
-        assert cache.cache.size() == 2
+        assert cache.map.size() == 2
     }
 }


[2/2] groovy git commit: Use `ConcurrentCommonCache` to memoize closure result

Posted by su...@apache.org.
Use `ConcurrentCommonCache` to memoize closure result

The original implementation of `UnlimitedConcurrentCache` can not check-and-put atomically, but the refined implementation may run into a potential issue of `computeIfAbsent`(See: https://stackoverflow.com/questions/28840047/recursive-concurrenthashmap-computeifabsent-call-never-terminates-bug-or-fea)


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

Branch: refs/heads/master
Commit: 3a3b32c3b823b972a0d097a85b76bead544bcebf
Parents: d1fc95c
Author: danielsun1106 <re...@hotmail.com>
Authored: Fri Mar 2 00:26:12 2018 +0800
Committer: danielsun1106 <re...@hotmail.com>
Committed: Fri Mar 2 00:26:12 2018 +0800

----------------------------------------------------------------------
 src/main/groovy/groovy/lang/Closure.java | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/3a3b32c3/src/main/groovy/groovy/lang/Closure.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/lang/Closure.java b/src/main/groovy/groovy/lang/Closure.java
index edac29f..13e3cf2 100644
--- a/src/main/groovy/groovy/lang/Closure.java
+++ b/src/main/groovy/groovy/lang/Closure.java
@@ -27,9 +27,9 @@ import org.codehaus.groovy.runtime.CurriedClosure;
 import org.codehaus.groovy.runtime.InvokerHelper;
 import org.codehaus.groovy.runtime.InvokerInvocationException;
 import org.codehaus.groovy.runtime.callsite.BooleanClosureWrapper;
+import org.codehaus.groovy.runtime.memoize.ConcurrentCommonCache;
 import org.codehaus.groovy.runtime.memoize.LRUCache;
 import org.codehaus.groovy.runtime.memoize.Memoize;
-import org.codehaus.groovy.runtime.memoize.UnlimitedConcurrentCache;
 
 import java.io.IOException;
 import java.io.Serializable;
@@ -701,7 +701,7 @@ public abstract class Closure<V> extends GroovyObjectSupport implements Cloneabl
      * @return A new closure forwarding to the original one while caching the results
      */
     public Closure<V> memoize() {
-        return Memoize.buildMemoizeFunction(new UnlimitedConcurrentCache(), this);
+        return Memoize.buildMemoizeFunction(new ConcurrentCommonCache(), this);
     }
 
     /**
@@ -750,7 +750,7 @@ public abstract class Closure<V> extends GroovyObjectSupport implements Cloneabl
     public Closure<V> memoizeAtLeast(final int protectedCacheSize) {
         if (protectedCacheSize < 0) throw new IllegalArgumentException("A non-negative number is required as the protectedCacheSize parameter for memoizeAtLeast.");
 
-        return Memoize.buildSoftReferenceMemoizeFunction(protectedCacheSize, new UnlimitedConcurrentCache(), this);
+        return Memoize.buildSoftReferenceMemoizeFunction(protectedCacheSize, new ConcurrentCommonCache(), this);
     }
 
     /**