RFR: 8289060: Undefined Behaviour in class VMReg [v4]
Vladimir Kozlov
kvn at openjdk.org
Thu Jun 30 19:24:41 UTC 2022
On Thu, 30 Jun 2022 08:38:32 GMT, Andrew Haley <aph at openjdk.org> wrote:
>> 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
My testing passed.
-------------
Marked as reviewed by kvn (Reviewer).
PR: https://git.openjdk.org/jdk/pull/9276
More information about the hotspot-compiler-dev
mailing list