@@ -111,6 +111,16 @@ static const ZStatSampler ZSamplerJavaThreads("System", "Java Threads", ZStatUni
111111ZGenerationYoung* ZGeneration::_young;
112112ZGenerationOld* ZGeneration::_old;
113113
114+ class ZRendezvousHandshakeClosure : public HandshakeClosure {
115+ public:
116+ ZRendezvousHandshakeClosure ()
117+ : HandshakeClosure(" ZRendezvous" ) {}
118+
119+ void do_thread (Thread* thread) {
120+ // Does nothing
121+ }
122+ };
123+
114124ZGeneration::ZGeneration (ZGenerationId id, ZPageTable* page_table, ZPageAllocator* page_allocator)
115125 : _id(id),
116126 _page_allocator(page_allocator),
@@ -168,11 +178,19 @@ void ZGeneration::free_empty_pages(ZRelocationSetSelector* selector, int bulk) {
168178}
169179
170180void ZGeneration::flip_age_pages (const ZRelocationSetSelector* selector) {
171- if (is_young ()) {
172- _relocate.flip_age_pages (selector->not_selected_small ());
173- _relocate.flip_age_pages (selector->not_selected_medium ());
174- _relocate.flip_age_pages (selector->not_selected_large ());
175- }
181+ _relocate.flip_age_pages (selector->not_selected_small ());
182+ _relocate.flip_age_pages (selector->not_selected_medium ());
183+ _relocate.flip_age_pages (selector->not_selected_large ());
184+
185+ // Perform a handshake between flip promotion and running the promotion barrier. This ensures
186+ // that ZBarrierSet::on_slowpath_allocation_exit() observing a young page that was then racingly
187+ // flip promoted, will run any stores without barriers to completion before responding to the
188+ // handshake at the subsequent safepoint poll. This ensures that the flip promotion barriers always
189+ // run after compiled code missing barriers, but before relocate start.
190+ ZRendezvousHandshakeClosure cl;
191+ Handshake::execute (&cl);
192+
193+ _relocate.barrier_flip_promoted_pages (_relocation_set.flip_promoted_pages ());
176194}
177195
178196static double fragmentation_limit (ZGenerationId generation) {
@@ -235,7 +253,9 @@ void ZGeneration::select_relocation_set(bool promote_all) {
235253 _relocation_set.install (&selector);
236254
237255 // Flip age young pages that were not selected
238- flip_age_pages (&selector);
256+ if (is_young ()) {
257+ flip_age_pages (&selector);
258+ }
239259
240260 // Setup forwarding table
241261 ZRelocationSetIterator rs_iter (&_relocation_set);
@@ -1280,16 +1300,6 @@ bool ZGenerationOld::uses_clear_all_soft_reference_policy() const {
12801300 return _reference_processor.uses_clear_all_soft_reference_policy ();
12811301}
12821302
1283- class ZRendezvousHandshakeClosure : public HandshakeClosure {
1284- public:
1285- ZRendezvousHandshakeClosure ()
1286- : HandshakeClosure(" ZRendezvous" ) {}
1287-
1288- void do_thread (Thread* thread) {
1289- // Does nothing
1290- }
1291- };
1292-
12931303class ZRendezvousGCThreads : public VM_Operation {
12941304 public:
12951305 VMOp_Type type () const { return VMOp_ZRendezvousGCThreads; }
0 commit comments