/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* This class is the main class for the JMap utility. It parses its arguments
* and decides if the command should be satisifed using the VM attach mechanism
* or an SA tool. At this time the only option that uses the VM attach mechanism
* is the -dump option to get a heap dump of a running application. All other
* options are mapped to SA tools.
*/
public class JMap {
// Options handled by the attach mechanism
// These options imply the use of a SA tool
"-heap|-heap:format=b|-permstat|-finalizerinfo";
// The -F (force) option is currently not passed through to SA
// Default option (if nothing provided)
usage(); // no arguments
}
// used to indicate if we should use SA
boolean useSA = false;
// the chosen option (-heap, -dump:*, ... )
// First iterate over the options (arguments starting with -). There should be
// one (but maybe two if -F is also used).
int optionCount = 0;
break;
}
useSA = true;
} else {
usage(); // option already specified
}
}
optionCount++;
}
// if no option provided then use default.
}
useSA = true;
}
// Next we check the parameter count. For the SA tools there are
// one or two parameters. For the built-in -dump option there is
// only one parameter (the process-id)
usage();
}
useSA = true;
} else {
// the parameter for the -dump option is a process-id.
// If it doesn't parse to a number then it must be SA
// debug server
useSA = true;
}
}
// at this point we know if we are executing an SA tool or a built-in
// option.
if (useSA) {
// parameters (<pid> or <exe> <core>)
}
} else {
// Here we handle the built-in options
// As more options are added we should create an abstract tool class and
// have a table to map the options
} else {
usage();
}
}
}
// Invoke SA tool with the given arguments
{ "-pmap", "sun.jvm.hotspot.tools.PMap" },
{ "-heap", "sun.jvm.hotspot.tools.HeapSummary" },
{ "-heap:format=b", "sun.jvm.hotspot.tools.HeapDumper" },
{ "-histo", "sun.jvm.hotspot.tools.ObjectHistogram" },
{ "-permstat", "sun.jvm.hotspot.tools.PermStat" },
{ "-finalizerinfo", "sun.jvm.hotspot.tools.FinalizerInfo" },
};
// -dump option needs to be handled in a special way
// first check that the option can be parsed
// tool for heap dumping
tool = "sun.jvm.hotspot.tools.HeapDumper";
// HeapDumper -f <file>
} else {
int i=0;
break;
}
i++;
}
}
usage(); // no mapping to tool
}
// Tool not available on this platform.
if (c == null) {
usage();
}
// invoke the main method with the arguments
}
// loads the given class using the system class loader
//
// We specify the system clas loader so as to cater for development
// environments where this class is on the boot class path but sa-jdi.jar
// is on the system class path. Once the JDK is deployed then both
// tools.jar and sa-jdi.jar are on the system class path.
//
try {
} catch (Exception x) { }
return null;
}
}
// parse the options to get the dump filename
usage(); // invalid options or no filename
}
// get the canonical path - important to avoid just passing
// a "heap.bin" and having the dump created in the target VM
// working directory rather than the directory where jmap
// is executed.
// dump live objects only or not
}
// Parse the options to the -dump option. Valid options are format=b and
// file=<file>. Returns <file> if provided. Returns null if <file> not
// provided, or invalid option.
// options are separated by comma (,)
// ignore format (not needed at this time)
// a valid suboption
} else {
// file=<file> - check that <file> is specified
return null;
}
} else {
return null; // option not recognized
}
}
}
return filename;
}
// options are separated by comma (,)
return true;
}
}
return false;
}
// Attach to <pid>, existing if we fail to attach
try {
} catch (Exception x) {
} else {
x.printStackTrace();
}
if ((x instanceof AttachNotSupportedException) && haveSA()) {
"target process is not responding");
}
return null; // keep compiler happy
}
}
// Read the stream from the target VM until EOF, then detach
// read to EOF and just print output
byte b[] = new byte[256];
int n;
do {
if (n > 0) {
}
} while (n > 0);
}
// return a new string array with arg as the first element
return newargs;
}
// returns true if SA is available
private static boolean haveSA() {
return (c != null);
}
// print usage message
private static void usage() {
if (haveSA()) {
} else {
}
}
}