RFR: 8289060: Undefined Behaviour in class VMReg [v4]

Andrew Haley aph at openjdk.org
Thu Jun 30 08:38:32 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.

Andrew Haley has updated the pull request incrementally with one additional commit since the last revision:

  8289060: Undefined Behaviour in class VMReg

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/9276/files
  - new: https://git.openjdk.org/jdk/pull/9276/files/62c71eeb..1cf884f1

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=9276&range=03
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=9276&range=02-03

  Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 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