From fd5ad8b1d45c867fc8aad3f4a57c5696a6f41008 Mon Sep 17 00:00:00 2001 From: Stefan Johansson Date: Mon, 9 Sep 2024 08:37:37 +0200 Subject: [PATCH] Review - use explicit null checks --- src/hotspot/share/gc/z/zObjectAllocator.cpp | 18 +++++++++--------- src/hotspot/share/gc/z/zObjectAllocator.hpp | 1 - 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/hotspot/share/gc/z/zObjectAllocator.cpp b/src/hotspot/share/gc/z/zObjectAllocator.cpp index 3acff4b70b229..bf6dc98fc729b 100644 --- a/src/hotspot/share/gc/z/zObjectAllocator.cpp +++ b/src/hotspot/share/gc/z/zObjectAllocator.cpp @@ -79,20 +79,17 @@ void ZObjectAllocator::undo_alloc_page(ZPage* page) { ZHeap::heap()->undo_alloc_page(page); } -zaddress ZObjectAllocator::alloc_object_in_page_atomic(ZPage* page, size_t size) { - if (page == nullptr) { - return zaddress::null; - } - return page->alloc_object_atomic(size); -} - zaddress ZObjectAllocator::alloc_object_in_shared_page(ZPage** shared_page, ZPageType page_type, size_t page_size, size_t size, ZAllocationFlags flags) { + zaddress addr = zaddress::null; ZPage* page = Atomic::load_acquire(shared_page); - zaddress addr = alloc_object_in_page_atomic(page, size); + + if (page != nullptr) { + addr = page->alloc_object_atomic(size); + } if (is_null(addr)) { // Allocate new page @@ -133,10 +130,13 @@ zaddress ZObjectAllocator::alloc_object_in_shared_page(ZPage** shared_page, zaddress ZObjectAllocator::alloc_object_in_medium_page(size_t size, ZAllocationFlags flags) { + zaddress addr = zaddress::null; ZPage** shared_medium_page = _shared_medium_page.addr(); ZPage* page = Atomic::load_acquire(shared_medium_page); - zaddress addr = alloc_object_in_page_atomic(page, size); + if (page != nullptr) { + addr = page->alloc_object_atomic(size); + } if (is_null(addr)) { // When a new medium page is required, we synchronize the allocation diff --git a/src/hotspot/share/gc/z/zObjectAllocator.hpp b/src/hotspot/share/gc/z/zObjectAllocator.hpp index 4840a36f5f246..5377972b7baf7 100644 --- a/src/hotspot/share/gc/z/zObjectAllocator.hpp +++ b/src/hotspot/share/gc/z/zObjectAllocator.hpp @@ -65,7 +65,6 @@ class ZObjectAllocator { zaddress alloc_medium_object(size_t size, ZAllocationFlags flags); zaddress alloc_small_object(size_t size, ZAllocationFlags flags); zaddress alloc_object(size_t size, ZAllocationFlags flags); - zaddress alloc_object_in_page_atomic(ZPage* page, size_t size); public: ZObjectAllocator(ZPageAge age);