diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/Main.java b/HMCL/src/main/java/org/jackhuang/hmcl/Main.java index c1d9c0ad8..e9e394ce9 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/Main.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/Main.java @@ -32,6 +32,7 @@ import javax.net.ssl.TrustManagerFactory; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.lang.reflect.Method; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -71,6 +72,7 @@ public final class Main { checkJavaFX(); verifyJavaFX(); addEnableNativeAccess(); + enableUnsafeMemoryAccess(); Launcher.main(args); } @@ -134,6 +136,20 @@ public final class Main { } } + private static void enableUnsafeMemoryAccess() { + // https://openjdk.org/jeps/498 + if (JavaRuntime.CURRENT_VERSION == 24 || JavaRuntime.CURRENT_VERSION == 25) { + try { + Class clazz = Class.forName("sun.misc.Unsafe"); + Method trySetMemoryAccessWarned = clazz.getDeclaredMethod("trySetMemoryAccessWarned"); + trySetMemoryAccessWarned.setAccessible(true); + trySetMemoryAccessWarned.invoke(null); + } catch (Throwable e) { + e.printStackTrace(System.err); + } + } + } + /** * Indicates that a fatal error has occurred, and that the application cannot start. */