--- a/hotspot/src/share/vm/classfile/stringTable.cpp Mon Mar 13 16:07:17 2017 +0100
+++ b/hotspot/src/share/vm/classfile/stringTable.cpp Wed Mar 15 13:03:13 2017 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -96,10 +96,14 @@
// Pick hashing algorithm
unsigned int StringTable::hash_string(const jchar* s, int len) {
- return use_alternate_hashcode() ? AltHashing::murmur3_32(seed(), s, len) :
+ return use_alternate_hashcode() ? alt_hash_string(s, len) :
java_lang_String::hash_code(s, len);
}
+unsigned int StringTable::alt_hash_string(const jchar* s, int len) {
+ return AltHashing::murmur3_32(seed(), s, len);
+}
+
unsigned int StringTable::hash_string(oop string) {
EXCEPTION_MARK;
if (string == NULL) {
@@ -117,11 +121,10 @@
}
}
-oop StringTable::lookup_shared(jchar* name, int len) {
- // java_lang_String::hash_code() was used to compute hash values in the shared table. Don't
- // use the hash value from StringTable::hash_string() as it might use alternate hashcode.
- return _shared_table.lookup((const char*)name,
- java_lang_String::hash_code(name, len), len);
+oop StringTable::lookup_shared(jchar* name, int len, unsigned int hash) {
+ assert(hash == java_lang_String::hash_code(name, len),
+ "hash must be computed using java_lang_String::hash_code");
+ return _shared_table.lookup((const char*)name, hash, len);
}
oop StringTable::lookup_in_main_table(int index, jchar* name,
@@ -156,7 +159,7 @@
unsigned int hashValue;
int index;
if (use_alternate_hashcode()) {
- hashValue = hash_string(name, len);
+ hashValue = alt_hash_string(name, len);
index = hash_to_index(hashValue);
} else {
hashValue = hashValue_arg;
@@ -199,12 +202,15 @@
}
oop StringTable::lookup(jchar* name, int len) {
- oop string = lookup_shared(name, len);
+ // shared table always uses java_lang_String::hash_code
+ unsigned int hash = java_lang_String::hash_code(name, len);
+ oop string = lookup_shared(name, len, hash);
if (string != NULL) {
return string;
}
-
- unsigned int hash = hash_string(name, len);
+ if (use_alternate_hashcode()) {
+ hash = alt_hash_string(name, len);
+ }
int index = the_table()->hash_to_index(hash);
string = the_table()->lookup_in_main_table(index, name, len, hash);
@@ -215,12 +221,15 @@
oop StringTable::intern(Handle string_or_null, jchar* name,
int len, TRAPS) {
- oop found_string = lookup_shared(name, len);
+ // shared table always uses java_lang_String::hash_code
+ unsigned int hashValue = java_lang_String::hash_code(name, len);
+ oop found_string = lookup_shared(name, len, hashValue);
if (found_string != NULL) {
return found_string;
}
-
- unsigned int hashValue = hash_string(name, len);
+ if (use_alternate_hashcode()) {
+ hashValue = alt_hash_string(name, len);
+ }
int index = the_table()->hash_to_index(hashValue);
found_string = the_table()->lookup_in_main_table(index, name, len, hashValue);