From e7d90b941fff095f4b1555020c09270d201c7402 Mon Sep 17 00:00:00 2001 From: Axel Boldt-Christmas Date: Thu, 14 Nov 2024 06:13:19 +0000 Subject: [PATCH] 8343460: ZGC: Crash in ZRemembered::scan_page_and_clear_remset Reviewed-by: jsikstro, eosterlund, stefank --- src/hotspot/share/gc/z/zHeap.cpp | 7 ------- src/hotspot/share/gc/z/zPageAllocator.cpp | 22 +++++++++------------- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/hotspot/share/gc/z/zHeap.cpp b/src/hotspot/share/gc/z/zHeap.cpp index 1e917bb5ee3..d29a5d15795 100644 --- a/src/hotspot/share/gc/z/zHeap.cpp +++ b/src/hotspot/share/gc/z/zHeap.cpp @@ -248,10 +248,6 @@ void ZHeap::free_page(ZPage* page, bool allow_defragment) { // Remove page table entry _page_table.remove(page); - if (page->is_old()) { - page->remset_delete(); - } - // Free page _page_allocator.free_page(page, allow_defragment); } @@ -262,9 +258,6 @@ size_t ZHeap::free_empty_pages(const ZArray* pages) { ZArrayIterator iter(pages); for (ZPage* page; iter.next(&page);) { _page_table.remove(page); - if (page->is_old()) { - page->remset_delete(); - } freed += page->size(); } diff --git a/src/hotspot/share/gc/z/zPageAllocator.cpp b/src/hotspot/share/gc/z/zPageAllocator.cpp index 12c17468bfb..ecd9f3e34b9 100644 --- a/src/hotspot/share/gc/z/zPageAllocator.cpp +++ b/src/hotspot/share/gc/z/zPageAllocator.cpp @@ -809,6 +809,11 @@ ZPage* ZPageAllocator::prepare_to_recycle(ZPage* page, bool allow_defragment) { return defragment_page(to_recycle); } + // Remove the remset before recycling + if (to_recycle->is_old() && to_recycle == page) { + to_recycle->remset_delete(); + } + return to_recycle; } @@ -880,18 +885,9 @@ void ZPageAllocator::free_pages(const ZArray* pages) { } void ZPageAllocator::free_pages_alloc_failed(ZPageAllocation* allocation) { - ZArray to_recycle_pages; - - // Prepare pages for recycling before taking the lock - ZListRemoveIterator allocation_pages_iter(allocation->pages()); - for (ZPage* page; allocation_pages_iter.next(&page);) { - // Prepare to recycle - ZPage* const to_recycle = prepare_to_recycle(page, false /* allow_defragment */); - - // Register for recycling - to_recycle_pages.push(to_recycle); - } - + // The page(s) in the allocation are either taken from the cache or a newly + // created, mapped and commited ZPage. These page(s) have not been inserted in + // the page table, nor allocated a remset, so prepare_to_recycle is not required. ZLocker locker(&_lock); // Only decrease the overall used and not the generation used, @@ -901,7 +897,7 @@ void ZPageAllocator::free_pages_alloc_failed(ZPageAllocation* allocation) { size_t freed = 0; // Free any allocated/flushed pages - ZArrayIterator iter(&to_recycle_pages); + ZListRemoveIterator iter(allocation->pages()); for (ZPage* page; iter.next(&page);) { freed += page->size(); recycle_page(page);