Mercurial > hg > truffle
annotate agent/src/share/classes/sun/jvm/hotspot/debugger/remote/RemoteDebuggerClient.java @ 6073:78d2ae5ab35b
7163117: Agent can't connect to process on Mac OSX
Reviewed-by: dholmes, coleenp, sla, minqi, kvn
author | nloodin |
---|---|
date | Wed, 09 May 2012 16:24:07 +0200 |
parents | c18cbe5936b8 |
children | a9fed06c01d2 |
rev | line source |
---|---|
0 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
844
diff
changeset
|
2 * Copyright (c) 2002, 2009, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
844
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
844
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
844
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 package sun.jvm.hotspot.debugger.remote; | |
26 | |
27 import java.rmi.*; | |
28 import java.util.*; | |
29 | |
30 import sun.jvm.hotspot.debugger.*; | |
31 import sun.jvm.hotspot.debugger.cdbg.*; | |
32 import sun.jvm.hotspot.debugger.remote.sparc.*; | |
33 import sun.jvm.hotspot.debugger.remote.x86.*; | |
34 import sun.jvm.hotspot.debugger.remote.amd64.*; | |
35 | |
36 /** An implementation of Debugger which wraps a | |
37 RemoteDebugger, providing remote debugging via RMI. | |
38 This implementation provides caching of the remote process's | |
39 address space on the local machine where the user interface is | |
40 running. */ | |
41 | |
42 public class RemoteDebuggerClient extends DebuggerBase implements JVMDebugger { | |
43 private RemoteDebugger remoteDebugger; | |
44 private RemoteThreadFactory threadFactory; | |
45 private boolean unalignedAccessesOkay = false; | |
46 private static final int cacheSize = 16 * 1024 * 1024; // 16 MB | |
47 | |
48 public RemoteDebuggerClient(RemoteDebugger remoteDebugger) throws DebuggerException { | |
49 super(); | |
50 try { | |
51 this.remoteDebugger = remoteDebugger; | |
52 machDesc = remoteDebugger.getMachineDescription(); | |
53 utils = new DebuggerUtilities(machDesc.getAddressSize(), machDesc.isBigEndian()); | |
54 int cacheNumPages; | |
55 int cachePageSize; | |
56 String cpu = remoteDebugger.getCPU(); | |
57 // page size. (FIXME: should pick this up from the remoteDebugger.) | |
58 if (cpu.equals("sparc")) { | |
59 threadFactory = new RemoteSPARCThreadFactory(this); | |
60 cachePageSize = 8192; | |
61 cacheNumPages = parseCacheNumPagesProperty(cacheSize / cachePageSize); | |
62 } else if (cpu.equals("x86")) { | |
63 threadFactory = new RemoteX86ThreadFactory(this); | |
64 cachePageSize = 4096; | |
65 cacheNumPages = parseCacheNumPagesProperty(cacheSize / cachePageSize); | |
66 unalignedAccessesOkay = true; | |
6073
78d2ae5ab35b
7163117: Agent can't connect to process on Mac OSX
nloodin
parents:
1552
diff
changeset
|
67 } else if (cpu.equals("amd64") || cpu.equals("x86_64")) { |
0 | 68 threadFactory = new RemoteAMD64ThreadFactory(this); |
69 cachePageSize = 4096; | |
70 cacheNumPages = parseCacheNumPagesProperty(cacheSize / cachePageSize); | |
71 unalignedAccessesOkay = true; | |
72 } else { | |
73 throw new DebuggerException("Thread access for CPU architecture " + cpu + " not yet supported"); | |
74 } | |
75 | |
76 // Cache portion of the remote process's address space. | |
77 initCache(cachePageSize, cacheNumPages); | |
78 | |
79 jbooleanSize = remoteDebugger.getJBooleanSize(); | |
80 jbyteSize = remoteDebugger.getJByteSize(); | |
81 jcharSize = remoteDebugger.getJCharSize(); | |
82 jdoubleSize = remoteDebugger.getJDoubleSize(); | |
83 jfloatSize = remoteDebugger.getJFloatSize(); | |
84 jintSize = remoteDebugger.getJIntSize(); | |
85 jlongSize = remoteDebugger.getJLongSize(); | |
86 jshortSize = remoteDebugger.getJShortSize(); | |
87 javaPrimitiveTypesConfigured = true; | |
642
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
196
diff
changeset
|
88 narrowOopBase = remoteDebugger.getNarrowOopBase(); |
660978a2a31a
6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents:
196
diff
changeset
|
89 narrowOopShift = remoteDebugger.getNarrowOopShift(); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
90 heapOopSize = remoteDebugger.getHeapOopSize(); |
0 | 91 } |
92 catch (RemoteException e) { | |
93 throw new DebuggerException(e); | |
94 } | |
95 } | |
96 | |
97 public long[] getThreadIntegerRegisterSet(Address addr) { | |
98 try { | |
99 return remoteDebugger.getThreadIntegerRegisterSet(getAddressValue(addr), true); | |
100 } | |
101 catch (RemoteException e) { | |
102 throw new DebuggerException(e); | |
103 } | |
104 } | |
105 | |
106 public long[] getThreadIntegerRegisterSet(long id) { | |
107 try { | |
108 return remoteDebugger.getThreadIntegerRegisterSet(id, false); | |
109 } | |
110 catch (RemoteException e) { | |
111 throw new DebuggerException(e); | |
112 } | |
113 } | |
114 | |
115 /** Unimplemented in this class (remote remoteDebugger should already be attached) */ | |
116 public boolean hasProcessList() throws DebuggerException { | |
117 throw new DebuggerException("Should not be called on RemoteDebuggerClient"); | |
118 } | |
119 | |
120 /** Unimplemented in this class (remote remoteDebugger should already be attached) */ | |
121 public List getProcessList() throws DebuggerException { | |
122 throw new DebuggerException("Should not be called on RemoteDebuggerClient"); | |
123 } | |
124 | |
125 /** Unimplemented in this class (remote remoteDebugger should already be attached) */ | |
126 public void attach(int processID) throws DebuggerException { | |
127 throw new DebuggerException("Should not be called on RemoteDebuggerClient"); | |
128 } | |
129 | |
130 /** Unimplemented in this class (remote remoteDebugger should already be attached) */ | |
131 public void attach(String executableName, String coreFileName) throws DebuggerException { | |
132 throw new DebuggerException("Should not be called on RemoteDebuggerClient"); | |
133 } | |
134 | |
135 /** Unimplemented in this class (remote remoteDebugger can not be detached) */ | |
136 public boolean detach() { | |
137 throw new DebuggerException("Should not be called on RemoteDebuggerClient"); | |
138 } | |
139 | |
140 public Address parseAddress(String addressString) throws NumberFormatException { | |
141 long addr = utils.scanAddress(addressString); | |
142 if (addr == 0) { | |
143 return null; | |
144 } | |
145 return new RemoteAddress(this, addr); | |
146 } | |
147 | |
148 public String getOS() throws DebuggerException { | |
149 try { | |
150 return remoteDebugger.getOS(); | |
151 } | |
152 catch (RemoteException e) { | |
153 throw new DebuggerException(e); | |
154 } | |
155 } | |
156 | |
157 public String getCPU() { | |
158 try { | |
159 return remoteDebugger.getCPU(); | |
160 } | |
161 catch (RemoteException e) { | |
162 throw new DebuggerException(e); | |
163 } | |
164 } | |
165 | |
166 public boolean hasConsole() throws DebuggerException { | |
167 try { | |
168 return remoteDebugger.hasConsole(); | |
169 } catch (RemoteException e) { | |
170 throw new DebuggerException(e); | |
171 } | |
172 } | |
173 | |
174 public String consoleExecuteCommand(String cmd) throws DebuggerException { | |
175 try { | |
176 return remoteDebugger.consoleExecuteCommand(cmd); | |
177 } | |
178 catch (RemoteException e) { | |
179 throw new DebuggerException(e); | |
180 } | |
181 } | |
182 | |
183 public String getConsolePrompt() throws DebuggerException { | |
184 try { | |
185 return remoteDebugger.getConsolePrompt(); | |
186 } catch (RemoteException e) { | |
187 throw new DebuggerException(e); | |
188 } | |
189 } | |
190 | |
191 public CDebugger getCDebugger() throws DebuggerException { | |
192 return null; | |
193 } | |
194 | |
195 //-------------------------------------------------------------------------------- | |
196 // Implementation of SymbolLookup interface | |
197 | |
198 public Address lookup(String objectName, String symbol) { | |
199 try { | |
200 long addr = remoteDebugger.lookupInProcess(objectName, symbol); | |
201 if (addr == 0) { | |
202 return null; | |
203 } | |
204 return new RemoteAddress(this, addr); | |
205 } | |
206 catch (RemoteException e) { | |
207 throw new DebuggerException(e); | |
208 } | |
209 } | |
210 | |
211 public OopHandle lookupOop(String objectName, String symbol) { | |
212 try { | |
213 long addr = remoteDebugger.lookupInProcess(objectName, symbol); | |
214 if (addr == 0) { | |
215 return null; | |
216 } | |
217 return new RemoteOopHandle(this, addr); | |
218 } | |
219 catch (RemoteException e) { | |
220 throw new DebuggerException(e); | |
221 } | |
222 } | |
223 | |
224 /** Need to override this to relax alignment checks on x86. */ | |
225 public long readCInteger(long address, long numBytes, boolean isUnsigned) | |
226 throws UnmappedAddressException, UnalignedAddressException { | |
227 if (!unalignedAccessesOkay) { | |
228 utils.checkAlignment(address, numBytes); | |
229 } else { | |
230 // Only slightly relaxed semantics -- this is a hack, but is | |
231 // necessary on x86 where it seems the compiler is | |
232 // putting some global 64-bit data on 32-bit boundaries | |
233 if (numBytes == 8) { | |
234 utils.checkAlignment(address, 4); | |
235 } else { | |
236 utils.checkAlignment(address, numBytes); | |
237 } | |
238 } | |
239 byte[] data = readBytes(address, numBytes); | |
240 return utils.dataToCInteger(data, isUnsigned); | |
241 } | |
242 | |
243 // Overridden from DebuggerBase because we need to relax alignment | |
244 // constraints on x86 | |
245 public long readJLong(long address) | |
246 throws UnmappedAddressException, UnalignedAddressException { | |
247 // FIXME: allow this to be configurable. Undesirable to add a | |
248 // dependency on the runtime package here, though, since this | |
249 // package should be strictly underneath it. | |
250 if (unalignedAccessesOkay) { | |
251 utils.checkAlignment(address, jintSize); | |
252 } else { | |
253 utils.checkAlignment(address, jlongSize); | |
254 } | |
255 byte[] data = readBytes(address, jlongSize); | |
256 return utils.dataToJLong(data, jlongSize); | |
257 } | |
258 | |
259 | |
260 //-------------------------------------------------------------------------------- | |
261 // Implementation of JVMDebugger interface | |
262 // | |
263 | |
264 /** Unimplemented in this class (remote remoteDebugger should already be configured) */ | |
265 public void configureJavaPrimitiveTypeSizes(long jbooleanSize, | |
266 long jbyteSize, | |
267 long jcharSize, | |
268 long jdoubleSize, | |
269 long jfloatSize, | |
270 long jintSize, | |
271 long jlongSize, | |
272 long jshortSize) { | |
273 throw new DebuggerException("Should not be called on RemoteDebuggerClient"); | |
274 } | |
275 | |
276 public void setMachineDescription(MachineDescription machDesc) { | |
277 throw new DebuggerException("Should not be called on RemoteDebuggerClient"); | |
278 } | |
279 | |
280 public int getRemoteProcessAddressSize() { | |
281 throw new DebuggerException("Should not be called on RemoteDebuggerClient"); | |
282 } | |
283 | |
284 public String addressValueToString(long addr) { | |
285 return utils.addressValueToString(addr); | |
286 } | |
287 | |
288 public long getAddressValue(Address addr) throws DebuggerException { | |
289 if (addr == null) return 0; | |
290 return ((RemoteAddress) addr).getValue(); | |
291 } | |
292 | |
293 public Address newAddress(long value) { | |
294 if (value == 0) return null; | |
295 return new RemoteAddress(this, value); | |
296 } | |
297 | |
298 RemoteAddress readAddress(long address) | |
299 throws UnmappedAddressException, UnalignedAddressException { | |
300 long value = readAddressValue(address); | |
301 return (value == 0 ? null : new RemoteAddress(this, value)); | |
302 } | |
303 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
304 RemoteAddress readCompOopAddress(long address) |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
305 throws UnmappedAddressException, UnalignedAddressException { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
306 long value = readCompOopAddressValue(address); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
307 return (value == 0 ? null : new RemoteAddress(this, value)); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
308 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
309 |
0 | 310 RemoteOopHandle readOopHandle(long address) |
311 throws UnmappedAddressException, UnalignedAddressException, NotInHeapException { | |
312 long value = readAddressValue(address); | |
313 return (value == 0 ? null : new RemoteOopHandle(this, value)); | |
314 } | |
315 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
316 RemoteOopHandle readCompOopHandle(long address) |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
317 throws UnmappedAddressException, UnalignedAddressException, NotInHeapException { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
318 long value = readCompOopAddressValue(address); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
319 return (value == 0 ? null : new RemoteOopHandle(this, value)); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
320 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
321 |
0 | 322 boolean areThreadsEqual(Address addr1, Address addr2) { |
323 try { | |
324 return remoteDebugger.areThreadsEqual(getAddressValue(addr1), true, | |
325 getAddressValue(addr2), true); | |
326 } catch (RemoteException e) { | |
327 } | |
328 return false; | |
329 } | |
330 | |
331 boolean areThreadsEqual(long id1, long id2) { | |
332 try { | |
333 return remoteDebugger.areThreadsEqual(id1, false, id2, false); | |
334 } catch (RemoteException e) { | |
335 } | |
336 return false; | |
337 } | |
338 | |
339 boolean areThreadsEqual(Address addr1, long id2) { | |
340 try { | |
341 return remoteDebugger.areThreadsEqual(getAddressValue(addr1), true, id2, false); | |
342 } catch (RemoteException e) { | |
343 } | |
344 return false; | |
345 } | |
346 | |
347 boolean areThreadsEqual(long id1, Address addr2) { | |
348 try { | |
349 return remoteDebugger.areThreadsEqual(id1, false, getAddressValue(addr2), true); | |
350 } catch (RemoteException e) { | |
351 } | |
352 return false; | |
353 } | |
354 | |
355 int getThreadHashCode(Address a) { | |
356 try { | |
357 return remoteDebugger.getThreadHashCode(getAddressValue(a), true); | |
358 } catch (RemoteException e) { | |
359 } | |
360 return a.hashCode(); | |
361 } | |
362 | |
363 int getThreadHashCode(long id) { | |
364 try { | |
365 return remoteDebugger.getThreadHashCode(id, false); | |
366 } catch (RemoteException e) { | |
367 } | |
368 return (int) id; | |
369 } | |
370 | |
371 public ThreadProxy getThreadForIdentifierAddress(Address addr) { | |
372 return threadFactory.createThreadWrapper(addr); | |
373 } | |
374 | |
375 public ThreadProxy getThreadForThreadId(long id) { | |
376 return threadFactory.createThreadWrapper(id); | |
377 } | |
378 | |
379 public MachineDescription getMachineDescription() throws DebuggerException { | |
380 return machDesc; | |
381 } | |
382 | |
383 /** This reads bytes from the remote process. */ | |
384 public ReadResult readBytesFromProcess(long address, long numBytes) { | |
385 try { | |
386 return remoteDebugger.readBytesFromProcess(address, numBytes); | |
387 } | |
388 catch (RemoteException e) { | |
389 throw new DebuggerException(e); | |
390 } | |
391 } | |
392 | |
393 public void writeBytesToProcess(long a, long b, byte[] c) { | |
394 throw new DebuggerException("Unimplemented!"); | |
395 } | |
396 } |