Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use a single global lock for proxy creation to avoid deadlocks.
This is a temporary measure to avoid deadlocks when multiple
threads load mutually-dependent Java classes. We should replace
this with some sort of atomic update of the proxy classes.

Temporary fix for #1621.
  • Loading branch information
headius committed Feb 26, 2015
1 parent 0ca486c commit 1ad3c67
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/javasupport/JavaClass.java
Expand Up @@ -518,7 +518,7 @@ static boolean isConstant(final Field field) {
private RubyModule unfinishedProxyModule;
private RubyClass unfinishedProxyClass;

private final ReentrantLock proxyLock = new ReentrantLock();
private final ReentrantLock proxyLock;

private final Initializer initializer;

Expand Down Expand Up @@ -576,6 +576,7 @@ public JavaClass(Ruby runtime, Class<?> javaClass) {
} else {
initializer = DUMMY_INITIALIZER;
}
this.proxyLock = runtime.getJavaSupport().getProxyLock();
}

@Override
Expand Down
7 changes: 7 additions & 0 deletions core/src/main/java/org/jruby/javasupport/JavaSupport.java
Expand Up @@ -40,6 +40,7 @@
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;
Expand Down Expand Up @@ -135,6 +136,8 @@ public IRubyObject allocateProxy(Object javaObject, RubyClass clazz) {

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>());

Expand Down Expand Up @@ -374,4 +377,8 @@ public Map<Set<?>, JavaProxyClass> getJavaProxyClassCache() {
return this.javaProxyClassCache;
}

public ReentrantLock getProxyLock() {
return proxyLock;
}

}

0 comments on commit 1ad3c67

Please sign in to comment.