Integrated: 8301612: OopLoadProxy constructor should be explicit
Axel Boldt-Christmas
aboldtch at openjdk.org
Thu Feb 2 14:07:45 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.
This pull request has now been integrated.
Changeset: 21c1afbc
Author: Axel Boldt-Christmas <aboldtch at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/21c1afbc3229e898146022935bc589bcf95aa1f7
Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod
8301612: OopLoadProxy constructor should be explicit
Reviewed-by: stefank, jsjolen
-------------
PR: https://git.openjdk.org/jdk/pull/12364
More information about the hotspot-dev
mailing list