mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8200131: Improve lazy init of InetAddress.canonicalHostName and NativeObject.pageSize
Reviewed-by: alanb
This commit is contained in:
parent
5c8c67c523
commit
2137690f0a
2 changed files with 16 additions and 9 deletions
|
@ -290,7 +290,10 @@ class InetAddress implements java.io.Serializable {
|
|||
/* Used to store the name service provider */
|
||||
private static transient NameService nameService = null;
|
||||
|
||||
/* Used to store the best available hostname */
|
||||
/**
|
||||
* 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 */
|
||||
|
@ -622,11 +625,11 @@ class InetAddress implements java.io.Serializable {
|
|||
* @since 1.4
|
||||
*/
|
||||
public String getCanonicalHostName() {
|
||||
if (canonicalHostName == null) {
|
||||
canonicalHostName =
|
||||
String value = canonicalHostName;
|
||||
if (value == null)
|
||||
canonicalHostName = value =
|
||||
InetAddress.getHostFromNameService(this, true);
|
||||
}
|
||||
return canonicalHostName;
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -388,7 +388,10 @@ class NativeObject { // package-private
|
|||
return byteOrder;
|
||||
}
|
||||
|
||||
// Cache for page size
|
||||
/**
|
||||
* Cache for page size.
|
||||
* Lazily initialized via a data race; safe because ints are atomic.
|
||||
*/
|
||||
private static int pageSize = -1;
|
||||
|
||||
/**
|
||||
|
@ -397,9 +400,10 @@ class NativeObject { // package-private
|
|||
* @return The page size, in bytes
|
||||
*/
|
||||
static int pageSize() {
|
||||
if (pageSize == -1)
|
||||
pageSize = unsafe.pageSize();
|
||||
return pageSize;
|
||||
int value = pageSize;
|
||||
if (value == -1)
|
||||
pageSize = value = unsafe.pageSize();
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue