RFR: 8301612: OopLoadProxy constructor should be explicit

Stefan Karlsson stefank at openjdk.org
Wed Feb 1 15:00:49 UTC 2023


On Wed, 1 Feb 2023 14:41:35 GMT, Axel Boldt-Christmas <aboldtch at openjdk.org> wrote:

> The implicit conversion via constructor `OopLoadProxy(P* addr)` can cause problems when using the access API and nullptr.
> For example code like
> ```c++
> oop o = (_obj == NULL) ? nullptr : NativeAccess<>::oop_load(_obj);
> 
> will compile but is wrong and will crash.
> This is because it will be interpreted as:
> ```c++
> oop o = static_cast<oop>((_obj == NULL) ? OopLoadProxy(nullptr) : NativeAccess<>::oop_load(_obj));
> 
> while the intent of the programmer probably was:
> ```c++
> oop o = (_obj == NULL) ? (oop)nullptr : NativeAccess<>::oop_load(_obj);
> 
> or more explicitly:
> ```c++
> oop o = (_obj == NULL) ? static_cast<oop>(nullptr) : static_cast<oop>(NativeAccess<>::oop_load(_obj));
> 
> 
> Marking `OopLoadProxy(P* addr)` explicit will make this example, and similar code not compile.

Looks good and can be considered "trivial".

-------------

Marked as reviewed by stefank (Reviewer).

PR: https://git.openjdk.org/jdk/pull/12364


More information about the hotspot-dev mailing list