[code-reflection] RFR: Make sure method parameters keep their slots when lowering

Paul Sandoz psandoz at openjdk.org
Fri Jan 26 21:27:14 UTC 2024


On Fri, 26 Jan 2024 08:47:23 GMT, Hannes Greule <hgreule at openjdk.org> wrote:

> Previously, unused method parameters didn't get a slot, resulting in either wrong results or bad classfiles.
> 
> I propose a simple fix: Make sure that all parameters of the entry block get a slot, in the order they are defined.
> I didn't want to change too much code here, so I decided to add a boolean flag to indicate that even values without uses get a slot.
> If you have a better idea or more plans on this, please let me know.
> 
> I also added multiple test cases showcasing the issue: One that results in the wrong value returned, one with a type mismatch resulting in a VerifyError, and one with a type mismatch due to being non-static, also causing a VerifyError (this is the case that made me discover this issue).
> 
> I ran the tests in `langtools/tools/javac/reflect/` and `java/lang/reflect/code/` to make sure they all (still) pass.

The approach looks good. (Note this area is very much a prototype and we will almost certainly find more issues as progress.)

A possible simplification is to modify lines 482 to 483:

            // If b is the entry block then all its parameters conservatively require slots
            // Some unused parameters might be declared before others that are used
            b.parameters().forEach(p -> c.getOrAssignSlot(p, pb == null));


Testing-wise I think we only need to test static methods for an unused int and double parameter, since refs behave like int.

Renaming the boolean to `assignIfUnused` seems clearer.

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

PR Comment: https://git.openjdk.org/babylon/pull/8#issuecomment-1912714642


More information about the babylon-dev mailing list