< prev index next >
src/jdk.unsupported/share/classes/sun/misc/Unsafe.java
Print this page
*** 23,38 ****
* questions.
*/
package sun.misc;
import jdk.internal.vm.annotation.ForceInline;
- import jdk.internal.misc.VM;
- import jdk.internal.ref.Cleaner;
import jdk.internal.reflect.CallerSensitive;
import jdk.internal.reflect.Reflection;
- import sun.nio.ch.DirectBuffer;
import java.lang.reflect.Field;
import java.util.Set;
--- 23,36 ----
* questions.
*/
package sun.misc;
+ import jdk.internal.unsupported.UnsafeForwarder;
import jdk.internal.vm.annotation.ForceInline;
import jdk.internal.reflect.CallerSensitive;
import jdk.internal.reflect.Reflection;
import java.lang.reflect.Field;
import java.util.Set;
*** 61,71 ****
}
private Unsafe() {}
private static final Unsafe theUnsafe = new Unsafe();
! private static final jdk.internal.misc.Unsafe theInternalUnsafe = jdk.internal.misc.Unsafe.getUnsafe();
/**
* Provides the caller with the capability of performing unsafe
* operations.
*
--- 59,69 ----
}
private Unsafe() {}
private static final Unsafe theUnsafe = new Unsafe();
! private static final UnsafeForwarder theInternalUnsafe = UnsafeForwarder.getUnsafeHelper();
/**
* Provides the caller with the capability of performing unsafe
* operations.
*
*** 94,104 ****
* are granted.
*/
@CallerSensitive
public static Unsafe getUnsafe() {
Class<?> caller = Reflection.getCallerClass();
! if (!VM.isSystemDomainLoader(caller.getClassLoader()))
throw new SecurityException("Unsafe");
return theUnsafe;
}
/// peek and poke operations
--- 92,103 ----
* are granted.
*/
@CallerSensitive
public static Unsafe getUnsafe() {
Class<?> caller = Reflection.getCallerClass();
! ClassLoader loader = caller.getClassLoader();
! if (loader != null && loader != ClassLoader.getPlatformClassLoader())
throw new SecurityException("Unsafe");
return theUnsafe;
}
/// peek and poke operations
*** 614,624 ****
/**
* This constant differs from all results that will ever be returned from
* {@link #staticFieldOffset}, {@link #objectFieldOffset},
* or {@link #arrayBaseOffset}.
*/
! public static final int INVALID_FIELD_OFFSET = jdk.internal.misc.Unsafe.INVALID_FIELD_OFFSET;
/**
* Reports the location of a given field in the storage allocation of its
* class. Do not expect to perform any sort of arithmetic on this offset;
* it is just a cookie which is passed to the unsafe heap memory accessors.
--- 613,623 ----
/**
* This constant differs from all results that will ever be returned from
* {@link #staticFieldOffset}, {@link #objectFieldOffset},
* or {@link #arrayBaseOffset}.
*/
! public static final int INVALID_FIELD_OFFSET = jdk.internal.unsupported.UnsafeForwarder.INVALID_FIELD_OFFSET;
/**
* Reports the location of a given field in the storage allocation of its
* class. Do not expect to perform any sort of arithmetic on this offset;
* it is just a cookie which is passed to the unsafe heap memory accessors.
*** 713,747 ****
public int arrayBaseOffset(Class<?> arrayClass) {
return theInternalUnsafe.arrayBaseOffset(arrayClass);
}
/** The value of {@code arrayBaseOffset(boolean[].class)} */
! public static final int ARRAY_BOOLEAN_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_BOOLEAN_BASE_OFFSET;
/** The value of {@code arrayBaseOffset(byte[].class)} */
! public static final int ARRAY_BYTE_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_BYTE_BASE_OFFSET;
/** The value of {@code arrayBaseOffset(short[].class)} */
! public static final int ARRAY_SHORT_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_SHORT_BASE_OFFSET;
/** The value of {@code arrayBaseOffset(char[].class)} */
! public static final int ARRAY_CHAR_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_CHAR_BASE_OFFSET;
/** The value of {@code arrayBaseOffset(int[].class)} */
! public static final int ARRAY_INT_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_INT_BASE_OFFSET;
/** The value of {@code arrayBaseOffset(long[].class)} */
! public static final int ARRAY_LONG_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_LONG_BASE_OFFSET;
/** The value of {@code arrayBaseOffset(float[].class)} */
! public static final int ARRAY_FLOAT_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_FLOAT_BASE_OFFSET;
/** The value of {@code arrayBaseOffset(double[].class)} */
! public static final int ARRAY_DOUBLE_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_DOUBLE_BASE_OFFSET;
/** The value of {@code arrayBaseOffset(Object[].class)} */
! public static final int ARRAY_OBJECT_BASE_OFFSET = jdk.internal.misc.Unsafe.ARRAY_OBJECT_BASE_OFFSET;
/**
* Reports the scale factor for addressing elements in the storage
* allocation of a given array class. However, arrays of "narrow" types
* will generally not work properly with accessors like {@link
--- 712,746 ----
public int arrayBaseOffset(Class<?> arrayClass) {
return theInternalUnsafe.arrayBaseOffset(arrayClass);
}
/** The value of {@code arrayBaseOffset(boolean[].class)} */
! public static final int ARRAY_BOOLEAN_BASE_OFFSET = jdk.internal.unsupported.UnsafeForwarder.ARRAY_BOOLEAN_BASE_OFFSET;
/** The value of {@code arrayBaseOffset(byte[].class)} */
! public static final int ARRAY_BYTE_BASE_OFFSET = jdk.internal.unsupported.UnsafeForwarder.ARRAY_BYTE_BASE_OFFSET;
/** The value of {@code arrayBaseOffset(short[].class)} */
! public static final int ARRAY_SHORT_BASE_OFFSET = jdk.internal.unsupported.UnsafeForwarder.ARRAY_SHORT_BASE_OFFSET;
/** The value of {@code arrayBaseOffset(char[].class)} */
! public static final int ARRAY_CHAR_BASE_OFFSET = jdk.internal.unsupported.UnsafeForwarder.ARRAY_CHAR_BASE_OFFSET;
/** The value of {@code arrayBaseOffset(int[].class)} */
! public static final int ARRAY_INT_BASE_OFFSET = jdk.internal.unsupported.UnsafeForwarder.ARRAY_INT_BASE_OFFSET;
/** The value of {@code arrayBaseOffset(long[].class)} */
! public static final int ARRAY_LONG_BASE_OFFSET = jdk.internal.unsupported.UnsafeForwarder.ARRAY_LONG_BASE_OFFSET;
/** The value of {@code arrayBaseOffset(float[].class)} */
! public static final int ARRAY_FLOAT_BASE_OFFSET = jdk.internal.unsupported.UnsafeForwarder.ARRAY_FLOAT_BASE_OFFSET;
/** The value of {@code arrayBaseOffset(double[].class)} */
! public static final int ARRAY_DOUBLE_BASE_OFFSET = jdk.internal.unsupported.UnsafeForwarder.ARRAY_DOUBLE_BASE_OFFSET;
/** The value of {@code arrayBaseOffset(Object[].class)} */
! public static final int ARRAY_OBJECT_BASE_OFFSET = jdk.internal.unsupported.UnsafeForwarder.ARRAY_OBJECT_BASE_OFFSET;
/**
* Reports the scale factor for addressing elements in the storage
* allocation of a given array class. However, arrays of "narrow" types
* will generally not work properly with accessors like {@link
*** 756,790 ****
public int arrayIndexScale(Class<?> arrayClass) {
return theInternalUnsafe.arrayIndexScale(arrayClass);
}
/** The value of {@code arrayIndexScale(boolean[].class)} */
! public static final int ARRAY_BOOLEAN_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_BOOLEAN_INDEX_SCALE;
/** The value of {@code arrayIndexScale(byte[].class)} */
! public static final int ARRAY_BYTE_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_BYTE_INDEX_SCALE;
/** The value of {@code arrayIndexScale(short[].class)} */
! public static final int ARRAY_SHORT_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_SHORT_INDEX_SCALE;
/** The value of {@code arrayIndexScale(char[].class)} */
! public static final int ARRAY_CHAR_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_CHAR_INDEX_SCALE;
/** The value of {@code arrayIndexScale(int[].class)} */
! public static final int ARRAY_INT_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_INT_INDEX_SCALE;
/** The value of {@code arrayIndexScale(long[].class)} */
! public static final int ARRAY_LONG_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_LONG_INDEX_SCALE;
/** The value of {@code arrayIndexScale(float[].class)} */
! public static final int ARRAY_FLOAT_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_FLOAT_INDEX_SCALE;
/** The value of {@code arrayIndexScale(double[].class)} */
! public static final int ARRAY_DOUBLE_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_DOUBLE_INDEX_SCALE;
/** The value of {@code arrayIndexScale(Object[].class)} */
! public static final int ARRAY_OBJECT_INDEX_SCALE = jdk.internal.misc.Unsafe.ARRAY_OBJECT_INDEX_SCALE;
/**
* Reports the size in bytes of a native pointer, as stored via {@link
* #putAddress}. This value will be either 4 or 8. Note that the sizes of
* other primitive types (as stored in native memory blocks) is determined
--- 755,789 ----
public int arrayIndexScale(Class<?> arrayClass) {
return theInternalUnsafe.arrayIndexScale(arrayClass);
}
/** The value of {@code arrayIndexScale(boolean[].class)} */
! public static final int ARRAY_BOOLEAN_INDEX_SCALE = jdk.internal.unsupported.UnsafeForwarder.ARRAY_BOOLEAN_INDEX_SCALE;
/** The value of {@code arrayIndexScale(byte[].class)} */
! public static final int ARRAY_BYTE_INDEX_SCALE = jdk.internal.unsupported.UnsafeForwarder.ARRAY_BYTE_INDEX_SCALE;
/** The value of {@code arrayIndexScale(short[].class)} */
! public static final int ARRAY_SHORT_INDEX_SCALE = jdk.internal.unsupported.UnsafeForwarder.ARRAY_SHORT_INDEX_SCALE;
/** The value of {@code arrayIndexScale(char[].class)} */
! public static final int ARRAY_CHAR_INDEX_SCALE = jdk.internal.unsupported.UnsafeForwarder.ARRAY_CHAR_INDEX_SCALE;
/** The value of {@code arrayIndexScale(int[].class)} */
! public static final int ARRAY_INT_INDEX_SCALE = jdk.internal.unsupported.UnsafeForwarder.ARRAY_INT_INDEX_SCALE;
/** The value of {@code arrayIndexScale(long[].class)} */
! public static final int ARRAY_LONG_INDEX_SCALE = jdk.internal.unsupported.UnsafeForwarder.ARRAY_LONG_INDEX_SCALE;
/** The value of {@code arrayIndexScale(float[].class)} */
! public static final int ARRAY_FLOAT_INDEX_SCALE = jdk.internal.unsupported.UnsafeForwarder.ARRAY_FLOAT_INDEX_SCALE;
/** The value of {@code arrayIndexScale(double[].class)} */
! public static final int ARRAY_DOUBLE_INDEX_SCALE = jdk.internal.unsupported.UnsafeForwarder.ARRAY_DOUBLE_INDEX_SCALE;
/** The value of {@code arrayIndexScale(Object[].class)} */
! public static final int ARRAY_OBJECT_INDEX_SCALE = jdk.internal.unsupported.UnsafeForwarder.ARRAY_OBJECT_INDEX_SCALE;
/**
* Reports the size in bytes of a native pointer, as stored via {@link
* #putAddress}. This value will be either 4 or 8. Note that the sizes of
* other primitive types (as stored in native memory blocks) is determined
*** 1074,1093 ****
* This method retrieves the given {@code nelem} samples and
* assigns to the elements of the given {@code loadavg} array.
* The system imposes a maximum of 3 samples, representing
* averages over the last 1, 5, and 15 minutes, respectively.
*
* @param loadavg an array of double of size nelems
* @param nelems the number of samples to be retrieved and
* must be 1 to 3.
*
* @return the number of samples actually retrieved; or -1
* if the load average is unobtainable.
*/
! @ForceInline
public int getLoadAverage(double[] loadavg, int nelems) {
! return theInternalUnsafe.getLoadAverage(loadavg, nelems);
}
// The following contain CAS-based Java implementations used on
// platforms not supporting native instructions
--- 1073,1099 ----
* This method retrieves the given {@code nelem} samples and
* assigns to the elements of the given {@code loadavg} array.
* The system imposes a maximum of 3 samples, representing
* averages over the last 1, 5, and 15 minutes, respectively.
*
+ * @implNote This method returns -1.
+ *
* @param loadavg an array of double of size nelems
* @param nelems the number of samples to be retrieved and
* must be 1 to 3.
*
* @return the number of samples actually retrieved; or -1
* if the load average is unobtainable.
+ *
+ * @deprecated This method is planned to be removed in a future release.
+ * To get system load average, use
+ * {@link java.lang.management.OperatingSystemMXBean#getSystemLoadAverage()}
+ * instead.
*/
! @Deprecated(since="12", forRemoval=true)
public int getLoadAverage(double[] loadavg, int nelems) {
! return -1;
}
// The following contain CAS-based Java implementations used on
// platforms not supporting native instructions
*** 1232,1246 ****
*/
public void invokeCleaner(java.nio.ByteBuffer directBuffer) {
if (!directBuffer.isDirect())
throw new IllegalArgumentException("buffer is non-direct");
! DirectBuffer db = (DirectBuffer)directBuffer;
! if (db.attachment() != null)
! throw new IllegalArgumentException("duplicate or slice");
!
! Cleaner cleaner = db.cleaner();
! if (cleaner != null) {
! cleaner.clean();
! }
}
}
--- 1238,1245 ----
*/
public void invokeCleaner(java.nio.ByteBuffer directBuffer) {
if (!directBuffer.isDirect())
throw new IllegalArgumentException("buffer is non-direct");
! theInternalUnsafe.invokeCleaner(directBuffer);
}
}
< prev index next >