3333#include " gc/shared/collectedHeap.hpp"
3434#include " gc/shared/oopStorage.inline.hpp"
3535#include " gc/shared/oopStorageSet.hpp"
36+ #include " gc/shared/stringdedup/stringDedup.hpp"
3637#include " logging/log.hpp"
3738#include " logging/logStream.hpp"
3839#include " memory/allocation.inline.hpp"
3940#include " memory/resourceArea.hpp"
40- #include " memory/universe.hpp"
4141#include " oops/access.inline.hpp"
4242#include " oops/compressedOops.hpp"
4343#include " oops/oop.inline.hpp"
@@ -346,15 +346,17 @@ oop StringTable::do_intern(Handle string_or_null_h, const jchar* name,
346346 string_h = java_lang_String::create_from_unicode (name, len, CHECK_NULL);
347347 }
348348
349- // Deduplicate the string before it is interned. Note that we should never
350- // deduplicate a string after it has been interned. Doing so will counteract
351- // compiler optimizations done on e.g. interned string literals.
352- Universe::heap ()->deduplicate_string (string_h ());
353-
354349 assert (java_lang_String::equals (string_h (), name, len),
355350 " string must be properly initialized" );
356351 assert (len == java_lang_String::length (string_h ()), " Must be same length" );
357352
353+ // Notify deduplication support that the string is being interned. A string
354+ // must never be deduplicated after it has been interned. Doing so interferes
355+ // with compiler optimizations done on e.g. interned string literals.
356+ if (StringDedup::is_enabled ()) {
357+ StringDedup::notify_intern (string_h ());
358+ }
359+
358360 StringTableLookupOop lookup (THREAD, hash, string_h);
359361 StringTableGet stg (THREAD);
360362
@@ -700,12 +702,20 @@ void StringtableDCmd::execute(DCmdSource source, TRAPS) {
700702
701703// Sharing
702704#if INCLUDE_CDS_JAVA_HEAP
705+ size_t StringTable::shared_entry_count () {
706+ return _shared_table.entry_count ();
707+ }
708+
703709oop StringTable::lookup_shared (const jchar* name, int len, unsigned int hash) {
704710 assert (hash == java_lang_String::hash_code (name, len),
705711 " hash must be computed using java_lang_String::hash_code" );
706712 return _shared_table.lookup (name, hash, len);
707713}
708714
715+ oop StringTable::lookup_shared (const jchar* name, int len) {
716+ return _shared_table.lookup (name, java_lang_String::hash_code (name, len), len);
717+ }
718+
709719oop StringTable::create_archived_string (oop s) {
710720 assert (DumpSharedSpaces, " this function is only used with -Xshare:dump" );
711721 assert (java_lang_String::is_instance (s), " sanity" );
@@ -724,6 +734,10 @@ oop StringTable::create_archived_string(oop s) {
724734
725735 // adjust the pointer to the 'value' field in the new String oop
726736 java_lang_String::set_value_raw (new_s, new_v);
737+ // Prevent string deduplication from changing the 'value' field to
738+ // something not in the archive before building the archive. Also marks
739+ // the shared string when loaded.
740+ java_lang_String::set_deduplication_forbidden (new_s);
727741 return new_s;
728742}
729743
@@ -769,17 +783,4 @@ void StringTable::serialize_shared_table_header(SerializeClosure* soc) {
769783 }
770784}
771785
772- class SharedStringIterator {
773- OopClosure* _oop_closure;
774- public:
775- SharedStringIterator (OopClosure* f) : _oop_closure(f) {}
776- void do_value (oop string) {
777- _oop_closure->do_oop (&string);
778- }
779- };
780-
781- void StringTable::shared_oops_do (OopClosure* f) {
782- SharedStringIterator iter (f);
783- _shared_table.iterate(&iter);
784- }
785786#endif // INCLUDE_CDS_JAVA_HEAP
0 commit comments