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