/* * Copyright (c) 2022 SAP SE. All rights reserved. * 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. *
*/
/* * @test id=global-limit * @summary Verify -XX:MallocLimit with a global limit * @modules java.base/jdk.internal.misc * @library /test/lib * @run driver MallocLimitTest global-limit
*/
/* * @test id=limit-without-nmt * @summary Verify that the VM warns if -XX:MallocLimit is given but NMT is disabled * @modules java.base/jdk.internal.misc * @library /test/lib * @run driver MallocLimitTest limit-without-nmt
*/
privatestaticvoid testGlobalLimit() throws IOException { long smallMemorySize = 1024*1024; // 1m
ProcessBuilder pb = processBuilderWithSetting("-XX:MallocLimit=" + smallMemorySize);
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldNotHaveExitValue(0);
output.shouldContain("[nmt] MallocLimit: total limit: 1024K"); // printed by byte_size_in_proper_unit()
String s = output.firstMatch(".*MallocLimit: reached limit \\(size: (\\d+), limit: " + smallMemorySize + "\\).*", 1);
Asserts.assertNotNull(s); long size = Long.parseLong(s);
Asserts.assertGreaterThan(size, smallMemorySize);
}
privatestaticvoid testCompilerLimit() throws IOException { // Here, we count on the VM, running with -Xcomp and with 1m of arena space allowed, will start a compilation // and then trip over the limit. // If limit is too small, Compiler stops too early and we won't get a Retry file (see below, we check that). // If limit is too large, we may not trigger it for java -version. // 1m seems to work out fine. long smallMemorySize = 1024*1024; // 1m
ProcessBuilder pb = processBuilderWithSetting("-XX:MallocLimit=compiler:" + smallMemorySize, "-Xcomp"// make sure we hit the compiler category limit
);
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldNotHaveExitValue(0);
output.shouldContain("[nmt] MallocLimit: category \"Compiler\" limit: 1024K"); // printed by byte_size_in_proper_unit
String s = output.firstMatch(".*MallocLimit: category \"Compiler\" reached limit \\(size: (\\d+), limit: " + smallMemorySize + "\\).*", 1);
Asserts.assertNotNull(s); long size = Long.parseLong(s);
output.shouldContain("Compiler replay data is saved as");
Asserts.assertGreaterThan(size, smallMemorySize);
}
privatestaticvoid testInvalidSettings() throws IOException { // Test a number of invalid settings the parser should catch. VM should abort in initialization.
testInvalidSetting("gc", "MallocLimit: colon missing: gc");
testInvalidSetting("gc:abc", "Invalid MallocLimit size: abc");
testInvalidSetting("abcd:10m", "MallocLimit: invalid nmt category: abcd");
testInvalidSetting("nmt:100m,abcd:10m", "MallocLimit: invalid nmt category: abcd");
testInvalidSetting("0", "MallocLimit: limit must be > 0");
testInvalidSetting("GC:0", "MallocLimit: limit must be > 0");
}
privatestaticvoid testLimitWithoutNmt() throws IOException {
ProcessBuilder pb = processBuilderWithSetting("-XX:NativeMemoryTracking=off", // overrides "summary" from processBuilderWithSetting() "-XX:MallocLimit=3g");
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.reportDiagnosticSummary();
output.shouldHaveExitValue(0); // Not a fatal error, just a warning
output.shouldContain("MallocLimit will be ignored since NMT is disabled");
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.