Skip to content

Commit

Permalink
Showing 70 changed files with 662 additions and 336 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -65,8 +65,8 @@ matrix:
- env: JT='test mri'
jdk: oraclejdk8
- env: JT='test gems' JAVA_OPTS="$JAVA_OPTS -Xmx512m" HAS_REDIS=true
- env: PHASE='-Pj2ee'
jdk: oraclejdk7
#- env: PHASE='-Pj2ee'
# jdk: oraclejdk7
# NOTE: build seems to never start (waited for any to finish for more than a day) - probably a travis-ci bug
#- env: PHASE='-Pmain'
# sudo: required
28 changes: 24 additions & 4 deletions bench/java/bench_array_to_java.rb
Original file line number Diff line number Diff line change
@@ -5,9 +5,29 @@

TIMES.times do
Benchmark.bm(30) do |bm|
bm.report("control") {a = [1,2,3,4]; 100_000.times {a}}
bm.report("ary.to_java") {a = [1,2,3,4]; 100_000.times {a.to_java}}
bm.report("ary.to_java :object") {a = [1,2,3,4]; 100_000.times {a.to_java :object}}
bm.report("ary.to_java :string") {a = [1,2,3,4]; 100_000.times {a.to_s.to_java :string}}
bm.report("control") { ary = [1,2,3,4,5,6,7,8]; 1_000_000.times { ary } }
bm.report("ary.to_java") { ary = [1,2,3,4,5,6,7,8]; 1_000_000.times { ary.to_java } }
bm.report("ary.to_java :object") { ary = [1,2,3,4,5,6,7,8]; 1_000_000.times { ary.to_java :object } }
bm.report("ary.to_java java.lang.Integer") { ary = [1,2,3,4,5,6,7,8]; 1_000_000.times { ary.to_java java.lang.Integer } }
bm.report("ary.to_java :int") { ary = [1,2,3,4,5,6,7,8]; 1_000_000.times { ary.to_java :int } }
bm.report("ary.to_java Java::int") { ary = [1,2,3,4,5,6,7,8]; 1_000_000.times { ary.to_java Java::int } }
bm.report("ary.to_java :short") { ary = [1,2,3,4,5,6,7,8]; 1_000_000.times { ary.to_java :short } }

bm.report("long_ary.to_java") do
long_ary = (0..255).to_a
100_000.times { long_ary.to_java }
end
bm.report("long_ary.to_java :int") do
long_ary = (0..255).to_a
100_000.times { long_ary.to_java :int }
end
bm.report("long_ary.to_java Java::int") do
long_ary = (0..255).to_a
100_000.times { long_ary.to_java Java::int }
end
bm.report("long_ary.to_java :short") do
long_ary = (0..255).to_a
100_000.times { long_ary.to_java :short }
end
end
end
Original file line number Diff line number Diff line change
@@ -825,9 +825,6 @@ public static RubyModule findInstanceMethodContainer(ThreadContext context, Dyna
// in b65a5842ecf56ca32edc2a17800968f021b6a064. At that time,
// I was wondering if it would affect this site here and looks
// like it does.
//
// Verify that the test in GH issue 4014 runs when ripping out
// this special instanceof check below.
return self instanceof RubyModule ? (RubyModule) self : self.getMetaClass();

case INSTANCE_METHOD:
@@ -1860,7 +1857,7 @@ public static RubyString freezeLiteralString(ThreadContext context, RubyString s

@JIT
public static IRubyObject callOptimizedAref(ThreadContext context, IRubyObject caller, IRubyObject target, RubyString keyStr, CallSite site) {
if (target instanceof RubyHash && ((CachingCallSite) site).retrieveCache(target.getMetaClass(), "[]").method.isBuiltin()) {
if (target instanceof RubyHash && ((CachingCallSite) site).isBuiltin(target.getMetaClass())) {
// call directly with cached frozen string
return ((RubyHash) target).op_aref(context, keyStr);
}
28 changes: 16 additions & 12 deletions core/src/main/java/org/jruby/java/addons/KernelJavaAddons.java
Original file line number Diff line number Diff line change
@@ -2,21 +2,19 @@

import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.javasupport.*;
import org.jruby.RubyKernel;
import org.jruby.RubyModule;
import org.jruby.RubyString;
import org.jruby.RubySymbol;
import org.jruby.anno.JRubyMethod;
import org.jruby.java.proxies.ConcreteJavaProxy;
import org.jruby.java.proxies.JavaProxy;
import org.jruby.javasupport.Java;
import org.jruby.javasupport.JavaClass;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.Block;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;

public class KernelJavaAddons {

@JRubyMethod
public static IRubyObject to_java(ThreadContext context, final IRubyObject fromObject) {
if ( fromObject instanceof RubyArray ) {
@@ -31,8 +29,8 @@ public static IRubyObject to_java(ThreadContext context, final IRubyObject fromO
if ( type.isNil() ) return to_java(context, fromObject);

final Ruby runtime = context.runtime;
final JavaClass targetType = getTargetType(context, runtime, type);

final JavaClass targetType = getTargetType(context, runtime, type);
if ( fromObject instanceof RubyArray ) {
return targetType.javaArrayFromRubyArray(context, (RubyArray) fromObject);
}
@@ -85,11 +83,9 @@ private static JavaClass getTargetType(ThreadContext context, Ruby runtime, IRub
JavaClass targetType;

if (type instanceof RubyString || type instanceof RubySymbol) {
targetType = runtime.getJavaSupport().getNameClassMap().get(type.asJavaString());
if (targetType == null) targetType = JavaClass.forNameVerbose(runtime, type.asJavaString());
}
else if (type instanceof RubyModule && type.respondsTo("java_class")) {
targetType = (JavaClass) Helpers.invoke(context, type, "java_class");
final String className = type.toString();
targetType = runtime.getJavaSupport().getNameClassMap().get(className);
if ( targetType == null ) targetType = JavaClass.forNameVerbose(runtime, className);
}
else if (type instanceof JavaProxy) {
final Object wrapped = ((JavaProxy) type).getObject();
@@ -98,10 +94,18 @@ else if (type instanceof JavaProxy) {
} else {
throw runtime.newTypeError("not a valid target type: " + type);
}
} else {
}
else if (type instanceof JavaClass) {
return (JavaClass) type;
}
else if (type instanceof RubyModule && type.respondsTo("java_class")) {
targetType = (JavaClass) Helpers.invoke(context, type, "java_class");
}
else {
throw runtime.newTypeError("unable to convert to type: " + type);
}

return targetType;
}

}
7 changes: 5 additions & 2 deletions core/src/main/java/org/jruby/java/proxies/ArrayJavaProxy.java
Original file line number Diff line number Diff line change
@@ -99,6 +99,10 @@ public void set(final int index, final Object value) {
Array.set(getObject(), index, value);
}

public IRubyObject setValue(final Ruby runtime, final int index, final IRubyObject value) {
return ArrayUtils.asetDirect(runtime, getObject(), converter, index, value);
}

@JRubyMethod(name = "[]", required = 1, rest = true)
public final IRubyObject op_aref(ThreadContext context, IRubyObject[] args) {
if ( args.length == 1 ) return op_aref(context, args[0]);
@@ -107,8 +111,7 @@ public final IRubyObject op_aref(ThreadContext context, IRubyObject[] args) {

@JRubyMethod(name = "[]=")
public final IRubyObject op_aset(ThreadContext context, IRubyObject index, IRubyObject value) {
final int i = convertArrayIndex(index);
return ArrayUtils.asetDirect(context.runtime, getObject(), converter, i, value);
return setValue(context.runtime, convertArrayIndex(index), value);
}

@JRubyMethod(name = "dig", required = 1, rest = true)
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@
public class ArrayJavaProxyCreator extends RubyObject {
private static final int[] EMPTY = new int[0];

/* final */ Class<?> elementType;
final Class<?> elementType;
int[] dimensions = EMPTY;

public static RubyClass createArrayJavaProxyCreator(ThreadContext context) {
@@ -37,18 +37,17 @@ public static RubyClass createArrayJavaProxyCreator(ThreadContext context) {
return arrayJavaProxyCreator;
}

@Deprecated
public ArrayJavaProxyCreator(final Ruby runtime) {
super(runtime, runtime.getJavaSupport().getArrayJavaProxyCreatorClass());
}

ArrayJavaProxyCreator(final ThreadContext context, JavaClass elementType, final IRubyObject[] sizes) {
this(context.runtime);
this.elementType = elementType.javaClass();
this(context.runtime, elementType.javaClass());
assert sizes.length > 0;
aggregateDimensions(sizes);
}

private ArrayJavaProxyCreator(final Ruby runtime, Class<?> elementType) {
super(runtime, runtime.getJavaSupport().getArrayJavaProxyCreatorClass());
this.elementType = elementType;
}

@JRubyMethod(name = "[]", required = 1, rest = true)
public final IRubyObject op_aref(ThreadContext context, IRubyObject[] sizes) {
Arity.checkArgumentCount(context.runtime, sizes, 1, -1);
Loading

0 comments on commit fe91143

Please sign in to comment.