RFR: 8305922: [aix,linux] Avoid comparing 'this' to nullptr
David Holmes
dholmes at openjdk.org
Fri Apr 21 04:26:42 UTC 2023
On Wed, 12 Apr 2023 18:08:44 GMT, Tyler Steele <tsteele at openjdk.org> wrote:
> This PR removes the remaining 'this' vs. 'nullptr' checks from osThread_linux.cpp and osThread_aix.cpp which cause a build warning on AIX and Linux (when building with Clang). My grepping finds no other occurrences.
>
> As the warning indicates, `this` cannot be `nullptr` in well-formed C++ code. Previous issues have removed these checks, and I believe it makes sense to do so again in these places.
So IIUC if you are using an operator new that can return null, and you have not setup C++ in a way that the compiler inserts a null check before calling the constructor, then you can get a null `this` ptr. If that is not possible here (`OSThread` is a `CHeapObj` so I guess that aborts the VM by default!) then the assert is unnecessary.
Though if we abort on allocation failure then this code is also unnecessary:
// Allocate the OSThread object
OSThread* osthread = new OSThread();
if (osthread == nullptr) {
return false;
}
-------------
PR Review: https://git.openjdk.org/jdk/pull/13448#pullrequestreview-1395035793
More information about the hotspot-runtime-dev
mailing list