On Thu, 21 Apr 2022 03:44:18 GMT, liach <[email protected]> wrote:
>> Currently, in ProxyBuilder::mapToModule and ProxyBuilder::defineProxyClass,
>> the interfaces are iterated twice. The two passes can be merged into one,
>> yielding the whole proxy definition context (module, package, whether
>> there's package-private interface) when determining the module.
>>
>> Split from #8278. Helpful for moving proxies to hidden classes, but is a
>> good cleanup on its own.
>
> liach has updated the pull request incrementally with one additional commit
> since the last revision:
>
> Don't need to complexify module cache
src/java.base/share/classes/java/lang/reflect/Proxy.java line 498:
> 496: new ClassLoaderValue<>();
> 497:
> 498: private record ProxyContext(Module module, String pkg, boolean
> packagePrivate) {}
This represents the context for a proxy class. It seems `ProxyClassContext`
would be clearer. I suggest the context to have the accessFlags for a proxy
class rather than the boolean whether it's package private. The constructor
should check that it must be 0 or `Modifier.PUBLIC`. `FINAL` will be added to
the access flags when it generates the proxy class.
src/java.base/share/classes/java/lang/reflect/Proxy.java line 766:
> 764: * Reads edge and qualified exports are added for dynamic module
> to access.
> 765: */
> 766: private static ProxyContext setupContext(ClassLoader loader,
Perhaps name this method `proxyClassContext` that returns `ProxyClassContext`.
src/java.base/share/classes/java/lang/reflect/Proxy.java line 831:
> 829: // All proxy interfaces are public. So maps to a dynamic
> proxy module
> 830: // and add reads edge and qualified exports, if necessary
> 831: var context = getDynamicModuleContext(loader, nonExported);
I suggest to keep the `getDynamicModule` method as creating a dynamic module of
a given class loader is a clear function. The context can be created in this
method body.
var targetModule = getDynamicModule(loader);
var pkgName = nonExported ? PROXY_PACKAGE_PREFIX + '.' +
targetModule.getName()
: targetModule.getName();
var context = new ProxyClassContext(targetModule, pkgName,
Modifier.PUBLIC);
-------------
PR: https://git.openjdk.java.net/jdk/pull/8281