Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f4a2944d26d9
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1123d3b4af8d
Choose a head ref
  • 15 commits
  • 13 files changed
  • 1 contributor

Commits on Apr 8, 2016

  1. simplify JavaProxyClass internals to do less work (on __jcreate!)

    ... started hiding some of the internal state to not leak into instance variables
    kares committed Apr 8, 2016
    Copy the full SHA
    d5e5c6d View commit details
  2. Copy the full SHA
    2763cce View commit details
  3. 3
    Copy the full SHA
    94291fc View commit details
  4. make proxy class (generated) field public - no need to supress access…

    …ible on class init
    
    + some readability improvements and notes
    kares committed Apr 8, 2016
    Copy the full SHA
    d99aa87 View commit details
  5. Copy the full SHA
    b4a930b View commit details
  6. Copy the full SHA
    05d50fa View commit details
  7. Copy the full SHA
    a752446 View commit details
  8. Copy the full SHA
    78b83e5 View commit details
  9. Copy the full SHA
    f9dfb75 View commit details
  10. Copy the full SHA
    115b95f View commit details
  11. Copy the full SHA
    b8796fc View commit details
  12. Copy the full SHA
    8b61c85 View commit details
  13. Copy the full SHA
    752bfc9 View commit details
  14. Copy the full SHA
    36a4905 View commit details
  15. Copy the full SHA
    1123d3b View commit details
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyBasicObject.java
Original file line number Diff line number Diff line change
@@ -1075,7 +1075,7 @@ public IRubyObject inspect() {
return to_s();
}

public IRubyObject hashyInspect() {
public final IRubyObject hashyInspect() {
final Ruby runtime = getRuntime();
String cname = getMetaClass().getRealClass().getName();
StringBuilder part = new StringBuilder(2 + cname.length() + 3 + 8 + 1); // #<Object:0x5a1c0542>
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
@@ -517,7 +517,7 @@ public static RubyString newUTF8String(Ruby runtime, CharSequence str) {
}

public static RubyString newUTF16String(Ruby runtime, CharSequence str) {
ByteList byteList = new ByteList(RubyEncoding.encodeUTF16(str.toString()), UTF16BEEncoding.INSTANCE, false);
ByteList byteList = new ByteList(RubyEncoding.encodeUTF16(str), UTF16BEEncoding.INSTANCE, false);
return new RubyString(runtime, runtime.getString(), byteList);
}

2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/java/proxies/JavaProxy.java
Original file line number Diff line number Diff line change
@@ -89,7 +89,7 @@ public void dataWrapStruct(Object object) {
this.object = javaObject.getValue();
}

public Object getObject() {
public final Object getObject() {
// FIXME: Added this because marshal_spec seemed to reconstitute objects without calling dataWrapStruct
// this resulted in object being null after unmarshalling...
if (object == null) {
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/javasupport/JavaObject.java
Original file line number Diff line number Diff line change
@@ -252,7 +252,7 @@ public IRubyObject is_java_proxy() {
}

@JRubyMethod(name = "synchronized")
public IRubyObject ruby_synchronized(ThreadContext context, Block block) {
public final IRubyObject ruby_synchronized(ThreadContext context, Block block) {
Object lock = getValue();
synchronized (lock != null ? lock : NULL_LOCK) {
return block.yield(context, null);
87 changes: 54 additions & 33 deletions core/src/main/java/org/jruby/javasupport/JavaProxyMethods.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,47 @@
/***** BEGIN LICENSE BLOCK *****
* Version: EPL 1.0/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Eclipse Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.eclipse.org/legal/epl-v10.html
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the EPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the EPL, the GPL or the LGPL.
***** END LICENSE BLOCK *****/
package org.jruby.javasupport;

import org.jruby.Ruby;
import org.jruby.RubyBasicObject;
import org.jruby.RubyFixnum;
import org.jruby.RubyModule;
import org.jruby.RubyObject;
import org.jruby.anno.JRubyMethod;
import org.jruby.java.proxies.JavaProxy;
import org.jruby.runtime.Block;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

public class JavaProxyMethods {

private JavaProxyMethods() { /* no instances */ }

public static RubyModule createJavaProxyMethods(ThreadContext context) {
Ruby runtime = context.runtime;
RubyModule javaProxyMethods = runtime.defineModule("JavaProxyMethods");

javaProxyMethods.defineAnnotatedMethods(JavaProxyMethods.class);

return javaProxyMethods;
RubyModule JavaProxyMethods = context.runtime.defineModule("JavaProxyMethods");
JavaProxyMethods.defineAnnotatedMethods(JavaProxyMethods.class);
return JavaProxyMethods;
}

@JRubyMethod
@@ -28,7 +51,7 @@ public static IRubyObject java_class(ThreadContext context, IRubyObject recv) {

@JRubyMethod
public static IRubyObject java_object(ThreadContext context, IRubyObject recv) {
return (IRubyObject)recv.dataGetStruct();
return (IRubyObject) recv.dataGetStruct();
}

@JRubyMethod(name = "java_object=")
@@ -38,57 +61,55 @@ public static IRubyObject java_object_set(ThreadContext context, IRubyObject rec
return obj;
}

@JRubyMethod(name = {"=="})
@JRubyMethod
public static IRubyObject to_java_object(IRubyObject recv) {
return (JavaObject) recv.dataGetStruct();
}

@JRubyMethod(name = "eql?")
public static IRubyObject op_eql(IRubyObject recv, IRubyObject obj) {
return op_equal(recv, obj);
}

@JRubyMethod(name = "==")
public static IRubyObject op_equal(IRubyObject recv, IRubyObject rhs) {
if (recv instanceof JavaProxy) {
return JavaObject.op_equal((JavaProxy)recv, rhs);
return JavaObject.op_equal((JavaProxy) recv, rhs);
}
return ((JavaObject)recv.dataGetStruct()).op_equal(rhs);
}

@JRubyMethod
public static IRubyObject to_s(IRubyObject recv) {
if (recv instanceof JavaProxy) {
return JavaObject.to_s(recv.getRuntime(), ((JavaProxy)recv).getObject());
} else if (recv.dataGetStruct() != null) {
return ((JavaObject)recv.dataGetStruct()).to_s();
} else {
return ((RubyObject)recv).to_s();
return JavaObject.to_s(recv.getRuntime(), ((JavaProxy) recv).getObject());
}
final Object unwrap = recv.dataGetStruct();
if (unwrap != null) return ((JavaObject) unwrap).to_s();
return ((RubyBasicObject) recv).to_s();
}

@JRubyMethod
public static IRubyObject inspect(IRubyObject recv) {
if (recv instanceof RubyBasicObject) {
return ((RubyBasicObject)recv).hashyInspect();
} else {
return recv.inspect();
return ((RubyBasicObject) recv).hashyInspect();
}
}

@JRubyMethod(name = "eql?")
public static IRubyObject op_eql(IRubyObject recv, IRubyObject rhs) {
return op_equal(recv, rhs);
return recv.inspect();
}

@JRubyMethod
public static IRubyObject hash(IRubyObject recv) {
if (recv instanceof JavaProxy) {
return RubyFixnum.newFixnum(recv.getRuntime(), ((JavaProxy)recv).getObject().hashCode());
return RubyFixnum.newFixnum(recv.getRuntime(), ((JavaProxy) recv).getObject().hashCode());
}
return ((JavaObject)recv.dataGetStruct()).hash();
}

@JRubyMethod
public static IRubyObject to_java_object(IRubyObject recv) {
return (JavaObject)recv.dataGetStruct();
return ((JavaObject) recv.dataGetStruct()).hash();
}

@JRubyMethod(name = "synchronized")
public static IRubyObject rbSynchronized(ThreadContext context, IRubyObject recv, Block block) {
if (recv instanceof JavaProxy) {
return JavaObject.ruby_synchronized(context, ((JavaProxy)recv).getObject(), block);
return JavaObject.ruby_synchronized(context, ((JavaProxy) recv).getObject(), block);
}
return ((JavaObject)recv.dataGetStruct()).ruby_synchronized(context, block);
return ((JavaObject) recv.dataGetStruct()).ruby_synchronized(context, block);
}
}
89 changes: 85 additions & 4 deletions core/src/main/java/org/jruby/javasupport/JavaSupport.java
Original file line number Diff line number Diff line change
@@ -63,10 +63,12 @@ public abstract class JavaSupport {

public abstract Map<String, JavaClass> getNameClassMap();

public abstract void setJavaObjectVariable(Object o, int i, Object v);

@Deprecated
public abstract Object getJavaObjectVariable(Object o, int i);

@Deprecated
public abstract void setJavaObjectVariable(Object o, int i, Object v);

public abstract RubyModule getJavaModule();

public abstract RubyModule getJavaUtilitiesModule();
@@ -108,15 +110,94 @@ public abstract class JavaSupport {

public abstract RubyClass getJavaProxyConstructorClass();

public abstract Map<Set<?>, JavaProxyClass> getJavaProxyClassCache();

public abstract ClassValue<Map<String, AssignedName>> getStaticAssignedNames();

public abstract ClassValue<Map<String, AssignedName>> getInstanceAssignedNames();

@Deprecated // internal API - no longer used
public abstract Map<Set<?>, JavaProxyClass> getJavaProxyClassCache();

/**
* a replacement for {@link #getJavaProxyClassCache()} API
*/
abstract JavaProxyClass fetchJavaProxyClass(ProxyClassKey classKey);

/**
* a replacement for {@link #getJavaProxyClassCache()} API
*/
abstract JavaProxyClass saveJavaProxyClass(ProxyClassKey classKey, JavaProxyClass klass);

/**
* @note Internal API - subject to change!
*/
public static final class ProxyClassKey {
final Class superClass;
final Class[] interfaces;
final Set<String> names; // "usable" method names - assumed immutable

private ProxyClassKey(Class superClass, Class[] interfaces, Set<String> names) {
this.superClass = superClass;
this.interfaces = interfaces;
this.names = names;
}

public static ProxyClassKey getInstance(Class superClass, Class[] interfaces, Set<String> names) {
return new ProxyClassKey(superClass, interfaces, names);
}

@Override
public boolean equals(Object obj) {
if ( obj instanceof ProxyClassKey ) {
final ProxyClassKey that = (ProxyClassKey) obj;
if (this.superClass != that.superClass) return false;

if (this.names.size() != that.names.size()) return false;
if ( ! this.names.equals(that.names) ) return false;

final int len = this.interfaces.length;
if (len != that.interfaces.length) return false;
// order is not important :
for ( int i = 0; i < len; i++ ) {
final Class iface = this.interfaces[i];
boolean ifaceFound = false;
for ( int j = 0; j < len; j++ ) {
if ( iface == that.interfaces[j] ) {
ifaceFound = true; break;
}
}
if ( ! ifaceFound ) return false;
}
return true;
}
return false;
}

private int hash;

@Override
public int hashCode() {
int hash = this.hash;
if (hash != 0) return hash;

for ( int i = 0; i < interfaces.length; i++ ) {
hash += interfaces[i].hashCode();
}
return this.hash = (hash * superClass.hashCode()) ^ this.names.hashCode();
}
}

/**
* @deprecated Internal API that should not be accessible.
*/
public abstract void beginProxy(Class cls, RubyModule proxy);

/**
* @deprecated Internal API that should not be accessible.
*/
public abstract void endProxy(Class cls);

/**
* @deprecated Internal API that should not be accessible.
*/
public abstract RubyModule getUnfinishedProxy(Class cls);
}
Loading