1 /* 2 * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2018, SAP and/or its affiliates. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 */ 24 25 import jdk.test.lib.process.ProcessTools; 26 import jdk.test.lib.process.OutputAnalyzer; 27 import jdk.test.lib.JDKToolFinder; 28 29 /* 30 * @test 31 * @summary Test the VM.metaspace command 32 * @requires vm.gc != "Z" & vm.bits != "32" 33 * @library /test/lib 34 * @modules java.base/jdk.internal.misc 35 * java.management 36 * @run main/othervm -XX:MaxMetaspaceSize=201M -Xmx100M -XX:+UseCompressedOops -XX:+UseCompressedClassPointers PrintMetaspaceDcmd with-compressed-class-space 37 * @run main/othervm -XX:MaxMetaspaceSize=201M -Xmx100M -XX:-UseCompressedOops -XX:-UseCompressedClassPointers PrintMetaspaceDcmd without-compressed-class-space 38 */ 39 /* 40 * @test 41 * @summary Test the VM.metaspace command 42 * @requires vm.gc != "Z" & vm.bits == "32" 43 * @library /test/lib 44 * @modules java.base/jdk.internal.misc 45 * java.management 46 * @run main/othervm -XX:MaxMetaspaceSize=201M -Xmx100M PrintMetaspaceDcmd without-compressed-class-space 47 */ 48 49 public class PrintMetaspaceDcmd { 50 51 // Run jcmd VM.metaspace against a VM with CompressedClassPointers on. 52 // The report should detail Non-Class and Class portions separately. 53 private static void doTheTest(boolean usesCompressedClassSpace) throws Exception { 54 ProcessBuilder pb = new ProcessBuilder(); 55 OutputAnalyzer output; 56 // Grab my own PID 57 String pid = Long.toString(ProcessTools.getProcessId()); 58 59 pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace", "basic"}); 60 output = new OutputAnalyzer(pb.start()); 61 output.shouldHaveExitValue(0); 62 if (usesCompressedClassSpace) { 63 output.shouldContain("Non-Class:"); 64 output.shouldContain("Class:"); 65 } 66 output.shouldContain("Virtual space:"); 67 output.shouldContain("Chunk freelists:"); 68 output.shouldMatch("MaxMetaspaceSize:.*201.00.*MB"); 69 70 pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace"}); 71 output = new OutputAnalyzer(pb.start()); 72 output.shouldHaveExitValue(0); 73 if (usesCompressedClassSpace) { 74 output.shouldContain("Non-Class:"); 75 output.shouldContain("Class:"); 76 } 77 output.shouldContain("Virtual space:"); 78 output.shouldContain("Chunk freelist"); 79 output.shouldContain("Waste"); 80 output.shouldMatch("MaxMetaspaceSize:.*201.00.*MB"); 81 82 pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace", "show-loaders"}); 83 output = new OutputAnalyzer(pb.start()); 84 output.shouldHaveExitValue(0); 85 output.shouldMatch("CLD.*<bootstrap>"); 86 87 pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace", "by-chunktype"}); 88 output = new OutputAnalyzer(pb.start()); 89 output.shouldHaveExitValue(0); 90 output.shouldContain("1k:"); 91 output.shouldContain("2k:"); 92 output.shouldContain("4k:"); 93 output.shouldContain("8k:"); 94 output.shouldContain("16k:"); 95 output.shouldContain("32k:"); 96 output.shouldContain("64k:"); 97 output.shouldContain("128k:"); 98 output.shouldContain("256k:"); 99 output.shouldContain("512k:"); 100 output.shouldContain("1m:"); 101 output.shouldContain("2m:"); 102 output.shouldContain("4m:"); 103 104 pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace", "vslist"}); 105 output = new OutputAnalyzer(pb.start()); 106 output.shouldHaveExitValue(0); 107 output.shouldContain("Virtual space list"); 108 output.shouldMatch("node.*reserved.*committed.*used.*"); 109 110 // Test with different scales 111 pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace", "scale=G"}); 112 output = new OutputAnalyzer(pb.start()); 113 output.shouldHaveExitValue(0); 114 output.shouldMatch("MaxMetaspaceSize:.*0.2.*GB"); 115 116 pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace", "scale=K"}); 117 output = new OutputAnalyzer(pb.start()); 118 output.shouldHaveExitValue(0); 119 output.shouldMatch("MaxMetaspaceSize:.*205824.00 KB"); 120 121 pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace", "scale=1"}); 122 output = new OutputAnalyzer(pb.start()); 123 output.shouldHaveExitValue(0); 124 output.shouldMatch("MaxMetaspaceSize:.*210763776 bytes"); 125 } 126 127 public static void main(String args[]) throws Exception { 128 boolean testForCompressedClassSpace = false; 129 if (args[0].equals("with-compressed-class-space")) { 130 testForCompressedClassSpace = true; 131 } else if (args[0].equals("without-compressed-class-space")) { 132 testForCompressedClassSpace = false; 133 } else { 134 throw new IllegalArgumentException("Invalid argument: " + args[0]); 135 } 136 doTheTest(testForCompressedClassSpace); 137 } 138 }