4040#include " gc/z/zRootsIterator.hpp"
4141#include " gc/z/zStackWatermark.hpp"
4242#include " gc/z/zStat.hpp"
43+ #include " gc/z/zStringDedup.inline.hpp"
4344#include " gc/z/zTask.hpp"
4445#include " gc/z/zUncoloredRoot.inline.hpp"
4546#include " gc/z/zVerify.hpp"
@@ -559,12 +560,14 @@ class ZRelocateMediumAllocator {
559560template <typename Allocator>
560561class ZRelocateWork : public StackObj {
561562private:
562- Allocator* const _allocator;
563- ZForwarding* _forwarding;
564- ZPage* _target[ZAllocator::_relocation_allocators];
565- ZGeneration* const _generation;
566- size_t _other_promoted;
567- size_t _other_compacted;
563+ Allocator* const _allocator;
564+ ZForwarding* _forwarding;
565+ ZPage* _target[ZAllocator::_relocation_allocators];
566+ ZGeneration* const _generation;
567+ size_t _other_promoted;
568+ size_t _other_compacted;
569+ ZStringDedupContext _string_dedup_context;
570+
568571
569572 ZPage* target (ZPageAge age) {
570573 return _target[static_cast <uint>(age) - 1 ];
@@ -795,6 +798,13 @@ class ZRelocateWork : public StackObj {
795798 update_remset_promoted (to_addr);
796799 }
797800
801+ void maybe_string_dedup (zaddress to_addr) {
802+ if (_forwarding->is_promotion ()) {
803+ // Only deduplicate promoted objects, and let short-lived strings simply die instead.
804+ _string_dedup_context.request (to_oop (to_addr));
805+ }
806+ }
807+
798808 bool try_relocate_object (zaddress from_addr) {
799809 const zaddress to_addr = try_relocate_object_inner (from_addr);
800810
@@ -804,6 +814,8 @@ class ZRelocateWork : public StackObj {
804814
805815 update_remset_for_fields (from_addr, to_addr);
806816
817+ maybe_string_dedup (to_addr);
818+
807819 return true ;
808820 }
809821
@@ -1176,10 +1188,15 @@ class ZRelocateAddRemsetForFlipPromoted : public ZRestartableTask {
11761188
11771189 virtual void work () {
11781190 SuspendibleThreadSetJoiner sts_joiner;
1191+ ZStringDedupContext string_dedup_context;
11791192
11801193 for (ZPage* page; _iter.next (&page);) {
11811194 page->object_iterate ([&](oop obj) {
1195+ // Remap oops and add remset if needed
11821196 ZIterator::basic_oop_iterate_safe (obj, remap_and_maybe_add_remset);
1197+
1198+ // String dedup
1199+ string_dedup_context.request (obj);
11831200 });
11841201
11851202 SuspendibleThreadSet::yield ();
0 commit comments