< prev index next >

src/java.base/share/classes/jdk/internal/misc/Unsafe.java

Print this page
rev 54303 : 8221477: Inject os/cpu-specific constants into Unsafe from JVM
Summary: Initialize Unsafe os/cpu-specific constants using injection instead of native callouts
Reviewed-by: duke

@@ -24,10 +24,11 @@
  */
 
 package jdk.internal.misc;
 
 import jdk.internal.HotSpotIntrinsicCandidate;
+import jdk.internal.misc.UnsafeConstants;
 import jdk.internal.ref.Cleaner;
 import jdk.internal.vm.annotation.ForceInline;
 import sun.nio.ch.DirectBuffer;
 
 import java.lang.reflect.Field;

@@ -1164,18 +1165,15 @@
     public int addressSize() {
         return ADDRESS_SIZE;
     }
 
     /** The value of {@code addressSize()} */
-    public static final int ADDRESS_SIZE = theUnsafe.addressSize0();
-
-    /**
-     * Reports the size in bytes of a native memory page (whatever that is).
-     * This value will always be a power of two.
-     */
-    public native int pageSize();
+    public static final int ADDRESS_SIZE = UnsafeConstants.ADDRESS_SIZE;
 
+    public int pageSize() {
+        return UnsafeConstants.PAGE_SIZE;
+    }
 
     /// random trusted operations from JNI:
 
     /**
      * Tells the VM to define a class, without security checks.  By default, the

@@ -3359,11 +3357,11 @@
     /**
      * @return Returns true if this platform is capable of performing
      * accesses at addresses which are not aligned for the type of the
      * primitive type being accessed, false otherwise.
      */
-    public final boolean unalignedAccess() { return unalignedAccess; }
+    public final boolean unalignedAccess() { return UnsafeConstants.UNALIGNED_ACCESS; }
 
     /**
      * Fetches a value at some byte offset into a given Java object.
      * More specifically, fetches a value within the given object
      * <code>o</code> at the given offset, or (if <code>o</code> is

@@ -3601,16 +3599,12 @@
     /** @see #putLongUnaligned(Object, long, long, boolean) */
     public final void putCharUnaligned(Object o, long offset, char x, boolean bigEndian) {
         putCharUnaligned(o, offset, convEndian(bigEndian, x));
     }
 
-    // JVM interface methods
     // BE is true iff the native endianness of this platform is big.
-    private static final boolean BE = theUnsafe.isBigEndian0();
-
-    // unalignedAccess is true iff this platform can perform unaligned accesses.
-    private static final boolean unalignedAccess = theUnsafe.unalignedAccess0();
+    private static final boolean BE = UnsafeConstants.BIG_ENDIAN;
 
     private static int pickPos(int top, int pos) { return BE ? top - pos : pos; }
 
     // These methods construct integers from bytes.  The byte ordering
     // is the native endianness of this platform.

@@ -3719,15 +3713,12 @@
     private native Object staticFieldBase0(Field f);
     private native boolean shouldBeInitialized0(Class<?> c);
     private native void ensureClassInitialized0(Class<?> c);
     private native int arrayBaseOffset0(Class<?> arrayClass);
     private native int arrayIndexScale0(Class<?> arrayClass);
-    private native int addressSize0();
     private native Class<?> defineAnonymousClass0(Class<?> hostClass, byte[] data, Object[] cpPatches);
     private native int getLoadAverage0(double[] loadavg, int nelems);
-    private native boolean unalignedAccess0();
-    private native boolean isBigEndian0();
 
 
     /**
      * Invokes the given direct byte buffer's cleaner, if any.
      *
< prev index next >