Don't use VM.maxDirectMemory() on z/OS to retrieve direct memory limit. (#7886)

Motivation:

On z/OS netty initializes this value with 64M, even the direct accessible memory is actually unbounded.

Modifications:

Skip usage of VM.maxDirectMemory() on z/OS.

Result:

More correct direct memory limit detection. Fixes https://github.com/netty/netty/issues/7654.
This commit is contained in:
Norman Maurer 2018-04-25 07:33:07 +02:00 committed by GitHub
parent b47fb81799
commit eaf1771336
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -988,13 +988,20 @@ public final class PlatformDependent {
private static long maxDirectMemory0() {
long maxDirectMemory = 0;
ClassLoader systemClassLoader = null;
try {
// Try to get from sun.misc.VM.maxDirectMemory() which should be most accurate.
systemClassLoader = getSystemClassLoader();
Class<?> vmClass = Class.forName("sun.misc.VM", true, systemClassLoader);
Method m = vmClass.getDeclaredMethod("maxDirectMemory");
maxDirectMemory = ((Number) m.invoke(null)).longValue();
// On z/OS 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")) {
// 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");
maxDirectMemory = ((Number) m.invoke(null)).longValue();
}
} catch (Throwable ignored) {
// Ignore
}