comparison agent/src/share/classes/sun/jvm/hotspot/tools/Tool.java @ 13388:5280822ddfcd

6626412: jstack using SA prints some info messages into err stream Reviewed-by: coleenp, farvidsson, jbachorik, dsamersoff, sspitsyn
author sla
date Thu, 14 Nov 2013 20:03:15 +0100
parents 7fe6ef09d242
children de6a9e811145
comparison
equal deleted inserted replaced
13387:b03f33670080 13388:5280822ddfcd
23 */ 23 */
24 24
25 package sun.jvm.hotspot.tools; 25 package sun.jvm.hotspot.tools;
26 26
27 import java.io.PrintStream; 27 import java.io.PrintStream;
28 import java.util.Hashtable; 28
29 29 import sun.jvm.hotspot.HotSpotAgent;
30 import sun.jvm.hotspot.*; 30 import sun.jvm.hotspot.debugger.DebuggerException;
31 import sun.jvm.hotspot.runtime.*; 31 import sun.jvm.hotspot.debugger.JVMDebugger;
32 import sun.jvm.hotspot.debugger.*; 32 import sun.jvm.hotspot.runtime.VM;
33 33
34 // generic command line or GUI tool. 34 // generic command line or GUI tool.
35 // override run & code main as shown below. 35 // override run & code main as shown below.
36 36
37 public abstract class Tool implements Runnable { 37 public abstract class Tool implements Runnable {
145 usage(); 145 usage();
146 return 1; 146 return 1;
147 } 147 }
148 148
149 PrintStream err = System.err; 149 PrintStream err = System.err;
150 PrintStream out = System.out;
150 151
151 int pid = 0; 152 int pid = 0;
152 String coreFileName = null; 153 String coreFileName = null;
153 String executableName = null; 154 String executableName = null;
154 String remoteServer = null; 155 String remoteServer = null;
178 179
179 agent = new HotSpotAgent(); 180 agent = new HotSpotAgent();
180 try { 181 try {
181 switch (debugeeType) { 182 switch (debugeeType) {
182 case DEBUGEE_PID: 183 case DEBUGEE_PID:
183 err.println("Attaching to process ID " + pid + ", please wait..."); 184 out.println("Attaching to process ID " + pid + ", please wait...");
184 agent.attach(pid); 185 agent.attach(pid);
185 break; 186 break;
186 187
187 case DEBUGEE_CORE: 188 case DEBUGEE_CORE:
188 err.println("Attaching to core " + coreFileName + 189 out.println("Attaching to core " + coreFileName +
189 " from executable " + executableName + ", please wait..."); 190 " from executable " + executableName + ", please wait...");
190 agent.attach(executableName, coreFileName); 191 agent.attach(executableName, coreFileName);
191 break; 192 break;
192 193
193 case DEBUGEE_REMOTE: 194 case DEBUGEE_REMOTE:
194 err.println("Attaching to remote server " + remoteServer + ", please wait..."); 195 out.println("Attaching to remote server " + remoteServer + ", please wait...");
195 agent.attach(remoteServer); 196 agent.attach(remoteServer);
196 break; 197 break;
197 } 198 }
198 } 199 }
199 catch (DebuggerException e) { 200 catch (DebuggerException e) {
216 } 217 }
217 err.println(); 218 err.println();
218 return 1; 219 return 1;
219 } 220 }
220 221
221 err.println("Debugger attached successfully."); 222 out.println("Debugger attached successfully.");
222 startInternal(); 223 startInternal();
223 return 0; 224 return 0;
224 } 225 }
225 226
226 // When using an existing JVMDebugger. 227 // When using an existing JVMDebugger.
235 } 236 }
236 237
237 // Remains of the start mechanism, common to both start methods. 238 // Remains of the start mechanism, common to both start methods.
238 private void startInternal() { 239 private void startInternal() {
239 240
240 PrintStream err = System.err; 241 PrintStream out = System.out;
241 VM vm = VM.getVM(); 242 VM vm = VM.getVM();
242 if (vm.isCore()) { 243 if (vm.isCore()) {
243 err.println("Core build detected."); 244 out.println("Core build detected.");
244 } else if (vm.isClientCompiler()) { 245 } else if (vm.isClientCompiler()) {
245 err.println("Client compiler detected."); 246 out.println("Client compiler detected.");
246 } else if (vm.isServerCompiler()) { 247 } else if (vm.isServerCompiler()) {
247 err.println("Server compiler detected."); 248 out.println("Server compiler detected.");
248 } else { 249 } else {
249 throw new RuntimeException("Fatal error: " 250 throw new RuntimeException("Fatal error: "
250 + "should have been able to detect core/C1/C2 build"); 251 + "should have been able to detect core/C1/C2 build");
251 } 252 }
252 253
253 String version = vm.getVMRelease(); 254 String version = vm.getVMRelease();
254 if (version != null) { 255 if (version != null) {
255 err.print("JVM version is "); 256 out.print("JVM version is ");
256 err.println(version); 257 out.println(version);
257 } 258 }
258 259
259 run(); 260 run();
260 } 261 }
261 } 262 }