RFR: 8299976: Initialize static fields in Net eagerly
Alan Bateman
alanb at openjdk.org
Thu Jan 12 08:21:21 UTC 2023
On Wed, 11 Jan 2023 15:01:54 GMT, Per Minborg <pminborg at openjdk.org> wrote:
> This PR proposes initializing some static fields eagerly using `final` fields.
>
> This will improve performance slightly and will allow us to remove two static fields.
>
> The PR also contains "blessed" variable casing and deduplication of exception creation.
src/java.base/share/classes/sun/nio/ch/Net.java line 76:
> 74: // -- Miscellaneous utilities --
> 75:
> 76: private static final boolean IP_V6_AVAILABLE;
The protocol is IPv6 so the underscore between "IP" and "V6" looks strange, maybe IPV6_AVAILABLE would be better.
src/java.base/share/classes/sun/nio/ch/Net.java line 77:
> 75:
> 76: private static final boolean IP_V6_AVAILABLE;
> 77: private static final boolean REUSE_PORT_AVAILABLE;
The socket option is SO_REUSEPORT so the underscore between "REUSE" and "PORT" looks strange, maybe SO_REUSEPORT_AVAILABLE would be better.
src/java.base/share/classes/sun/nio/ch/Net.java line 250:
> 248: private static final InetAddress ANY_LOCAL_INET_6_ADDRESS;
> 249: private static final InetAddress INET_4_LOOPBACK_ADDRESS;
> 250: private static final InetAddress INET_6_LOOPBACK_ADDRESS;
The class name is Inet4Address so the name looks a bit strange, maybe INET4 and INE4ADDRESS would be better.
src/java.base/share/classes/sun/nio/ch/Net.java line 815:
> 813: EXCLUSIVE_BIND = exclBindProp.isEmpty() || Boolean.parseBoolean(exclBindProp);
> 814: } else {
> 815: EXCLUSIVE_BIND = availLevel == 1;
If you put parentheses around "avaiLevel == 1" then it may be a bit more readable.
src/java.base/share/classes/sun/nio/ch/Net.java line 833:
> 831: private static SocketException newSocketException(String msg) {
> 832: return new SocketException(msg);
> 833: }
These would be easier to find if you add them close to translateToSocketException.
-------------
PR: https://git.openjdk.org/jdk/pull/11948
More information about the nio-dev
mailing list