author | iignatyev |
Sat, 19 Jul 2014 00:34:20 +0400 | |
changeset 25736 | 6f35dbe32581 |
parent 22490 | 039128291aa6 |
permissions | -rw-r--r-- |
22490
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
1 |
/* |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
2 |
* Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
4 |
* |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
8 |
* |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
13 |
* accompanied this code). |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
14 |
* |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
18 |
* |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
21 |
* questions. |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
22 |
*/ |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
23 |
|
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
24 |
import sun.management.ManagementFactoryHelper; |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
25 |
|
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
26 |
import com.sun.management.DiagnosticCommandMBean; |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
27 |
|
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
28 |
public class DcmdUtil |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
29 |
{ |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
30 |
public static String executeDcmd(String cmd, String ... args) { |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
31 |
DiagnosticCommandMBean dcmd = ManagementFactoryHelper.getDiagnosticCommandMBean(); |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
32 |
Object[] dcmdArgs = {args}; |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
33 |
String[] signature = {String[].class.getName()}; |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
34 |
|
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
35 |
try { |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
36 |
System.out.print("> " + cmd + " "); |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
37 |
for (String s : args) { |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
38 |
System.out.print(s + " "); |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
39 |
} |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
40 |
System.out.println(":"); |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
41 |
String result = (String) dcmd.invoke(transform(cmd), dcmdArgs, signature); |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
42 |
System.out.println(result); |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
43 |
return result; |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
44 |
} catch(Exception ex) { |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
45 |
ex.printStackTrace(); |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
46 |
} |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
47 |
return null; |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
48 |
} |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
49 |
|
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
50 |
private static String transform(String name) { |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
51 |
StringBuilder sb = new StringBuilder(); |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
52 |
boolean toLower = true; |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
53 |
boolean toUpper = false; |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
54 |
for (int i = 0; i < name.length(); i++) { |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
55 |
char c = name.charAt(i); |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
56 |
if (c == '.' || c == '_') { |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
57 |
toLower = false; |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
58 |
toUpper = true; |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
59 |
} else { |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
60 |
if (toUpper) { |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
61 |
toUpper = false; |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
62 |
sb.append(Character.toUpperCase(c)); |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
63 |
} else if(toLower) { |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
64 |
sb.append(Character.toLowerCase(c)); |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
65 |
} else { |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
66 |
sb.append(c); |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
67 |
} |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
68 |
} |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
69 |
} |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
70 |
return sb.toString(); |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
71 |
} |
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
72 |
|
039128291aa6
8031304: Add dcmd to print all loaded dynamic libraries.
farvidsson
parents:
diff
changeset
|
73 |
} |