During review of JDK-8244500 it was discovered that with the new cgroups implementation supporting v1 and v2 Metrics.getMemoryAndSwapLimit() will never return 0 when relevant cgroup files are missing. E.g. on a system where the kernel doesn't support swap limit capabilities. Therefore this code introduced with JDK-8236617 can no longer be reached and should get removed:
if (limit >= 0 && memLimit >= 0) {
- return limit - memLimit;
+ // we see a limit == 0 on some machines where "kernel does not support swap limit capabilities"
+ return (limit < memLimit) ? 0 : limit - memLimit;
}
More details here:
http://mail.openjdk.java.net/pipermail/hotspot-dev/2020-June/042167.html