Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/runtime/NMT/JcmdWithNMTDisabled.java
32284 views
/*1* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @key nmt jcmd26* @summary Verify that jcmd correctly reports that NMT is not enabled27* @library /testlibrary28* @run main JcmdWithNMTDisabled 129*/3031import com.oracle.java.testlibrary.*;3233public class JcmdWithNMTDisabled {34static ProcessBuilder pb = new ProcessBuilder();35static String pid;3637public static void main(String args[]) throws Exception {3839// This test explicitly needs to be run with the exact command lines below, not passing on40// arguments from the parent VM is a conscious choice to avoid NMT being turned on.41if (args.length > 0) {42ProcessBuilder pb;43OutputAnalyzer output;44String testjdkPath = System.getProperty("test.jdk");4546// First run without enabling NMT47pb = ProcessTools.createJavaProcessBuilder("-Dtest.jdk=" + testjdkPath, "JcmdWithNMTDisabled");48output = new OutputAnalyzer(pb.start());49output.shouldHaveExitValue(0);5051// Then run with explicitly disabling NMT, should not be any difference52pb = ProcessTools.createJavaProcessBuilder("-Dtest.jdk=" + testjdkPath, "-XX:NativeMemoryTracking=off", "JcmdWithNMTDisabled");53output = new OutputAnalyzer(pb.start());54output.shouldHaveExitValue(0);5556return;57}5859// Grab my own PID60pid = Integer.toString(ProcessTools.getProcessId());6162jcmdCommand("summary");63jcmdCommand("detail");64jcmdCommand("baseline");65jcmdCommand("summary.diff");66jcmdCommand("detail.diff");67jcmdCommand("scale=GB");68jcmdCommand("shutdown");69}7071// Helper method for invoking different jcmd calls, all should fail with the same message saying NMT is not enabled72public static void jcmdCommand(String command) throws Exception {7374pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", command});75OutputAnalyzer output = new OutputAnalyzer(pb.start());7677// Verify that jcmd reports that NMT is not enabled78output.shouldContain("Native memory tracking is not enabled");79}80}818283