8201494: Avoid early initialization of java.nio.Bits
Reviewed-by: rriggs, alanb
This commit is contained in:
parent
d9440e4e39
commit
9ab38159e8
src/java.base/share/classes/java/nio
@ -65,25 +65,13 @@ class Bits { // package-private
|
||||
|
||||
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
|
||||
|
||||
static Unsafe unsafe() {
|
||||
return UNSAFE;
|
||||
}
|
||||
|
||||
|
||||
// -- Processor and memory-system properties --
|
||||
|
||||
private static final ByteOrder BYTE_ORDER
|
||||
= UNSAFE.isBigEndian() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
|
||||
|
||||
static ByteOrder byteOrder() {
|
||||
return BYTE_ORDER;
|
||||
}
|
||||
|
||||
private static int PAGE_SIZE = -1;
|
||||
|
||||
static int pageSize() {
|
||||
if (PAGE_SIZE == -1)
|
||||
PAGE_SIZE = unsafe().pageSize();
|
||||
PAGE_SIZE = UNSAFE.pageSize();
|
||||
return PAGE_SIZE;
|
||||
}
|
||||
|
||||
|
@ -183,7 +183,7 @@ import java.util.Spliterator;
|
||||
|
||||
public abstract class Buffer {
|
||||
// Cached unsafe-access object
|
||||
static final Unsafe UNSAFE = Bits.unsafe();
|
||||
static final Unsafe UNSAFE = Unsafe.getUnsafe();
|
||||
|
||||
/**
|
||||
* The characteristics of Spliterators that traverse and split elements
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
package java.nio;
|
||||
|
||||
import jdk.internal.misc.Unsafe;
|
||||
|
||||
/**
|
||||
* A typesafe enumeration for byte orders.
|
||||
@ -57,6 +58,12 @@ public final class ByteOrder {
|
||||
public static final ByteOrder LITTLE_ENDIAN
|
||||
= new ByteOrder("LITTLE_ENDIAN");
|
||||
|
||||
// Retrieve the native byte order. It's used early during bootstrap, and
|
||||
// must be initialized after BIG_ENDIAN and LITTLE_ENDIAN.
|
||||
private static final ByteOrder NATIVE_ORDER
|
||||
= Unsafe.getUnsafe().isBigEndian()
|
||||
? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
|
||||
|
||||
/**
|
||||
* Retrieves the native byte order of the underlying platform.
|
||||
*
|
||||
@ -69,7 +76,7 @@ public final class ByteOrder {
|
||||
* virtual machine is running
|
||||
*/
|
||||
public static ByteOrder nativeOrder() {
|
||||
return Bits.byteOrder();
|
||||
return NATIVE_ORDER;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1579,7 +1579,7 @@ public abstract class $Type$Buffer
|
||||
boolean bigEndian // package-private
|
||||
= true;
|
||||
boolean nativeByteOrder // package-private
|
||||
= (Bits.byteOrder() == ByteOrder.BIG_ENDIAN);
|
||||
= (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN);
|
||||
|
||||
/**
|
||||
* Retrieves this buffer's byte order.
|
||||
@ -1608,7 +1608,7 @@ public abstract class $Type$Buffer
|
||||
public final $Type$Buffer order(ByteOrder bo) {
|
||||
bigEndian = (bo == ByteOrder.BIG_ENDIAN);
|
||||
nativeByteOrder =
|
||||
(bigEndian == (Bits.byteOrder() == ByteOrder.BIG_ENDIAN));
|
||||
(bigEndian == (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user