< prev index next >
src/share/vm/classfile/stringTable.cpp
Print this page
rev 12679 : 8176593: Throwable::getStackTrace performance regression
Reviewed-by: jiangli, iklam, coleenp, sspitsyn
@@ -1,7 +1,7 @@
/*
- * 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
@@ -94,14 +94,18 @@
CompactHashtable<oop, char> StringTable::_shared_table;
// 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) {
return hash_string((jchar*)NULL, 0);
}
@@ -115,15 +119,14 @@
vm_exit_out_of_memory(length, OOM_MALLOC_ERROR, "unable to create Unicode string for verification");
return 0;
}
}
-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,
int len, unsigned int hash) {
int count = 0;
@@ -154,11 +157,11 @@
// Check if the symbol table has been rehashed, if so, need to recalculate
// the hash value and index before second lookup.
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;
index = index_arg;
}
@@ -197,32 +200,38 @@
}
#endif
}
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);
ensure_string_alive(string);
return string;
}
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);
// Found
if (found_string != NULL) {
< prev index next >