[jruby~main:208b4af7] Modify proxied Java objects to use a separate weak table of ivars, as par
- From: nicksieger@kenai.com
- To: commits@jruby.kenai.com
- Subject: [jruby~main:208b4af7] Modify proxied Java objects to use a separate weak table of ivars, as par
- Date: Thu, 4 Mar 2010 18:21:47 +0000
Project: jruby
Repository: main
Revision: 208b4af739feef0e9e428b3f5ba682ce7af9c71d
Author: nicksieger
Date: 2010-03-04 18:11:24 UTC
Link:
Log Message:
------------
Modify proxied Java objects to use a separate weak table of ivars, as part of
a push to eliminate ObjectProxyCache and the idempotency of wrappers.
Revisions:
----------
208b4af739feef0e9e428b3f5ba682ce7af9c71d
Modified Paths:
---------------
src/org/jruby/java/proxies/ConcreteJavaProxy.java
src/org/jruby/javasupport/JavaSupport.java
Diffs:
------
diff --git a/src/org/jruby/java/proxies/ConcreteJavaProxy.java
b/src/org/jruby/java/proxies/ConcreteJavaProxy.java
index 9960fd9..31161d5 100644
--- a/src/org/jruby/java/proxies/ConcreteJavaProxy.java
+++ b/src/org/jruby/java/proxies/ConcreteJavaProxy.java
@@ -73,4 +73,14 @@ public class ConcreteJavaProxy extends JavaProxy {
return concreteJavaProxy;
}
+
+ @Override
+ public Object getVariable(int index) {
+ return getRuntime().getJavaSupport().getJavaObjectVariable(this,
index);
+ }
+
+ @Override
+ public void setVariable(int index, Object value) {
+ getRuntime().getJavaSupport().setJavaObjectVariable(this, index,
value);
+ }
}
diff --git a/src/org/jruby/javasupport/JavaSupport.java
b/src/org/jruby/javasupport/JavaSupport.java
index 6bb30ef..8d920e8 100644
--- a/src/org/jruby/javasupport/JavaSupport.java
+++ b/src/org/jruby/javasupport/JavaSupport.java
@@ -37,6 +37,7 @@ import java.lang.reflect.Member;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import org.jruby.Ruby;
@@ -46,6 +47,7 @@ import org.jruby.exceptions.RaiseException;
import org.jruby.javasupport.util.ObjectProxyCache;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.callback.Callback;
+import org.jruby.util.WeakIdentityHashMap;
public class JavaSupport {
private static final Map<String,Class> PRIMITIVE_CLASSES = new
HashMap<String,Class>();
@@ -109,6 +111,8 @@ public class JavaSupport {
private RubyClass concreteProxyClass;
private final Map<String, JavaClass> nameClassMap = new HashMap<String,
JavaClass>();
+
+ private final Map<Object, Object[]> javaObjectVariables = new
WeakIdentityHashMap();
public JavaSupport(Ruby ruby) {
this.runtime = ruby;
@@ -199,6 +203,31 @@ public class JavaSupport {
public Map<String, JavaClass> getNameClassMap() {
return nameClassMap;
}
+
+ public void setJavaObjectVariable(Object o, int i, Object v) {
+ synchronized (javaObjectVariables) {
+ Object[] vars = javaObjectVariables.get(o);
+ if (vars == null) {
+ vars = new Object[i + 1];
+ javaObjectVariables.put(o, vars);
+ } else if (vars.length <= i) {
+ Object[] newVars = new Object[i + 1];
+ System.arraycopy(vars, 0, newVars, 0, vars.length);
+ javaObjectVariables.put(o, newVars);
+ vars = newVars;
+ }
+ vars[i] = v;
+ }
+ }
+
+ public Object getJavaObjectVariable(Object o, int i) {
+ synchronized (javaObjectVariables) {
+ Object[] vars = javaObjectVariables.get(o);
+ if (vars == null) return null;
+ if (vars.length <= i) return null;
+ return vars[i];
+ }
+ }
public RubyModule getJavaModule() {
RubyModule module;
|
[jruby~main:208b4af7] Modify proxied Java objects to use a separate weak table of ivars, as par |
nicksieger | 03/04/2010 |





