From 3059c3b69ec8fb7cefd740bc2eb52b5ca5390ae1 Mon Sep 17 00:00:00 2001 From: Kim Barrett Date: Thu, 25 Jan 2024 05:44:18 +0000 Subject: [PATCH] 8324242: Avoid null check for OopHandle::ptr_raw() Reviewed-by: shade, jsjolen, coleenp --- src/hotspot/share/classfile/classLoaderData.cpp | 8 ++++---- src/hotspot/share/oops/klass.hpp | 4 ++-- src/hotspot/share/oops/oopHandle.inline.hpp | 7 +++---- src/hotspot/share/runtime/javaThread.cpp | 4 ++-- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/hotspot/share/classfile/classLoaderData.cpp b/src/hotspot/share/classfile/classLoaderData.cpp index be91f26bdef..00687d21a7e 100644 --- a/src/hotspot/share/classfile/classLoaderData.cpp +++ b/src/hotspot/share/classfile/classLoaderData.cpp @@ -838,10 +838,10 @@ OopHandle ClassLoaderData::add_handle(Handle h) { void ClassLoaderData::remove_handle(OopHandle h) { assert(!is_unloading(), "Do not remove a handle for a CLD that is unloading"); - oop* ptr = h.ptr_raw(); - if (ptr != nullptr) { - assert(_handles.owner_of(ptr), "Got unexpected handle " PTR_FORMAT, p2i(ptr)); - NativeAccess<>::oop_store(ptr, oop(nullptr)); + if (!h.is_empty()) { + assert(_handles.owner_of(h.ptr_raw()), + "Got unexpected handle " PTR_FORMAT, p2i(h.ptr_raw())); + h.replace(oop(nullptr)); } } diff --git a/src/hotspot/share/oops/klass.hpp b/src/hotspot/share/oops/klass.hpp index 96f8f8efdb6..0c9c05bed32 100644 --- a/src/hotspot/share/oops/klass.hpp +++ b/src/hotspot/share/oops/klass.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -582,7 +582,7 @@ protected: if (has_archived_mirror_index()) { // _java_mirror is not a valid OopHandle but rather an encoded reference in the shared heap return false; - } else if (_java_mirror.ptr_raw() == nullptr) { + } else if (_java_mirror.is_empty()) { return false; } else { return true; diff --git a/src/hotspot/share/oops/oopHandle.inline.hpp b/src/hotspot/share/oops/oopHandle.inline.hpp index 95db9210e96..23a13cb35e3 100644 --- a/src/hotspot/share/oops/oopHandle.inline.hpp +++ b/src/hotspot/share/oops/oopHandle.inline.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -57,9 +57,8 @@ inline void OopHandle::release(OopStorage* storage) { } inline void OopHandle::replace(oop obj) { - oop* ptr = ptr_raw(); - assert(ptr != nullptr, "should not use replace"); - NativeAccess<>::oop_store(ptr, obj); + assert(!is_empty(), "should not use replace"); + NativeAccess<>::oop_store(_obj, obj); } inline oop OopHandle::xchg(oop new_value) { diff --git a/src/hotspot/share/runtime/javaThread.cpp b/src/hotspot/share/runtime/javaThread.cpp index a789988e379..9242fd65483 100644 --- a/src/hotspot/share/runtime/javaThread.cpp +++ b/src/hotspot/share/runtime/javaThread.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2021, Azul Systems, Inc. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -194,7 +194,7 @@ oop JavaThread::scopedValueCache() const { } void JavaThread::set_scopedValueCache(oop p) { - if (_scopedValueCache.ptr_raw() != nullptr) { // i.e. if the OopHandle has been allocated + if (!_scopedValueCache.is_empty()) { // i.e. if the OopHandle has been allocated _scopedValueCache.replace(p); } else { assert(p == nullptr, "not yet initialized");