8310026: [8u] make java_lang_String::hash_code consistent across platforms

Reviewed-by: phh, adinn, stuefe
This commit is contained in:
Zdenek Zambersky 2023-07-10 11:44:01 +00:00
parent 108003eb37
commit 15077ad189
3 changed files with 13 additions and 3 deletions

View File

@ -63,7 +63,7 @@ public class Hashtable extends BasicHashtable {
int len = buf.length;
// Emulate the unsigned int in java_lang_String::hash_code
while (len-- > 0) {
h = 31*h + (0xFFFFFFFFL & buf[s]);
h = 31*h + (0xFFL & buf[s]);
s++;
}
return h & 0xFFFFFFFFL;

View File

@ -177,7 +177,7 @@ class java_lang_String : AllStatic {
// hash P(31) from Kernighan & Ritchie
//
// For this reason, THIS ALGORITHM MUST MATCH String.hashCode().
template <typename T> static unsigned int hash_code(T* s, int len) {
static unsigned int hash_code(const jchar* s, int len) {
unsigned int h = 0;
while (len-- > 0) {
h = 31*h + (unsigned int) *s;
@ -185,6 +185,16 @@ class java_lang_String : AllStatic {
}
return h;
}
static unsigned int hash_code(const jbyte* s, int len) {
unsigned int h = 0;
while (len-- > 0) {
h = 31*h + (((unsigned int) *s) & 0xFF);
s++;
}
return h;
}
static unsigned int hash_code(oop java_string);
// This is the string hash code used by the StringTable, which may be

View File

@ -225,7 +225,7 @@ Symbol* SymbolTable::lookup(int index, const char* name,
unsigned int SymbolTable::hash_symbol(const char* s, int len) {
return use_alternate_hashcode() ?
AltHashing::halfsiphash_32(seed(), (const uint8_t*)s, len) :
java_lang_String::hash_code(s, len);
java_lang_String::hash_code((const jbyte*)s, len);
}