Collisions.java revision 5383
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 7126277
* @run main Collisions -shortrun
* @run main Collisions -Djdk.map.althashing.threshold=0 -shortrun
* @summary Ensure Maps behave well with lots of hashCode() collisions.
* @author Mike Duigou
*/
public class Collisions {
/**
* Number of elements per map.
*/
private static final int TEST_SIZE = 5000;
final int value;
final int hashmask; //yes duplication
}
if (obj instanceof HashableInteger) {
}
return false;
}
public int hashCode() {
}
public int compareTo(HashableInteger o) {
}
}
}
for (int i = 0; i < size; i++) {
UNIQUE_STRINGS[i] = unhash(i);
? UNIQUE_STRINGS[i / 2]
}
return new Object[][] {
};
}
/**
* Returns a string with a hash equal to the argument.
*
* @return string with a hash equal to the argument.
*/
if (target < 0) {
// String with hash of Integer.MIN_VALUE, 0x80000000
}
// Find target without sign bit set
}
}
if (div != 0) {
}
} else {
}
}
// loop through data sets
new HashMap<>(),
new Hashtable<>(),
new IdentityHashMap<>(),
new LinkedHashMap<>(),
new TreeMap<>(),
new WeakHashMap<>(),
new ConcurrentHashMap<>(),
new ConcurrentSkipListMap<>()
};
// for each map type.
try {
}
}
}
}
} else {
}
}
}
}
private static void testIntegerIteration(Map<HashableInteger, HashableInteger> map, HashableInteger[] keys) {
}
}
int count = 0;
count++;
}
}
}
}
int count = 0;
count++;
}
}
}
}
}
}
}
}
}
}
}
}
//--------------------- Infrastructure ---------------------------
static void pass() {
passed++;
}
static void fail() {
failed++;
}
failed++;
}
static void abort() {
fail();
}
}
unexpected(t);
}
static void unexpected(Throwable t) {
failed++;
}
if (cond) {
pass();
} else {
fail();
}
}
if (cond) {
pass();
} else {
}
}
pass();
} else {
fail(x + " not equal to " + y);
}
}
// Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
try {
} catch (Throwable t) {
unexpected(t);
}
if (failed > 0) {
throw new Error("Some tests failed");
}
}
}