从 Colt OpenLongObjectHashMap 除以零错误

Divide by zero error from Colt OpenLongObjectHashMap

我从 Colt OpenLongObjectHashMap 看到了这个异常:

java.lang.ArithmeticException: divide by zero
        at cern.colt.map.OpenLongObjectHashMap.indexOfKey(Unknown Source)
        at cern.colt.map.OpenLongObjectHashMap.get(Unknown Source)

不可复制。

这是 indexOfKey:

protected int indexOfKey(long key) {
    final long tab[] = table;
    final byte stat[] = state;
    final int length = tab.length;

    final int hash = HashFunctions.hash(key) & 0x7FFFFFFF;
    int i = hash % length;
    int decrement = hash % (length-2); // double hashing, see http://www.eece.unm.edu/faculty/heileman/hash/node4.html
    //int decrement = (hash / length) % length;
    if (decrement == 0) decrement = 1;

    // stop if we find a free slot, or if we find the key itself.
    // do skip over removed slots (yes, open addressing is like that...)
    while (stat[i] != FREE && (stat[i] == REMOVED || tab[i] != key)) {
        i -= decrement;
        //hashCollisions++;
        if (i<0) i+=length;
    }

    if (stat[i] == FREE) return -1; // not found
    return i; //found, return index where key is contained
}

所以唯一使用的除数是 length(length - 2),其中 lengthtable.lengthtable 是一个内部数组。

但是,table 仅初始化为最小大小为 3 的数组(默认值为 277,这是我正在使用的)。整数环绕似乎也不可能。

所以这似乎是一个不可能的错误。

有什么想法吗?

这原来是正在使用的 IBM JDK JIT 编译器中的 Java 编译器优化错误。

查看此错误报告:IJ06000: UNEXPECTED DIVIDE BY ZERO EXCEPTION

建议的解决方法是禁用问题方法的 LoopVersioner 优化。