OpenJDK / jdk / jdk
changeset 57662:ab10165b4141
8236617: jtreg test containers/docker/TestMemoryAwareness.java fails after 8226575
Reviewed-by: bobv, clanger, mdoerr
author | mbaesken |
---|---|
date | Fri, 03 Jan 2020 11:10:42 +0100 |
parents | b42b794ac348 |
children | 641736f3fe11 |
files | src/jdk.management/unix/classes/com/sun/management/internal/OperatingSystemImpl.java test/hotspot/jtreg/containers/docker/TestMemoryAwareness.java |
diffstat | 2 files changed, 19 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/src/jdk.management/unix/classes/com/sun/management/internal/OperatingSystemImpl.java Mon Jan 13 11:26:44 2020 +0100 +++ b/src/jdk.management/unix/classes/com/sun/management/internal/OperatingSystemImpl.java Fri Jan 03 11:10:42 2020 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -61,7 +61,8 @@ // it can use as much memory as the host's OS allows. long memLimit = containerMetrics.getMemoryLimit(); 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; } } return getTotalSwapSpaceSize0();
--- a/test/hotspot/jtreg/containers/docker/TestMemoryAwareness.java Mon Jan 13 11:26:44 2020 +0100 +++ b/test/hotspot/jtreg/containers/docker/TestMemoryAwareness.java Fri Jan 03 11:10:42 2020 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -144,16 +144,21 @@ "--memory-swap", swapAllocation ); - DockerTestUtils.dockerRunJava(opts) - .shouldHaveExitValue(0) - .shouldContain("Checking OperatingSystemMXBean") - .shouldContain("OperatingSystemMXBean.getTotalPhysicalMemorySize: " + expectedMemory) - .shouldMatch("OperatingSystemMXBean\\.getFreePhysicalMemorySize: [1-9][0-9]+") - .shouldContain("OperatingSystemMXBean.getTotalMemorySize: " + expectedMemory) - .shouldMatch("OperatingSystemMXBean\\.getFreeMemorySize: [1-9][0-9]+") - .shouldContain("OperatingSystemMXBean.getTotalSwapSpaceSize: " + expectedSwap) - .shouldMatch("OperatingSystemMXBean\\.getFreeSwapSpaceSize: [1-9][0-9]+") - ; + OutputAnalyzer out = DockerTestUtils.dockerRunJava(opts); + out.shouldHaveExitValue(0) + .shouldContain("Checking OperatingSystemMXBean") + .shouldContain("OperatingSystemMXBean.getTotalPhysicalMemorySize: " + expectedMemory) + .shouldMatch("OperatingSystemMXBean\\.getFreePhysicalMemorySize: [1-9][0-9]+") + .shouldContain("OperatingSystemMXBean.getTotalMemorySize: " + expectedMemory) + .shouldMatch("OperatingSystemMXBean\\.getFreeMemorySize: [1-9][0-9]+") + .shouldMatch("OperatingSystemMXBean\\.getFreeSwapSpaceSize: [1-9][0-9]+"); + // in case of warnings like : "Your kernel does not support swap limit capabilities or the cgroup is not mounted. Memory limited without swap." + // the getTotalSwapSpaceSize does not return the expected result, but 0 + try { + out.shouldContain("OperatingSystemMXBean.getTotalSwapSpaceSize: " + expectedSwap); + } catch(RuntimeException ex) { + out.shouldContain("OperatingSystemMXBean.getTotalSwapSpaceSize: 0"); + } } }