Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ final class OpConstants {
/**
* Supplier of the jvm-static trusted lookup instance, only initialized on the first access.
*/
@SuppressWarnings("deprecation") // fine until stable values are available
static final Supplier<MethodHandles.Lookup> TRUSTED_LOOKUP = new LazyMemoizingSupplier<>(() -> {
static final Supplier<MethodHandles.Lookup> TRUSTED_LOOKUP = StableValue.supplier(() -> {
try {
var trustedLookupField = MethodHandles.Lookup.class.getDeclaredField("IMPL_LOOKUP");
trustedLookupField.setAccessible(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ final class UnsafeReplacementDefiner {
"ArrayOps",
"FieldAccessor",
"FieldOffsetOps",
"LazyMemoizingSupplier",
"MemoryControlOps",
"MemoryOps",
"OpConstants",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.function.Consumer;
import java.util.function.Supplier;
import lombok.NonNull;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.VisibleForTesting;

Expand All @@ -41,9 +42,8 @@
* methods in {@code sun.misc.Unsafe} have a safe replacement within the jdk, use those instead!
*
* @since 4.0
* @deprecated should not be used in new user code, use safe replacements like the ffm api or var handles instead.
*/
@Deprecated
@ApiStatus.Internal
public final class UnsafeReplacementDelegate {

// accessor for cleaning up direct byte buffers
Expand All @@ -55,7 +55,7 @@ public final class UnsafeReplacementDelegate {

// accessor for the operating system mx bean
private static final Supplier<OperatingSystemMXBean> OS_MX_BEAN =
new LazyMemoizingSupplier<>(ManagementFactory::getOperatingSystemMXBean);
StableValue.supplier(ManagementFactory::getOperatingSystemMXBean);

// method handle to define a class in any class loader, takes the target class loader as the first argument
// method descriptor: ClassLoader.defineClass1(ClassLoader, String, byte[], int, int, ProtectionDomain, String)
Expand All @@ -76,7 +76,7 @@ private UnsafeReplacementDelegate() {
* @return a supplier for a method handle to invoke {@code ClassLoader.defineClass}.
*/
private static @NonNull Supplier<MethodHandle> createClassDefineMethodHandleSupplier() {
return new LazyMemoizingSupplier<>(() -> {
return StableValue.supplier(() -> {
try {
// resolves the method handle for: Class<?> defineClass1(ClassLoader, String, byte[], int, int, ProtectionDomain, String)
var lookup = OpConstants.TRUSTED_LOOKUP.get();
Expand All @@ -103,7 +103,7 @@ private UnsafeReplacementDelegate() {
* @return a supplier that creates a consumer to clean a direct byte buffer.
*/
private static @NonNull Supplier<Consumer<ByteBuffer>> createByteBufferCleaner() {
return new LazyMemoizingSupplier<>(() -> {
return StableValue.supplier(() -> {
try {
var lookup = OpConstants.TRUSTED_LOOKUP.get();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
* @since 4.0
*/
@ApiStatus.Internal
@SuppressWarnings("deprecation")
public final class UnsafeUsageTraceLogger {

/**
Expand All @@ -37,7 +36,7 @@ public final class UnsafeUsageTraceLogger {
* Stack walker to get the caller of the unsafe replacement method.
*/
private static final Supplier<StackWalker> CALLER_GET_STACK_WALKER =
new LazyMemoizingSupplier<>(() -> StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE));
StableValue.supplier(() -> StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE));

private UnsafeUsageTraceLogger() {
throw new UnsupportedOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,43 +32,42 @@
*
* @since 4.0
*/
@SuppressWarnings("deprecation") // uses LazyMemoizingSupplier
enum ValueTypeKind {

// CHECKSTYLE.OFF: checkstyle isn't really helping here
BYTE(
(left, right) -> (byte) left == (byte) right,
new LazyMemoizingSupplier<>(() -> MethodHandles.arrayElementVarHandle(byte[].class)),
StableValue.supplier(() -> MethodHandles.arrayElementVarHandle(byte[].class)),
arr -> MemorySegment.ofArray((byte[]) arr),
ValueLayout.JAVA_BYTE),
SHORT(
(left, right) -> (short) left == (short) right,
new LazyMemoizingSupplier<>(() -> MethodHandles.arrayElementVarHandle(short[].class)),
StableValue.supplier(() -> MethodHandles.arrayElementVarHandle(short[].class)),
arr -> MemorySegment.ofArray((short[]) arr),
ValueLayout.JAVA_SHORT),
INT(
(left, right) -> (int) left == (int) right,
new LazyMemoizingSupplier<>(() -> MethodHandles.arrayElementVarHandle(int[].class)),
StableValue.supplier(() -> MethodHandles.arrayElementVarHandle(int[].class)),
arr -> MemorySegment.ofArray((int[]) arr),
ValueLayout.JAVA_INT),
LONG(
(left, right) -> (long) left == (long) right,
new LazyMemoizingSupplier<>(() -> MethodHandles.arrayElementVarHandle(long[].class)),
StableValue.supplier(() -> MethodHandles.arrayElementVarHandle(long[].class)),
arr -> MemorySegment.ofArray((long[]) arr),
ValueLayout.JAVA_LONG),
FLOAT(
(left, right) -> (float) left == (float) right,
new LazyMemoizingSupplier<>(() -> MethodHandles.arrayElementVarHandle(float[].class)),
StableValue.supplier(() -> MethodHandles.arrayElementVarHandle(float[].class)),
arr -> MemorySegment.ofArray((float[]) arr),
ValueLayout.JAVA_FLOAT),
DOUBLE(
(left, right) -> (double) left == (double) right,
new LazyMemoizingSupplier<>(() -> MethodHandles.arrayElementVarHandle(double[].class)),
StableValue.supplier(() -> MethodHandles.arrayElementVarHandle(double[].class)),
arr -> MemorySegment.ofArray((double[]) arr),
ValueLayout.JAVA_DOUBLE),
BOOL(
(left, right) -> (boolean) left == (boolean) right,
new LazyMemoizingSupplier<>(() -> MethodHandles.arrayElementVarHandle(boolean[].class)),
StableValue.supplier(() -> MethodHandles.arrayElementVarHandle(boolean[].class)),
arr -> {
// boolean arrays aren't natively supported, but they are basically byte arrays with 0/1 values
var boolArray = (boolean[]) arr;
Expand All @@ -81,12 +80,12 @@ enum ValueTypeKind {
ValueLayout.JAVA_BOOLEAN),
CHAR(
(left, right) -> (char) left == (char) right,
new LazyMemoizingSupplier<>(() -> MethodHandles.arrayElementVarHandle(char[].class)),
StableValue.supplier(() -> MethodHandles.arrayElementVarHandle(char[].class)),
arr -> MemorySegment.ofArray((char[]) arr),
ValueLayout.JAVA_CHAR),
REF(
(left, right) -> left == right,
new LazyMemoizingSupplier<>(() -> MethodHandles.arrayElementVarHandle(Object[].class)),
StableValue.supplier(() -> MethodHandles.arrayElementVarHandle(Object[].class)),
null,
null);
// CHECKSTYLE.ON
Expand Down
Loading