Skip to content
Permalink
Browse files
8262099: jcmd VM.metaspace should report unlimited size if MaxMetaspa…
…ceSize isn't specified

Reviewed-by: stuefe, lucy
  • Loading branch information
kelthuzadx authored and David Holmes committed Feb 25, 2021
1 parent a50725d commit 3a0d6a64bc4438da6b2bb34863370ec3f5d9a2e9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2020 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -95,7 +95,8 @@ static void print_vs(outputStream* out, size_t scale) {

static void print_settings(outputStream* out, size_t scale) {
out->print("MaxMetaspaceSize: ");
if (MaxMetaspaceSize >= (max_uintx) - (2 * os::vm_page_size())) {
// See Metaspace::ergo_initialize() for how MaxMetaspaceSize is rounded
if (MaxMetaspaceSize >= align_down(max_uintx, Metaspace::commit_alignment())) {
// aka "very big". Default is max_uintx, but due to rounding in arg parsing the real
// value is smaller.
out->print("unlimited");
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, SAP and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -33,7 +33,7 @@
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management
* @run main/othervm -XX:MaxMetaspaceSize=201M -Xmx100M -XX:+UseCompressedOops -XX:+UseCompressedClassPointers PrintMetaspaceDcmd with-compressed-class-space
* @run main/othervm -Dwith-compressed-class-space -XX:MaxMetaspaceSize=201M -Xmx100M -XX:+UseCompressedOops -XX:+UseCompressedClassPointers PrintMetaspaceDcmd
*/

/*
@@ -43,7 +43,7 @@
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management
* @run main/othervm -XX:MaxMetaspaceSize=201M -Xmx100M -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:MetaspaceReclaimPolicy=none PrintMetaspaceDcmd with-compressed-class-space
* @run main/othervm -Dwith-compressed-class-space -XX:MaxMetaspaceSize=201M -Xmx100M -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:MetaspaceReclaimPolicy=none PrintMetaspaceDcmd
*/

/*
@@ -53,7 +53,7 @@
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management
* @run main/othervm -XX:MaxMetaspaceSize=201M -Xmx100M -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:MetaspaceReclaimPolicy=aggressive PrintMetaspaceDcmd with-compressed-class-space
* @run main/othervm -Dwith-compressed-class-space -XX:MaxMetaspaceSize=201M -Xmx100M -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:MetaspaceReclaimPolicy=aggressive PrintMetaspaceDcmd
*/

/*
@@ -64,7 +64,7 @@
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management
* @run main/othervm -XX:MaxMetaspaceSize=201M -Xmx100M -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UnlockDiagnosticVMOptions -XX:+MetaspaceGuardAllocations PrintMetaspaceDcmd with-compressed-class-space
* @run main/othervm -Dwith-compressed-class-space -XX:MaxMetaspaceSize=201M -Xmx100M -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UnlockDiagnosticVMOptions -XX:+MetaspaceGuardAllocations PrintMetaspaceDcmd
*/

/*
@@ -74,7 +74,17 @@
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management
* @run main/othervm -XX:MaxMetaspaceSize=201M -Xmx100M -XX:-UseCompressedOops -XX:-UseCompressedClassPointers PrintMetaspaceDcmd without-compressed-class-space
* @run main/othervm -Dwithout-compressed-class-space -XX:MaxMetaspaceSize=201M -Xmx100M -XX:-UseCompressedOops -XX:-UseCompressedClassPointers PrintMetaspaceDcmd
*/

/*
* @test id=test-nospecified
* @summary Test the VM.metaspace command
* @requires vm.bits == "64"
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management
* @run main/othervm -Dno-specified-flag -Xmx100M -XX:-UseCompressedOops -XX:-UseCompressedClassPointers PrintMetaspaceDcmd
*/

/*
@@ -84,12 +94,24 @@
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management
* @run main/othervm -XX:MaxMetaspaceSize=201M -Xmx100M PrintMetaspaceDcmd without-compressed-class-space
* @run main/othervm -Dwithout-compressed-class-space -XX:MaxMetaspaceSize=201M -Xmx100M PrintMetaspaceDcmd
*/

public class PrintMetaspaceDcmd {

private static void doTheTest(boolean usesCompressedClassSpace) throws Exception {
private static void doTheNoSpecifiedPropTest() throws Exception {
ProcessBuilder pb = new ProcessBuilder();
OutputAnalyzer output;
// Grab my own PID
String pid = Long.toString(ProcessTools.getProcessId());

pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace", "basic"});
output = new OutputAnalyzer(pb.start());
output.shouldHaveExitValue(0);
output.shouldMatch("MaxMetaspaceSize: unlimited");
}

private static void doTheCCSPropTest(boolean usesCompressedClassSpace) throws Exception {
ProcessBuilder pb = new ProcessBuilder();
OutputAnalyzer output;
// Grab my own PID
@@ -164,14 +186,14 @@ private static void doTheTest(boolean usesCompressedClassSpace) throws Exception
}

public static void main(String args[]) throws Exception {
boolean testForCompressedClassSpace = false;
if (args[0].equals("with-compressed-class-space")) {
testForCompressedClassSpace = true;
} else if (args[0].equals("without-compressed-class-space")) {
testForCompressedClassSpace = false;
if (System.getProperty("no-specified-flag") != null) {
doTheNoSpecifiedPropTest();
} else if (System.getProperty("with-compressed-class-space") != null) {
doTheCCSPropTest(true);
} else if (System.getProperty("without-compressed-class-space") != null) {
doTheCCSPropTest(false);
} else {
throw new IllegalArgumentException("Invalid argument: " + args[0]);
throw new IllegalArgumentException("Unrecognized running mode");
}
doTheTest(testForCompressedClassSpace);
}
}

0 comments on commit 3a0d6a6

Please sign in to comment.