RFR: 8289060: Undefined Behaviour in class VMReg [v2]
Andrew Haley
aph at openjdk.org
Wed Jun 29 16:31:44 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 two additional commits since the last revision:
- 8289060: Undefined Behaviour in class VMReg
- 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/bb201e77..ab85170c
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=9276&range=01
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=9276&range=00-01
Stats: 20 lines in 4 files changed: 7 ins; 2 del; 11 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