1 | /** |
2 | * |
3 | */ |
4 | package net.sf.madmap; |
5 | |
6 | import java.lang.management.ManagementFactory; |
7 | |
8 | import javax.management.MBeanServer; |
9 | import javax.management.ObjectName; |
10 | import javax.swing.JOptionPane; |
11 | import org.springframework.context.*; |
12 | import org.springframework.context.support.*; |
13 | /** |
14 | * MadmapMain is the main class of the application, it launches the primordial |
15 | * window or starts execution if running cmd-line only. |
16 | * |
17 | * @author ecaspole |
18 | * |
19 | */ |
20 | public class MadmapMain { |
21 | |
22 | static boolean _runDumpPhase = false; |
23 | static boolean _runAnalysisPhase = true; |
24 | static int _concurrency = Runtime.getRuntime().availableProcessors(); // 1; |
25 | static int _running = 0; |
26 | static boolean _verbose = false; |
27 | static boolean _saveMemberNames = true; |
28 | static boolean _printFinalizers = true; |
29 | static boolean _do_recursive_children_size = false; |
30 | static boolean _do_gc = false; |
31 | static boolean _jdk14_compatible = true; |
32 | static boolean _nogui = false; |
33 | static boolean _testFeature = false; |
34 | |
35 | static ApplicationContext _appContext = new ClassPathXmlApplicationContext("madmapContext.xml"); |
36 | |
37 | public static ApplicationContext appContext() { return _appContext; } |
38 | static ILogger _logger = (ILogger)(MadmapMain.appContext()).getBean("logger"); |
39 | static IResources _resources = (IResources)(MadmapMain.appContext()).getBean("resources"); |
40 | |
41 | static Object _guiLock = new Object(); |
42 | |
43 | public static void guiNotify() { |
44 | synchronized( _guiLock ) { |
45 | _guiLock.notify(); |
46 | } |
47 | } |
48 | |
49 | public static boolean runDump() { return _runDumpPhase; } |
50 | public static boolean runAnalysis() { return _runAnalysisPhase; } |
51 | public static boolean runSystemGC() { return _do_gc; } |
52 | public static boolean runRecursiveChildrenSize() { return _do_recursive_children_size; } |
53 | public static void setVerbose(boolean newVal) { _verbose = newVal; } |
54 | public static boolean verbose() { return _verbose; } |
55 | public static void setSaveMemberNames(boolean newVal) { _saveMemberNames = newVal; } |
56 | public static boolean getSaveMemberNames() { return _saveMemberNames; } |
57 | |
58 | public static boolean printFinalizers() { return _printFinalizers; } |
59 | public static boolean noGUI() { return _nogui; } |
60 | public static boolean testFeature() { return _testFeature; } |
61 | public static boolean jdk14_compatible() { return _jdk14_compatible; } |
62 | public static int concurrency() { return _concurrency; } |
63 | |
64 | public static void waitForGui() { |
65 | try { |
66 | synchronized( _guiLock ) { |
67 | _guiLock.wait(); |
68 | } |
69 | } catch( InterruptedException ie ) { |
70 | System. out. println ( "Error opening file : Caught " + ie ); |
71 | ie.printStackTrace(); |
72 | } |
73 | } |
74 | |
75 | public static void usage() { |
76 | System.out.println(_resources.getString("usageStrs")); |
77 | } |
78 | |
79 | /** |
80 | * @param args |
81 | */ |
82 | public static void main( String argv[] ) |
83 | { |
84 | String name = null; |
85 | String arg; |
86 | boolean seenFile = false; |
87 | boolean firstTime = true; |
88 | |
89 | try { |
90 | for ( int i = 0; i < argv.length; i++ ) { |
91 | if ( argv[ i ].equals( "-d" ) ) { |
92 | _runDumpPhase = true; |
93 | } else if ( argv[ i ].equals( "-a" ) ) { |
94 | _runAnalysisPhase = true; |
95 | } else if ( argv[ i ].equals( "-c" ) ) { |
96 | _do_gc = true; |
97 | } else if ( argv[ i ].equals( "-f" ) ) { |
98 | _printFinalizers = true; |
99 | } else if ( argv[ i ].equals( "-h" ) ) { |
100 | usage(); |
101 | return; |
102 | } else if ( argv[ i ].equals( "-n" ) ) { |
103 | _nogui = true; |
104 | } else if ( argv[ i ].equals( "-m" ) ) { |
105 | _saveMemberNames = false; |
106 | } else if ( argv[ i ].equals( "-r" ) ) { |
107 | _do_recursive_children_size = true; |
108 | } else if ( argv[ i ].equals( "-u" ) ) { |
109 | _concurrency = 1; |
110 | } else if ( argv[ i ].equals( "-x" ) ) { |
111 | _testFeature = true; |
112 | |
113 | } else if ( argv[ i ].equals( "-v" ) ) { |
114 | _verbose = true; |
115 | //} else if ( argv[ i ].equals( "-y" ) ) { |
116 | // _jdk14_compatible = true; |
117 | } else { |
118 | if (argv[ i ].startsWith("-") == false) { |
119 | if ( seenFile == false ) { |
120 | name = argv[ i ]; |
121 | seenFile = true; |
122 | } else { |
123 | System.out.println( "Unknown:" + argv[ i ] ); |
124 | usage(); |
125 | return; |
126 | } |
127 | } |
128 | } |
129 | } |
130 | } catch (ArrayIndexOutOfBoundsException e) { // argv is empty |
131 | System.out.println("Must specify an argument"); |
132 | usage(); |
133 | return; |
134 | } |
135 | |
136 | usage(); |
137 | |
138 | if ( _nogui ) { |
139 | try { |
140 | Madmap app = new Madmap( name ); |
141 | app.init(); |
142 | } catch (OutOfMemoryError e) { |
143 | System.out.println("OutOfMemoryError in main thread. Relaunch Madmap with larger heap size."); |
144 | e.printStackTrace(); |
145 | System.exit(-1); |
146 | } catch (Exception e) { |
147 | System.out.println("Exception in main: " + e); |
148 | e.printStackTrace(); |
149 | return; |
150 | } |
151 | } else { |
152 | MainWindow.init(); |
153 | waitForGui(); |
154 | |
155 | //System. out. println ( "======== All System Properties ========" ); |
156 | //System.getProperties().list(System. out); |
157 | //System. out. println ( "=======================================" ); |
158 | |
159 | while ( true ) { |
160 | waitForGui(); |
161 | } |
162 | } |
163 | } |
164 | } |