From d1bde28c4c5d14055bcc51de5a1e9557969e8352 Mon Sep 17 00:00:00 2001 From: KIRIYAMA Takuya Date: Thu, 24 Mar 2022 15:50:01 +0900 Subject: [PATCH 1/7] 8280761: UseCompressedOops should be set after limit_heap_by_allocatable_memor --- src/hotspot/share/runtime/arguments.cpp | 32 +++---- .../TestUseCompressedOopsFlagsWithUlimit.java | 95 +++++++++++++++++++ 2 files changed, 111 insertions(+), 16 deletions(-) create mode 100755 test/hotspot/jtreg/gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java diff --git a/src/hotspot/share/runtime/arguments.cpp b/src/hotspot/share/runtime/arguments.cpp index 1d7fb5f983a50..4257fef6af85b 100644 --- a/src/hotspot/share/runtime/arguments.cpp +++ b/src/hotspot/share/runtime/arguments.cpp @@ -1778,6 +1778,22 @@ void Arguments::set_heap_size() { reasonable_max = MIN2(reasonable_max, (julong)ErgoHeapSizeLimit); } + reasonable_max = limit_heap_by_allocatable_memory(reasonable_max); + + if (!FLAG_IS_DEFAULT(InitialHeapSize)) { + // An initial heap size was specified on the command line, + // so be sure that the maximum size is consistent. Done + // after call to limit_heap_by_allocatable_memory because that + // method might reduce the allocation size. + reasonable_max = MAX2(reasonable_max, (julong)InitialHeapSize); + } else if (!FLAG_IS_DEFAULT(MinHeapSize)) { + reasonable_max = MAX2(reasonable_max, (julong)MinHeapSize); + } + + log_trace(gc, heap)(" Maximum heap size " SIZE_FORMAT, (size_t) reasonable_max); + FLAG_SET_ERGO(MaxHeapSize, (size_t)reasonable_max); + } + #ifdef _LP64 if (UseCompressedOops || UseCompressedClassPointers) { // HeapBaseMinAddress can be greater than default but not less than. @@ -1824,22 +1840,6 @@ void Arguments::set_heap_size() { } #endif // _LP64 - reasonable_max = limit_heap_by_allocatable_memory(reasonable_max); - - if (!FLAG_IS_DEFAULT(InitialHeapSize)) { - // An initial heap size was specified on the command line, - // so be sure that the maximum size is consistent. Done - // after call to limit_heap_by_allocatable_memory because that - // method might reduce the allocation size. - reasonable_max = MAX2(reasonable_max, (julong)InitialHeapSize); - } else if (!FLAG_IS_DEFAULT(MinHeapSize)) { - reasonable_max = MAX2(reasonable_max, (julong)MinHeapSize); - } - - log_trace(gc, heap)(" Maximum heap size " SIZE_FORMAT, (size_t) reasonable_max); - FLAG_SET_ERGO(MaxHeapSize, (size_t)reasonable_max); - } - // If the minimum or initial heap_size have not been set or requested to be set // ergonomically, set them accordingly. if (InitialHeapSize == 0 || MinHeapSize == 0) { diff --git a/test/hotspot/jtreg/gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java b/test/hotspot/jtreg/gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java new file mode 100755 index 0000000000000..84ca430f3c11a --- /dev/null +++ b/test/hotspot/jtreg/gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2022, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package gc.arguments; + +/* + * @test TestUseCompressedOopsFlagsWithUlimit + * @bug 8280761 + * @summary Verify correct UseCompressedOops when MaxRAM and MaxRAMPercentage + * are specified with ulimit -v. + * @library /test/lib + * @library / + * @requires vm.bits == "64" + * @requires os.family != "aix" & os.family != "windows" + * @run driver gc.arguments.TestUseCompressedOopsFlagsWithUlimit + */ + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import java.util.ArrayList; +import java.util.Arrays; + +import jdk.test.lib.process.OutputAnalyzer; +import jdk.test.lib.process.ProcessTools; + +public class TestUseCompressedOopsFlagsWithUlimit { + + private static void checkFlag(long maxram, int maxrampercent, boolean forcecoop, boolean expectcoop) throws Exception { + + ArrayList args = new ArrayList(); + args.add("-XX:MaxRAM=" + maxram); + args.add("-XX:MaxRAMPercentage=" + maxrampercent); + if (forcecoop) { + args.add("-XX:+UseCompressedOops"); + } + + args.add("-XX:+PrintFlagsFinal"); + args.add("-version"); + + String cmd = ProcessTools.getCommandLine(ProcessTools.createTestJvm(args.toArray(String[]::new))); + ProcessBuilder pb = new ProcessBuilder("sh", "-c", "ulimit -v 10485760;" + cmd); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldHaveExitValue(0); + String stdout = output.getStdout(); + + boolean actualcoop = getFlagBoolValue("UseCompressedOops", stdout); + if (actualcoop != expectcoop) { + throw new RuntimeException("UseCompressedOops set to " + actualcoop + + ", expected " + expectcoop + " when running with the following flags: " + Arrays.asList(args).toString()); + } + } + + private static boolean getFlagBoolValue(String flag, String where) { + Matcher m = Pattern.compile(flag + "\\s+:?= (true|false)").matcher(where); + if (!m.find()) { + throw new RuntimeException("Could not find value for flag " + flag + " in output string"); + } + return m.group(1).equals("true"); + } + + public static void main(String args[]) throws Exception { + // Tests + // 1. Verify that MaxRAMPercentage overrides UseCompressedOops Ergo + // 2. Verify that UseCompressedOops forces compressed oops limit even + // when other flags are specified. + + long oneG = 1L * 1024L * 1024L * 1024L; + + // Args: MaxRAM , MaxRAMPercentage, forcecoop, expect coop + checkFlag(32 * oneG, 100, false, true); + checkFlag(128 * oneG, 100, false, true); + checkFlag(128 * oneG, 100, true, true); + } +} From 73c1c93512fc5d331e4abcf30a8a63042ac88c55 Mon Sep 17 00:00:00 2001 From: KIRIYAMA Takuya Date: Thu, 24 Mar 2022 15:59:17 +0900 Subject: [PATCH 2/7] 8280761: UseCompressedOops should be set after limit_heap_by_allocatable_mem --- .../jtreg/gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 test/hotspot/jtreg/gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java diff --git a/test/hotspot/jtreg/gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java b/test/hotspot/jtreg/gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java old mode 100755 new mode 100644 From cf5a93527716e6c0c5959c9b98656214a4dcdde6 Mon Sep 17 00:00:00 2001 From: KIRIYAMA Takuya Date: Thu, 7 Apr 2022 15:53:27 +0900 Subject: [PATCH 3/7] 8280761: UseCompressedOops should be set after limit_heap_by_allocatable_memory --- src/hotspot/share/runtime/arguments.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hotspot/share/runtime/arguments.cpp b/src/hotspot/share/runtime/arguments.cpp index 4257fef6af85b..fdef5f2ded637 100644 --- a/src/hotspot/share/runtime/arguments.cpp +++ b/src/hotspot/share/runtime/arguments.cpp @@ -1790,10 +1790,6 @@ void Arguments::set_heap_size() { reasonable_max = MAX2(reasonable_max, (julong)MinHeapSize); } - log_trace(gc, heap)(" Maximum heap size " SIZE_FORMAT, (size_t) reasonable_max); - FLAG_SET_ERGO(MaxHeapSize, (size_t)reasonable_max); - } - #ifdef _LP64 if (UseCompressedOops || UseCompressedClassPointers) { // HeapBaseMinAddress can be greater than default but not less than. @@ -1840,6 +1836,10 @@ void Arguments::set_heap_size() { } #endif // _LP64 + log_trace(gc, heap)(" Maximum heap size " SIZE_FORMAT, (size_t) reasonable_max); + FLAG_SET_ERGO(MaxHeapSize, (size_t)reasonable_max); + } + // If the minimum or initial heap_size have not been set or requested to be set // ergonomically, set them accordingly. if (InitialHeapSize == 0 || MinHeapSize == 0) { From 148d0fd6454108d1a7f13a4c11df5c219cc62b49 Mon Sep 17 00:00:00 2001 From: KIRIYAMA Takuya Date: Fri, 8 Apr 2022 16:33:15 +0900 Subject: [PATCH 4/7] 8280761 UseCompressedOops should be set after limit_heap_by_allocatable_memory --- .../gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/hotspot/jtreg/gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java b/test/hotspot/jtreg/gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java index 84ca430f3c11a..0dd1afd906328 100644 --- a/test/hotspot/jtreg/gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java +++ b/test/hotspot/jtreg/gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java @@ -81,9 +81,9 @@ private static boolean getFlagBoolValue(String flag, String where) { public static void main(String args[]) throws Exception { // Tests - // 1. Verify that MaxRAMPercentage overrides UseCompressedOops Ergo + // 1. Verify that UseCompressedOops Ergo follows ulimit -v setting. // 2. Verify that UseCompressedOops forces compressed oops limit even - // when other flags are specified. + // when ulimit -v are specified. long oneG = 1L * 1024L * 1024L * 1024L; From 486aa9effa3225865d87dd17b846c9a258958e58 Mon Sep 17 00:00:00 2001 From: KIRIYAMA Takuya Date: Tue, 12 Apr 2022 15:38:53 +0900 Subject: [PATCH 5/7] 8280761 UseCompressedOops should be set after limit_heap_by_allocatable_memory --- .../TestUseCompressedOopsFlagsWithUlimit.java | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/test/hotspot/jtreg/gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java b/test/hotspot/jtreg/gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java index 0dd1afd906328..2f73492ccfb95 100644 --- a/test/hotspot/jtreg/gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java +++ b/test/hotspot/jtreg/gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java @@ -46,15 +46,11 @@ public class TestUseCompressedOopsFlagsWithUlimit { - private static void checkFlag(long maxram, int maxrampercent, boolean forcecoop, boolean expectcoop) throws Exception { + private static void checkFlag(long maxram, int maxrampercent, boolean expectcoop) throws Exception { ArrayList args = new ArrayList(); args.add("-XX:MaxRAM=" + maxram); args.add("-XX:MaxRAMPercentage=" + maxrampercent); - if (forcecoop) { - args.add("-XX:+UseCompressedOops"); - } - args.add("-XX:+PrintFlagsFinal"); args.add("-version"); @@ -81,15 +77,13 @@ private static boolean getFlagBoolValue(String flag, String where) { public static void main(String args[]) throws Exception { // Tests - // 1. Verify that UseCompressedOops Ergo follows ulimit -v setting. - // 2. Verify that UseCompressedOops forces compressed oops limit even - // when ulimit -v are specified. + // Verify that UseCompressedOops Ergo follows ulimit -v setting. long oneG = 1L * 1024L * 1024L * 1024L; - // Args: MaxRAM , MaxRAMPercentage, forcecoop, expect coop - checkFlag(32 * oneG, 100, false, true); - checkFlag(128 * oneG, 100, false, true); - checkFlag(128 * oneG, 100, true, true); + // Args: MaxRAM , MaxRAMPercentage, expect coop + // Having MaxRAMPercentage set explicitly instead of relying on its default value indeed makes the test more resilient. + checkFlag(32 * oneG, 100, true); + checkFlag(128 * oneG, 100, true); } } From e2fe253f33e8937ba334ff1e3218f86d0ac6fda0 Mon Sep 17 00:00:00 2001 From: KIRIYAMA Takuya Date: Wed, 13 Apr 2022 17:32:56 +0900 Subject: [PATCH 6/7] 8280761 UseCompressedOops should be set after limit_heap_by_allocatable_memory --- .../TestUseCompressedOopsFlagsWithUlimit.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/hotspot/jtreg/gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java b/test/hotspot/jtreg/gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java index 2f73492ccfb95..00cec19803b60 100644 --- a/test/hotspot/jtreg/gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java +++ b/test/hotspot/jtreg/gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java @@ -46,7 +46,7 @@ public class TestUseCompressedOopsFlagsWithUlimit { - private static void checkFlag(long maxram, int maxrampercent, boolean expectcoop) throws Exception { + private static void checkFlag(long ulimit, long maxram, int maxrampercent, boolean expectcoop) throws Exception { ArrayList args = new ArrayList(); args.add("-XX:MaxRAM=" + maxram); @@ -55,7 +55,7 @@ private static void checkFlag(long maxram, int maxrampercent, boolean expectcoop args.add("-version"); String cmd = ProcessTools.getCommandLine(ProcessTools.createTestJvm(args.toArray(String[]::new))); - ProcessBuilder pb = new ProcessBuilder("sh", "-c", "ulimit -v 10485760;" + cmd); + ProcessBuilder pb = new ProcessBuilder("sh", "-c", "ulimit -v " + ulimit + ";" + cmd); OutputAnalyzer output = new OutputAnalyzer(pb.start()); output.shouldHaveExitValue(0); String stdout = output.getStdout(); @@ -81,9 +81,9 @@ public static void main(String args[]) throws Exception { long oneG = 1L * 1024L * 1024L * 1024L; - // Args: MaxRAM , MaxRAMPercentage, expect coop - // Having MaxRAMPercentage set explicitly instead of relying on its default value indeed makes the test more resilient. - checkFlag(32 * oneG, 100, true); - checkFlag(128 * oneG, 100, true); + // Args: ulimit, max_ram, max_ram_percent, expected_coop + // Setting MaxRAMPercentage explicitly to make the test more resilient. + checkFlag(10 * oneG, 32 * oneG, 100, true); + checkFlag(10 * oneG, 128 * oneG, 100, true); } } From 65223a523c7d536138bf4cf7c4edeb90c0703d72 Mon Sep 17 00:00:00 2001 From: KIRIYAMA Takuya Date: Thu, 14 Apr 2022 15:25:39 +0900 Subject: [PATCH 7/7] 8280761 UseCompressedOops should be set after limit_heap_by_allocatable_memory --- .../gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/hotspot/jtreg/gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java b/test/hotspot/jtreg/gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java index 00cec19803b60..bd4d82230df41 100644 --- a/test/hotspot/jtreg/gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java +++ b/test/hotspot/jtreg/gc/arguments/TestUseCompressedOopsFlagsWithUlimit.java @@ -54,8 +54,11 @@ private static void checkFlag(long ulimit, long maxram, int maxrampercent, boole args.add("-XX:+PrintFlagsFinal"); args.add("-version"); + // Convert bytes to kbytes for ulimit -v + var ulimit_prefix = "ulimit -v " + (ulimit / 1024); + String cmd = ProcessTools.getCommandLine(ProcessTools.createTestJvm(args.toArray(String[]::new))); - ProcessBuilder pb = new ProcessBuilder("sh", "-c", "ulimit -v " + ulimit + ";" + cmd); + ProcessBuilder pb = new ProcessBuilder("sh", "-c", ulimit_prefix + ";" + cmd); OutputAnalyzer output = new OutputAnalyzer(pb.start()); output.shouldHaveExitValue(0); String stdout = output.getStdout();