From 4e5ea6639695faf2b81cf2c1b5b7d7217cbcebea Mon Sep 17 00:00:00 2001 From: sendaoYan Date: Fri, 12 Apr 2024 23:24:51 +0800 Subject: [PATCH] 1. if (isCgroupV1) only contains opts.addDockerOpts("--memory-swappiness=60"); 2. delete extra space at the beginning of the line in testSwapMemory --- .../containers/docker/TestJFREvents.java | 62 ++++++++----------- 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/test/hotspot/jtreg/containers/docker/TestJFREvents.java b/test/hotspot/jtreg/containers/docker/TestJFREvents.java index 552d8901a3322..abc9de45db842 100644 --- a/test/hotspot/jtreg/containers/docker/TestJFREvents.java +++ b/test/hotspot/jtreg/containers/docker/TestJFREvents.java @@ -227,45 +227,37 @@ private static void testMemory(String valueToSet, String expectedValue) throws E private static void testSwapMemory(String memValueToSet, String swapValueToSet, String expectedTotalValue, String expectedFreeValue) throws Exception { - OutputAnalyzer out; + Common.logNewTestCase("Memory: --memory = " + memValueToSet + " --memory-swap = " + swapValueToSet); + DockerRunOptions opts = commonDockerOpts(); + opts.addDockerOpts("--memory=" + memValueToSet) + .addDockerOpts("--memory-swap=" + swapValueToSet) + .addClassOptions("jdk.SwapSpace"); if (isCgroupV1) { - Common.logNewTestCase("Memory: --memory = " + memValueToSet + " --memory-swap = " + swapValueToSet + " --memory-swappiness = 60"); - out = DockerTestUtils.dockerRunJava( - commonDockerOpts() - .addDockerOpts("--memory=" + memValueToSet) - .addDockerOpts("--memory-swap=" + swapValueToSet) - // With Cgroupv1, The default memory-swappiness vaule is inherited from the host machine, which maybe 0 - .addDockerOpts("--memory-swappiness=60") - .addClassOptions("jdk.SwapSpace")); - } else { - Common.logNewTestCase("Memory: --memory = " + memValueToSet + " --memory-swap = " + swapValueToSet); - out = DockerTestUtils.dockerRunJava( - commonDockerOpts() - .addDockerOpts("--memory=" + memValueToSet) - .addDockerOpts("--memory-swap=" + swapValueToSet) - .addClassOptions("jdk.SwapSpace")); + // With Cgroupv1, The default memory-swappiness vaule is inherited from the host machine, which maybe 0 + opts.addDockerOpts("--memory-swappiness=60"); } - out.shouldHaveExitValue(0) + OutputAnalyzer out = DockerTestUtils.dockerRunJava(opts); + out.shouldHaveExitValue(0) .shouldContain("totalSize = " + expectedTotalValue) .shouldContain("freeSize = "); - List ls = out.asLinesWithoutVMWarnings(); - for (String cur : ls) { - int idx = cur.indexOf("freeSize = "); - if (idx != -1) { - int startNbr = idx+11; - int endNbr = cur.indexOf(' ', startNbr); - if (endNbr == -1) endNbr = cur.length(); - String freeSizeStr = cur.substring(startNbr, endNbr); - long freeval = Long.parseLong(freeSizeStr); - long totalval = Long.parseLong(expectedTotalValue); - if (0 <= freeval && freeval <= totalval) { - System.out.println("Found freeSize value " + freeval + " is fine"); - } else { - System.out.println("Found freeSize value " + freeval + " is bad"); - throw new Exception("Found free size value is bad"); - } - } - } + List ls = out.asLinesWithoutVMWarnings(); + for (String cur : ls) { + int idx = cur.indexOf("freeSize = "); + if (idx != -1) { + int startNbr = idx+11; + int endNbr = cur.indexOf(' ', startNbr); + if (endNbr == -1) endNbr = cur.length(); + String freeSizeStr = cur.substring(startNbr, endNbr); + long freeval = Long.parseLong(freeSizeStr); + long totalval = Long.parseLong(expectedTotalValue); + if (0 <= freeval && freeval <= totalval) { + System.out.println("Found freeSize value " + freeval + " is fine"); + } else { + System.out.println("Found freeSize value " + freeval + " is bad"); + throw new Exception("Found free size value is bad"); + } + } + } }