152 String filename = opt.substring(5);
153 try {
154 // Get the canonical path - important to avoid just
155 // passing a "heap.bin" and having the dump created
156 // in the target VM working directory rather than the
157 // directory where jmap is executed.
158 return new File(filename).getCanonicalPath();
159 } catch (IOException ioe) {
160 return null;
161 }
162 }
163 // no filename
164 return null;
165 }
166
167 private static void histo(String pid, String options)
168 throws AttachNotSupportedException, IOException,
169 UnsupportedEncodingException {
170 String liveopt = "-all";
171 String filename = null;
172 String subopts[] = options.split(",");
173
174 for (int i = 0; i < subopts.length; i++) {
175 String subopt = subopts[i];
176 if (subopt.equals("") || subopt.equals("all")) {
177 // pass
178 } else if (subopt.equals("live")) {
179 liveopt = "-live";
180 } else if (subopt.startsWith("file=")) {
181 filename = parseFileName(subopt);
182 if (filename == null) {
183 usage(1); // invalid options or no filename
184 }
185 } else {
186 usage(1);
187 }
188 }
189
190 System.out.flush();
191
192 // inspectHeap is not the same as jcmd GC.class_histogram
193 executeCommandForPid(pid, "inspectheap", liveopt, filename);
194 }
195
196 private static void dump(String pid, String options)
197 throws AttachNotSupportedException, IOException,
198 UnsupportedEncodingException {
199
200 String subopts[] = options.split(",");
201 String filename = null;
202 String liveopt = "-all";
203
204 for (int i = 0; i < subopts.length; i++) {
205 String subopt = subopts[i];
206 if (subopt.equals("live")) {
207 liveopt = "-live";
208 } else if (subopt.startsWith("file=")) {
209 filename = parseFileName(subopt);
210 }
211 }
212
213 if (filename == null) {
270 System.err.println(" to connect to running process and print information on objects awaiting finalization");
271 System.err.println(" jmap -histo[:[<histo-options>]] <pid>");
272 System.err.println(" to connect to running process and print histogram of java object heap");
273 System.err.println(" jmap -dump:<dump-options> <pid>");
274 System.err.println(" to connect to running process and dump java heap");
275 System.err.println(" jmap -? -h --help");
276 System.err.println(" to print this help message");
277 System.err.println("");
278 System.err.println(" dump-options:");
279 System.err.println(" live dump only live objects");
280 System.err.println(" all dump all objects in the heap (default if one of \"live\" or \"all\" is not specified");
281 System.err.println(" format=b binary format");
282 System.err.println(" file=<file> dump heap to <file>");
283 System.err.println("");
284 System.err.println(" Example: jmap -dump:live,format=b,file=heap.bin <pid>");
285 System.err.println("");
286 System.err.println(" histo-options:");
287 System.err.println(" live count only live objects");
288 System.err.println(" all count all objects in the heap (default if one of \"live\" or \"all\" is not specified)");
289 System.err.println(" file=<file> dump data to <file>");
290 System.err.println("");
291 System.err.println(" Example: jmap -histo:live,file=/tmp/histo.data <pid>");
292 System.exit(exit);
293 }
294 }
|
152 String filename = opt.substring(5);
153 try {
154 // Get the canonical path - important to avoid just
155 // passing a "heap.bin" and having the dump created
156 // in the target VM working directory rather than the
157 // directory where jmap is executed.
158 return new File(filename).getCanonicalPath();
159 } catch (IOException ioe) {
160 return null;
161 }
162 }
163 // no filename
164 return null;
165 }
166
167 private static void histo(String pid, String options)
168 throws AttachNotSupportedException, IOException,
169 UnsupportedEncodingException {
170 String liveopt = "-all";
171 String filename = null;
172 String parallel = null;
173 String subopts[] = options.split(",");
174 boolean set_all = false;
175 boolean set_live = false;
176
177 for (int i = 0; i < subopts.length; i++) {
178 String subopt = subopts[i];
179 if (subopt.equals("") || subopt.equals("all")) {
180 set_all = true;
181 liveopt = "-all";
182 } else if (subopt.equals("live")) {
183 // Add '-' for compatibility.
184 set_live = true;
185 liveopt = "-live";
186 } else if (subopt.startsWith("file=")) {
187 filename = parseFileName(subopt);
188 if (filename == null) {
189 usage(1); // invalid options or no filename
190 }
191 } else if (subopt.startsWith("parallel=")) {
192 parallel = subopt.substring("parallel=".length());
193 if (parallel == null) {
194 usage(1);
195 }
196 } else {
197 usage(1);
198 }
199 }
200 if (set_live && set_all) {
201 usage(1);
202 }
203
204 System.out.flush();
205 // inspectHeap is not the same as jcmd GC.class_histogram
206 executeCommandForPid(pid, "inspectheap", liveopt, filename, parallel);
207 }
208
209 private static void dump(String pid, String options)
210 throws AttachNotSupportedException, IOException,
211 UnsupportedEncodingException {
212
213 String subopts[] = options.split(",");
214 String filename = null;
215 String liveopt = "-all";
216
217 for (int i = 0; i < subopts.length; i++) {
218 String subopt = subopts[i];
219 if (subopt.equals("live")) {
220 liveopt = "-live";
221 } else if (subopt.startsWith("file=")) {
222 filename = parseFileName(subopt);
223 }
224 }
225
226 if (filename == null) {
283 System.err.println(" to connect to running process and print information on objects awaiting finalization");
284 System.err.println(" jmap -histo[:[<histo-options>]] <pid>");
285 System.err.println(" to connect to running process and print histogram of java object heap");
286 System.err.println(" jmap -dump:<dump-options> <pid>");
287 System.err.println(" to connect to running process and dump java heap");
288 System.err.println(" jmap -? -h --help");
289 System.err.println(" to print this help message");
290 System.err.println("");
291 System.err.println(" dump-options:");
292 System.err.println(" live dump only live objects");
293 System.err.println(" all dump all objects in the heap (default if one of \"live\" or \"all\" is not specified");
294 System.err.println(" format=b binary format");
295 System.err.println(" file=<file> dump heap to <file>");
296 System.err.println("");
297 System.err.println(" Example: jmap -dump:live,format=b,file=heap.bin <pid>");
298 System.err.println("");
299 System.err.println(" histo-options:");
300 System.err.println(" live count only live objects");
301 System.err.println(" all count all objects in the heap (default if one of \"live\" or \"all\" is not specified)");
302 System.err.println(" file=<file> dump data to <file>");
303 System.err.println(" parallel=<number> parallel threads number for heap iteration:");
304 System.err.println(" parallel=0 default behavior, use predefined number of threads");
305 System.err.println(" parallel=1 disable parallel heap iteration");
306 System.err.println(" parallel=<N> use N threads for parallel heap iteration");
307 System.err.println("");
308 System.err.println(" Example: jmap -histo:live,file=/tmp/histo.data <pid>");
309 System.exit(exit);
310 }
311 }
|