RFR: 8289060: Undefined Behaviour in class VMReg

Andrew Haley aph at openjdk.org
Fri Jun 24 14:14:03 UTC 2022


Like class `Register`, class `VMReg` exhibits undefined behaviour, in particular null pointer dereferences.

The right way to fix this is simple: make instances of `VMReg` point to reified instances of `VMRegImpl`. We do this by creating a static array of `VMRegImpl`, and making all `VMReg` instances point into it, making the code well defined.

However, while `VMReg` instances are no longer null, and so do not generate compile warnings or errors, there is still a problem in that higher-numbered `VMReg` instances point outside the static array of `VMRegImpl`. This is hard to avoid, given that (as far as I can tell) there is no upper limit on the number of stack slots that can be allocated as `VMReg` instances. While this is in theory UB, it's not likely to cause problems. We could fix this by creating a much larger static array of `VMRegImpl`, up to the largest plausible size of stack offsets.

We could instead make `VMReg` instances objects with a single numeric field rather than pointers, but some C++ compilers pass all such objects by reference, so I don't think we should.

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

Commit messages:
 - 8289060: Undefined Behaviour in class VMReg
 - First

Changes: https://git.openjdk.org/jdk/pull/9276/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=9276&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8289060
  Stats: 28 lines in 2 files changed: 14 ins; 2 del; 12 mod
  Patch: https://git.openjdk.org/jdk/pull/9276.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/9276/head:pull/9276

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


More information about the hotspot-compiler-dev mailing list