< 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,33 **** --- 24,34 ---- */ 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,1181 **** 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(); /// random trusted operations from JNI: /** * Tells the VM to define a class, without security checks. By default, the --- 1165,1179 ---- public int addressSize() { return ADDRESS_SIZE; } /** The value of {@code addressSize()} */ ! 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,3369 **** /** * @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; } /** * 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 --- 3357,3367 ---- /** * @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 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,3616 **** /** @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 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. --- 3599,3610 ---- /** @see #putLongUnaligned(Object, long, long, boolean) */ public final void putCharUnaligned(Object o, long offset, char x, boolean bigEndian) { putCharUnaligned(o, offset, convEndian(bigEndian, x)); } // BE is true iff the native endianness of this platform is big. ! 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,3733 **** 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. * --- 3713,3724 ----
< prev index next >