1 /*
2 * Copyright 2001-2002 Sun Microsystems, Inc. All Rights Reserved.
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 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
24
25 package sun.jvm.hotspot.debugger;
26
27 /** <P> DebuggerBase is a recommended base class for debugger
28 implementations. It can use a PageCache to cache data from the
29 target process. Note that this class would not be suitable if the
30 system were used to reflect upon itself; it would never be safe to
31 store the value in an OopHandle in anything but an OopHandle.
32 However, it provides a fair amount of code sharing to the current
33 dbx and win32 implementations. </P>
34
35 <P> NOTE that much of the code sharing is achieved by having this
36 class implement many of the methods in the Win32Debugger and
37 DbxDebugger interfaces. </P> */
38
39 public abstract class DebuggerBase implements Debugger {
40 // May be set lazily, but must be set before calling any of the read
41 // routines below
42 protected MachineDescription machDesc;
43 protected DebuggerUtilities utils;
44 // Java primitive type sizes, set during bootstrapping. Do not call
45 // any of the Java read routines until these are set up.
46 protected long jbooleanSize;
47 protected long jbyteSize;
48 protected long jcharSize;
49 protected long jdoubleSize;
50 protected long jfloatSize;
51 protected long jintSize;
52 protected long jlongSize;
53 protected long jshortSize;
54 protected boolean javaPrimitiveTypesConfigured;
55 // Should be initialized if desired by calling initCache()
56 private PageCache cache;
57
58 // State for faster accessors that don't allocate memory on each read
59 private boolean useFastAccessors;
60 private boolean bigEndian;
61
62 // Page-fetching functionality for LRU cache
63 class Fetcher implements PageFetcher {
64 public Page fetchPage(long pageBaseAddress, long numBytes) {
65 // This assumes that if any byte is unmapped, that the entire
66 // page is. The common case, however, is that the page is
67 // mapped, so we always fetch the entire thing all at once to
68 // avoid two round-trip communications per page fetch, even
69 // though fetching of unmapped pages will be slow.
70 ReadResult res = readBytesFromProcess(pageBaseAddress, numBytes);
71 if (res.getData() == null) {
72 return new Page(pageBaseAddress, numBytes);
73 }
74 return new Page(pageBaseAddress, res.getData());
136
137 if (jlongSize != jdoubleSize) {
138 // If dataToJDouble were rewritten, this wouldn't be necessary
139 throw new RuntimeException("jlong size and jdouble size must be equal");
140 }
141
142 useFastAccessors =
143 ((cache != null) &&
144 (jbooleanSize == 1) &&
145 (jbyteSize == 1) &&
146 (jcharSize == 2) &&
147 (jdoubleSize == 8) &&
148 (jfloatSize == 4) &&
149 (jintSize == 4) &&
150 (jlongSize == 8) &&
151 (jshortSize == 2));
152
153 javaPrimitiveTypesConfigured = true;
154 }
155
156 /** May be called by subclasses if desired to initialize the page
157 cache but may not be overridden */
158 protected final void initCache(long pageSize, long maxNumPages) {
159 cache = new PageCache(pageSize, maxNumPages, new Fetcher());
160 if (machDesc != null) {
161 bigEndian = machDesc.isBigEndian();
162 }
163 }
164
165 /** May be called by subclasses if needed (if the machine
166 description is not available at the time of cache
167 initialization, as on Solaris) but may not be overridden */
168 protected final void setBigEndian(boolean bigEndian) {
169 this.bigEndian = bigEndian;
170 }
171
172 /** May be called by subclasses to clear out the cache but may not
173 be overridden. For convenience, this can be called even if the
174 cache has not been initialized. */
175 protected final void clearCache() {
425 throws UnmappedAddressException, UnalignedAddressException {
426 checkJavaConfigured();
427 utils.checkAlignment(address, jshortSize);
428 byte[] data = utils.jshortToData(value);
429 writeBytes(address, jshortSize, data);
430 }
431
432 public void writeCInteger(long address, long numBytes, long value)
433 throws UnmappedAddressException, UnalignedAddressException {
434 checkConfigured();
435 utils.checkAlignment(address, numBytes);
436 byte[] data = utils.cIntegerToData(numBytes, value);
437 writeBytes(address, numBytes, data);
438 }
439
440 protected long readAddressValue(long address)
441 throws UnmappedAddressException, UnalignedAddressException {
442 return readCInteger(address, machDesc.getAddressSize(), true);
443 }
444
445 protected void writeAddressValue(long address, long value)
446 throws UnmappedAddressException, UnalignedAddressException {
447 writeCInteger(address, machDesc.getAddressSize(), value);
448 }
449
450 /** Can be called by subclasses but can not be overridden */
451 protected final void checkConfigured() {
452 if (machDesc == null) {
453 throw new RuntimeException("MachineDescription must have been set by this point");
454 }
455 if (utils == null) {
456 throw new RuntimeException("DebuggerUtilities must have been set by this point");
457 }
458 }
459
460 /** Can be called by subclasses but can not be overridden */
461 protected final void checkJavaConfigured() {
462 checkConfigured();
463
464 if (!javaPrimitiveTypesConfigured) {
501
502 public long getJDoubleSize() {
503 return jdoubleSize;
504 }
505
506 public long getJFloatSize() {
507 return jfloatSize;
508 }
509
510 public long getJIntSize() {
511 return jintSize;
512 }
513
514 public long getJLongSize() {
515 return jlongSize;
516 }
517
518 public long getJShortSize() {
519 return jshortSize;
520 }
521 }
|
1 /*
2 * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved.
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 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
24
25 package sun.jvm.hotspot.debugger;
26
27 /** <P> DebuggerBase is a recommended base class for debugger
28 implementations. It can use a PageCache to cache data from the
29 target process. Note that this class would not be suitable if the
30 system were used to reflect upon itself; it would never be safe to
31 store the value in an OopHandle in anything but an OopHandle.
32 However, it provides a fair amount of code sharing to the current
33 dbx and win32 implementations. </P>
34
35 <P> NOTE that much of the code sharing is achieved by having this
36 class implement many of the methods in the Win32Debugger and
37 DbxDebugger interfaces. </P> */
38
39 public abstract class DebuggerBase implements Debugger {
40
41 // May be set lazily, but must be set before calling any of the read
42 // routines below
43 protected MachineDescription machDesc;
44 protected DebuggerUtilities utils;
45 // Java primitive type sizes, set during bootstrapping. Do not call
46 // any of the Java read routines until these are set up.
47 protected long jbooleanSize;
48 protected long jbyteSize;
49 protected long jcharSize;
50 protected long jdoubleSize;
51 protected long jfloatSize;
52 protected long jintSize;
53 protected long jlongSize;
54 protected long jshortSize;
55 protected boolean javaPrimitiveTypesConfigured;
56 // heap data.
57 protected long oopSize;
58 protected long heapOopSize;
59 protected long heapBase; // heap base for compressed oops.
60 protected long logMinObjAlignmentInBytes; // Used to decode compressed oops.
61 // Should be initialized if desired by calling initCache()
62 private PageCache cache;
63
64 // State for faster accessors that don't allocate memory on each read
65 private boolean useFastAccessors;
66 private boolean bigEndian;
67
68 // Page-fetching functionality for LRU cache
69 class Fetcher implements PageFetcher {
70 public Page fetchPage(long pageBaseAddress, long numBytes) {
71 // This assumes that if any byte is unmapped, that the entire
72 // page is. The common case, however, is that the page is
73 // mapped, so we always fetch the entire thing all at once to
74 // avoid two round-trip communications per page fetch, even
75 // though fetching of unmapped pages will be slow.
76 ReadResult res = readBytesFromProcess(pageBaseAddress, numBytes);
77 if (res.getData() == null) {
78 return new Page(pageBaseAddress, numBytes);
79 }
80 return new Page(pageBaseAddress, res.getData());
142
143 if (jlongSize != jdoubleSize) {
144 // If dataToJDouble were rewritten, this wouldn't be necessary
145 throw new RuntimeException("jlong size and jdouble size must be equal");
146 }
147
148 useFastAccessors =
149 ((cache != null) &&
150 (jbooleanSize == 1) &&
151 (jbyteSize == 1) &&
152 (jcharSize == 2) &&
153 (jdoubleSize == 8) &&
154 (jfloatSize == 4) &&
155 (jintSize == 4) &&
156 (jlongSize == 8) &&
157 (jshortSize == 2));
158
159 javaPrimitiveTypesConfigured = true;
160 }
161
162 public void putHeapConst(long heapBase, long heapOopSize, long logMinObjAlignmentInBytes) {
163 this.heapBase = heapBase;
164 this.heapOopSize = heapOopSize;
165 this.logMinObjAlignmentInBytes = logMinObjAlignmentInBytes;
166 }
167
168 /** May be called by subclasses if desired to initialize the page
169 cache but may not be overridden */
170 protected final void initCache(long pageSize, long maxNumPages) {
171 cache = new PageCache(pageSize, maxNumPages, new Fetcher());
172 if (machDesc != null) {
173 bigEndian = machDesc.isBigEndian();
174 }
175 }
176
177 /** May be called by subclasses if needed (if the machine
178 description is not available at the time of cache
179 initialization, as on Solaris) but may not be overridden */
180 protected final void setBigEndian(boolean bigEndian) {
181 this.bigEndian = bigEndian;
182 }
183
184 /** May be called by subclasses to clear out the cache but may not
185 be overridden. For convenience, this can be called even if the
186 cache has not been initialized. */
187 protected final void clearCache() {
437 throws UnmappedAddressException, UnalignedAddressException {
438 checkJavaConfigured();
439 utils.checkAlignment(address, jshortSize);
440 byte[] data = utils.jshortToData(value);
441 writeBytes(address, jshortSize, data);
442 }
443
444 public void writeCInteger(long address, long numBytes, long value)
445 throws UnmappedAddressException, UnalignedAddressException {
446 checkConfigured();
447 utils.checkAlignment(address, numBytes);
448 byte[] data = utils.cIntegerToData(numBytes, value);
449 writeBytes(address, numBytes, data);
450 }
451
452 protected long readAddressValue(long address)
453 throws UnmappedAddressException, UnalignedAddressException {
454 return readCInteger(address, machDesc.getAddressSize(), true);
455 }
456
457 protected long readCompOopAddressValue(long address)
458 throws UnmappedAddressException, UnalignedAddressException {
459 long value = readCInteger(address, getHeapOopSize(), true);
460 if (value != 0) {
461 // See oop.inline.hpp decode_heap_oop
462 value = (long)(heapBase + (long)(value << logMinObjAlignmentInBytes));
463 }
464 return value;
465 }
466
467 protected void writeAddressValue(long address, long value)
468 throws UnmappedAddressException, UnalignedAddressException {
469 writeCInteger(address, machDesc.getAddressSize(), value);
470 }
471
472 /** Can be called by subclasses but can not be overridden */
473 protected final void checkConfigured() {
474 if (machDesc == null) {
475 throw new RuntimeException("MachineDescription must have been set by this point");
476 }
477 if (utils == null) {
478 throw new RuntimeException("DebuggerUtilities must have been set by this point");
479 }
480 }
481
482 /** Can be called by subclasses but can not be overridden */
483 protected final void checkJavaConfigured() {
484 checkConfigured();
485
486 if (!javaPrimitiveTypesConfigured) {
523
524 public long getJDoubleSize() {
525 return jdoubleSize;
526 }
527
528 public long getJFloatSize() {
529 return jfloatSize;
530 }
531
532 public long getJIntSize() {
533 return jintSize;
534 }
535
536 public long getJLongSize() {
537 return jlongSize;
538 }
539
540 public long getJShortSize() {
541 return jshortSize;
542 }
543
544 public long getHeapOopSize() {
545 return heapOopSize;
546 }
547
548 public long getHeapBase() {
549 return heapBase;
550 }
551 public long getLogMinObjAlignmentInBytes() {
552 return logMinObjAlignmentInBytes;
553 }
554 }
|