Skip to content

Commit

Permalink
Showing 285 changed files with 8,677 additions and 4,503 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -40,8 +40,8 @@ matrix:
include:
- env: COMMAND=test/check_versions.sh
jdk: oraclejdk8
#- env: JT=check_ambiguous_arguments
# jdk: oraclejdk8
- env: JT=check_ambiguous_arguments
jdk: oraclejdk8
allow_failures:
- env: PHASE='-Prake -Dtask=test:mri:fullint'
- env: JT=check_ambiguous_arguments
46 changes: 39 additions & 7 deletions core/src/main/java/org/jruby/NativeException.java
Original file line number Diff line number Diff line change
@@ -27,8 +27,6 @@
***** END LICENSE BLOCK *****/
package org.jruby;

import java.io.PrintStream;

import java.lang.reflect.Member;
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
@@ -41,18 +39,19 @@
public class NativeException extends RubyException {

private final Throwable cause;
private final String messageAsJavaString;
public static final String CLASS_NAME = "NativeException";

public NativeException(Ruby runtime, RubyClass rubyClass, Throwable cause) {
super(runtime, rubyClass);
this.cause = cause;
this.message = runtime.newString(cause.getClass().getName() + ": " + searchStackMessage(cause));
this.messageAsJavaString = cause.getClass().getName() + ": " + searchStackMessage(cause);
}

private NativeException(Ruby runtime, RubyClass rubyClass) {
super(runtime, rubyClass);
this.cause = new Throwable();
this.message = RubyString.newEmptyString(runtime);
super(runtime, rubyClass, null);
this.cause = new Throwable();
this.messageAsJavaString = null;
}

private static ObjectAllocator NATIVE_EXCEPTION_ALLOCATOR = new ObjectAllocator() {
@@ -85,10 +84,27 @@ public IRubyObject cause(Block unusedBlock) {
public final IRubyObject backtrace() {
IRubyObject rubyTrace = super.backtrace();
if ( rubyTrace.isNil() ) return rubyTrace;

final Ruby runtime = getRuntime();
final RubyArray rTrace = (RubyArray) rubyTrace;
StackTraceElement[] jTrace = cause.getStackTrace();

// NOTE: with the new filtering ruby trace will already include the source (Java) part
if ( rTrace.size() > 0 && jTrace.length > 0 ) {
final String r0 = rTrace.eltInternal(0).toString();
// final StackTraceElement j0 = jTrace[0];
final String method = jTrace[0].getMethodName();
final String file = jTrace[0].getFileName();
if ( method != null && file != null &&
r0.indexOf(method) != -1 && r0.indexOf(file) != -1 ) {
return rTrace; // as is
}
}
// so join-ing is mostly unnecessary, but just in case (due compatibility) make sure :

return joinedBacktrace(runtime, rTrace, jTrace);
}

private static RubyArray joinedBacktrace(final Ruby runtime, final RubyArray rTrace, final StackTraceElement[] jTrace) {
final IRubyObject[] trace = new IRubyObject[jTrace.length + rTrace.size()];
final StringBuilder line = new StringBuilder(32);
for ( int i = 0; i < jTrace.length; i++ ) {
@@ -150,6 +166,22 @@ public void trimStackTrace(Member target) {
}
}

@Override
public final IRubyObject getMessage() {
if (message == null) {
if (messageAsJavaString == null) {
return message = getRuntime().getNil();
}
return message = getRuntime().newString(messageAsJavaString);
}
return message;
}

@Override
public final String getMessageAsJavaString() {
return messageAsJavaString;
}

public final Throwable getCause() {
return cause;
}
5 changes: 5 additions & 0 deletions core/src/main/java/org/jruby/RubyBignum.java
Original file line number Diff line number Diff line change
@@ -666,6 +666,11 @@ public IRubyObject op_or(ThreadContext context, IRubyObject other) {
return coerceBit(context, "|", other);
}

@JRubyMethod
public IRubyObject bit_length(ThreadContext context) {
return context.runtime.newFixnum(value.bitLength());
}

public IRubyObject op_or19(ThreadContext context, IRubyObject other) {
return op_or(context, other);
}
6 changes: 1 addition & 5 deletions core/src/main/java/org/jruby/RubyComparable.java
Original file line number Diff line number Diff line change
@@ -35,13 +35,9 @@

import org.jruby.anno.JRubyMethod;
import org.jruby.anno.JRubyModule;
import org.jruby.common.RubyWarnings;
import org.jruby.exceptions.RaiseException;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

import java.util.concurrent.Callable;

import static org.jruby.runtime.Helpers.invokedynamic;
import static org.jruby.runtime.invokedynamic.MethodNames.OP_CMP;

@@ -68,7 +64,7 @@ public static RubyModule createComparable(Ruby runtime) {
*
*/
public static int cmpint(ThreadContext context, IRubyObject val, IRubyObject a, IRubyObject b) {
if (val.isNil()) cmperr(a, b);
if (val == context.nil) cmperr(a, b);
if (val instanceof RubyFixnum) {
final int asInt = RubyNumeric.fix2int((RubyFixnum) val);

29 changes: 21 additions & 8 deletions core/src/main/java/org/jruby/RubyException.java
Original file line number Diff line number Diff line change
@@ -62,8 +62,11 @@
*/
@JRubyClass(name="Exception")
public class RubyException extends RubyObject {

protected RubyException(Ruby runtime, RubyClass rubyClass) {
this(runtime, rubyClass, null);
super(runtime, rubyClass);
// this.message = null; its an internal constructor for sub-classes
this.cause = RubyBasicObject.UNDEF;
}

public RubyException(Ruby runtime, RubyClass rubyClass, String message) {
@@ -133,10 +136,9 @@ public RubyException exception(IRubyObject[] args) {

@JRubyMethod(name = "to_s")
public IRubyObject to_s(ThreadContext context) {
if (message.isNil()) {
return context.runtime.newString(getMetaClass().getRealClass().getName());
}
return message.asString();
final IRubyObject msg = getMessage();
if ( ! msg.isNil() ) return msg.asString();
return context.runtime.newString(getMetaClass().getRealClass().getName());
}

@Deprecated
@@ -343,8 +345,7 @@ public void marshalTo(Ruby runtime, Object obj, RubyClass type,

marshalStream.registerLinkTarget(exc);
List<Variable<Object>> attrs = exc.getVariableList();
attrs.add(new VariableEntry<Object>(
"mesg", exc.message == null ? runtime.getNil() : exc.message));
attrs.add(new VariableEntry<Object>("mesg", exc.getMessage()));
attrs.add(new VariableEntry<Object>("bt", exc.getBacktrace()));
marshalStream.dumpVariables(attrs);
}
@@ -388,12 +389,24 @@ public static IRubyObject newException(ThreadContext context, RubyClass exceptio
return exceptionClass.callMethod(context, "new", message.convertToString());
}

/**
* @return error message if provided or nil
*/
public IRubyObject getMessage() {
return message;
return message == null ? getRuntime().getNil() : message;
}

public String getMessageAsJavaString() {
final IRubyObject msg = getMessage();
return msg.isNil() ? null : msg.toString();
}

private BacktraceData backtraceData;
private IRubyObject backtrace;
/**
* @deprecated do not access the field directly
* @see #getMessage()
*/
public IRubyObject message;
IRubyObject cause;

7 changes: 6 additions & 1 deletion core/src/main/java/org/jruby/RubyFixnum.java
Original file line number Diff line number Diff line change
@@ -1192,7 +1192,12 @@ public IRubyObject succ(ThreadContext context) {

@JRubyMethod
public IRubyObject bit_length(ThreadContext context) {
return context.runtime.newFixnum(64 - Long.numberOfLeadingZeros(value));
long tmpValue = value;
if (value < 0) {
tmpValue = Math.abs(value);
}

return context.runtime.newFixnum(64 - Long.numberOfLeadingZeros(tmpValue));
}

@Override
57 changes: 48 additions & 9 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -82,9 +82,9 @@
import org.jruby.internal.runtime.methods.WrapperMethod;
import org.jruby.ir.IRClosure;
import org.jruby.ir.IRMethod;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.javasupport.binding.Initializer;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Arity;
import org.jruby.runtime.Block;
import org.jruby.runtime.CallSite;
import org.jruby.runtime.ClassIndex;
@@ -93,21 +93,18 @@
import org.jruby.runtime.MethodFactory;
import org.jruby.runtime.MethodIndex;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.Signature;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.builtin.Variable;
import org.jruby.runtime.callsite.CacheEntry;
import org.jruby.runtime.callsite.FunctionalCachingCallSite;
import org.jruby.runtime.ivars.MethodData;
import org.jruby.runtime.load.IAutoloadMethod;
import org.jruby.runtime.marshal.MarshalStream;
import org.jruby.runtime.marshal.UnmarshalStream;
import org.jruby.runtime.opto.Invalidator;
import org.jruby.runtime.opto.OptoFactory;
import org.jruby.runtime.profile.MethodEnhancer;
import org.jruby.util.ByteList;
import org.jruby.util.ClassProvider;
import org.jruby.util.IdUtil;
import org.jruby.util.TypeConverter;
@@ -468,10 +465,6 @@ public RubyModule getDelegate() {
return this;
}

public RubyModule getNonPrependedClass() {
return this;
}

/**
* Get the base name of this class, or null if it is an anonymous class.
*
@@ -690,7 +683,7 @@ public IRubyObject using(ThreadContext context, IRubyObject refinedModule) {

// I pass the cref even though I don't need to so that the concept is simpler to read
StaticScope staticScope = context.getCurrentStaticScope();
RubyModule overlayModule = staticScope.getOverlayModule(context);
RubyModule overlayModule = staticScope.getOverlayModuleForWrite(context);
usingModule(context, overlayModule, refinedModule);

return this;
@@ -1237,10 +1230,39 @@ public DynamicMethod searchMethod(String name) {
return searchWithCache(name).method;
}

/**
* Search for the named method in this class and in superclasses, and if found return the CacheEntry representing
* the method and this class's serial number.
*
* @param name the method name
* @return the CacheEntry corresponding to the method and this class's serial number
*/
public CacheEntry searchWithCache(String name) {
return searchWithCache(name, true);
}

/**
* Search for the named method in this class and in superclasses applying refinements from the given scope. If
* found return the method; otherwise, return UndefinedMethod.
*
* @param name the method name
* @param refinedScope the scope containing refinements to search
* @return the method or UndefinedMethod
*/
public DynamicMethod searchWithRefinements(String name, StaticScope refinedScope) {
DynamicMethod method = searchMethodWithRefinementsInner(name, refinedScope);

if (method instanceof CacheableMethod) {
method = ((CacheableMethod) method).getMethodForCaching();
}

if (method != null) {
return method;
}

return UndefinedMethod.INSTANCE;
}

/**
* Search through this module and supermodules for method definitions. Cache superclass definitions in this class.
*
@@ -1432,6 +1454,23 @@ public DynamicMethod searchMethodInner(String name) {
return null;
}

public DynamicMethod searchMethodWithRefinementsInner(String name, StaticScope refinedScope) {
// This flattens some of the recursion that would be otherwise be necessary.
// Used to recurse up the class hierarchy which got messy with prepend.
for (RubyModule module = this; module != null; module = module.getSuperClass()) {
// Check for refinements in the given scope
DynamicMethod method = IRRuntimeHelpers.getRefinedMethodForClass(refinedScope, this.getNonIncludedClass(), name);
if (method != null && !method.isNull()) return method;

// Only recurs if module is an IncludedModuleWrapper.
// This way only the recursion needs to be handled differently on
// IncludedModuleWrapper.
method = module.searchMethodCommon(name);
if (method != null) return method.isNull() ? null : method;
}
return null;
}

// The local method resolution logic. Overridden in IncludedModuleWrapper for recursion.
protected DynamicMethod searchMethodCommon(String name) {
return getMethods().get(name);
6 changes: 4 additions & 2 deletions core/src/main/java/org/jruby/RubyNameError.java
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@
@JRubyClass(name="NameError", parent="StandardError")
public class RubyNameError extends RubyException {
private IRubyObject name;
private IRubyObject receiver;

/**
* Nested class whose instances act as thunks reacting to to_str method
@@ -207,6 +208,7 @@ static RubyException newNameError(IRubyObject recv, IRubyObject message, IRubyOb
@Override
public IRubyObject initialize(IRubyObject[] args, Block block) {
if ( args.length > 0 ) this.message = args[0];
if (message instanceof RubyNameErrorMessage) this.receiver = ((RubyNameErrorMessage) message).object;
if ( args.length > 1 ) this.name = args[1];
else this.name = getRuntime().getNil();
super.initialize(NULL_ARRAY, block); // message already set
@@ -231,8 +233,8 @@ public IRubyObject name() {

@JRubyMethod
public IRubyObject receiver(ThreadContext context) {
if (message instanceof RubyNameErrorMessage) {
return ((RubyNameErrorMessage) message).object;
if (receiver != null) {
return receiver;
}

throw context.runtime.newArgumentError("no receiver is available");
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyProc.java
Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@ protected RubyProc(Ruby runtime, RubyClass rubyClass, Block.Type type, String fi
}


RubyProc(Ruby runtime, RubyClass rubyClass, Block block, String file, int line) {
public RubyProc(Ruby runtime, RubyClass rubyClass, Block block, String file, int line) {
this(runtime, rubyClass, block.type);
this.block = block;
this.file = file;
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/RubyRange.java
Original file line number Diff line number Diff line change
@@ -760,6 +760,8 @@ public IRubyObject size(ThreadContext context) {
return context.nil;
}

public final boolean isExcludeEnd() { return isExclusive; }

private static final ObjectMarshal RANGE_MARSHAL = new ObjectMarshal() {
@Override
public void marshalTo(Ruby runtime, Object obj, RubyClass type,
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/TopSelfFactory.java
Original file line number Diff line number Diff line change
@@ -109,7 +109,7 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
Arity.checkArgumentCount(context.runtime, args, 1, 1);
RubyModule cref = context.getCurrentStaticScope().getOverlayModule(context);
RubyModule cref = context.getCurrentStaticScope().getOverlayModuleForWrite(context);
// unclear what the equivalent check would be for us
// rb_control_frame_t * prev_cfp = previous_frame(GET_THREAD());
//
Loading

0 comments on commit 6bb303c

Please sign in to comment.