Skip to content

Commit

Permalink
Don't use sun.misc.Unsafe when IKVM.NET is used
Browse files Browse the repository at this point in the history
Motivation:

IKVM.NET seems to ship a bug sun.misc.Unsafe class, for this reason we should better disable our sun.misc.Unsafe usage when we detect IKVM.NET is used.

Modifications:

Check if IKVM.NET is used and if so do not use sun.misc.Unsafe by default.

Result:

Fixes #9035 and #8916.
  • Loading branch information
normanmaurer committed Apr 12, 2019
1 parent bedc8a6 commit 5cdf247
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions common/src/main/java/io/netty/util/internal/PlatformDependent.java
Expand Up @@ -75,6 +75,7 @@ public final class PlatformDependent {
private static final boolean IS_WINDOWS = isWindows0();
private static final boolean IS_OSX = isOsx0();
private static final boolean IS_J9_JVM = isJ9Jvm0();
private static final boolean IS_IVKVM_DOT_NET = isIkvmDotNet0();

private static final boolean MAYBE_SUPER_USER;

Expand Down Expand Up @@ -953,6 +954,12 @@ private static Throwable unsafeUnavailabilityCause0() {
logger.debug("sun.misc.Unsafe: unavailable (Android)");
return new UnsupportedOperationException("sun.misc.Unsafe: unavailable (Android)");
}

if (isIkvmDotNet()) {
logger.debug("sun.misc.Unsafe: unavailable (IKVM.NET)");
return new UnsupportedOperationException("sun.misc.Unsafe: unavailable (IKVM.NET)");
}

Throwable cause = PlatformDependent0.getUnsafeUnavailabilityCause();
if (cause != null) {
return cause;
Expand Down Expand Up @@ -982,6 +989,18 @@ private static boolean isJ9Jvm0() {
return vmName.startsWith("ibm j9") || vmName.startsWith("eclipse openj9");
}

/**
* Returns {@code true} if the running JVM is <a href="https://www.ikvm.net">IKVM.NET</a>, {@code false} otherwise.
*/
public static boolean isIkvmDotNet() {
return IS_IVKVM_DOT_NET;
}

private static boolean isIkvmDotNet0() {
String vmName = SystemPropertyUtil.get("java.vm.name", "").toUpperCase(Locale.US);
return vmName.equals("IKVM.NET");
}

private static long maxDirectMemory0() {
long maxDirectMemory = 0;

Expand Down

0 comments on commit 5cdf247

Please sign in to comment.