RFR: 8152641: Plugin to generate BMH$Species classes ahead-of-time
mandy.chung at oracle.com
Fri Mar 25 01:51:38 UTC 2016
This is a good interesting work to generate BoundMethodHandle$Species_* classes at link time. This will save the class generation time. Instead of Class.forName, you may want to have a class (similar to SystemModules ) that will be updated at link time so that BoundMethodHandle can reference it statically to determine what species are generated at link time and even return statically Class<?> of the generated class.
About CNFE, the new Class.forName(Module, String) method does not throw CNFE that you could use instead (if not static reference as suggested above). If not found, it will return null.
This plugin accesses the non-public methods in BoundMethodHandle and has to invoke it via reflection. With module boundary enforced now, maybe we could consider moving to some internal package to share with this jlink plugin.
I think there are tests needed to be updated when a new plugin is added.
> On Mar 24, 2016, at 6:42 AM, Claes Redestad <claes.redestad at oracle.com> wrote:
> please review this patch which add an enabled-by-default plugin to generate a
> configurable list of BoundMethodHandle$Species_*-classes using jlink.
> Bug: https://bugs.openjdk.java.net/browse/JDK-8152641
> Webrev: http://cr.openjdk.java.net/~redestad/8152641/webrev.01/
> This plugin adds the --generate-bmh flag to jlink, which takes a
> comma-separated list of shortened species type strings.
> As an example: --generate-bmh LL,L3,L4 will generate
> BoundMethodHandle$Species_LL, ...$Species_L3 and ...$Species_L4 and add
> them to the java.base module.
> The Species class lookup in BoundMethodHandle will first check if there is a
> generated class, otherwise generate it as previously. Adding an exceptional
> path might seem problematic, but as the code generation is magnitudes more
> expensive than the exception it doesn't seem fruitful to go to lengths to avoid
> the CNFE.
> More notes along with some results can be found here:
More information about the core-libs-dev