groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwagenleit...@apache.org
Subject groovy git commit: GROOVY-8230: Deadlock in GroovyClassLoader (closes #561)
Date Sat, 24 Jun 2017 18:48:30 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 635ccc2c9 -> 443eaace7


GROOVY-8230: Deadlock in GroovyClassLoader (closes #561)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: 443eaace7ae380cfd706123adee11cde7a82acaf
Parents: 635ccc2
Author: John Wagenleitner <jwagenleitner@apache.org>
Authored: Sun Jun 18 17:16:07 2017 -0700
Committer: John Wagenleitner <jwagenleitner@apache.org>
Committed: Sat Jun 24 11:47:49 2017 -0700

----------------------------------------------------------------------
 src/main/groovy/lang/GroovyClassLoader.java | 28 +++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/443eaace/src/main/groovy/lang/GroovyClassLoader.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/GroovyClassLoader.java b/src/main/groovy/lang/GroovyClassLoader.java
index 11dedfd..394627b 100644
--- a/src/main/groovy/lang/GroovyClassLoader.java
+++ b/src/main/groovy/lang/GroovyClassLoader.java
@@ -963,23 +963,45 @@ public class GroovyClassLoader extends URLClassLoader {
 
     /**
      * Removes all classes from the class cache.
+     * <p>
+     * In addition to internal caches this method also clears any
+     * previously set MetaClass information for the given set of
+     * classes being removed.
      *
      * @see #getClassCacheEntry(String)
      * @see #setClassCacheEntry(Class)
      * @see #removeClassCacheEntry(String)
      */
     public void clearCache() {
+        Class<?>[] clearedClasses;
         synchronized (classCache) {
-            for (Class cl : classCache.values()) {
-                InvokerHelper.removeClass(cl);
-            }
+            clearedClasses = getLoadedClasses();
             classCache.clear();
         }
         synchronized (sourceCache) {
             sourceCache.clear();
         }
+        for (Class<?> c : clearedClasses) {
+            // Another Thread may be using an instance of this class
+            // (for the first time) requiring a ClassInfo lock and
+            // classloading which would require a lock on classCache.
+            // The following locks on ClassInfo and to avoid deadlock
+            // should not be done with a classCache lock.
+            InvokerHelper.removeClass(c);
+        }
     }
 
+    /**
+     * Closes this GroovyClassLoader and clears any caches it maintains.
+     * <p>
+     * No use should be made of this instance after this method is
+     * invoked. Any classes that are already loaded are still accessible.
+     *
+     * @throws IOException
+     * @see URLClassLoader#close()
+     * @see #clearCache()
+     * @since 2.5.0
+     */
     @Override
     public void close() throws IOException {
         super.close();


Mime
View raw message