Last active
August 29, 2015 14:16
-
-
Save headius/2aec24578482427e88d9 to your computer and use it in GitHub Desktop.
Short-term fix for proxy-creation deadlocking as in jruby/jruby#1621
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/core/src/main/java/org/jruby/javasupport/JavaClass.java b/core/src/main/java/org/jruby/javasupport/JavaClass.java | |
index 2d25d29..ab917e8 100644 | |
--- a/core/src/main/java/org/jruby/javasupport/JavaClass.java | |
+++ b/core/src/main/java/org/jruby/javasupport/JavaClass.java | |
@@ -518,7 +518,7 @@ public class JavaClass extends JavaObject { | |
private RubyModule unfinishedProxyModule; | |
private RubyClass unfinishedProxyClass; | |
- private final ReentrantLock proxyLock = new ReentrantLock(); | |
+ private final ReentrantLock proxyLock; | |
private final Initializer initializer; | |
@@ -576,6 +576,7 @@ public class JavaClass extends JavaObject { | |
} else { | |
initializer = DUMMY_INITIALIZER; | |
} | |
+ proxyLock = runtime.getJavaSupport().getProxyCreationLock(); | |
} | |
@Override | |
diff --git a/core/src/main/java/org/jruby/javasupport/JavaSupport.java b/core/src/main/java/org/jruby/javasupport/JavaSupport.java | |
index ea215d0..70bc243 100644 | |
--- a/core/src/main/java/org/jruby/javasupport/JavaSupport.java | |
+++ b/core/src/main/java/org/jruby/javasupport/JavaSupport.java | |
@@ -43,6 +43,7 @@ import org.jruby.runtime.builtin.IRubyObject; | |
import java.lang.reflect.Member; | |
import java.util.Map; | |
import java.util.Set; | |
+import java.util.concurrent.locks.ReentrantLock; | |
public interface JavaSupport { | |
Class loadJavaClass(String className) throws ClassNotFoundException; | |
@@ -102,4 +103,6 @@ public interface JavaSupport { | |
RubyClass getJavaConstructorClass(); | |
Map<Set<?>, JavaProxyClass> getJavaProxyClassCache(); | |
+ | |
+ ReentrantLock getProxyCreationLock(); | |
} | |
diff --git a/core/src/main/java/org/jruby/javasupport/JavaSupportImpl.java b/core/src/main/java/org/jruby/javasupport/JavaSupportImpl.java | |
index ec4320a..e9be2eb 100644 | |
--- a/core/src/main/java/org/jruby/javasupport/JavaSupportImpl.java | |
+++ b/core/src/main/java/org/jruby/javasupport/JavaSupportImpl.java | |
@@ -40,6 +40,7 @@ import java.util.Collections; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.Set; | |
+import java.util.concurrent.locks.ReentrantLock; | |
import org.jruby.Ruby; | |
import org.jruby.RubyClass; | |
@@ -135,6 +136,8 @@ public class JavaSupportImpl implements JavaSupport { | |
private final Map<Object, Object[]> javaObjectVariables = new WeakIdentityHashMap(); | |
+ private final ReentrantLock proxyLock = new ReentrantLock(); | |
+ | |
// A cache of all JavaProxyClass objects created for this runtime | |
private Map<Set<?>, JavaProxyClass> javaProxyClassCache = Collections.synchronizedMap(new HashMap<Set<?>, JavaProxyClass>()); | |
@@ -403,4 +406,9 @@ public class JavaSupportImpl implements JavaSupport { | |
return this.javaProxyClassCache; | |
} | |
+ @Override | |
+ public ReentrantLock getProxyCreationLock() { | |
+ return this.proxyLock; | |
+ } | |
+ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment