Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into ruby-2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Nov 17, 2016
2 parents 3995a2d + d7ecebc commit 3e1131e
Show file tree
Hide file tree
Showing 20 changed files with 430 additions and 306 deletions.
8 changes: 3 additions & 5 deletions .travis.yml
Expand Up @@ -9,13 +9,15 @@ cache:
before_install:
- rm ~/.m2/settings.xml
- export MAVEN_SKIP_RC=true
- mvn -Xmx32M -v | grep 1.7.0; if [ $? = 0 ]; then export MAVEN_OPTS="-XX:MaxPermSize=240M"; else export MAVEN_OPTS="-XX:MaxMetaspaceSize=240M -XX:CompressedClassSpaceSize=240M"; fi
- mvn -Xmx32M -v | grep 1.7.0; if [ $? = 0 ]; then export MAVEN_OPTS="-XX:MaxPermSize=200M"; else export MAVEN_OPTS="-XX:MaxMetaspaceSize=200M -XX:CompressedClassSpaceSize=200M"; fi
- export MAVEN_OPTS="-Xmx512M $MAVEN_OPTS"

before_script:
- unset GEM_PATH GEM_HOME IRBRC JRUBY_OPTS
- export PATH="`pwd`/bin:$PATH"
- echo $HOME
- echo $JAVA_OPTS
- echo $MAVEN_OPTS

jdk:
- openjdk7
Expand Down Expand Up @@ -98,10 +100,6 @@ notifications:
- "%{repository} (%{branch}:%{commit} by %{author}): %{message} (%{build_url})"
skip_join: true

# update jruby-head installed on Travis CI
webhooks:
urls:
- "https://rubies.travis-ci.org/rebuild/jruby-head"
# we are on a branch
on_success: always
on_failure: never
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 @@ -130,14 +130,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 @@ -695,7 +695,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 @@ -846,8 +846,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 @@ -859,8 +858,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 @@ -977,7 +975,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 @@ -1372,7 +1370,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 @@ -1859,7 +1857,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 @@ -2071,7 +2069,7 @@ public IRubyObject compact_bang() {
}
}
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
throw concurrentModification(getRuntime(), e);
}

p -= begin;
Expand Down Expand Up @@ -2122,7 +2120,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 @@ -2217,7 +2215,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 @@ -2426,7 +2424,7 @@ public IRubyObject reverse_bang() {
}
}
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
throw concurrentModification(getRuntime(), e);
}
return this;
}
Expand Down Expand Up @@ -2458,7 +2456,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 @@ -2653,7 +2651,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 @@ -2689,7 +2687,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 @@ -2761,7 +2759,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 @@ -2863,7 +2861,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 @@ -3067,7 +3065,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 @@ -3211,7 +3209,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 @@ -3246,7 +3244,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 @@ -3342,7 +3340,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 @@ -3363,19 +3361,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 @@ -3491,7 +3490,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 @@ -4054,7 +4053,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 @@ -4182,8 +4181,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 @@ -4216,10 +4214,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 @@ -4241,7 +4239,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 @@ -4554,7 +4552,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 @@ -4611,9 +4609,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 @@ -5062,8 +5059,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 @@ -5075,8 +5071,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 @@ -5090,8 +5085,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 @@ -5105,8 +5099,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 @@ -5118,9 +5111,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 3e1131e

Please sign in to comment.