Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into truffle-head
Browse files Browse the repository at this point in the history
* Except the update to jnr-enxio:0.14-SNAPSHOT.
  • Loading branch information
eregon committed Nov 27, 2016
2 parents f739f77 + 51e244e commit be4f7af
Show file tree
Hide file tree
Showing 34 changed files with 356 additions and 288 deletions.
4 changes: 2 additions & 2 deletions BUILDING.md
Expand Up @@ -125,10 +125,10 @@ from MRI's tests (under test/mri), use one of the following commands:
The MRI suite (under `test/mri`) has a runner script in `test/mri/runner.rb` that sets up
an appropriate test environment. Many of the MRI tests will need to be run via this script.
```
jruby test/mri/runner.rb test/mri/<path to test>
jruby -r ./test/mri_test_env.rb test/mri/runner.rb test/mri/<path to test>
```

You can pass `-v` to the runner for verbose output or `-n test_method_name` to only run a single test method.
You can pass `-v` to the runner for verbose output or `-n test_method_name` to only run a single test method. If you are interested in all failures you can exlude the -r option (of mri_test_env.rb). Some excluded tests are inherent limitations of JRuby and some are just problems we have not gotten to yet.

#### Run a test file with known-failing tests excluded

Expand Down
26 changes: 26 additions & 0 deletions bench/core/string/bench_index.rb
@@ -0,0 +1,26 @@
require 'benchmark'

TIMES = 10_000_000

Benchmark.bmbm do |x|

x.report("'foo'.index('o') [#{TIMES}x]") do
TIMES.times do
'foo'.index('o')
end
end

x.report("'0123456789001234567890'.index('abc') [#{TIMES}x]") do
TIMES.times do
'0123456789001234567890'.index('abc')
end
end

x.report("(('foo' * 100) + '012').index('01') [#{TIMES}x]") do
str = (('foo' * 100) + '012')
TIMES.times do
str.index('01')
end
end

end
90 changes: 41 additions & 49 deletions core/src/main/java/org/jruby/RubyArray.java
Expand Up @@ -129,14 +129,14 @@ public ClassIndex getNativeClassIndex() {
}

protected final void concurrentModification() {
concurrentModification(getRuntime(), null);
throw concurrentModification(getRuntime(), null);
}

private static void concurrentModification(Ruby runtime, Exception cause) {
private static RuntimeException concurrentModification(Ruby runtime, Exception cause) {
RuntimeException ex = runtime.newConcurrencyError("Detected invalid array contents due to unsynchronized modifications with concurrent users");
// NOTE: probably not useful to be on except for debugging :
// if ( cause != null ) ex.initCause(cause);
throw ex;
return ex;
}

/** rb_ary_s_create
Expand Down Expand Up @@ -694,7 +694,7 @@ protected IRubyObject initializeCommon(ThreadContext context, IRubyObject arg0,
fill(values, begin, begin + ilen, arg1);
}
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(runtime, ex);
throw concurrentModification(runtime, ex);
}
realLength = ilen;
}
Expand Down Expand Up @@ -845,8 +845,7 @@ public IRubyObject eltOk(long offset) {
try {
return eltInternal((int)offset);
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(getRuntime(), ex);
return null; // not reached
throw concurrentModification(getRuntime(), ex);
}
}

Expand All @@ -858,8 +857,7 @@ public IRubyObject eltSetOk(int offset, IRubyObject value) {
try {
return eltInternalSet(offset, value);
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(getRuntime(), ex);
return null; // not reached
throw concurrentModification(getRuntime(), ex);
}
}

Expand Down Expand Up @@ -976,7 +974,7 @@ private final void splice(long beg, long len, IRubyObject rpl, boolean oneNine)
try {
Helpers.fillNil(values, begin + realLength, begin + ((int) beg), getRuntime());
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
throw concurrentModification(getRuntime(), e);
}
realLength = (int) len;
} else {
Expand Down Expand Up @@ -1371,7 +1369,7 @@ public IRubyObject unshift(IRubyObject item) {
if (newLength < ARRAY_DEFAULT_SIZE) newLength = ARRAY_DEFAULT_SIZE;

newLength += valuesLength;
IRubyObject[]vals = new IRubyObject[newLength];
IRubyObject[] vals = new IRubyObject[newLength];
safeArrayCopy(values, begin, vals, 1, valuesLength);
Helpers.fillNil(vals, valuesLength + 1, newLength, getRuntime());
values = vals;
Expand Down Expand Up @@ -1858,7 +1856,7 @@ protected RubyString joinStrings(RubyString sep, int max, RubyString result) {
result.append19(eltInternal(i));
}
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
throw concurrentModification(getRuntime(), e);
}

return result;
Expand Down Expand Up @@ -2070,7 +2068,7 @@ public IRubyObject compact_bang() {
}
}
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
throw concurrentModification(getRuntime(), e);
}

p -= begin;
Expand Down Expand Up @@ -2121,7 +2119,7 @@ public IRubyObject rb_clear() {
begin = 0;
Helpers.fillNil(values, 0, realLength, getRuntime());
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
throw concurrentModification(getRuntime(), e);
}
}

Expand Down Expand Up @@ -2216,7 +2214,7 @@ protected IRubyObject fillCommon(ThreadContext context, int beg, long len, IRuby
try {
fill(values, begin + beg, begin + end, item);
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(context.runtime, ex);
throw concurrentModification(context.runtime, ex);
}
}

Expand Down Expand Up @@ -2425,7 +2423,7 @@ public IRubyObject reverse_bang() {
}
}
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
throw concurrentModification(getRuntime(), e);
}
return this;
}
Expand Down Expand Up @@ -2457,7 +2455,7 @@ protected RubyArray safeReverse() {
vals[length - i - 1] = myValues[myBegin + i];
}
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
throw concurrentModification(getRuntime(), e);
}
return new RubyArray(getRuntime(), getMetaClass(), vals);
}
Expand Down Expand Up @@ -2652,7 +2650,7 @@ public IRubyObject delete(ThreadContext context, IRubyObject item, Block block)
if (i2 << 1 < valuesLength && valuesLength > ARRAY_DEFAULT_SIZE) realloc(i2 << 1, valuesLength);
}
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(context.runtime, ex);
throw concurrentModification(context.runtime, ex);
}

return value;
Expand Down Expand Up @@ -2688,7 +2686,7 @@ public IRubyObject delete_at(int pos) {
System.arraycopy(values, begin + pos + 1, values, begin + pos, len - (pos + 1));
values[begin + len - 1] = getRuntime().getNil();
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
throw concurrentModification(getRuntime(), e);
}
realLength--;

Expand Down Expand Up @@ -2760,7 +2758,7 @@ else if (realLength > 0) {
try {
Helpers.fillNil(values, beg + i2, beg + i1, runtime);
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(runtime, ex);
throw concurrentModification(runtime, ex);
}
}
}
Expand Down Expand Up @@ -2862,7 +2860,7 @@ private IRubyObject zipCommon(ThreadContext context, IRubyObject[] args, Block b
result[i] = newArrayMayCopy(runtime, tmp);
}
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(context.runtime, ex);
throw concurrentModification(runtime, ex);
}
return newArrayMayCopy(runtime, result);
}
Expand Down Expand Up @@ -3066,7 +3064,7 @@ protected boolean flatten(ThreadContext context, final int level, final RubyArra
ary = (RubyArray) stack.pop(context);
}
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(context.runtime, ex);
throw concurrentModification(context.runtime, ex);
}
return modified;
}
Expand Down Expand Up @@ -3210,7 +3208,7 @@ public IRubyObject op_plus(IRubyObject obj) {
copyInto(z.values, 0);
y.copyInto(z.values, realLength);
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
throw concurrentModification(runtime, e);
}
z.realLength = len;
return z;
Expand Down Expand Up @@ -3245,7 +3243,7 @@ public IRubyObject op_times(ThreadContext context, IRubyObject times) {
copyInto(ary2.values, i);
}
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
throw concurrentModification(runtime, e);
}

ary2.infectBy(this);
Expand Down Expand Up @@ -3341,7 +3339,7 @@ public IRubyObject uniq(ThreadContext context) {
if (hash.fastDelete(v)) result.values[j++] = v;
}
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(context.runtime, ex);
throw concurrentModification(context.runtime, ex);
}
result.realLength = j;
return result;
Expand All @@ -3362,19 +3360,20 @@ public IRubyObject uniq19(ThreadContext context, Block block) {
*/
@JRubyMethod(name = "-", required = 1)
public IRubyObject op_diff(IRubyObject other) {
Ruby runtime = getRuntime();
RubyHash hash = other.convertToArray().makeHash();
RubyArray ary3 = newArray(getRuntime());
RubyArray ary3 = newArray(runtime);

try {
for (int i = 0; i < realLength; i++) {
IRubyObject value = eltOk(i);
if (hash.fastARef(value) != null) continue;
ary3.append(value);
}
} catch (ArrayIndexOutOfBoundsException aioob) {
concurrentModification();
} catch (ArrayIndexOutOfBoundsException e) {
throw concurrentModification(runtime, e);
}
Helpers.fillNil(ary3.values, ary3.realLength, ary3.values.length, getRuntime());
Helpers.fillNil(ary3.values, ary3.realLength, ary3.values.length, runtime);

return ary3;
}
Expand Down Expand Up @@ -3490,7 +3489,7 @@ public int compare(Object o1, Object o2) {
}
});
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(context.runtime, ex);
throw concurrentModification(context.runtime, ex);
}
return this;
}
Expand Down Expand Up @@ -4053,7 +4052,7 @@ public IRubyObject shuffle_bang(ThreadContext context, IRubyObject[] args) {
eltSetOk(r, tmp);
}
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(context.runtime, ex);
throw concurrentModification(context.runtime, ex);
}

return this;
Expand Down Expand Up @@ -4181,8 +4180,7 @@ public IRubyObject sample(ThreadContext context, IRubyObject[] args) {
return ary;
}
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(context.runtime, ex);
return this; // not reached
throw concurrentModification(context.runtime, ex);
}
}

Expand Down Expand Up @@ -4215,10 +4213,10 @@ protected IRubyObject internalRotateBang(ThreadContext context, int cnt) {
}
}
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(context.runtime, ex);
throw concurrentModification(context.runtime, ex);
}

return context.runtime.getNil();
return context.nil;
}

private static int rotateCount(int cnt, int len) {
Expand All @@ -4240,7 +4238,7 @@ protected IRubyObject internalRotate(ThreadContext context, int cnt) {
System.arraycopy(ptr, begin, ptr2, len, cnt);
}
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(context.runtime, ex);
throw concurrentModification(context.runtime, ex);
}

return rotated;
Expand Down Expand Up @@ -4357,7 +4355,7 @@ public static void marshalTo(RubyArray array, MarshalStream output) throws IOExc
output.dumpObject(array.eltInternal(i));
}
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(array.getRuntime(), ex);
throw concurrentModification(array.getRuntime(), ex);
}
}

Expand Down Expand Up @@ -4414,9 +4412,8 @@ public RubyString pack(ThreadContext context, IRubyObject obj) {
RubyString iFmt = obj.convertToString();
try {
return Pack.pack(context, context.runtime, this, iFmt);
} catch (ArrayIndexOutOfBoundsException aioob) {
concurrentModification();
return null; // not reached
} catch (ArrayIndexOutOfBoundsException e) {
throw concurrentModification(context.runtime, e);
}
}

Expand Down Expand Up @@ -4865,8 +4862,7 @@ private static IRubyObject safeArrayRef(Ruby runtime, IRubyObject[] values, int
try {
return values[i];
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(runtime, ex);
return null; // not reached
throw concurrentModification(runtime, ex);
}
}

Expand All @@ -4878,8 +4874,7 @@ private static IRubyObject safeArraySet(Ruby runtime, IRubyObject[] values, int
try {
return values[i] = value;
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(runtime, ex);
return null; // not reached
throw concurrentModification(runtime, ex);
}
}

Expand All @@ -4893,8 +4888,7 @@ private static IRubyObject safeArrayRefSet(Ruby runtime, IRubyObject[] values, i
values[i] = value;
return tmp;
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification(runtime, e);
return null; // not reached
throw concurrentModification(runtime, e);
}
}

Expand All @@ -4908,8 +4902,7 @@ private static IRubyObject safeArrayRefCondSet(Ruby runtime, IRubyObject[] value
if (doSet) values[i] = value;
return tmp;
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(runtime, ex);
return null; // not reached
throw concurrentModification(runtime, ex);
}
}

Expand All @@ -4921,9 +4914,8 @@ private static void safeArrayCopy(Ruby runtime, IRubyObject[] source, int source
try {
System.arraycopy(source, sourceStart, target, targetStart, length);
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(runtime, ex);
throw concurrentModification(runtime, ex);
}
// not reached
}

private static ArraySites sites(ThreadContext context) {
Expand Down

0 comments on commit be4f7af

Please sign in to comment.