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

Commits on Sep 25, 2017

  1. Copy the full SHA
    97c8e92 View commit details
  2. Copy the full SHA
    35b0321 View commit details
  3. Copy the full SHA
    a962b22 View commit details
  4. Copy the full SHA
    825e9a0 View commit details
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ env:
matrix:
- PHASE='-Ptest'
- PHASE='-Prake -Dtask=test:jruby'
- PHASE='-Prake -Dtask=test:jruby:fullint'
#- PHASE='-Prake -Dtask=test:jruby:fullint' # included with OpenJDK bellow
- PHASE='-Prake -Dtask=test:jruby:jit'
- PHASE='-Prake -Dtask=test:jruby:aot'
- PHASE='-Prake -Dtask=test:mri'
@@ -53,11 +53,15 @@ env:

matrix:
include:
- env: PHASE='-Ptest'
jdk: openjdk8
- env: PHASE='-Prake -Dtask=test:jruby:fullint'
jdk: openjdk8
# these profile do no need to run for all JDKs
- env: PHASE='-Pdist'
jdk: oraclejdk8
jdk: openjdk8
- env: PHASE='-Pjruby-jars'
jdk: oraclejdk8
jdk: openjdk8
- env: PHASE='-Pmain'
jdk: oraclejdk8
- env: PHASE='-Pcomplete'
@@ -66,7 +70,6 @@ matrix:
jdk: oraclejdk8
- env: PHASE='-Pj2ee'
jdk: oraclejdk8
# These next two started crashing on JDK7 in March 2015, possibly due to JVM issues on Travis's Docker-based env
- env: PHASE='-Pjruby-jars,test -Dinvoker.test=extended'
jdk: oraclejdk8
- env: PHASE='-Pmain,test -Dinvoker.test=extended'
11 changes: 11 additions & 0 deletions core/src/main/java/org/jruby/ext/set/RubySet.java
Original file line number Diff line number Diff line change
@@ -399,6 +399,17 @@ public RubySet to_set(final ThreadContext context, final IRubyObject[] args, fin
return set;
}

@JRubyMethod
public IRubyObject compare_by_identity(ThreadContext context) {
this.hash.compare_by_identity(context);
return this;
}

@JRubyMethod(name = "compare_by_identity?")
public IRubyObject compare_by_identity_p(ThreadContext context) {
return this.hash.compare_by_identity_p(context);
}

@JRubyMethod(visibility = Visibility.PROTECTED)
public RubySet flatten_merge(final ThreadContext context, IRubyObject set) {
flattenMerge(context, set, new IdentityHashMap());
14 changes: 6 additions & 8 deletions core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java
Original file line number Diff line number Diff line change
@@ -470,10 +470,10 @@ public static IRubyObject[] convertValueIntoArgArray(ThreadContext context, IRub
if (argIsArray) {
RubyArray valArray = (RubyArray)value;
if (valArray.size() == 1) value = valArray.eltInternal(0);
value = Helpers.aryToAry(value);
value = Helpers.aryToAry(context, value);
return (value instanceof RubyArray) ? ((RubyArray)value).toJavaArray() : new IRubyObject[] { value };
} else {
IRubyObject val0 = Helpers.aryToAry(value);
IRubyObject val0 = Helpers.aryToAry(context, value);
// FIXME: This logic exists in RubyProc and IRRubyBlockBody. consolidate when we do block call protocol work
if (val0.isNil()) {
return new IRubyObject[] { value };
@@ -1669,12 +1669,10 @@ public static RubyFixnum getArgScopeDepth(ThreadContext context, StaticScope cur
}

public static IRubyObject[] toAry(ThreadContext context, IRubyObject[] args) {
if (args.length == 1 && args[0].respondsTo("to_ary")) {
IRubyObject newAry = Helpers.aryToAry(args[0]);
if (newAry.isNil()) {
args = new IRubyObject[] { args[0] };
} else if (newAry instanceof RubyArray) {
args = ((RubyArray) newAry).toJavaArray();
IRubyObject ary;
if (args.length == 1 && (ary = Helpers.aryOrToAry(context, args[0])) != context.nil) {
if (ary instanceof RubyArray) {
args = ((RubyArray) ary).toJavaArray();
} else {
throw context.runtime.newTypeError(args[0].getType().getName() + "#to_ary should return Array");
}
28 changes: 17 additions & 11 deletions core/src/main/java/org/jruby/runtime/CompiledIRBlockBody.java
Original file line number Diff line number Diff line change
@@ -11,16 +11,11 @@

public class CompiledIRBlockBody extends IRBlockBody {
protected final MethodHandle handle;
protected volatile MethodHandle normalYieldSpecificHandle;
protected volatile MethodHandle normalYieldHandle;
protected volatile MethodHandle normalYieldUnwrapHandle;
protected volatile MethodHandle yieldTwoValuesHandle;
protected volatile MethodHandle yieldThreeValuesHandle;

public CompiledIRBlockBody(MethodHandle handle, IRScope closure, long encodedSignature) {
super(closure, Signature.decode(encodedSignature));
// evalType copied (shared) on MixedModeIRBlockBody#completeBuild
this.handle = handle;

// Done in the interpreter (WrappedIRClosure) but we do it here
closure.getStaticScope().determineModule();
}
@@ -67,10 +62,17 @@ public MethodHandle getHandle() {
return handle;
}

protected volatile MethodHandle normalYieldSpecificHandle;
protected volatile MethodHandle normalYieldHandle;
protected volatile MethodHandle normalYieldUnwrapHandle;
protected volatile MethodHandle yieldTwoValuesHandle;
protected volatile MethodHandle yieldThreeValuesHandle;

public MethodHandle getNormalYieldSpecificHandle() {
MethodHandle normalYieldSpecificHandle = this.normalYieldSpecificHandle;
if (normalYieldSpecificHandle != null) return normalYieldSpecificHandle;

return normalYieldSpecificHandle = Binder.from(IRubyObject.class, ThreadContext.class, Block.class)
return this.normalYieldSpecificHandle = Binder.from(IRubyObject.class, ThreadContext.class, Block.class)
.foldVoid(SET_NORMAL)
.fold(FOLD_METHOD1)
.fold(FOLD_TYPE1)
@@ -81,9 +83,10 @@ public MethodHandle getNormalYieldSpecificHandle() {
}

public MethodHandle getNormalYieldHandle() {
MethodHandle normalYieldHandle = this.normalYieldHandle;
if (normalYieldHandle != null) return normalYieldHandle;

return normalYieldHandle = Binder.from(IRubyObject.class, ThreadContext.class, Block.class, IRubyObject.class)
return this.normalYieldHandle = Binder.from(IRubyObject.class, ThreadContext.class, Block.class, IRubyObject.class)
.foldVoid(SET_NORMAL)
.fold(FOLD_METHOD2)
.fold(FOLD_TYPE2)
@@ -95,9 +98,10 @@ public MethodHandle getNormalYieldHandle() {
}

public MethodHandle getNormalYieldUnwrapHandle() {
MethodHandle normalYieldUnwrapHandle = this.normalYieldUnwrapHandle;
if (normalYieldUnwrapHandle != null) return normalYieldUnwrapHandle;

return normalYieldUnwrapHandle = Binder.from(IRubyObject.class, ThreadContext.class, Block.class, IRubyObject.class)
return this.normalYieldUnwrapHandle = Binder.from(IRubyObject.class, ThreadContext.class, Block.class, IRubyObject.class)
.foldVoid(SET_NORMAL)
.fold(FOLD_METHOD2)
.fold(FOLD_TYPE2)
@@ -109,9 +113,10 @@ public MethodHandle getNormalYieldUnwrapHandle() {
}

public MethodHandle getYieldTwoValuesHandle() {
MethodHandle yieldTwoValuesHandle = this.yieldTwoValuesHandle;
if (yieldTwoValuesHandle != null) return yieldTwoValuesHandle;

return yieldTwoValuesHandle = Binder.from(IRubyObject.class, ThreadContext.class, Block.class, IRubyObject.class, IRubyObject.class)
return this.yieldTwoValuesHandle = Binder.from(IRubyObject.class, ThreadContext.class, Block.class, IRubyObject.class, IRubyObject.class)
.foldVoid(SET_NORMAL)
.fold(FOLD_METHOD1)
.fold(FOLD_TYPE1)
@@ -124,9 +129,10 @@ public MethodHandle getYieldTwoValuesHandle() {
}

public MethodHandle getYieldThreeValuesHandle() {
MethodHandle yieldThreeValuesHandle = this.yieldThreeValuesHandle;
if (yieldThreeValuesHandle != null) return yieldThreeValuesHandle;

return yieldThreeValuesHandle = Binder.from(IRubyObject.class, ThreadContext.class, Block.class, IRubyObject.class, IRubyObject.class, IRubyObject.class)
return this.yieldThreeValuesHandle = Binder.from(IRubyObject.class, ThreadContext.class, Block.class, IRubyObject.class, IRubyObject.class, IRubyObject.class)
.foldVoid(SET_NORMAL)
.fold(FOLD_METHOD1)
.fold(FOLD_TYPE1)
37 changes: 25 additions & 12 deletions core/src/main/java/org/jruby/runtime/Helpers.java
Original file line number Diff line number Diff line change
@@ -1430,13 +1430,27 @@ public static RubyArray asArray(ThreadContext context, IRubyObject value) {
}

public static IRubyObject aryToAry(IRubyObject value) {
return aryToAry(value.getRuntime().getCurrentContext(), value);
}

public static IRubyObject aryToAry(ThreadContext context, IRubyObject value) {
if (value instanceof RubyArray) return value;

if (value.respondsTo("to_ary")) {
return TypeConverter.convertToType(value, value.getRuntime().getArray(), "to_ary", false);
return TypeConverter.convertToType(context, value, context.runtime.getArray(), "to_ary", false);
}

return value.getRuntime().newArray(value);
return context.runtime.newArray(value);
}

public static IRubyObject aryOrToAry(ThreadContext context, IRubyObject value) {
if (value instanceof RubyArray) return value;

if (value.respondsTo("to_ary")) {
return TypeConverter.convertToType(context, value, context.runtime.getArray(), "to_ary", false);
}

return context.nil;
}

@Deprecated // not used
@@ -2228,20 +2242,19 @@ public static boolean needsSplat19(int requiredCount, boolean isRest) {
// . Array given to rest should pass itself
// . Array with rest + other args should extract array
// . Array with multiple values and NO rest should extract args if there are more than one argument
// Note: In 1.9 alreadyArray is only relevant from our internal Java code in core libs.
// We never use it from interpreter or JIT.
@Deprecated // not used
public static IRubyObject[] restructureBlockArgs19(IRubyObject value, Signature signature, Block.Type type, boolean needsSplat, boolean alreadyArray) {
return restructureBlockArgs(value, signature, type, needsSplat);
}

static IRubyObject[] restructureBlockArgs(IRubyObject value, Signature signature, Block.Type type, boolean needsSplat) {
if (!type.checkArity && signature == Signature.NO_ARGUMENTS) return IRubyObject.NULL_ARRAY;
static IRubyObject[] restructureBlockArgs(ThreadContext context,
IRubyObject value, Signature signature, Block.Type type, boolean needsSplat) {

if (value != null && needsSplat && !(value instanceof RubyArray)) value = Helpers.aryToAry(value);
if (!type.checkArity && signature == Signature.NO_ARGUMENTS) return IRubyObject.NULL_ARRAY;

if (value == null) return IRubyObject.NULL_ARRAY;
if (needsSplat && value instanceof RubyArray) return ((RubyArray) value).toJavaArrayMaybeUnsafe();

if (needsSplat) {
value = Helpers.aryToAry(context, value);
if (value instanceof RubyArray) return ((RubyArray) value).toJavaArrayMaybeUnsafe();
}

return new IRubyObject[] { value };
}

53 changes: 26 additions & 27 deletions core/src/main/java/org/jruby/runtime/IRBlockBody.java
Original file line number Diff line number Diff line change
@@ -13,17 +13,21 @@ public abstract class IRBlockBody extends ContextAwareBlockBody {
protected final String fileName;
protected final int lineNumber;
protected final IRClosure closure;
protected ThreadLocal<EvalType> evalType; // null is treated as NONE (@see getEvalType())
ThreadLocal<EvalType> evalType;

public IRBlockBody(IRScope closure, Signature signature) {
// ThreadLocal not set by default to avoid having many thread-local values initialized
// servers such as Tomcat tend to do thread-local checks when un-deploying apps,
// for JRuby leads to 100s of SEVERE warnings for a mid-size (booted) Rails app
this(closure, signature, new ThreadLocal());
}

/* internal */ IRBlockBody(IRScope closure, Signature signature, ThreadLocal evalType) {
super(closure.getStaticScope(), signature);
this.closure = (IRClosure) closure;
this.fileName = closure.getFileName();
this.lineNumber = closure.getLineNumber();
// null (not set) by default to avoid having many thread-local values initialized
// servers such as Tomcat tend to do thread-local checks when un-deploying apps,
// for JRuby leads to 100s of SEVERE warnings for a mid-size (booted) Rails app
this.evalType = new ThreadLocal();
this.evalType = evalType;
}

public final EvalType getEvalType() {
@@ -71,9 +75,8 @@ public IRubyObject call(ThreadContext context, Block block, IRubyObject[] args)
public IRubyObject call(ThreadContext context, Block block, IRubyObject[] args, Block blockArg) {
if (canCallDirect()) {
return callDirect(context, block, args, blockArg);
} else {
return commonYieldPath(context, block, Block.Type.PROC, prepareArgumentsForCall(context, args, block.type), null, blockArg);
}
return commonYieldPath(context, block, Block.Type.PROC, prepareArgumentsForCall(context, args, block.type), null, blockArg);
}

@Override
@@ -113,44 +116,40 @@ public IRubyObject yieldSpecific(ThreadContext context, Block block, IRubyObject
}
}

IRubyObject yieldSpecificMultiArgsCommon(ThreadContext context, Block block, IRubyObject[] args) {
int blockArity = getSignature().arityValue();
private IRubyObject yieldSpecificMultiArgsCommon(ThreadContext context, Block block, IRubyObject... args) {
int blockArity = signature.arityValue();
if (blockArity == 1) {
args = new IRubyObject[] { RubyArray.newArrayMayCopy(context.runtime, args) };
}

if (canCallDirect()) {
return yieldDirect(context, block, args, null);
} else {
if (blockArity == 0) {
args = IRubyObject.NULL_ARRAY; // discard args
}
if (block.type == Block.Type.LAMBDA) signature.checkArity(context.runtime, args);
if (canCallDirect()) return yieldDirect(context, block, args, null);

return commonYieldPath(context, block, Block.Type.NORMAL, args, null, Block.NULL_BLOCK);
if (blockArity == 0) {
args = IRubyObject.NULL_ARRAY; // discard args
}
if (block.type == Block.Type.LAMBDA) signature.checkArity(context.runtime, args);

return commonYieldPath(context, block, Block.Type.NORMAL, args, null, Block.NULL_BLOCK);
}

@Override
public IRubyObject yieldSpecific(ThreadContext context, Block block, IRubyObject arg0, IRubyObject arg1) {
return yieldSpecificMultiArgsCommon(context, block, new IRubyObject[]{arg0, arg1});
return yieldSpecificMultiArgsCommon(context, block, arg0, arg1);
}

@Override
public IRubyObject yieldSpecific(ThreadContext context, Block block, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
return yieldSpecificMultiArgsCommon(context, block, new IRubyObject[]{arg0, arg1, arg2});
return yieldSpecificMultiArgsCommon(context, block, arg0, arg1, arg2);
}

private IRubyObject[] toAry(ThreadContext context, IRubyObject value) {
IRubyObject val0 = Helpers.aryToAry(value);
final IRubyObject ary = Helpers.aryToAry(context, value);

if (val0.isNil()) return new IRubyObject[] { value };
if (ary == context.nil) return new IRubyObject[] { value };

if (!(val0 instanceof RubyArray)) {
throw context.runtime.newTypeError(value.getType().getName() + "#to_ary should return Array");
}
if (ary instanceof RubyArray) return ((RubyArray) ary).toJavaArray();

return ((RubyArray)val0).toJavaArray();
throw context.runtime.newTypeError(value.getType().getName() + "#to_ary should return Array");
}

protected IRubyObject doYieldLambda(ThreadContext context, Block block, IRubyObject value) {
@@ -174,12 +173,12 @@ protected IRubyObject doYieldLambda(ThreadContext context, Block block, IRubyObj
public IRubyObject doYield(ThreadContext context, Block block, IRubyObject value) {
if (block.type == Block.Type.LAMBDA) return doYieldLambda(context, block, value);

int blockArity = getSignature().arityValue();
int blockArity = signature.arityValue();

IRubyObject[] args;
if (value == null) { // no args case from BlockBody.yieldSpecific
args = IRubyObject.NULL_ARRAY;
} else if (!getSignature().hasKwargs() && blockArity >= -1 && blockArity <= 1) {
} else if (!signature.hasKwargs() && blockArity >= -1 && blockArity <= 1) {
args = new IRubyObject[] { value };
} else {
args = toAry(context, value);
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/runtime/MethodBlockBody.java
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ public IRubyObject call(ThreadContext context, Block block, IRubyObject[] args,

@Override
protected IRubyObject doYield(ThreadContext context, Block block, IRubyObject value) {
IRubyObject[] realArgs = Helpers.restructureBlockArgs(value, getSignature(), block.type, false);
IRubyObject[] realArgs = Helpers.restructureBlockArgs(context, value, getSignature(), block.type, false);
return method.call(context, receiver, originModule, originName, realArgs, Block.NULL_BLOCK);
}