8270333: -XX:+VerifyStringTableAtExit should not do linear search
Reviewed-by: dholmes, minqi
This commit is contained in:
parent
04b73bc4e0
commit
1ebd9469db
@ -502,7 +502,7 @@ jchar* java_lang_String::as_unicode_string_or_null(oop java_string, int& length)
|
||||
return result;
|
||||
}
|
||||
|
||||
unsigned int java_lang_String::hash_code(oop java_string) {
|
||||
inline unsigned int java_lang_String::hash_code_impl(oop java_string, bool update) {
|
||||
// The hash and hashIsZero fields are subject to a benign data race,
|
||||
// making it crucial to ensure that any observable result of the
|
||||
// calculation in this method stays correct under any possible read of
|
||||
@ -529,14 +529,25 @@ unsigned int java_lang_String::hash_code(oop java_string) {
|
||||
}
|
||||
}
|
||||
|
||||
if (hash != 0) {
|
||||
java_string->int_field_put(_hash_offset, hash);
|
||||
} else {
|
||||
java_string->bool_field_put(_hashIsZero_offset, true);
|
||||
if (update) {
|
||||
if (hash != 0) {
|
||||
java_string->int_field_put(_hash_offset, hash);
|
||||
} else {
|
||||
java_string->bool_field_put(_hashIsZero_offset, true);
|
||||
}
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
unsigned int java_lang_String::hash_code(oop java_string) {
|
||||
return hash_code_impl(java_string, /*update=*/true);
|
||||
}
|
||||
|
||||
unsigned int java_lang_String::hash_code_noupdate(oop java_string) {
|
||||
return hash_code_impl(java_string, /*update=*/false);
|
||||
}
|
||||
|
||||
|
||||
char* java_lang_String::as_quoted_ascii(oop java_string) {
|
||||
typeArrayOop value = java_lang_String::value(java_string);
|
||||
int length = java_lang_String::length(java_string, value);
|
||||
|
@ -127,6 +127,8 @@ class java_lang_String : AllStatic {
|
||||
// returning true if the bit was already set.
|
||||
static bool test_and_set_flag(oop java_string, uint8_t flag_mask);
|
||||
|
||||
static inline unsigned int hash_code_impl(oop java_string, bool update);
|
||||
|
||||
public:
|
||||
|
||||
// Coders
|
||||
@ -222,6 +224,7 @@ class java_lang_String : AllStatic {
|
||||
}
|
||||
|
||||
static unsigned int hash_code(oop java_string);
|
||||
static unsigned int hash_code_noupdate(oop java_string);
|
||||
|
||||
static bool equals(oop java_string, const jchar* chars, int len);
|
||||
static bool equals(oop str1, oop str2);
|
||||
|
@ -53,6 +53,7 @@
|
||||
#include "utilities/concurrentHashTable.inline.hpp"
|
||||
#include "utilities/concurrentHashTableTasks.inline.hpp"
|
||||
#include "utilities/macros.hpp"
|
||||
#include "utilities/resizeableResourceHash.hpp"
|
||||
#include "utilities/utf8.hpp"
|
||||
|
||||
// We prefer short chains of avg 2
|
||||
@ -597,39 +598,40 @@ void StringTable::verify() {
|
||||
|
||||
// Verification and comp
|
||||
class VerifyCompStrings : StackObj {
|
||||
GrowableArray<oop>* _oops;
|
||||
static unsigned string_hash(oop const& str) {
|
||||
return java_lang_String::hash_code_noupdate(str);
|
||||
}
|
||||
static bool string_equals(oop const& a, oop const& b) {
|
||||
return java_lang_String::equals(a, b);
|
||||
}
|
||||
|
||||
ResizeableResourceHashtable<oop, bool,
|
||||
ResourceObj::C_HEAP, mtInternal,
|
||||
string_hash, string_equals> _table;
|
||||
public:
|
||||
size_t _errors;
|
||||
VerifyCompStrings(GrowableArray<oop>* oops) : _oops(oops), _errors(0) {}
|
||||
VerifyCompStrings() : _table(unsigned(_items_count / 8) + 1), _errors(0) {}
|
||||
bool operator()(WeakHandle* val) {
|
||||
oop s = val->resolve();
|
||||
if (s == NULL) {
|
||||
return true;
|
||||
}
|
||||
int len = _oops->length();
|
||||
for (int i = 0; i < len; i++) {
|
||||
bool eq = java_lang_String::equals(s, _oops->at(i));
|
||||
assert(!eq, "Duplicate strings");
|
||||
if (eq) {
|
||||
_errors++;
|
||||
}
|
||||
bool created;
|
||||
_table.put_if_absent(s, true, &created);
|
||||
assert(created, "Duplicate strings");
|
||||
if (!created) {
|
||||
_errors++;
|
||||
}
|
||||
_oops->push(s);
|
||||
return true;
|
||||
};
|
||||
};
|
||||
|
||||
size_t StringTable::verify_and_compare_entries() {
|
||||
Thread* thr = Thread::current();
|
||||
GrowableArray<oop>* oops =
|
||||
new (ResourceObj::C_HEAP, mtInternal)
|
||||
GrowableArray<oop>((int)_current_size, mtInternal);
|
||||
|
||||
VerifyCompStrings vcs(oops);
|
||||
VerifyCompStrings vcs;
|
||||
if (!_local_table->try_scan(thr, vcs)) {
|
||||
log_info(stringtable)("verify unavailable at this moment");
|
||||
}
|
||||
delete oops;
|
||||
return vcs._errors;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user