RFR: 8376325: [IR Framework] Detect and report overloads
Marc Chevalier
mchevalier at openjdk.org
Thu Jan 29 09:56:03 UTC 2026
The IR framework should not only forbid overloads between test methods, but overloads of a test method, even if other overloads are not test methods themselves. Indeed, the compiler directive file designate methods only by the class name and method name, without the parameters. Something like:
{
match : "ir_framework.tests.BadOverloadedMethod::sameName",
log : true,
PrintIdeal : true,
}
This means that the same printing directive would apply to overloads, and make the output confusing in case these non-test methods are compiled. While test methods are necessarily compiled by the framework, the said framework doesn't prevent other methods to be compiled (a normal output of the test VM shows a lot of compilations).
One could emit compiler directives that take arguments into account, but this is not clear it is useful. Also, there is a simpler solution: disallow overloading of test methods at all. This way, if we regret and need overloads later, we can still allow them without breaking existing tests. With this change, one can get the new error message:
- Cannot overload @Test methods, but method public void ir_framework.tests.BadOverloadedMethod.sameName(double) has 2 overloads:
- public void ir_framework.tests.BadOverloadedMethod.sameName(boolean)
- public void ir_framework.tests.BadOverloadedMethod.sameName()
which should explain well enough what is happening. A little esthetic problem is that if all three methods (in the previous example) are test-method, one get an error for each of them. I considered it acceptable.
This change needed adjusting some tests. I've also made them a bit more robust/easy to maintain by using a map instead so I didn't have to sift a hundred array indices.
Let's also emphasize that this change doesn't mean that overloads are entirely forbidden: they are fine as long as they don't involve a test method.
Tested on tier1,tier2,tier3,hs-precheckin-comp,hs-comp-stress.
Thanks,
Marc
-------------
Commit messages:
- Forbid overloads when one of the methods is @Test
Changes: https://git.openjdk.org/jdk/pull/29483/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=29483&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8376325
Stats: 227 lines in 4 files changed: 10 ins; 77 del; 140 mod
Patch: https://git.openjdk.org/jdk/pull/29483.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/29483/head:pull/29483
PR: https://git.openjdk.org/jdk/pull/29483
More information about the hotspot-compiler-dev
mailing list