RFR: 8215990: Avoid using reflection to create common default URLStreamHandlers

Alan Bateman Alan.Bateman at oracle.com
Wed Jan 2 10:04:35 UTC 2019


On 02/01/2019 09:02, Claes Redestad wrote:
> Hi,
>
> during bootstrap we load and use at least two of the jrt, file and jar
> URLStreamHandlers via URL$DefaultFactory. Avoiding use of reflection to
> instantiate these slightly speed up bootstrap by reducing number of
> classes loaded and doing fewer relatively expensive reflective
> operations:
>
> http://cr.openjdk.java.net/~redestad/8215990/jdk.00/
This looks okay to me and will continue to work when the protocol is not 
in lower case (URL protocols/schemes are compared with regard to case).

While we're in the area then it would be nice to eliminate the use of 
Class::newInstance too - if each of the built-in protocol handlers is 
public with a public no-arg constructor then 
getConstructor().newInstance() should do it.

A bigger job of work in this area is to replace the use of Hashtable 
(handlers field). That's something for a bigger overhaul of course. We 
shy-ed away from doing this in JDK 9 due to OSGi implementations hacking 
the field directly.

-Alan



More information about the net-dev mailing list