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

Commits on Feb 18, 2016

  1. make JavaMethod arity sub-classes open-closed with call overrides (fo…

    …r less surprises)
    
    ... without following the introduced conventions one can not guarantee correct dispatch
    in corner cases such as native over-loaded (multi) method impls (e.g. using public_send)
    kares committed Feb 18, 2016

    Verified

    This commit was signed with the committer’s verified signature.
    headius Charles Oliver Nutter
    Copy the full SHA
    62aaa9c View commit details
  2. Copy the full SHA
    5e43269 View commit details
  3. Copy the full SHA
    e6b9bcc View commit details
Original file line number Diff line number Diff line change
@@ -302,7 +302,7 @@ public JavaMethodZeroOrNBlock(RubyModule implementationClass, Visibility visibil
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name) {
return call(context, self, clazz, name, Block.NULL_BLOCK);
}

@@ -320,7 +320,7 @@ public JavaMethodZeroOrOneOrNBlock(RubyModule implementationClass, Visibility vi
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0) {
return call(context, self, clazz, name, arg0, Block.NULL_BLOCK);
}

@@ -338,7 +338,7 @@ public JavaMethodZeroOrOneOrTwoOrNBlock(RubyModule implementationClass, Visibili
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1) {
return call(context, self, clazz, name, arg0, arg1, Block.NULL_BLOCK);
}

@@ -356,7 +356,7 @@ public JavaMethodZeroOrOneOrTwoOrThreeOrNBlock(RubyModule implementationClass, V
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
return call(context, self, clazz, name, arg0, arg1, arg2, Block.NULL_BLOCK);
}

@@ -376,7 +376,7 @@ public JavaMethodOneOrNBlock(RubyModule implementationClass, Visibility visibili
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0) {
return call(context, self, clazz, name, arg0, Block.NULL_BLOCK);
}

@@ -394,7 +394,7 @@ public JavaMethodOneOrTwoOrNBlock(RubyModule implementationClass, Visibility vis
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1) {
return call(context, self, clazz, name, arg0, arg1, Block.NULL_BLOCK);
}

@@ -412,7 +412,7 @@ public JavaMethodOneOrTwoOrThreeOrNBlock(RubyModule implementationClass, Visibil
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
return call(context, self, clazz, name, arg0, arg1, arg2, Block.NULL_BLOCK);
}

@@ -432,7 +432,7 @@ public JavaMethodTwoOrNBlock(RubyModule implementationClass, Visibility visibili
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1) {
return call(context, self, clazz, name, arg0, arg1, Block.NULL_BLOCK);
}

@@ -450,7 +450,7 @@ public JavaMethodTwoOrThreeOrNBlock(RubyModule implementationClass, Visibility v
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
return call(context, self, clazz, name, arg0, arg1, arg2, Block.NULL_BLOCK);
}

@@ -470,7 +470,7 @@ public JavaMethodThreeOrNBlock(RubyModule implementationClass, Visibility visibi
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
return call(context, self, clazz, name, arg0, arg1, arg2, Block.NULL_BLOCK);
}

@@ -761,7 +761,7 @@ public JavaMethodZeroOrN(RubyModule implementationClass, Visibility visibility,
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, Block block) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, Block block) {
return call(context, self, clazz, name);
}

@@ -779,7 +779,7 @@ public JavaMethodZeroOrOneOrN(RubyModule implementationClass, Visibility visibil
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, Block block) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, Block block) {
return call(context, self, clazz, name, arg0);
}

@@ -797,7 +797,7 @@ public JavaMethodZeroOrOneOrTwoOrN(RubyModule implementationClass, Visibility vi
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, Block block) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, Block block) {
return call(context, self, clazz, name, arg0, arg1);
}

@@ -815,7 +815,7 @@ public JavaMethodZeroOrOneOrTwoOrThreeOrN(RubyModule implementationClass, Visibi
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
return call(context, self, clazz, name, arg0, arg1, arg2);
}

@@ -842,7 +842,7 @@ public JavaMethodOneOrN(RubyModule implementationClass, Visibility visibility, C
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, Block block) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, Block block) {
return call(context, self, clazz, name, arg0);
}

@@ -860,7 +860,7 @@ public JavaMethodOneOrTwoOrN(RubyModule implementationClass, Visibility visibili
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, Block block) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, Block block) {
return call(context, self, clazz, name, arg0, arg1);
}

@@ -878,7 +878,7 @@ public JavaMethodOneOrTwoOrThreeOrN(RubyModule implementationClass, Visibility v
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
return call(context, self, clazz, name, arg0, arg1, arg2);
}

@@ -898,7 +898,7 @@ public JavaMethodTwoOrN(RubyModule implementationClass, Visibility visibility, C
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, Block block) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, Block block) {
return call(context, self, clazz, name, arg0, arg1);
}

@@ -916,7 +916,7 @@ public JavaMethodTwoOrThreeOrN(RubyModule implementationClass, Visibility visibi
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
return call(context, self, clazz, name, arg0, arg1, arg2);
}

@@ -936,7 +936,7 @@ public JavaMethodThreeOrN(RubyModule implementationClass, Visibility visibility,
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
return call(context, self, clazz, name, arg0, arg1, arg2);
}

@@ -962,7 +962,7 @@ public JavaMethodZero(RubyModule implementationClass, Visibility visibility, Cal
super(implementationClass, visibility, name);
}

public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
if (args.length != 0) return raiseArgumentError(this, context, name, args.length, 0, 0);
return call(context, self, clazz, name);
}
@@ -982,7 +982,7 @@ public JavaMethodZeroOrOne(RubyModule implementationClass, Visibility visibility
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
switch (args.length) {
case 0:
return call(context, self, clazz, name);
@@ -1004,7 +1004,7 @@ public JavaMethodZeroOrOneOrTwo(RubyModule implementationClass, Visibility visib
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
switch (args.length) {
case 0:
return call(context, self, clazz, name);
@@ -1027,7 +1027,7 @@ public JavaMethodZeroOrOneOrTwoOrThree(RubyModule implementationClass, Visibilit
super(implementationClass, visibility);
}

public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
switch (args.length) {
case 0:
return call(context, self, clazz, name);
@@ -1065,7 +1065,7 @@ public JavaMethodOne(RubyModule implementationClass, Visibility visibility, Call
setParameterList(ONE_REQ);
}

public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
if (args.length != 1) return raiseArgumentError(this, context, name, args.length, 1, 1);
return call(context, self, clazz, name, args[0]);
}
@@ -1085,7 +1085,7 @@ public JavaMethodOneOrTwo(RubyModule implementationClass, Visibility visibility,
super(implementationClass, visibility);
}

public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
switch (args.length) {
case 1:
return call(context, self, clazz, name, args[0]);
@@ -1106,7 +1106,7 @@ public JavaMethodOneOrTwoOrThree(RubyModule implementationClass, Visibility visi
super(implementationClass, visibility);
}

public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
switch (args.length) {
case 1:
return call(context, self, clazz, name, args[0]);
@@ -1133,7 +1133,7 @@ public JavaMethodTwo(RubyModule implementationClass, Visibility visibility, Call
setParameterList(TWO_REQ);
}

public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
if (args.length != 2) return raiseArgumentError(this, context, name, args.length, 2, 2);
return call(context, self, clazz, name, args[0], args[1]);
}
@@ -1153,7 +1153,7 @@ public JavaMethodTwoOrThree(RubyModule implementationClass, Visibility visibilit
super(implementationClass, visibility);
}

public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
switch (args.length) {
case 2:
return call(context, self, clazz, name, args[0], args[1]);
@@ -1177,7 +1177,7 @@ public JavaMethodThree(RubyModule implementationClass, Visibility visibility, Ca
super(implementationClass, visibility);
}

public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
if (args.length != 3) return raiseArgumentError(this, context, name, args.length, 3, 3);
return call(context, self, clazz, name, args[0], args[1], args[2]);
}
27 changes: 10 additions & 17 deletions core/src/main/java/org/jruby/util/StringSupport.java
Original file line number Diff line number Diff line change
@@ -58,23 +58,16 @@ public final class StringSupport {
public static final int CR_VALID = RubyObject.USER1_F;
public static final int CR_BROKEN = RubyObject.USER0_F | RubyObject.USER1_F;

public static final Object UNSAFE = getUnsafe();
private static final int OFFSET = UNSAFE != null ? ((Unsafe)UNSAFE).arrayBaseOffset(byte[].class) : 0;
static final int ARRAY_BYTE_BASE_OFFSET;
static {
final Unsafe unsafe = org.jruby.util.unsafe.UnsafeHolder.U;
ARRAY_BYTE_BASE_OFFSET = unsafe != null ? unsafe.arrayBaseOffset(byte[].class) : 0;
}

public static final int TRANS_SIZE = 256;

public static final String[] EMPTY_STRING_ARRAY = new String[0];

private static Object getUnsafe() {
try {
Class sunUnsafe = Class.forName("sun.misc.Unsafe");
java.lang.reflect.Field f = sunUnsafe.getDeclaredField("theUnsafe");
f.setAccessible(true);
return sun.misc.Unsafe.class.cast(f.get(sunUnsafe));
} catch (Exception ex) {
return null;
}
}

public static String codeRangeAsString(int codeRange) {
switch (codeRange) {
case CR_UNKNOWN: return "unknown";
@@ -235,18 +228,18 @@ private static int countUtf8LeadBytes(long d) {
private static final int LONG_SIZE = 8;
private static final int LOWBITS = LONG_SIZE - 1;
@SuppressWarnings("deprecation")
public static int utf8Length(byte[]bytes, int p, int end) {
public static int utf8Length(byte[] bytes, int p, int end) {
int len = 0;
if (UNSAFE != null) {
if (ARRAY_BYTE_BASE_OFFSET > 0) { // Unsafe
if (end - p > LONG_SIZE * 2) {
int ep = ~LOWBITS & (p + LOWBITS);
while (p < ep) {
if ((bytes[p++] & 0xc0 /*utf8 lead byte*/) != 0x80) len++;
}
Unsafe us = (Unsafe)UNSAFE;
final Unsafe unsafe = org.jruby.util.unsafe.UnsafeHolder.U;
int eend = ~LOWBITS & end;
while (p < eend) {
len += countUtf8LeadBytes(us.getLong(bytes, (long)(OFFSET + p)));
len += countUtf8LeadBytes(unsafe.getLong(bytes, (long) (ARRAY_BYTE_BASE_OFFSET + p)));
p += LONG_SIZE;
}
}
2 changes: 2 additions & 0 deletions test/jruby/hello_dummy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Hello = 'hello'
class Dummy ; Hello end
10 changes: 7 additions & 3 deletions test/jruby/test_load.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
require 'test/unit'
require 'test/jruby/test_helper'
require 'rbconfig'
require 'jruby/path_helper'


def load_behavior_block(&block)
eval("__FILE__", block.binding)
end
end # used in test_loading_behavior

class TestLoad < Test::Unit::TestCase
include TestHelper
@@ -319,4 +317,10 @@ def test_symlinked_jar
end
end
end

def test_load_wrapped
pend 'TODO: fix load module wrapping'
load(File.expand_path('hello_dummy.rb', File.dirname(__FILE__)), true)
end

end
28 changes: 28 additions & 0 deletions test/jruby/test_require_once.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'test/unit'

class TestRequireOnce < Test::Unit::TestCase

# This test repeatedly requires the same file across several threads, reverting $" each time.
# It passes when requires are only firing once, regardless of concurrency.
# See JRUBY-3078.
@@ -23,4 +24,31 @@ def test_feature_has_full_name
load File.dirname(__FILE__) + "/test_require_once_jruby_3234/all.rb"
assert_equal 1, $jruby_3234
end

# module ::Zlib; end
#
# def test_define_class_type_mismatch
# return if $LOADED_FEATURES.include?('zlib')
#
# Zlib.const_set :Error, 1
#
# assert_raise(TypeError) do
# require('zlib')
# end
# ensure
# Zlib.send :remove_const, :Error
# end

# def test_define_class_type_mismatch
# return if $LOADED_FEATURES.include?('socket')
#
# Object.const_set :BasicSocket, Class.new
#
# assert_raise(NameError) do
# require('socket')
# end
# ensure
# Object.send :remove_const, :BasicSocket
# end

end