Skip to content

Commit

Permalink
Add debug logging for ConcurrencyError, to show the original stack tr…
Browse files Browse the repository at this point in the history
…ace that caused it.

git-svn-id: http://svn.codehaus.org/jruby/tags/jruby-1_1_6RC2@8386 961051c9-f516-0410-bf72-c9f7e237a7b7
  • Loading branch information
headius committed Dec 17, 2008
1 parent a186aa9 commit b25d534
Showing 1 changed file with 38 additions and 35 deletions.
73 changes: 38 additions & 35 deletions src/org/jruby/RubyArray.java
Expand Up @@ -108,7 +108,10 @@ public int getNativeTypeIndex() {
return ClassIndex.ARRAY;
}

private final void concurrentModification() {
private final void concurrentModification(Exception e) {
if (getRuntime().getDebug().isTrue()) {
e.printStackTrace();
}
throw getRuntime().newConcurrencyError("Detected invalid array contents due to unsynchronized modifications with concurrent users");
}

Expand Down Expand Up @@ -333,7 +336,7 @@ private RubyArray(Ruby runtime, RubyClass klass, RubyArray original) {
try {
System.arraycopy(original.values, original.begin, values, 0, realLength);
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
}
}

Expand All @@ -359,7 +362,7 @@ private final void realloc(int newLength) {
System.arraycopy(values, 0, reallocated, 0, newLength);
}
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
}
values = reallocated;
}
Expand Down Expand Up @@ -410,7 +413,7 @@ public IRubyObject[] toJavaArray() {
try {
System.arraycopy(values, begin, copy, 0, realLength);
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
}
return copy;
}
Expand Down Expand Up @@ -483,7 +486,7 @@ private final void modify() {
try {
System.arraycopy(values, begin, vals, 0, realLength);
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
}
begin = 0;
values = vals;
Expand Down Expand Up @@ -586,7 +589,7 @@ private IRubyObject initializeCommon(ThreadContext context, IRubyObject arg0, IR
fill(values, 0, ilen, arg1);
}
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
}
realLength = ilen;
}
Expand Down Expand Up @@ -643,7 +646,7 @@ public boolean includes(ThreadContext context, IRubyObject item) {
try {
value = values[i];
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
continue;
}
if (equalInternal(context, value, item)) return true;
Expand All @@ -670,7 +673,7 @@ public RubyFixnum hash(ThreadContext context) {
try {
value = values[i];
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
continue;
}
h ^= RubyNumeric.num2long(value.callMethod(context, "hash"));
Expand Down Expand Up @@ -713,7 +716,7 @@ public final IRubyObject store(long index, IRubyObject value) {
try {
values[(int) index] = value;
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
}
return value;
}
Expand All @@ -731,7 +734,7 @@ private final IRubyObject eltOk(long offset) {
try {
return values[begin + (int)offset];
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
return getRuntime().getNil();
}
}
Expand Down Expand Up @@ -791,7 +794,7 @@ public IRubyObject fetch(ThreadContext context, IRubyObject arg0, Block block) {
try {
return values[begin + (int) index];
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
return getRuntime().getNil();
}
}
Expand All @@ -814,7 +817,7 @@ public IRubyObject fetch(ThreadContext context, IRubyObject arg0, IRubyObject ar
try {
return values[begin + (int) index];
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
return getRuntime().getNil();
}
}
Expand Down Expand Up @@ -877,7 +880,7 @@ private final void splice(long beg, long len, IRubyObject rpl) {
try {
System.arraycopy(values, (int) (beg + len), values, (int) beg + rlen, realLength - (int) (beg + len));
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
}
realLength = alen;
}
Expand All @@ -887,7 +890,7 @@ private final void splice(long beg, long len, IRubyObject rpl) {
try {
System.arraycopy(rplArr.values, rplArr.begin, values, (int) beg, rlen);
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
}
}
}
Expand Down Expand Up @@ -925,7 +928,7 @@ private final void spliceOne(long beg, long len, IRubyObject rpl) {
try {
System.arraycopy(values, (int) (beg + len), values, (int) beg + 1, realLength - (int) (beg + len));
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
}
realLength = alen;
}
Expand All @@ -934,7 +937,7 @@ private final void spliceOne(long beg, long len, IRubyObject rpl) {
try {
values[(int)beg] = rpl;
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
}
}

Expand Down Expand Up @@ -1147,7 +1150,7 @@ public RubyArray append(IRubyObject item) {
try {
values[realLength++] = item;
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
}
return this;
}
Expand Down Expand Up @@ -1183,7 +1186,7 @@ public IRubyObject pop(ThreadContext context) {
return obj;
}
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
return context.getRuntime().getNil();
}
}
Expand Down Expand Up @@ -1225,7 +1228,7 @@ public IRubyObject shift(ThreadContext context) {
values[realLength] = runtime.getNil();
}
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
return runtime.getNil();
}
return obj;
Expand Down Expand Up @@ -1265,7 +1268,7 @@ public RubyArray unshift(IRubyObject item) {
try {
System.arraycopy(values, 0, values, 1, realLength);
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
}

realLength++;
Expand All @@ -1290,7 +1293,7 @@ public RubyArray unshift_m(IRubyObject[] items) {
System.arraycopy(values, 0, values, items.length, (int) len);
System.arraycopy(items, 0, values, 0, items.length);
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
}

return this;
Expand Down Expand Up @@ -1631,7 +1634,7 @@ public RubyString join(ThreadContext context, IRubyObject sep) {
try {
value = values[i];
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
return runtime.newString("");
}
IRubyObject tmp = value.checkStringType();
Expand All @@ -1650,7 +1653,7 @@ public RubyString join(ThreadContext context, IRubyObject sep) {
try {
tmp = values[i];
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
return runtime.newString("");
}
if (tmp instanceof RubyString) {
Expand Down Expand Up @@ -1842,7 +1845,7 @@ public IRubyObject rb_clear() {
try {
fillNil(values, begin, begin + realLength, getRuntime());
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
}
}

Expand Down Expand Up @@ -1937,7 +1940,7 @@ private IRubyObject fillCommon(ThreadContext context, int beg, int len, IRubyObj
try {
fill(values, beg, beg + len, item);
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
}
}

Expand Down Expand Up @@ -1965,7 +1968,7 @@ private IRubyObject fillCommon(ThreadContext context, int beg, int len, Block bl
try {
values[i] = v;
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
}
}
return this;
Expand Down Expand Up @@ -2081,7 +2084,7 @@ public IRubyObject reverse_bang() {
}
}
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
}
return this;
}
Expand Down Expand Up @@ -2109,7 +2112,7 @@ private IRubyObject[] safeReverse(final IRubyObject[] values, final int length)
newValues[p2--] = values[p1++];
}
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
}
return newValues;
}
Expand Down Expand Up @@ -2219,7 +2222,7 @@ public IRubyObject delete(ThreadContext context, IRubyObject item, Block block)
try {
fillNil(values, begin + i2, begin + realLength, context.getRuntime());
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
}
this.realLength = i2;
if (i2 << 1 < values.length && values.length > ARRAY_DEFAULT_SIZE) realloc(i2 << 1);
Expand Down Expand Up @@ -2247,7 +2250,7 @@ private final IRubyObject delete_at(int pos) {
System.arraycopy(values, pos + 1, values, pos, len - (pos + 1));
values[realLength-1] = getRuntime().getNil();
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
}
realLength--;

Expand Down Expand Up @@ -2301,7 +2304,7 @@ public IRubyObject reject_bang(ThreadContext context, Block block) {
try {
fillNil(values, i2, realLength, context.getRuntime());
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
}
realLength = i2;
}
Expand Down Expand Up @@ -2682,7 +2685,7 @@ public IRubyObject op_plus(IRubyObject obj) {
System.arraycopy(values, begin, z.values, 0, realLength);
System.arraycopy(y.values, y.begin, z.values, realLength, y.realLength);
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
}
z.realLength = len;
return z;
Expand Down Expand Up @@ -2715,7 +2718,7 @@ public IRubyObject op_times(ThreadContext context, IRubyObject times) {
System.arraycopy(values, begin, ary2.values, i, realLength);
}
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
}

ary2.infectBy(this);
Expand Down Expand Up @@ -3106,7 +3109,7 @@ public IRubyObject shuffle_bang(ThreadContext context) {
values[begin + r] = tmp;
}
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
}

return this;
Expand All @@ -3127,7 +3130,7 @@ public IRubyObject sample(ThreadContext context) {
try {
return values[begin + i];
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
concurrentModification(e);
return runtime.getNil();
}
}
Expand Down

0 comments on commit b25d534

Please sign in to comment.