Integrated: 8289060: Undefined Behaviour in class VMReg
Andrew Haley
aph at openjdk.org
Wed Jul 6 15:25:45 UTC 2022
On Fri, 24 Jun 2022 13:58:29 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.
This pull request has now been integrated.
Changeset: dfb24ae4
Author: Andrew Haley <aph at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/dfb24ae4b7d32c0c625a9396429d167d9dcca183
Stats: 40 lines in 3 files changed: 20 ins; 3 del; 17 mod
8289060: Undefined Behaviour in class VMReg
Reviewed-by: jvernee, kvn
-------------
PR: https://git.openjdk.org/jdk/pull/9276
More information about the hotspot-compiler-dev
mailing list