annotate agent/src/share/classes/sun/jvm/hotspot/bugspot/PCFinder.java @ 152:c70a245cad3a

6670684: 4/5 SA command universe did not print out CMS space information Summary: Forward port of Yumin's fix for 6670684 from HSX-11; Yumin verified the port was correct. Reviewed-by: dcubed
author dcubed
date Fri, 09 May 2008 08:55:13 -0700
parents a61af66fc99e
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.bugspot;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import sun.jvm.hotspot.debugger.cdbg.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 /** Helper class for locating a program counter. Indicates the
a61af66fc99e Initial load
duke
parents:
diff changeset
31 confidence of the find. */
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 public class PCFinder {
a61af66fc99e Initial load
duke
parents:
diff changeset
34 public static final int LOW_CONFIDENCE = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 public static final int HIGH_CONFIDENCE = 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 public static class Info {
a61af66fc99e Initial load
duke
parents:
diff changeset
38 private String name;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 private long offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 private int confidence;
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 public Info(String name, long offset, int confidence) {
a61af66fc99e Initial load
duke
parents:
diff changeset
43 this.name = name;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 this.offset = offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 this.confidence = confidence;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 }
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 /** May be null */
a61af66fc99e Initial load
duke
parents:
diff changeset
49 public String getName() { return name; }
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 /** If this is -1, a symbol could not be found, and the offset
a61af66fc99e Initial load
duke
parents:
diff changeset
52 should not be shown */
a61af66fc99e Initial load
duke
parents:
diff changeset
53 public long getOffset() { return offset; }
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 /** PCFinder.LOW_CONFIDENCE or PCFinder.HIGH_CONFIDENCE */
a61af66fc99e Initial load
duke
parents:
diff changeset
56 public int getConfidence() { return confidence; }
a61af66fc99e Initial load
duke
parents:
diff changeset
57 }
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 /** Passed loadobject may be null in which case the returned Info
a61af66fc99e Initial load
duke
parents:
diff changeset
60 object has low confidence */
a61af66fc99e Initial load
duke
parents:
diff changeset
61 public static Info findPC(Address pc, LoadObject lo, CDebugger dbg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 if (lo == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
63 return new Info(null, -1, LOW_CONFIDENCE);
a61af66fc99e Initial load
duke
parents:
diff changeset
64 }
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 // First try debug info
a61af66fc99e Initial load
duke
parents:
diff changeset
67 BlockSym sym = lo.debugInfoForPC(pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
68 while (sym != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 if (sym.isFunction()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // Highest confidence
a61af66fc99e Initial load
duke
parents:
diff changeset
71 return new Info(sym.toString(), pc.minus(sym.getAddress()), HIGH_CONFIDENCE);
a61af66fc99e Initial load
duke
parents:
diff changeset
72 }
a61af66fc99e Initial load
duke
parents:
diff changeset
73 }
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 // Now try looking up symbol in loadobject
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // FIXME: must add support for mapfiles on Win32 and try looking
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // up there first if possible. Should we hide that behind
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // LoadObject.closestSymbolToPC and have the ClosestSymbol return
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // confidence? I think so. On Solaris there is no notion of a
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // mapfile, and the confidence for closestSymbolToPC will be high
a61af66fc99e Initial load
duke
parents:
diff changeset
82 // instead of low.
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 int confidence = HIGH_CONFIDENCE;
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 ClosestSymbol cs = lo.closestSymbolToPC(pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
87 if (cs != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // FIXME: currently low confidence (only on Win32)
a61af66fc99e Initial load
duke
parents:
diff changeset
89 return new Info(cs.getName() + "()", cs.getOffset(), LOW_CONFIDENCE);
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // Unknown location
a61af66fc99e Initial load
duke
parents:
diff changeset
93 return new Info(dbg.getNameOfFile(lo.getName()).toUpperCase() +
a61af66fc99e Initial load
duke
parents:
diff changeset
94 "! " + pc + "()", -1, HIGH_CONFIDENCE);
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }