< prev index next >

src/java.base/share/classes/java/net/InetAddress.java

Print this page
8200131: Improve lazy init of InetAddress.canonicalHostName and NativeObject.pageSize
Reviewed-by: alanb

*** 288,298 **** } /* Used to store the name service provider */ private static transient NameService nameService = null; ! /* Used to store the best available hostname */ private transient String canonicalHostName = null; /** use serialVersionUID from JDK 1.0.2 for interoperability */ private static final long serialVersionUID = 3286316764910316507L; --- 288,301 ---- } /* Used to store the name service provider */ private static transient NameService nameService = null; ! /** ! * Used to store the best available hostname. ! * Lazily initialized via a data race; safe because Strings are immutable. ! */ private transient String canonicalHostName = null; /** use serialVersionUID from JDK 1.0.2 for interoperability */ private static final long serialVersionUID = 3286316764910316507L;
*** 620,634 **** * @see SecurityManager#checkConnect * * @since 1.4 */ public String getCanonicalHostName() { ! if (canonicalHostName == null) { ! canonicalHostName = InetAddress.getHostFromNameService(this, true); ! } ! return canonicalHostName; } /** * Returns the hostname for this address. * --- 623,637 ---- * @see SecurityManager#checkConnect * * @since 1.4 */ public String getCanonicalHostName() { ! String value = canonicalHostName; ! if (value == null) ! canonicalHostName = value = InetAddress.getHostFromNameService(this, true); ! return value; } /** * Returns the hostname for this address. *
< prev index next >