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: 0f20cd4edb40
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 747c02564908
Choose a head ref
  • 11 commits
  • 11 files changed
  • 1 contributor

Commits on Feb 2, 2016

  1. Copy the full SHA
    0954bf9 View commit details
  2. Copy the full SHA
    26c9160 View commit details
  3. Copy the full SHA
    9902534 View commit details
  4. Copy the full SHA
    9a9a452 View commit details
  5. Copy the full SHA
    1412383 View commit details
  6. work-around (default_filename = true; '-') hack for JRuby compile/par…

    …se params
    
    ... also `compile` now correctly passes down block to `compile_ir`
    kares committed Feb 2, 2016
    Copy the full SHA
    ecf8614 View commit details
  7. Copy the full SHA
    430d461 View commit details
  8. wrap CharSequence instead of doing toString esp. since its on long ch…

    …ar sequences
    
    this will save an intermediate String in case of StringBuilder instances falling down
    
    also mark the UTF8 codes methods explicitly final
    kares committed Feb 2, 2016
    Copy the full SHA
    75a0117 View commit details
  9. Copy the full SHA
    465a794 View commit details
  10. Copy the full SHA
    54847e8 View commit details
  11. Copy the full SHA
    747c025 View commit details
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -3913,7 +3913,7 @@ public RaiseException newNameError(String message, String name, Throwable origEx

public RaiseException newNameError(String message, IRubyObject recv, IRubyObject name) {
IRubyObject msg = new RubyNameError.RubyNameErrorMessage(this, message, recv, name);
RubyException err = RubyNameError.newRubyNameError(getNameError(), msg, name);
RubyException err = RubyNameError.newNameError(getNameError(), msg, name);

return new RaiseException(err);
}
58 changes: 29 additions & 29 deletions core/src/main/java/org/jruby/RubyEncoding.java
Original file line number Diff line number Diff line change
@@ -117,28 +117,28 @@ public final Encoding getEncoding() {
if (encoding == null) encoding = getRuntime().getEncodingService().loadEncoding(name);
return encoding;
}

private static Encoding extractEncodingFromObject(IRubyObject obj) {
if (obj instanceof RubyEncoding) return ((RubyEncoding) obj).getEncoding();
if (obj instanceof RubySymbol) return ((RubySymbol) obj).asString().getEncoding();
if (obj instanceof EncodingCapable) return ((EncodingCapable) obj).getEncoding();

return null;
}

public static Encoding areCompatible(IRubyObject obj1, IRubyObject obj2) {
Encoding enc1 = extractEncodingFromObject(obj1);
Encoding enc2 = extractEncodingFromObject(obj2);

if (enc1 == null || enc2 == null) return null;
if (enc1 == enc2) return enc1;

if (obj2 instanceof RubyString && ((RubyString) obj2).getByteList().getRealSize() == 0) return enc1;
if (obj1 instanceof RubyString && ((RubyString) obj1).getByteList().getRealSize() == 0) {
return enc1.isAsciiCompatible() && obj2 instanceof RubyString &&
return enc1.isAsciiCompatible() && obj2 instanceof RubyString &&
((RubyString) obj2).isAsciiOnly() ? enc1 : enc2;
}

if (!enc1.isAsciiCompatible() || !enc2.isAsciiCompatible()) return null;

if (!(obj2 instanceof RubyString) && enc2 instanceof USASCIIEncoding) return enc1;
@@ -263,7 +263,7 @@ public static byte[] encodeUTF16(CharSequence str) {
}

public static byte[] encode(CharSequence cs, Charset charset) {
ByteBuffer buffer = charset.encode(cs.toString());
ByteBuffer buffer = charset.encode(CharBuffer.wrap(cs));
byte[] bytes = new byte[buffer.limit()];
buffer.get(bytes);
return bytes;
@@ -291,7 +291,7 @@ public static String decode(byte[] bytes, int start, int length, Charset charset
public static String decode(byte[] bytes, Charset charset) {
return charset.decode(ByteBuffer.wrap(bytes)).toString();
}

private static class UTF8Coder {
private final CharsetEncoder encoder = UTF8.newEncoder();
private final CharsetDecoder decoder = UTF8.newDecoder();
@@ -303,15 +303,15 @@ private static class UTF8Coder {
private final ByteBuffer byteBuffer = ByteBuffer.allocate(BUF_SIZE);
private final CharBuffer charBuffer = CharBuffer.allocate(BUF_SIZE);

public UTF8Coder() {
UTF8Coder() {
decoder.onMalformedInput(CodingErrorAction.REPLACE);
decoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
}

public byte[] encode(CharSequence cs) {
public final byte[] encode(CharSequence cs) {
ByteBuffer buffer;
if (cs.length() > CHAR_THRESHOLD) {
buffer = UTF8.encode(cs.toString());
buffer = UTF8.encode(CharBuffer.wrap(cs));
} else {
buffer = byteBuffer;
CharBuffer cbuffer = charBuffer;
@@ -322,13 +322,13 @@ public byte[] encode(CharSequence cs) {
encoder.encode(cbuffer, buffer, true);
buffer.flip();
}

byte[] bytes = new byte[buffer.limit()];
buffer.get(bytes);
return bytes;
}
public String decode(byte[] bytes, int start, int length) {

public final String decode(byte[] bytes, int start, int length) {
CharBuffer cbuffer;
if (length > CHAR_THRESHOLD) {
cbuffer = UTF8.decode(ByteBuffer.wrap(bytes, start, length));
@@ -342,11 +342,11 @@ public String decode(byte[] bytes, int start, int length) {
decoder.decode(buffer, cbuffer, true);
cbuffer.flip();
}

return cbuffer.toString();
}
public String decode(byte[] bytes) {

public final String decode(byte[] bytes) {
return decode(bytes, 0, bytes.length);
}
}
@@ -366,7 +366,7 @@ private static UTF8Coder getUTF8Coder() {
ref = new SoftReference<UTF8Coder>(coder);
UTF8_CODER.set(ref);
}

return coder;
}

@@ -381,7 +381,7 @@ public static IRubyObject locale_charmap(ThreadContext context, IRubyObject recv
Ruby runtime = context.runtime;
EncodingService service = runtime.getEncodingService();
ByteList name = new ByteList(service.getLocaleEncoding().getName());

return RubyString.newUsAsciiStringNoCopy(runtime, name);
}

@@ -390,25 +390,25 @@ public static IRubyObject locale_charmap(ThreadContext context, IRubyObject recv
public static IRubyObject name_list(ThreadContext context, IRubyObject recv) {
Ruby runtime = context.runtime;
EncodingService service = runtime.getEncodingService();

RubyArray result = runtime.newArray(service.getEncodings().size() + service.getAliases().size());
HashEntryIterator i;
i = service.getEncodings().entryIterator();
while (i.hasNext()) {
CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<Entry> e =
CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<Entry> e =
((CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<Entry>)i.next());
result.append(RubyString.newUsAsciiStringShared(runtime, e.bytes, e.p, e.end - e.p).freeze(context));
}
i = service.getAliases().entryIterator();
i = service.getAliases().entryIterator();
while (i.hasNext()) {
CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<Entry> e =
CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<Entry> e =
((CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<Entry>)i.next());
result.append(RubyString.newUsAsciiStringShared(runtime, e.bytes, e.p, e.end - e.p).freeze(context));
}

result.append(runtime.newString(EXTERNAL));
result.append(runtime.newString(LOCALE));

return result;
}

@@ -423,10 +423,10 @@ public static IRubyObject aliases(ThreadContext context, IRubyObject recv) {
RubyHash result = RubyHash.newHash(runtime);

while (i.hasNext()) {
CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<Entry> e =
CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<Entry> e =
((CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<Entry>)i.next());
IRubyObject alias = RubyString.newUsAsciiStringShared(runtime, e.bytes, e.p, e.end - e.p).freeze(context);
IRubyObject name = RubyString.newUsAsciiStringShared(runtime,
IRubyObject name = RubyString.newUsAsciiStringShared(runtime,
((RubyEncoding)list[e.value.getIndex()]).name).freeze(context);
result.fastASet(alias, name);
}
@@ -496,23 +496,23 @@ public IRubyObject names(ThreadContext context) {
HashEntryIterator i;
i = service.getEncodings().entryIterator();
while (i.hasNext()) {
CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<Entry> e =
CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<Entry> e =
((CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<Entry>)i.next());
if (e.value == entry) {
result.append(RubyString.newUsAsciiStringShared(runtime, e.bytes, e.p, e.end - e.p).freeze(context));
}
}
i = service.getAliases().entryIterator();
i = service.getAliases().entryIterator();
while (i.hasNext()) {
CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<Entry> e =
CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<Entry> e =
((CaseInsensitiveBytesHash.CaseInsensitiveBytesHashEntry<Entry>)i.next());
if (e.value == entry) {
result.append(RubyString.newUsAsciiStringShared(runtime, e.bytes, e.p, e.end - e.p).freeze(context));
}
}
result.append(runtime.newString(EXTERNAL));
result.append(runtime.newString(LOCALE));

return result;
}

32 changes: 23 additions & 9 deletions core/src/main/java/org/jruby/RubyNameError.java
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
* rights and limitations under the License.
*
* Copyright (C) 2006 Anders Bengtsson <ndrsbngtssn@yahoo.se>
*
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
@@ -46,7 +46,7 @@
public class RubyNameError extends RubyException {
private IRubyObject name;

/**
/**
* Nested class whose instances act as thunks reacting to to_str method
* called from (Exception#to_str, Exception#message)
* MRI equivalent: rb_cNameErrorMesg, class name: "message", construction method: "!",
@@ -164,37 +164,51 @@ public RubyNameError(Ruby runtime, RubyClass exceptionClass, String message, Str
super(runtime, exceptionClass, message);
this.name = name == null ? runtime.getNil() : runtime.newString(name);
}

public RubyNameError(Ruby runtime, RubyClass exceptionClass, String message, IRubyObject name) {
super(runtime, exceptionClass, message);
this.name = name;
}

@JRubyMethod(name = "exception", meta = true)
public static IRubyObject exception(ThreadContext context, IRubyObject recv) {
return newNameError(recv, NULL_ARRAY);
}

@JRubyMethod(name = "exception", meta = true)
public static RubyException exception(ThreadContext context, IRubyObject recv, IRubyObject message) {
return newRubyNameError(recv, message, context.nil);
return newNameError(recv, new IRubyObject[] { message });
}

@JRubyMethod(name = "exception", meta = true)
public static RubyException exception(ThreadContext context, IRubyObject recv, IRubyObject message, IRubyObject name) {
return newRubyNameError(recv, message, name);
return newNameError(recv, message, name);
}

public static RubyException newRubyNameError(IRubyObject recv, IRubyObject message, IRubyObject name) {
RubyClass klass = (RubyClass)recv;
private static RubyException newNameError(IRubyObject recv, IRubyObject[] args) {
final RubyClass klass = (RubyClass) recv;
RubyException newError = (RubyException) klass.allocate();

newError.callInit(args, Block.NULL_BLOCK);

return newError;
}

static RubyException newNameError(IRubyObject recv, IRubyObject message, IRubyObject name) {
final RubyClass klass = (RubyClass) recv;
RubyException newError = (RubyException) klass.allocate();

newError.callInit(message, name, Block.NULL_BLOCK);

return newError;
}

@JRubyMethod(required = 1, optional = 1, visibility = Visibility.PRIVATE)
@JRubyMethod(optional = 2, visibility = Visibility.PRIVATE)
@Override
public IRubyObject initialize(IRubyObject[] args, Block block) {
this.message = args[0];
if ( args.length > 0 ) this.message = args[0];
if ( args.length > 1 ) this.name = args[1];
else this.name = getRuntime().getNil();
super.initialize(NULL_ARRAY, block); // message already set
return this;
}
3 changes: 1 addition & 2 deletions core/src/main/java/org/jruby/RubyThread.java
Original file line number Diff line number Diff line change
@@ -87,6 +87,7 @@
import org.jruby.util.log.LoggerFactory;

import static org.jruby.runtime.Visibility.*;
import static org.jruby.runtime.backtrace.BacktraceData.EMPTY_STACK_TRACE;

/**
* Implementation of Ruby's <code>Thread</code> class. Each Ruby thread is
@@ -1532,8 +1533,6 @@ public IRubyObject backtrace_locations(ThreadContext context, IRubyObject[] args
return myContext.createCallerLocations(level, length, getNativeThread().getStackTrace());
}

static final StackTraceElement[] EMPTY_STACK_TRACE = new StackTraceElement[0];

public StackTraceElement[] javaBacktrace() {
if (threadImpl instanceof NativeThread) {
return ((NativeThread)threadImpl).getThread().getStackTrace();
18 changes: 10 additions & 8 deletions core/src/main/java/org/jruby/runtime/ThreadContext.java
Original file line number Diff line number Diff line change
@@ -337,7 +337,7 @@ public ThreadFiber getFiber() {
}

public void setFiber(ThreadFiber fiber) {
this.fiber = new WeakReference(fiber);
this.fiber = new WeakReference<ThreadFiber>(fiber);
}

public void setRootFiber(ThreadFiber rootFiber) {
@@ -667,16 +667,18 @@ public IRubyObject createCallerBacktrace(int level, Integer length, StackTraceEl

if (trace == null) return nil;

RubyArray newTrace = runtime.newArray(trace.length);
final RubyClass stringClass = runtime.getString();
final IRubyObject[] traceArray = new IRubyObject[trace.length];

for (int i = level; i - level < trace.length; i++) {
RubyString str = RubyString.newString(runtime, trace[i - level].mriStyleString());
newTrace.append(str);
for (int i = 0; i < trace.length; i++) {
traceArray[i] = new RubyString(runtime, stringClass, trace[i].mriStyleString());
}

if (RubyInstanceConfig.LOG_CALLERS) TraceType.logCaller(newTrace);
RubyArray backTrace = RubyArray.newArrayNoCopy(runtime, traceArray);

return newTrace;
if (RubyInstanceConfig.LOG_CALLERS) TraceType.logCaller(backTrace);

return backTrace;
}

/**
@@ -765,7 +767,7 @@ public static String createRawBacktraceStringFromThrowable(final Throwable ex, f
if (javaStackTrace == null || javaStackTrace.length == 0) return "";

return TraceType.printBacktraceJRuby(
new BacktraceData(javaStackTrace, new BacktraceElement[0], true, false, false).getBacktraceWithoutRuby(),
new BacktraceData(javaStackTrace, BacktraceElement.EMPTY_ARRAY, true, false, false).getBacktraceWithoutRuby(),
ex.getClass().getName(),
ex.getLocalizedMessage(),
color);
Original file line number Diff line number Diff line change
@@ -9,6 +9,9 @@
import java.util.Map;

public class BacktraceData implements Serializable {

public static final StackTraceElement[] EMPTY_STACK_TRACE = new StackTraceElement[0];

private RubyStackTraceElement[] backtraceElements;
private final StackTraceElement[] javaTrace;
private final BacktraceElement[] rubyTrace;
@@ -25,8 +28,8 @@ public BacktraceData(StackTraceElement[] javaTrace, BacktraceElement[] rubyTrace
}

public static final BacktraceData EMPTY = new BacktraceData(
new StackTraceElement[0],
new BacktraceElement[0],
EMPTY_STACK_TRACE,
BacktraceElement.EMPTY_ARRAY,
false,
false,
false);
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@

public class BacktraceElement {

public static final BacktraceElement[] EMPTY_ARRAY = new BacktraceElement[0];

public BacktraceElement() {
}

Loading