-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetVMOptions.java
executable file
·70 lines (68 loc) · 2.42 KB
/
GetVMOptions.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.util.ArrayList;
import java.util.List;
import java.lang.Class;
import java.lang.management.ManagementFactory;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import javax.management.MBeanServer;
import com.sun.management.HotSpotDiagnosticMXBean;
import com.sun.management.VMOption;
import com.sun.management.VMOption.Origin;
public class GetVMOptions {
public static void main(String[] args) {
MBeanServer pfServer = ManagementFactory.getPlatformMBeanServer();
HotSpotDiagnosticMXBean proxy = null;
try {
proxy = ManagementFactory.newPlatformMXBeanProxy(pfServer,
"com.sun.management:type=HotSpotDiagnostic",
HotSpotDiagnosticMXBean.class);
} catch (Exception e) {
e.printStackTrace();
}
//List<VMOption> options = proxy.getDiagnosticOptions();
ClassLoader cl = GetVMOptions.class.getClassLoader();
Class clazz = null;
try {
clazz = cl.loadClass("sun.management.Flag");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Constructor cons = null;
try {
Class[] types = new Class[] {String.class, Object.class, boolean.class, boolean.class, Origin.class};
cons = clazz.getDeclaredConstructor(types);
} catch (java.lang.NoSuchMethodException e) {
e.printStackTrace();
}
cons.setAccessible(true);
Method getAllFlags = null;
Method getVMOption = null;
try {
getAllFlags = clazz.getDeclaredMethod("getAllFlags", new Class[]{});
getVMOption = clazz.getDeclaredMethod("getVMOption", new Class[]{});
} catch (java.lang.NoSuchMethodException e) {
e.printStackTrace();
}
getAllFlags.setAccessible(true);
getVMOption.setAccessible(true);
Object ret = null;
try {
ret = getAllFlags.invoke(new Object[]{});
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (java.lang.reflect.InvocationTargetException e) {
e.printStackTrace();
}
for (Object flag : (List<Object>)ret) {
try {
System.out.println((VMOption)(getVMOption.invoke(flag, new Object[]{})));
} catch (NullPointerException e) {
//e.printStackTrace();
} catch (IllegalAccessException e) {
//e.printStackTrace();
} catch (java.lang.reflect.InvocationTargetException e) {
//e.printStackTrace();
}
}
}
}