8254598: StringDedupTable should use OopStorage

Co-authored-by: Kim Barrett <kbarrett@openjdk.org>
Co-authored-by: Zhengyu Gu <zgu@openjdk.org>
Reviewed-by: coleenp, iklam, tschatzl, ayang
This commit is contained in:
Kim Barrett 2021-05-14 18:38:58 +00:00
parent 360928d16d
commit be0a655208
97 changed files with 2399 additions and 3234 deletions

View file

@ -33,11 +33,11 @@
#include "gc/shared/collectedHeap.hpp"
#include "gc/shared/oopStorage.inline.hpp"
#include "gc/shared/oopStorageSet.hpp"
#include "gc/shared/stringdedup/stringDedup.hpp"
#include "logging/log.hpp"
#include "logging/logStream.hpp"
#include "memory/allocation.inline.hpp"
#include "memory/resourceArea.hpp"
#include "memory/universe.hpp"
#include "oops/access.inline.hpp"
#include "oops/compressedOops.hpp"
#include "oops/oop.inline.hpp"
@ -346,15 +346,17 @@ oop StringTable::do_intern(Handle string_or_null_h, const jchar* name,
string_h = java_lang_String::create_from_unicode(name, len, CHECK_NULL);
}
// Deduplicate the string before it is interned. Note that we should never
// deduplicate a string after it has been interned. Doing so will counteract
// compiler optimizations done on e.g. interned string literals.
Universe::heap()->deduplicate_string(string_h());
assert(java_lang_String::equals(string_h(), name, len),
"string must be properly initialized");
assert(len == java_lang_String::length(string_h()), "Must be same length");
// Notify deduplication support that the string is being interned. A string
// must never be deduplicated after it has been interned. Doing so interferes
// with compiler optimizations done on e.g. interned string literals.
if (StringDedup::is_enabled()) {
StringDedup::notify_intern(string_h());
}
StringTableLookupOop lookup(THREAD, hash, string_h);
StringTableGet stg(THREAD);
@ -700,12 +702,20 @@ void StringtableDCmd::execute(DCmdSource source, TRAPS) {
// Sharing
#if INCLUDE_CDS_JAVA_HEAP
size_t StringTable::shared_entry_count() {
return _shared_table.entry_count();
}
oop StringTable::lookup_shared(const 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(name, hash, len);
}
oop StringTable::lookup_shared(const jchar* name, int len) {
return _shared_table.lookup(name, java_lang_String::hash_code(name, len), len);
}
oop StringTable::create_archived_string(oop s) {
assert(DumpSharedSpaces, "this function is only used with -Xshare:dump");
assert(java_lang_String::is_instance(s), "sanity");
@ -724,6 +734,10 @@ oop StringTable::create_archived_string(oop s) {
// adjust the pointer to the 'value' field in the new String oop
java_lang_String::set_value_raw(new_s, new_v);
// Prevent string deduplication from changing the 'value' field to
// something not in the archive before building the archive. Also marks
// the shared string when loaded.
java_lang_String::set_deduplication_forbidden(new_s);
return new_s;
}
@ -769,17 +783,4 @@ void StringTable::serialize_shared_table_header(SerializeClosure* soc) {
}
}
class SharedStringIterator {
OopClosure* _oop_closure;
public:
SharedStringIterator(OopClosure* f) : _oop_closure(f) {}
void do_value(oop string) {
_oop_closure->do_oop(&string);
}
};
void StringTable::shared_oops_do(OopClosure* f) {
SharedStringIterator iter(f);
_shared_table.iterate(&iter);
}
#endif //INCLUDE_CDS_JAVA_HEAP