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

Claes Redestad claes.redestad at oracle.com
Wed Jan 2 10:43:47 UTC 2019


Hi,

On 2019-01-02 11:04, Alan Bateman wrote:
> 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).

thanks!

(The protocol input string should already be lower-case at this point)

> 
> 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.

To be perfectly compatible I think 
.getDeclaredConstructor().newInstance() should be used:

http://cr.openjdk.java.net/~redestad/8215990/jdk.01

> 
> 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.

I'm in favor of any effort to get rid of Hashtable usage, anywhere. :-)

/Claes


More information about the net-dev mailing list