Merge "Try to mitigate issue #31016187: system_server crash in ArraySet." into nyc-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
09cb4f2007
@@ -156,28 +156,46 @@ public final class ArraySet<E> implements Collection<E>, Set<E> {
|
|||||||
synchronized (ArraySet.class) {
|
synchronized (ArraySet.class) {
|
||||||
if (mTwiceBaseCache != null) {
|
if (mTwiceBaseCache != null) {
|
||||||
final Object[] array = mTwiceBaseCache;
|
final Object[] array = mTwiceBaseCache;
|
||||||
mArray = array;
|
try {
|
||||||
mTwiceBaseCache = (Object[])array[0];
|
mArray = array;
|
||||||
mHashes = (int[])array[1];
|
mTwiceBaseCache = (Object[]) array[0];
|
||||||
array[0] = array[1] = null;
|
mHashes = (int[]) array[1];
|
||||||
mTwiceBaseCacheSize--;
|
array[0] = array[1] = null;
|
||||||
if (DEBUG) Log.d(TAG, "Retrieving 2x cache " + mHashes
|
mTwiceBaseCacheSize--;
|
||||||
+ " now have " + mTwiceBaseCacheSize + " entries");
|
if (DEBUG) Log.d(TAG, "Retrieving 2x cache " + mHashes
|
||||||
return;
|
+ " now have " + mTwiceBaseCacheSize + " entries");
|
||||||
|
return;
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
}
|
||||||
|
// Whoops! Someone trampled the array (probably due to not protecting
|
||||||
|
// their access with a lock). Our cache is corrupt; report and give up.
|
||||||
|
Slog.wtf(TAG, "Found corrupt ArraySet cache: [0]=" + array[0]
|
||||||
|
+ " [1]=" + array[1]);
|
||||||
|
mTwiceBaseCache = null;
|
||||||
|
mTwiceBaseCacheSize = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (size == BASE_SIZE) {
|
} else if (size == BASE_SIZE) {
|
||||||
synchronized (ArraySet.class) {
|
synchronized (ArraySet.class) {
|
||||||
if (mBaseCache != null) {
|
if (mBaseCache != null) {
|
||||||
final Object[] array = mBaseCache;
|
final Object[] array = mBaseCache;
|
||||||
mArray = array;
|
try {
|
||||||
mBaseCache = (Object[])array[0];
|
mArray = array;
|
||||||
mHashes = (int[])array[1];
|
mBaseCache = (Object[]) array[0];
|
||||||
array[0] = array[1] = null;
|
mHashes = (int[]) array[1];
|
||||||
mBaseCacheSize--;
|
array[0] = array[1] = null;
|
||||||
if (DEBUG) Log.d(TAG, "Retrieving 1x cache " + mHashes
|
mBaseCacheSize--;
|
||||||
+ " now have " + mBaseCacheSize + " entries");
|
if (DEBUG) Log.d(TAG, "Retrieving 1x cache " + mHashes
|
||||||
return;
|
+ " now have " + mBaseCacheSize + " entries");
|
||||||
|
return;
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
}
|
||||||
|
// Whoops! Someone trampled the array (probably due to not protecting
|
||||||
|
// their access with a lock). Our cache is corrupt; report and give up.
|
||||||
|
Slog.wtf(TAG, "Found corrupt ArraySet cache: [0]=" + array[0]
|
||||||
|
+ " [1]=" + array[1]);
|
||||||
|
mBaseCache = null;
|
||||||
|
mBaseCacheSize = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user