Permalink
Browse files

Add debug logging for ConcurrencyError, to show the original stack tr…

…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...
1 parent a186aa9 commit b25d5342931e442b0bc03592f6377742ff65769f @headius headius committed Dec 17, 2008
Showing with 38 additions and 35 deletions.
  1. +38 −35 src/org/jruby/RubyArray.java
@@ -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");
}
@@ -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);
}
}
@@ -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;
}
@@ -410,7 +413,7 @@ public int getLength() {
try {
System.arraycopy(values, begin, copy, 0, realLength);
} catch (ArrayIndexOutOfBoundsException e) {
- concurrentModification();
+ concurrentModification(e);
}
return copy;
}
@@ -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;
@@ -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;
}
@@ -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;
@@ -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"));
@@ -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;
}
@@ -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();
}
}
@@ -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();
}
}
@@ -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();
}
}
@@ -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;
}
@@ -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);
}
}
}
@@ -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;
}
@@ -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);
}
}
@@ -1147,7 +1150,7 @@ public RubyArray append(IRubyObject item) {
try {
values[realLength++] = item;
} catch (ArrayIndexOutOfBoundsException e) {
- concurrentModification();
+ concurrentModification(e);
}
return this;
}
@@ -1183,7 +1186,7 @@ public IRubyObject pop(ThreadContext context) {
return obj;
}
} catch (ArrayIndexOutOfBoundsException e) {
- concurrentModification();
+ concurrentModification(e);
return context.getRuntime().getNil();
}
}
@@ -1225,7 +1228,7 @@ public IRubyObject shift(ThreadContext context) {
values[realLength] = runtime.getNil();
}
} catch (ArrayIndexOutOfBoundsException e) {
- concurrentModification();
+ concurrentModification(e);
return runtime.getNil();
}
return obj;
@@ -1265,7 +1268,7 @@ public RubyArray unshift(IRubyObject item) {
try {
System.arraycopy(values, 0, values, 1, realLength);
} catch (ArrayIndexOutOfBoundsException e) {
- concurrentModification();
+ concurrentModification(e);
}
realLength++;
@@ -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;
@@ -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();
@@ -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) {
@@ -1842,7 +1845,7 @@ public IRubyObject rb_clear() {
try {
fillNil(values, begin, begin + realLength, getRuntime());
} catch (ArrayIndexOutOfBoundsException e) {
- concurrentModification();
+ concurrentModification(e);
}
}
@@ -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);
}
}
@@ -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;
@@ -2081,7 +2084,7 @@ public IRubyObject reverse_bang() {
}
}
} catch (ArrayIndexOutOfBoundsException e) {
- concurrentModification();
+ concurrentModification(e);
}
return this;
}
@@ -2109,7 +2112,7 @@ public IRubyObject reverse() {
newValues[p2--] = values[p1++];
}
} catch (ArrayIndexOutOfBoundsException e) {
- concurrentModification();
+ concurrentModification(e);
}
return newValues;
}
@@ -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);
@@ -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--;
@@ -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;
}
@@ -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;
@@ -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);
@@ -3106,7 +3109,7 @@ public IRubyObject shuffle_bang(ThreadContext context) {
values[begin + r] = tmp;
}
} catch (ArrayIndexOutOfBoundsException e) {
- concurrentModification();
+ concurrentModification(e);
}
return this;
@@ -3127,7 +3130,7 @@ public IRubyObject sample(ThreadContext context) {
try {
return values[begin + i];
} catch (ArrayIndexOutOfBoundsException e) {
- concurrentModification();
+ concurrentModification(e);
return runtime.getNil();
}
}

0 comments on commit b25d534

Please sign in to comment.