Skip to content
Permalink
Browse files
8244500: jtreg test error in test/hotspot/jtreg/containers/docker/Tes…
…tMemoryAwareness.java

When the kernel doesn't support swap limits, expect host values instead.

Backport-of: 732d8865dfb56e2afbc13d7e53fb1017b9e8b10e
  • Loading branch information
Ekaterina Vergizova committed May 11, 2021
1 parent ca0a09e commit fb5132254d834ba01a4b65ce64143843e83c674e
Showing 3 changed files with 25 additions and 4 deletions.
@@ -24,11 +24,20 @@

import com.sun.management.OperatingSystemMXBean;
import java.lang.management.ManagementFactory;
import jdk.internal.platform.Metrics;

public class CheckOperatingSystemMXBean {

public static void main(String[] args) {
System.out.println("Checking OperatingSystemMXBean");
Metrics metrics = jdk.internal.platform.Container.metrics();
System.out.println("Metrics instance: " + (metrics == null ? "null" : "non-null"));
if (metrics != null) {
System.out.println("Metrics.getMemoryAndSwapLimit() == " + metrics.getMemoryAndSwapLimit());
System.out.println("Metrics.getMemoryLimit() == " + metrics.getMemoryLimit());
System.out.println("Metrics.getMemoryAndSwapUsage() == " + metrics.getMemoryAndSwapUsage());
System.out.println("Metrics.getMemoryUsage() == " + metrics.getMemoryUsage());
}

OperatingSystemMXBean osBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
System.out.println(String.format("Runtime.availableProcessors: %d", Runtime.getRuntime().availableProcessors()));
@@ -28,6 +28,7 @@
* @requires docker.support
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.base/jdk.internal.platform
* java.management
* jdk.jartool/sun.tools.jar
* @build PrintContainerInfo CheckOperatingSystemMXBean
@@ -237,7 +238,11 @@ private static void testOperatingSystemMXBeanAwareness(String cpuAllocation, Str
DockerRunOptions opts = Common.newOpts(imageName, "CheckOperatingSystemMXBean")
.addDockerOpts(
"--cpus", cpuAllocation
);
)
// CheckOperatingSystemMXBean uses Metrics (jdk.internal.platform) for
// diagnostics
.addJavaOpts("--add-exports")
.addJavaOpts("java.base/jdk.internal.platform=ALL-UNNAMED");

DockerTestUtils.dockerRunJava(opts)
.shouldHaveExitValue(0)
@@ -28,6 +28,7 @@
* @requires docker.support
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.base/jdk.internal.platform
* java.management
* jdk.jartool/sun.tools.jar
* @build AttemptOOM sun.hotspot.WhiteBox PrintContainerInfo CheckOperatingSystemMXBean
@@ -142,7 +143,11 @@ private static void testOperatingSystemMXBeanAwareness(String memoryAllocation,
.addDockerOpts(
"--memory", memoryAllocation,
"--memory-swap", swapAllocation
);
)
// CheckOperatingSystemMXBean uses Metrics (jdk.internal.platform) for
// diagnostics
.addJavaOpts("--add-exports")
.addJavaOpts("java.base/jdk.internal.platform=ALL-UNNAMED");

OutputAnalyzer out = DockerTestUtils.dockerRunJava(opts);
out.shouldHaveExitValue(0)
@@ -153,11 +158,13 @@ private static void testOperatingSystemMXBeanAwareness(String memoryAllocation,
.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
// the getTotalSwapSpaceSize returns the system values as the container setup isn't supported in that case.
try {
out.shouldContain("OperatingSystemMXBean.getTotalSwapSpaceSize: " + expectedSwap);
} catch(RuntimeException ex) {
out.shouldContain("OperatingSystemMXBean.getTotalSwapSpaceSize: 0");
out.shouldMatch("OperatingSystemMXBean.getTotalSwapSpaceSize: [1-9][0-9]+");
out.shouldContain("Metrics.getMemoryLimit() == " + expectedMemory);
out.shouldContain("Metrics.getMemoryAndSwapLimit() == -1");
}
}

3 comments on commit fb51322

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on fb51322 May 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ebaron
Copy link
Member

@ebaron ebaron commented on fb51322 Mar 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on fb51322 Mar 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ebaron Could not automatically backport fb513225 to openjdk/jdk11u-dev due to conflicts in the following files:

  • test/hotspot/jtreg/containers/docker/TestMemoryAwareness.java

To manually resolve these conflicts run the following commands in your personal fork of openjdk/jdk11u-dev:

$ git checkout -b ebaron-backport-fb513225
$ git fetch --no-tags https://git.openjdk.java.net/jdk15u-dev fb5132254d834ba01a4b65ce64143843e83c674e
$ git cherry-pick --no-commit fb5132254d834ba01a4b65ce64143843e83c674e
$ # Resolve conflicts
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport fb5132254d834ba01a4b65ce64143843e83c674e'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk11u-dev with the title Backport fb5132254d834ba01a4b65ce64143843e83c674e.

Please sign in to comment.