Path: blob/master/test/hotspot/jtreg/runtime/Metaspace/PrintMetaspaceDcmd.java
64479 views
/*1* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2018, SAP and/or its affiliates. All rights reserved.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324import jdk.test.lib.process.ProcessTools;25import jdk.test.lib.process.OutputAnalyzer;26import jdk.test.lib.JDKToolFinder;2728/*29* @test id=test-64bit-ccs30* @summary Test the VM.metaspace command31* @requires vm.bits == "64"32* @library /test/lib33* @modules java.base/jdk.internal.misc34* java.management35* @run main/othervm -Dwith-compressed-class-space -XX:MaxMetaspaceSize=201M -Xmx100M -XX:+UseCompressedOops -XX:+UseCompressedClassPointers PrintMetaspaceDcmd36*/3738/*39* @test id=test-64bit-ccs-noreclaim40* @summary Test the VM.metaspace command41* @requires vm.bits == "64"42* @library /test/lib43* @modules java.base/jdk.internal.misc44* java.management45* @run main/othervm -Dwith-compressed-class-space -XX:MaxMetaspaceSize=201M -Xmx100M -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:MetaspaceReclaimPolicy=none PrintMetaspaceDcmd46*/4748/*49* @test id=test-64bit-ccs-aggressivereclaim50* @summary Test the VM.metaspace command51* @requires vm.bits == "64"52* @library /test/lib53* @modules java.base/jdk.internal.misc54* java.management55* @run main/othervm -Dwith-compressed-class-space -XX:MaxMetaspaceSize=201M -Xmx100M -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:MetaspaceReclaimPolicy=aggressive PrintMetaspaceDcmd56*/5758/*59* @test id=test-64bit-ccs-guarded60* @summary Test the VM.metaspace command61* @requires vm.bits == "64"62* @requires vm.debug == true63* @library /test/lib64* @modules java.base/jdk.internal.misc65* java.management66* @run main/othervm -Dwith-compressed-class-space -XX:MaxMetaspaceSize=201M -Xmx100M -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UnlockDiagnosticVMOptions -XX:+MetaspaceGuardAllocations PrintMetaspaceDcmd67*/6869/*70* @test id=test-64bit-noccs71* @summary Test the VM.metaspace command72* @requires vm.bits == "64"73* @library /test/lib74* @modules java.base/jdk.internal.misc75* java.management76* @run main/othervm -Dwithout-compressed-class-space -XX:MaxMetaspaceSize=201M -Xmx100M -XX:-UseCompressedOops -XX:-UseCompressedClassPointers PrintMetaspaceDcmd77*/7879/*80* @test id=test-nospecified81* @summary Test the VM.metaspace command82* @requires vm.bits == "64"83* @library /test/lib84* @modules java.base/jdk.internal.misc85* java.management86* @run main/othervm -Dno-specified-flag -Xmx100M -XX:-UseCompressedOops -XX:-UseCompressedClassPointers PrintMetaspaceDcmd87*/8889/*90* @test test-32bit91* @summary Test the VM.metaspace command92* @requires vm.bits == "32"93* @library /test/lib94* @modules java.base/jdk.internal.misc95* java.management96* @run main/othervm -Dwithout-compressed-class-space -XX:MaxMetaspaceSize=201M -Xmx100M PrintMetaspaceDcmd97*/9899public class PrintMetaspaceDcmd {100101private static void doTheNoSpecifiedPropTest() throws Exception {102ProcessBuilder pb = new ProcessBuilder();103OutputAnalyzer output;104// Grab my own PID105String pid = Long.toString(ProcessTools.getProcessId());106107pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace", "basic"});108output = new OutputAnalyzer(pb.start());109output.shouldHaveExitValue(0);110output.shouldMatch("MaxMetaspaceSize: unlimited");111}112113private static void doTheCCSPropTest(boolean usesCompressedClassSpace) throws Exception {114ProcessBuilder pb = new ProcessBuilder();115OutputAnalyzer output;116// Grab my own PID117String pid = Long.toString(ProcessTools.getProcessId());118119pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace", "basic"});120output = new OutputAnalyzer(pb.start());121output.shouldHaveExitValue(0);122if (usesCompressedClassSpace) {123output.shouldContain("Non-Class:");124output.shouldContain("Class:");125}126output.shouldContain("Virtual space:");127output.shouldContain("Chunk freelists:");128output.shouldMatch("MaxMetaspaceSize:.*201.00.*MB");129130pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace"});131output = new OutputAnalyzer(pb.start());132output.shouldHaveExitValue(0);133if (usesCompressedClassSpace) {134output.shouldContain("Non-Class:");135output.shouldContain("Class:");136}137output.shouldContain("Virtual space:");138output.shouldContain("Chunk freelist");139output.shouldContain("Waste");140output.shouldMatch("MaxMetaspaceSize:.*201.00.*MB");141142pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace", "show-loaders"});143output = new OutputAnalyzer(pb.start());144output.shouldHaveExitValue(0);145output.shouldMatch("CLD.*<bootstrap>");146147pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace", "by-chunktype"});148output = new OutputAnalyzer(pb.start());149output.shouldHaveExitValue(0);150output.shouldContain("1k:");151output.shouldContain("2k:");152output.shouldContain("4k:");153output.shouldContain("8k:");154output.shouldContain("16k:");155output.shouldContain("32k:");156output.shouldContain("64k:");157output.shouldContain("128k:");158output.shouldContain("256k:");159output.shouldContain("512k:");160output.shouldContain("1m:");161output.shouldContain("2m:");162output.shouldContain("4m:");163164pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace", "vslist"});165output = new OutputAnalyzer(pb.start());166output.shouldHaveExitValue(0);167output.shouldContain("Virtual space list");168output.shouldMatch("node.*reserved.*committed.*used.*");169170pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace", "chunkfreelist"});171// Output should look somewhat like this...172// vvvvvvvvvvvvvvvv173// Chunk freelist details:174// Non-Class:175// cm non-class-space: 5 chunks, total word size: 402944.176// -- List[lv00]: empty177// -- List[lv01]: - <Chunk @0x00007f925c124090, state f, base 0x00007f9208600000, level lv01 (262144 words), used 0 words, committed 0 words.> - total : 1 chunks.178// -- List[lv02]: - <Chunk @0x00007f925c1240d8, state f, base 0x00007f9208500000, level lv02 (131072 words), used 0 words, committed 0 words.> - total : 1 chunks.179// -- List[lv03]: empty180// .....181//182// total chunks: 5, total word size: 402944.183// ^^^^^^^^^^^^^^^^^184// .... but the actual number of chunks in the freelist is difficult to predict and may be low or zero since185// no class unloading happened yet.186output = new OutputAnalyzer(pb.start());187output.shouldHaveExitValue(0);188output.shouldContain("Chunk freelist details:");189// ... but we should see at least one one chunk somewhere, the list should never be empty.190output.shouldMatch(".*-- List\\[lv00\\].*");191output.shouldMatch(".*total chunks.*total word size.*");192193// Test with different scales194pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace", "scale=G"});195output = new OutputAnalyzer(pb.start());196output.shouldHaveExitValue(0);197output.shouldMatch("MaxMetaspaceSize:.*0.2.*GB");198199pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace", "scale=K"});200output = new OutputAnalyzer(pb.start());201output.shouldHaveExitValue(0);202output.shouldMatch("MaxMetaspaceSize:.*205824.00 KB");203204pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace", "scale=1"});205output = new OutputAnalyzer(pb.start());206output.shouldHaveExitValue(0);207output.shouldMatch("MaxMetaspaceSize:.*210763776 bytes");208}209210public static void main(String args[]) throws Exception {211if (System.getProperty("no-specified-flag") != null) {212doTheNoSpecifiedPropTest();213} else if (System.getProperty("with-compressed-class-space") != null) {214doTheCCSPropTest(true);215} else if (System.getProperty("without-compressed-class-space") != null) {216doTheCCSPropTest(false);217} else {218throw new IllegalArgumentException("Unrecognized running mode");219}220}221}222223224