--- old/src/java.base/share/classes/jdk/internal/jimage/ImageStringsReader.java 2017-02-27 13:57:12.270472829 +0100 +++ new/src/java.base/share/classes/jdk/internal/jimage/ImageStringsReader.java 2017-02-27 13:57:12.030471639 +0100 @@ -38,6 +38,8 @@ */ public class ImageStringsReader implements ImageStrings { public static final int HASH_MULTIPLIER = 0x01000193; + public static final int POSITIVE_MASK = 0x7FFFFFFF; + private final BasicImageReader reader; ImageStringsReader(BasicImageReader reader) { @@ -54,40 +56,27 @@ throw new InternalError("Can not add strings at runtime"); } - private static int hashCode(byte[] bytes, int offset, int count, int seed) { - Objects.requireNonNull(bytes); - - if (offset < 0 || count < 0 || offset > bytes.length - count) { - throw new IndexOutOfBoundsException("offset=" + offset + ", count=" + count); - } - - int limit = offset + count; - - if (limit < 0 || limit > bytes.length) { - throw new IndexOutOfBoundsException("limit=" + limit); - } - - for (int i = offset; i < limit; i++) { - seed = (seed * HASH_MULTIPLIER) ^ (bytes[i] & 0xFF); - } - - return seed & 0x7FFFFFFF; + public static int hashCode(String string) { + return hashCode(string, HASH_MULTIPLIER); } - public static int hashCode(byte[] bytes, int seed) { - return hashCode(bytes, 0, bytes.length, seed); + public static int hashCode(String string, int seed) { + return unmaskedHashCode(string, seed) & POSITIVE_MASK; } - public static int hashCode(byte[] bytes) { - return hashCode(bytes, 0, bytes.length, HASH_MULTIPLIER); + public static int hashCode(String module, String string) { + return hashCode(module, string, HASH_MULTIPLIER); } - public static int hashCode(String string) { - return hashCode(string, HASH_MULTIPLIER); + public static int hashCode(String module, String string, int seed) { + seed = unmaskedHashCode("/", seed); + seed = unmaskedHashCode(module, seed); + seed = unmaskedHashCode("/", seed); + seed = unmaskedHashCode(string, seed); + return seed & POSITIVE_MASK; } - public static int hashCode(String string, int seed) { - + public static int unmaskedHashCode(String string, int seed) { int slen = string.length(); byte[] buffer = null; @@ -120,8 +109,7 @@ seed = (seed * HASH_MULTIPLIER) ^ (uch); } } - - return seed & 0x7FFFFFFF; + return seed; } static int charsFromMUTF8Length(byte[] bytes, int offset, int count) { @@ -265,6 +253,7 @@ static int mutf8FromStringLength(String s) { int length = 0; int slen = s.length(); + for (int i = 0; i < slen; i++) { char ch = s.charAt(i); int uch = ch & 0xFFFF;