RFR: JDK-8177107: Reduce memory footprint of java.lang.reflect.Constructor/Method

Claes Redestad redestad at openjdk.java.net
Thu Mar 3 14:34:02 UTC 2022


On Wed, 2 Mar 2022 20:28:45 GMT, Joe Darcy <darcy at openjdk.org> wrote:

> Refactoring of Method and Constructor to share a single empty array for parameters and exceptions as well as type variables.
> 
> Existing core reflection regression tests pass with the change.

This is also only a partial solution, since the initial array is created and injected by the VM on a "root" Constructor/Method, see for example the code for new method: https://github.com/openjdk/jdk/blob/5c187e34a58769a129a0aae9e4937907c9060202/src/hotspot/share/runtime/reflection.cpp#L778

Depending on usage pattern most of the Constructor/Method objects created are such root objects (often created in bulk), and only those exposed to user code via a copy will benefit from this particular enhancement. Which might be a good optimization when getting the same Constructor/Method from the same class over and over.

- Can we skip the `.clone()` when propagating these from a root object to one we'll expose? We have internal `getShared...` methods for that purpose.
- If we update the JVM code to inject a reference to `Class.EMPTY_CLASS_ARRAY` and we can skip the `.clone()`ing as per above we should see a decent benefit overall.

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

Changes requested by redestad (Reviewer).

PR: https://git.openjdk.java.net/jdk/pull/7667


More information about the core-libs-dev mailing list