Hi everyone,

a few hours ago I signed the Oracle Contributor Agreement.
I'd like to work on JDK-8229959: Convert proxy class to use constant dynamic.

Without further ado, here are some questions and answers you may ask:

* What are you exactly planing to do?
I'd like to replace the GETSTATIC instruction with an LDC instruction in the current generated bytecode for the proxies.

* What benefits would such a change have?
First, it allows us to drop the static final fields and the class initializer for the generated proxy classes. Second, it allows the code (both generated and generator) to be more clear by moving the essential parts together. Third, it might bring some performance improvement, because the j.l.r.Method lookup is delayed to it's first use - which in some cases might never happen.

* Are you able to write such a patch?
Yes. I have some experience with the Java bytecode, ASM and ConstantDynamic.

* But java.lang.reflect.Method is not immutable/persistent?
That's not a question, but you are right. j.l.r.Method has setAccessible, modifying the Method instance. Still, the current implementation shares the same Method instance with all proxies with the same interfaces in the same ClassLoader.

* What should the bootstrap method look like?
The bootstrap method will take one additional argument, a direct MethodHandle to the to be resolved method, and should crack it using it's passed Lookup and then reflect it as Method. In other words, it should do `return lookup.revealDirect(mh).reflectAs(Method.class, lookup);`

*  Where should this bootstrap method reside?
I'm glad you asked. After some thoughts, there are two promising places where I could put it:
a) As private static method in the proxy itself.
Benefits: No public API changes. Also allows easy migration to option b) if pursued later.
Downsides: The bootstrap method will be duplicated into every proxy class.
b) As a public static method in the java.* namespace, preferably in java.lang.invoke.ConstantBootstraps.
Benefits: Only one single implementation in the JVM.
Downside: Changes to the public API. Also leads to other questions like "Should j.l.r.Member implement Constable?" and "Should I add a subclass of j.l.c.DynamicConstantDesc for this bootstrap method?" I prefer option a), but I'm fine with both options. Please let me know what you think, or if you think of a better way.

* What do I expect from my Sponsor?
I expect my sponsor lo believe that this change will improve the OpenJDK. If consensus shows a preference for option b) above (bootstrap in j.l.i.ConstantBootstaps), a guidance what requests have to be made and where. In that case, I volunteer to write those requests and send them to my sponsor, who can (at their sole discretion) forward it to the relevant places.

If you have any additional questions, please don't hesitate to answer to this mail. I will try to answer all questions to the best of my ability.

With best regards,
Johannes Kuhn

Reply via email to