jdk/src/jdk.jcmd/share/classes/sun/tools/jinfo/JInfo.java
author dsamersoff
Mon, 09 May 2016 23:41:59 +0300
changeset 38360 fb63be22ffa6
parent 36511 9d0388c6b336
child 38361 8ea2d56bfdf3
permissions -rw-r--r--
8155091: Remove SA related functions from tmtools Summary: Remove options that enables support for non-cooperative mode Reviewed-by: alanb, mchung, sla
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23939
63144ee0e772 8039080: "jinfo server_id@host" fails with "Invalid process identifier"
jbachorik
parents: 23740
diff changeset
     2
 * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.tools.jinfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
23058
2e261b4319e9 8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents: 23010
diff changeset
    28
import java.util.Arrays;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import com.sun.tools.attach.VirtualMachine;
23058
2e261b4319e9 8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents: 23010
diff changeset
    33
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.tools.attach.HotSpotVirtualMachine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * This class is the main class for the JInfo utility. It parses its arguments
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 14342
diff changeset
    38
 * and decides if the command should be satisfied using the VM attach mechanism
23058
2e261b4319e9 8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents: 23010
diff changeset
    39
 * or an SA tool.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 */
23939
63144ee0e772 8039080: "jinfo server_id@host" fails with "Invalid process identifier"
jbachorik
parents: 23740
diff changeset
    41
final public class JInfo {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
38360
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    43
    public static void main(String[] args) throws Exception {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        if (args.length == 0) {
38360
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    45
            usage(1); // no arguments
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        }
38360
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    47
        checkForUnsupportedOptions(args);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
38360
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    49
        boolean doFlag = false;
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    50
        boolean doFlags = false;
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    51
        boolean doSysprops = false;
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    52
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    53
        // Parse the options (arguments starting with "-" )
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    54
        int optionCount = 0;
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    55
        while (optionCount < args.length) {
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    56
            String arg = args[optionCount];
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    57
            if (!arg.startsWith("-")) {
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    58
                break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            }
38360
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    60
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    61
            optionCount++;
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    62
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    63
            if (arg.equals("-help") || arg.equals("-h")) {
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    64
                usage(0);
23058
2e261b4319e9 8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents: 23010
diff changeset
    65
            }
38360
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    66
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    67
            if (arg.equals("-flag")) {
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    68
                doFlag = true;
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    69
                continue;
23939
63144ee0e772 8039080: "jinfo server_id@host" fails with "Invalid process identifier"
jbachorik
parents: 23740
diff changeset
    70
            }
38360
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    71
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    72
            if (arg.equals("-flags")) {
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    73
                doFlags = true;
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    74
                continue;
23939
63144ee0e772 8039080: "jinfo server_id@host" fails with "Invalid process identifier"
jbachorik
parents: 23740
diff changeset
    75
            }
63144ee0e772 8039080: "jinfo server_id@host" fails with "Invalid process identifier"
jbachorik
parents: 23740
diff changeset
    76
38360
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    77
            if (arg.equals("-sysprops")) {
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    78
                doSysprops = true;
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    79
                continue;
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    80
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
38360
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    83
        // Next we check the parameter count. -flag allows extra parameters
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    84
        int paramCount = args.length - optionCount;
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    85
        if ((doFlag && paramCount != 2) || (paramCount != 1)) {
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    86
            usage(1);
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    87
        }
23058
2e261b4319e9 8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents: 23010
diff changeset
    88
38360
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    89
        if (!doFlag && !doFlags && !doSysprops) {
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    90
            // Print flags and sysporps if no options given
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    91
            sysprops(args[optionCount]);
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    92
            System.out.println();
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    93
            flags(args[optionCount]);
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    94
            System.out.println();
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    95
            commandLine(args[optionCount]);
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    96
        }
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    97
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    98
        if (doFlag) {
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
    99
            flag(args[optionCount+1], args[optionCount]);
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   100
        }
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   101
        else {
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   102
            if (doFlags) {
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   103
                flags(args[optionCount]);
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   104
            }
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   105
            else if (doSysprops) {
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   106
                sysprops(args[optionCount]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private static void flag(String pid, String option) throws IOException {
23058
2e261b4319e9 8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents: 23010
diff changeset
   112
        HotSpotVirtualMachine vm = (HotSpotVirtualMachine) attach(pid);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        String flag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        InputStream in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        int index = option.indexOf('=');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        if (index != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            flag = option.substring(0, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            String value = option.substring(index + 1);
23058
2e261b4319e9 8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents: 23010
diff changeset
   119
            in = vm.setFlag(flag, value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            char c = option.charAt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            switch (c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                case '+':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                    flag = option.substring(1);
23058
2e261b4319e9 8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents: 23010
diff changeset
   125
                    in = vm.setFlag(flag, "1");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                case '-':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                    flag = option.substring(1);
23058
2e261b4319e9 8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents: 23010
diff changeset
   129
                    in = vm.setFlag(flag, "0");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                    flag = option;
23058
2e261b4319e9 8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents: 23010
diff changeset
   133
                    in = vm.printFlag(flag);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        drain(vm, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
23058
2e261b4319e9 8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents: 23010
diff changeset
   141
    private static void flags(String pid) throws IOException {
2e261b4319e9 8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents: 23010
diff changeset
   142
        HotSpotVirtualMachine vm = (HotSpotVirtualMachine) attach(pid);
2e261b4319e9 8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents: 23010
diff changeset
   143
        InputStream in = vm.executeJCmd("VM.flags");
2e261b4319e9 8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents: 23010
diff changeset
   144
        System.out.println("VM Flags:");
2e261b4319e9 8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents: 23010
diff changeset
   145
        drain(vm, in);
2e261b4319e9 8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents: 23010
diff changeset
   146
    }
2e261b4319e9 8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents: 23010
diff changeset
   147
24569
9e8d972e5e3b 8041923: Command line output is missing from jinfo
sla
parents: 23939
diff changeset
   148
    private static void commandLine(String pid) throws IOException {
9e8d972e5e3b 8041923: Command line output is missing from jinfo
sla
parents: 23939
diff changeset
   149
        HotSpotVirtualMachine vm = (HotSpotVirtualMachine) attach(pid);
9e8d972e5e3b 8041923: Command line output is missing from jinfo
sla
parents: 23939
diff changeset
   150
        InputStream in = vm.executeJCmd("VM.command_line");
9e8d972e5e3b 8041923: Command line output is missing from jinfo
sla
parents: 23939
diff changeset
   151
        drain(vm, in);
9e8d972e5e3b 8041923: Command line output is missing from jinfo
sla
parents: 23939
diff changeset
   152
    }
9e8d972e5e3b 8041923: Command line output is missing from jinfo
sla
parents: 23939
diff changeset
   153
23058
2e261b4319e9 8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents: 23010
diff changeset
   154
    private static void sysprops(String pid) throws IOException {
2e261b4319e9 8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents: 23010
diff changeset
   155
        HotSpotVirtualMachine vm = (HotSpotVirtualMachine) attach(pid);
2e261b4319e9 8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents: 23010
diff changeset
   156
        InputStream in = vm.executeJCmd("VM.system_properties");
2e261b4319e9 8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents: 23010
diff changeset
   157
        System.out.println("Java System Properties:");
2e261b4319e9 8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents: 23010
diff changeset
   158
        drain(vm, in);
2e261b4319e9 8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents: 23010
diff changeset
   159
    }
2e261b4319e9 8036599: Use Diagnostic Commands instead of SA by default in jinfo
sla
parents: 23010
diff changeset
   160
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    // Attach to <pid>, exiting if we fail to attach
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    private static VirtualMachine attach(String pid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            return VirtualMachine.attach(pid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            String msg = x.getMessage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            if (msg != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                System.err.println(pid + ": " + msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                x.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            return null; // keep compiler happy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    // Read the stream from the target VM until EOF, then detach
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    private static void drain(VirtualMachine vm, InputStream in) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        // read to EOF and just print output
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        byte b[] = new byte[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        int n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            n = in.read(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            if (n > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                String s = new String(b, 0, n, "UTF-8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                System.out.print(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        } while (n > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        in.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        vm.detach();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
38360
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   193
    private static void checkForUnsupportedOptions(String[] args) {
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   194
        // Check arguments for -F, and non-numeric value
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   195
        // and warn the user that SA is not supported anymore
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
38360
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   197
        int paramCount = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
38360
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   199
        for (String s : args) {
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   200
            if (s.equals("-F")) {
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   201
                SAOptionError("-F option used");
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   202
            }
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   203
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   204
            if (! s.startsWith("-")) {
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   205
                if (! s.matches("[0-9]+")) {
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   206
                   SAOptionError("non PID argument");
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   207
                }
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   208
                paramCount += 1;
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   209
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
38360
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   212
        if (paramCount > 1) {
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   213
            SAOptionError("More than one non-option argument");
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   214
        }
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   215
    }
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   216
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   217
    private static void SAOptionError(String msg) {
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   218
        System.err.println("Error: " + msg);
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   219
        System.err.println("Cannot connect to core dump or remote debug server. Use jhsdb jinfo instead");
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   220
        System.exit(1);
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   221
    }
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   222
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   223
     // print usage message
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   224
    private static void usage(int exit) {
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   225
        System.err.println("Usage:");
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   226
        System.err.println("    jinfo <option> <pid>");
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   227
        System.err.println("       (to connect to a running process)");
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   228
        System.err.println("");
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   229
        System.err.println("where <option> is one of:");
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   230
        System.err.println("    -flag <name>         to print the value of the named VM flag");
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   231
        System.err.println("    -flag [+|-]<name>    to enable or disable the named VM flag");
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   232
        System.err.println("    -flag <name>=<value> to set the named VM flag to the given value");
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   233
        System.err.println("    -flags               to print VM flags");
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   234
        System.err.println("    -sysprops            to print Java system properties");
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   235
        System.err.println("    <no option>          to print both VM flags and system properties");
fb63be22ffa6 8155091: Remove SA related functions from tmtools
dsamersoff
parents: 36511
diff changeset
   236
        System.err.println("    -h | -help           to print this help message");
21673
c5d341bc60dd 8027765: Make exit codes and stdout/stderr printing from jmap/jinfo/jstack/jps consistent
sla
parents: 21278
diff changeset
   237
        System.exit(exit);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
}