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: 24e62cf91a17
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ab12014777a9
Choose a head ref
  • 3 commits
  • 4 files changed
  • 1 contributor

Commits on Apr 6, 2016

  1. Copy the full SHA
    755d7c6 View commit details
  2. Copy the full SHA
    6843b55 View commit details
  3. Copy the full SHA
    ab12014 View commit details
Original file line number Diff line number Diff line change
@@ -222,12 +222,13 @@ public Object toJava(final Class type) {
return object;
}
}
else if (type.isAssignableFrom(clazz)) {
else if ( type.isAssignableFrom(clazz) ) {
if ( Java.OBJECT_PROXY_CACHE || metaClass.getCacheProxy() ) {
getRuntime().getJavaSupport().getObjectProxyCache().put(object, this);
}
return object;
}
else if ( type.isAssignableFrom(getClass()) ) return this; // e.g. IRubyObject.class

throw getRuntime().newTypeError("failed to coerce " + clazz.getName() + " to " + type.getName());
}
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/java/proxies/JavaProxy.java
Original file line number Diff line number Diff line change
@@ -451,6 +451,7 @@ public Object toJava(final Class type) {
final Class<?> clazz = object.getClass();

if ( type.isAssignableFrom(clazz) ) return object;
if ( type.isAssignableFrom(getClass()) ) return this; // e.g. IRubyObject.class

throw getRuntime().newTypeError("failed to coerce " + clazz.getName() + " to " + type.getName());
}
62 changes: 62 additions & 0 deletions core/src/test/java/org/jruby/util/StringSupportTest.java
Original file line number Diff line number Diff line change
@@ -77,4 +77,66 @@ public void testSplit() {
assertEquals(Arrays.asList(str.split(":", 1)), StringSupport.split(str, ':', 1));
}

public static void main(String[] args) {
System.out.println("WARMUP: ");
runSplitTest(100 * 1000);
System.gc(); System.gc();
System.out.println("\n\n");
runSplitTest(500 * 1000);
}

private static void runSplitTest(final long TIMES) {
long time;

System.gc();
time = stringSupportSplit(TIMES, "1:2", ':');

System.out.println("StringSupport.split(\"1:2\", ':') " + TIMES + "x took: " + time);

System.gc();
time = javaStringSplit(TIMES, "1:2", ":");

System.out.println("\"1:2\".split(\":\") " + TIMES + "x took: " + time);

//

System.gc();
time = stringSupportSplit(TIMES, "no-split-separator-match", ';');

System.out.println("StringSupport.split(\"no-split-separator-match\", ';') " + TIMES + "x took: " + time);

System.gc();
time = javaStringSplit(TIMES, "no-split-separator-match", ";");

System.out.println("\"no-split-separator-match\".split(\";\") " + TIMES + "x took: " + time);

//

System.gc();
time = stringSupportSplit(TIMES, "this\nis\na\nlonger\n\nstring\n,well\nnot\nvery-long-but\nstill\n", '\n');

System.out.println("StringSupport.split(\"this...\", '\\n') " + TIMES + "x took: " + time);

System.gc();
time = javaStringSplit(TIMES, "this\nis\na\nlonger\n\nstring\n,well\nnot\nvery-long-but\nstill\n", "\n");

System.out.println("\"this...\".split(\"\\n\") " + TIMES + "x took: " + time);
}

private static long stringSupportSplit(final long TIMES, final String str, final char sep) {
long time = System.currentTimeMillis();
for ( int i=0; i<TIMES; i++ ) {
StringSupport.split(str, sep);
}
return System.currentTimeMillis() - time;
}

private static long javaStringSplit(final long TIMES, final String str, final String sep) {
long time = System.currentTimeMillis();
for ( int i=0; i<TIMES; i++ ) {
str.split(sep);
}
return System.currentTimeMillis() - time;
}

}
10 changes: 9 additions & 1 deletion test/jruby/test_higher_javasupport.rb
Original file line number Diff line number Diff line change
@@ -1463,7 +1463,7 @@ def test_concurrent_proxy_class_initialization_invalid_method_dispatch

# reproducing https://github.com/jruby/jruby/issues/1621
def test_concurrent_proxy_class_initialization_dead_lock
timeout = 0.5; threads_to_kill = []
timeout = (ENV['TEST_CONCURRENT_TIMEOUT'] || 0.5).to_f; threads_to_kill = []
begin
threads = %w{ A B C D E F G H }.map do |sym|
Thread.new { Java::Default.const_get "Bug1621#{sym}" }
@@ -1479,6 +1479,14 @@ def test_concurrent_proxy_class_initialization_dead_lock
end
end

def test_java_proxy_coerce_into_ruby_object; require 'jruby' # @see GH-1925
proxied_java_object = java.util.concurrent.atomic.AtomicReference.new '42'
# defineReadonlyVariable expects an IRubyObject
JRuby.runtime.defineReadonlyVariable('$an_answer', proxied_java_object, org.jruby.internal.runtime.GlobalVariable::Scope::GLOBAL)
assert $an_answer
assert_equal 42.to_s, $an_answer.get
end

def test_callable_no_match_raised_errors
begin
java.lang.StringBuilder.new([])