[code-reflection] RFR: Method code model uniquness [v4]
Maurizio Cimadamore
mcimadamore at openjdk.org
Wed Apr 30 08:19:09 UTC 2025
On Wed, 30 Apr 2025 01:19:55 GMT, Mourad Abbay <mabbay at openjdk.org> wrote:
>> Multiple `Method` objects that represent the same java method, have different code models. This is because every time we call `Class.getMethod` or `Class.getDeclaredMethod` we get a newly created instance. One possible solution is to attach the model to the root `Method` object.
>
> Mourad Abbay has updated the pull request incrementally with one additional commit since the last revision:
>
> Avoid caching Method.codeModel on non-root instances
src/java.base/share/classes/java/lang/reflect/Method.java line 233:
> 231: /* package */
> 232: Optional<?> setCodeModelIfNeeded(Function<Method, Optional<?>> modelFactory) {
> 233: if (root != null) {
This logic is subtly different to the one I pointed out -- this always recurse if the root is non null. The one I pointed out calls the method on the root, but than saves the result on the copy locally. I'm not sure which is better -- but it seems odd to use slightly different idioms in the same class to do effectively the same thing?
-------------
PR Review Comment: https://git.openjdk.org/babylon/pull/415#discussion_r2068136860
More information about the babylon-dev
mailing list