Skip to content

Commit 7ad6160

Browse files
jsikstrostefank
authored andcommittedSep 4, 2024
8339163: ZGC: Race in clearing of remembered sets
Reviewed-by: stefank, eosterlund, aboldtch
1 parent a618605 commit 7ad6160

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed
 

‎src/hotspot/share/gc/z/zRemembered.cpp

+16-11
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ bool ZRemembered::should_scan_page(ZPage* page) const {
125125
return false;
126126
}
127127

128-
bool ZRemembered::scan_page(ZPage* page) const {
128+
bool ZRemembered::scan_page_and_clear_remset(ZPage* page) const {
129129
const bool can_trust_live_bits =
130130
page->is_relocatable() && !ZGeneration::old()->is_phase_mark();
131131

@@ -151,6 +151,20 @@ bool ZRemembered::scan_page(ZPage* page) const {
151151
// All objects are dead - do nothing
152152
}
153153

154+
if (ZVerifyRemembered) {
155+
// Make sure self healing of pointers is ordered before clearing of
156+
// the previous bits so that ZVerify::after_scan can detect missing
157+
// remset entries accurately.
158+
OrderAccess::storestore();
159+
}
160+
161+
// If we have consumed the remset entries above we also clear them.
162+
// The exception is if the page is completely empty/garbage, where we don't
163+
// want to race with an old collection modifying the remset as well.
164+
if (!can_trust_live_bits || page->is_marked()) {
165+
page->clear_remset_previous();
166+
}
167+
154168
return result;
155169
}
156170

@@ -500,16 +514,7 @@ class ZRememberedScanMarkFollowTask : public ZRestartableTask {
500514
if (page != nullptr) {
501515
if (_remembered->should_scan_page(page)) {
502516
// Visit all entries pointing into young gen
503-
bool found_roots = _remembered->scan_page(page);
504-
505-
// ... and as a side-effect clear the previous entries
506-
if (ZVerifyRemembered) {
507-
// Make sure self healing of pointers is ordered before clearing of
508-
// the previous bits so that ZVerify::after_scan can detect missing
509-
// remset entries accurately.
510-
OrderAccess::storestore();
511-
}
512-
page->clear_remset_previous();
517+
bool found_roots = _remembered->scan_page_and_clear_remset(page);
513518

514519
if (found_roots && !left_marking) {
515520
// Follow remembered set when possible

‎src/hotspot/share/gc/z/zRemembered.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class ZRemembered {
7373

7474
bool should_scan_page(ZPage* page) const;
7575

76-
bool scan_page(ZPage* page) const;
76+
bool scan_page_and_clear_remset(ZPage* page) const;
7777
bool scan_forwarding(ZForwarding* forwarding, void* context) const;
7878

7979
public:

0 commit comments

Comments
 (0)
Please sign in to comment.