On 16/03/2016 20:04, Peter Levart wrote:
:
I have another optimization...
In java.lang.reflect.Proxy, a package is added dynamically to the
module the 1st time a proxy class is defined in that module. Each time
new proxy class is defined, an array of module package names is
compiled by concatenating two Streams, dumping them into array,
wrapping it with an ArrayStream and searching for package if it is
already defined:
583 // add the package to the runtime module if not exists
584 if (m.isNamed() &&
!Stream.of(m.getPackages()).anyMatch(proxyPkg::equals)) {
585 m.addPackage(proxyPkg);
586 }
... just to avoid calling Module.addPackage() in case the package is
already defined in that module, although the Module.addPackage() is
idempotent. Presumably to avoid synchronization? But if the module has
lots of packages, then such linear search is expensive and produces
garbage.
Here's how this linear search and the synchronization in
Module.addPackage() can be avoided:
http://cr.openjdk.java.net/~plevart/jake/Proxy.addPackage.opt/webrev.01/
Ugh, I haven't noticed that ProxyClassFactory defineProxyClass was doing
a linear search, that's a consequence of getPackages() returning an
array. So I think what you have make sense - thanks!
-Alan