Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/JInfo.java
41161 views
/*1* Copyright (c) 2004, 2019, 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*22*/2324package sun.jvm.hotspot.tools;2526import sun.jvm.hotspot.debugger.JVMDebugger;27import sun.jvm.hotspot.runtime.Arguments;28import sun.jvm.hotspot.runtime.VM;2930public class JInfo extends Tool {31public JInfo() {32super();33}3435public JInfo(int m) {36mode = m;37}3839public JInfo(JVMDebugger d) {40super(d);41}4243protected boolean needsJavaPrefix() {44return false;45}4647@Override48public String getName() {49return "jinfo";50}5152protected void printFlagsUsage() {53System.out.println(" -flags\tto print VM flags");54System.out.println(" -sysprops\tto print Java System properties");55System.out.println(" <no option>\tto print both of the above");56super.printFlagsUsage();57}5859public static final int MODE_FLAGS = 0;60public static final int MODE_SYSPROPS = 1;61public static final int MODE_BOTH = 2;6263public void run() {64Tool tool = null;65switch (mode) {66case MODE_FLAGS:67printVMFlags();68return;69case MODE_SYSPROPS:70tool = new SysPropsDumper();71break;72case MODE_BOTH: {73tool = new Tool() {74public void run() {75Tool sysProps = new SysPropsDumper();76sysProps.setAgent(getAgent());77System.out.println("Java System Properties:");78System.out.println();79sysProps.run();80System.out.println();81System.out.println("VM Flags:");82printVMFlags();83System.out.println();84}85};86}87break;8889default:90usage();91break;92}93tool.setAgent(getAgent());94tool.run();95}9697public void runWithArgs(String... args) {98int mode = -1;99switch (args.length) {100case 1:101if (args[0].charAt(0) == '-') {102// -h or -help or some invalid flag103usage();104} else {105mode = MODE_BOTH;106}107break;108case 2:109case 3: {110String modeFlag = args[0];111if (modeFlag.equals("-flags")) {112mode = MODE_FLAGS;113} else if (modeFlag.equals("-sysprops")) {114mode = MODE_SYSPROPS;115} else if (modeFlag.charAt(0) == '-') {116// -h or -help or some invalid flag117usage();118} else {119mode = MODE_BOTH;120}121122if (mode != MODE_BOTH) {123// we have to consume first flag argument.124String[] newArgs = new String[args.length - 1];125for (int i = 0; i < newArgs.length; i++) {126newArgs[i] = args[i + 1];127}128args = newArgs;129}130break;131}132133default:134usage();135}136137this.mode = mode;138execute(args);139}140141public static void main(String[] args) {142JInfo jinfo = new JInfo();143jinfo.runWithArgs(args);144}145146private void printVMFlags() {147VM.Flag[] flags = VM.getVM().getCommandLineFlags();148System.out.print("Non-default VM flags: ");149for (VM.Flag flag : flags) {150if (flag.getOrigin() == VM.Flags_DEFAULT) {151// only print flags which aren't their defaults152continue;153}154if (flag.isBool()) {155String onoff = flag.getBool() ? "+" : "-";156System.out.print("-XX:" + onoff + flag.getName() + " ");157} else {158System.out.print("-XX:" + flag.getName() + "="159+ flag.getValue() + " ");160}161}162System.out.println();163164System.out.print("Command line: ");165String str = Arguments.getJVMFlags();166if (str != null) {167System.out.print(str + " ");168}169str = Arguments.getJVMArgs();170if (str != null) {171System.out.print(str);172}173System.out.println();174}175176private int mode;177}178179180