RFR: 8332586: Avoid cloning empty arrays in java.lang.reflect.{Method,Constructor}
Chen Liang
liach at openjdk.org
Thu May 30 19:30:14 UTC 2024
On Wed, 22 May 2024 14:24:40 GMT, jengebr <duke at openjdk.org> wrote:
>> No, I mean here: https://github.com/openjdk/jdk/blob/4f1a10f84bcfadef263a0890b6834ccd3d5bb52f/src/java.base/share/classes/java/lang/Class.java#L1329
>>
>> (That's also why I suggest putting the utiltiy method in ReflectionFactory instead of AccessibleObject or Executable)
>>
>> `Proxy` is meaningless with an empty list of interfaces, as it's solely for implementing interfaces and delegating method calls to the given InvocationHandler. So I would ignore that scenario.
>
> Thanks. Unfortunately the variable `cloneArray` is actually a method parameter, and most of the callers pass in `false` - so using this utility method to control cloning would actually introduce cloning in several places where it is explicitly avoided. We may get a performance gain by modifying `Class.getInterfaces()` directly (the sole caller that passes `true`) then eliminating the parameter, then modifying each caller, etc. but that feels like a separate change inspired by this one.
>
> Thoughts?
Why can't you do something like this:
return cloneArray ? ReflectionFactory.copyClasses(interfaces) : interfaces;
Alternatively, your proposal is a good one too; we can rename this `getInterfaces(boolean)` to `getInterfacesShared()` (like `getSharedEnumConstants()`) and move this copy operation to `getInterfaces()` as you suggest.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/19327#discussion_r1610109601
More information about the core-libs-dev
mailing list