You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by jw...@apache.org on 2016/10/12 03:14:39 UTC

[1/2] groovy git commit: GROOVY-7646: allow classes to be removed from the ClassInfo cache (closes #444)

Repository: groovy
Updated Branches:
  refs/heads/master 2706b53c3 -> 4ea1207f2


GROOVY-7646: allow classes to be removed from the ClassInfo cache (closes #444)


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

Branch: refs/heads/master
Commit: d4eadc4cfe63f0d2a01ba872cc2abfdaaf1a8323
Parents: 2706b53
Author: Jochen Kemnade <jo...@eddyson.de>
Authored: Mon Oct 10 11:15:55 2016 +0200
Committer: John Wagenleitner <jw...@apache.org>
Committed: Tue Oct 11 19:33:16 2016 -0700

----------------------------------------------------------------------
 .../org/codehaus/groovy/reflection/ClassInfo.java   | 16 ++++++++++++++++
 .../org/codehaus/groovy/runtime/InvokerHelper.java  |  2 ++
 2 files changed, 18 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/d4eadc4c/src/main/org/codehaus/groovy/reflection/ClassInfo.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/reflection/ClassInfo.java b/src/main/org/codehaus/groovy/reflection/ClassInfo.java
index b5bf80e..57956af 100644
--- a/src/main/org/codehaus/groovy/reflection/ClassInfo.java
+++ b/src/main/org/codehaus/groovy/reflection/ClassInfo.java
@@ -144,6 +144,22 @@ public class ClassInfo implements Finalizable {
         return globalClassValue.get(cls);
     }
 
+    /**
+     * Removes a {@code ClassInfo} from the cache.
+     *
+     * This is useful in cases where the Class is parsed from a script, such as when
+     * using GroovyClassLoader#parseClass, and is executed for its result but the Class
+     * is not retained or cached.  Removing the {@code ClassInfo} associated with the Class
+     * will make the Class and its ClassLoader eligible for garbage collection sooner that
+     * it would otherwise.
+     *
+     * @param cls the Class associated with the ClassInfo to remove
+     *            from cache
+     */
+    public static void remove(Class<?> cls) {
+        globalClassValue.remove(cls);
+    }
+
     public static Collection<ClassInfo> getAllClassInfo () {
         return getAllGlobalClassInfo();
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/d4eadc4c/src/main/org/codehaus/groovy/runtime/InvokerHelper.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/InvokerHelper.java b/src/main/org/codehaus/groovy/runtime/InvokerHelper.java
index faa142c..6f7406a 100644
--- a/src/main/org/codehaus/groovy/runtime/InvokerHelper.java
+++ b/src/main/org/codehaus/groovy/runtime/InvokerHelper.java
@@ -36,6 +36,7 @@ import groovy.lang.SpreadMapEvaluatingException;
 import groovy.lang.Tuple;
 import groovy.lang.Writable;
 import org.codehaus.groovy.control.ResolveVisitor;
+import org.codehaus.groovy.reflection.ClassInfo;
 import org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl;
 import org.codehaus.groovy.runtime.metaclass.MissingMethodExecutionFailed;
 import org.codehaus.groovy.runtime.powerassert.PowerAssertionError;
@@ -86,6 +87,7 @@ public class InvokerHelper {
 
     public static void removeClass(Class clazz) {
         metaRegistry.removeMetaClass(clazz);
+        ClassInfo.remove(clazz);
         Introspector.flushFromCaches(clazz);
     }
 


[2/2] groovy git commit: GROOVY-7646: remove classes via InvokerHelper when closing the GroovyClassLoader or flushing its cache (closes #445)

Posted by jw...@apache.org.
GROOVY-7646: remove classes via InvokerHelper when closing the GroovyClassLoader or flushing its cache (closes #445)


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

Branch: refs/heads/master
Commit: 4ea1207f21b93a15dbcca17538c379721d9217de
Parents: d4eadc4
Author: Jochen Berger <fo...@gmail.com>
Authored: Mon Oct 10 11:40:53 2016 +0200
Committer: John Wagenleitner <jw...@apache.org>
Committed: Tue Oct 11 19:41:36 2016 -0700

----------------------------------------------------------------------
 src/main/groovy/lang/GroovyClassLoader.java | 10 ++++++++++
 1 file changed, 10 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/4ea1207f/src/main/groovy/lang/GroovyClassLoader.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/GroovyClassLoader.java b/src/main/groovy/lang/GroovyClassLoader.java
index ac1f9f9..c75bb2f 100644
--- a/src/main/groovy/lang/GroovyClassLoader.java
+++ b/src/main/groovy/lang/GroovyClassLoader.java
@@ -34,6 +34,7 @@ import org.codehaus.groovy.ast.expr.ConstantExpression;
 import org.codehaus.groovy.classgen.GeneratorContext;
 import org.codehaus.groovy.classgen.Verifier;
 import org.codehaus.groovy.control.*;
+import org.codehaus.groovy.runtime.InvokerHelper;
 import org.codehaus.groovy.runtime.IOGroovyMethods;
 import org.objectweb.asm.ClassVisitor;
 import org.objectweb.asm.ClassWriter;
@@ -969,6 +970,9 @@ public class GroovyClassLoader extends URLClassLoader {
      */
     public void clearCache() {
         synchronized (classCache) {
+            for (Class cl : classCache.values()) {
+                InvokerHelper.removeClass(cl);
+            }
             classCache.clear();
         }
         synchronized (sourceCache) {
@@ -976,6 +980,12 @@ public class GroovyClassLoader extends URLClassLoader {
         }
     }
 
+    @Override
+    public void close() throws IOException {
+        super.close();
+        clearCache();
+    }
+
     private static class TimestampAdder extends CompilationUnit.PrimaryClassNodeOperation implements Opcodes {
         private final static TimestampAdder INSTANCE = new TimestampAdder();