RFR: 8301612: OopLoadProxy constructor should be explicit

Axel Boldt-Christmas aboldtch at openjdk.org
Wed Feb 1 14:48:32 UTC 2023


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.

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

Commit messages:
 - 8301612: OopLoadProxy constructor should be explicit

Changes: https://git.openjdk.org/jdk/pull/12364/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=12364&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8301612
  Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/12364.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/12364/head:pull/12364

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


More information about the hotspot-dev mailing list