diff --git a/common/src/main/java/io/netty/util/internal/PlatformDependent.java b/common/src/main/java/io/netty/util/internal/PlatformDependent.java index 4623459c5d..e6b082d859 100644 --- a/common/src/main/java/io/netty/util/internal/PlatformDependent.java +++ b/common/src/main/java/io/netty/util/internal/PlatformDependent.java @@ -993,10 +993,14 @@ public final class PlatformDependent { try { systemClassLoader = getSystemClassLoader(); - // On z/OS we should not use VM.maxDirectMemory() as it not reflects the correct value. + // When using IBM J9 / Eclipse OpenJ9 we should not use VM.maxDirectMemory() as it not reflects the + // correct value. // See: // - https://github.com/netty/netty/issues/7654 - if (!SystemPropertyUtil.get("os.name", "").toLowerCase().contains("z/os")) { + String vmName = SystemPropertyUtil.get("java.vm.name", "").toLowerCase(); + if (!vmName.startsWith("ibm j9") && + // https://github.com/eclipse/openj9/blob/openj9-0.8.0/runtime/include/vendor_version.h#L53 + !vmName.startsWith("eclipse openj9")) { // Try to get from sun.misc.VM.maxDirectMemory() which should be most accurate. Class vmClass = Class.forName("sun.misc.VM", true, systemClassLoader); Method m = vmClass.getDeclaredMethod("maxDirectMemory");