boolean (final int alivePagesCount) { final int expectedTableSize = (int)Math.ceil(alivePagesCount / loadFactor); if (expectedTableSize >= MIN_TABLE_SIZE && expectedTableSize * SHRINK_FACTOR < pages.length()) { pagesLock.lock(); try { try { rehashToSize(expectedTableSize); } catch (NoFreeSpaceException e) { //RC: table content could change between alivePagesCount calculation, and actual rehash under // the lock: more pages could be inserted into a table, so alivePagesCount is an underestimation. // It could be so huge an underestimation that shrinking is not appropriate at all -- e.g. // there will be not enough slots in a table, if shrunk. We deal with it speculatively: try // to rehashToSize(), and cancel resize if NoFreeSpaceException is thrown: return false; } return true; } finally { pagesLock.unlock(); } } return false; }