annotate agent/src/share/classes/sun/jvm/hotspot/debugger/posix/DSO.java @ 1913:3b2dea75431e

6984311: JSR 292 needs optional bootstrap method parameters Summary: Allow CONSTANT_InvokeDynamic nodes to have any number of extra operands. Reviewed-by: twisti
author jrose
date Sat, 30 Oct 2010 13:08:23 -0700
parents c18cbe5936b8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 2001, 2003, Oracle and/or its affiliates. All rights reserved.
0
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 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
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: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24 package sun.jvm.hotspot.debugger.posix;
a61af66fc99e Initial load
duke
parents:
diff changeset
25
a61af66fc99e Initial load
duke
parents:
diff changeset
26 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import sun.jvm.hotspot.debugger.cdbg.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import sun.jvm.hotspot.debugger.posix.elf.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.utilities.memo.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 /** Provides a simple wrapper around the ELF library which handles
a61af66fc99e Initial load
duke
parents:
diff changeset
32 relocation. */
a61af66fc99e Initial load
duke
parents:
diff changeset
33 public abstract class DSO implements LoadObject {
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 private MemoizedObject file; // contains ELFFile
a61af66fc99e Initial load
duke
parents:
diff changeset
36 private String filename;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 private Address addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 private long size;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 private IsDSO dso = new IsDSO();
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 class IsDSO extends MemoizedBoolean {
a61af66fc99e Initial load
duke
parents:
diff changeset
42 protected boolean computeValue() {
a61af66fc99e Initial load
duke
parents:
diff changeset
43 return getFile().getHeader().getFileType() == ELFHeader.FT_DYN;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 }
a61af66fc99e Initial load
duke
parents:
diff changeset
45 };
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 class ELFFileByName extends MemoizedObject {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 protected Object computeValue() {
a61af66fc99e Initial load
duke
parents:
diff changeset
49 return ELFFileParser.getParser().parse(DSO.this.filename);
a61af66fc99e Initial load
duke
parents:
diff changeset
50 }
a61af66fc99e Initial load
duke
parents:
diff changeset
51 };
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 class ELFFileByAddress extends MemoizedObject {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 protected Object computeValue() {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 return ELFFileParser.getParser().parse(new AddressDataSource(DSO.this.addr));
a61af66fc99e Initial load
duke
parents:
diff changeset
56 }
a61af66fc99e Initial load
duke
parents:
diff changeset
57 };
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 public DSO(String filename, long size, Address relocation) throws ELFException {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 this.filename = filename;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 this.size = size;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 this.addr = relocation;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 this.file = new ELFFileByName();
a61af66fc99e Initial load
duke
parents:
diff changeset
64 }
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 public DSO(long size, Address relocation) throws ELFException {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 this.addr = relocation;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 this.size = size;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 this.file = new ELFFileByAddress();
a61af66fc99e Initial load
duke
parents:
diff changeset
70 }
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 public String getName() {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 return filename;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 }
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 public Address getBase() {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 return addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
78 }
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 /** if this .so is unloaded and re-loaded in the same process at a different
a61af66fc99e Initial load
duke
parents:
diff changeset
81 base, change the base by calling this to avoid re-parsing the ELF. */
a61af66fc99e Initial load
duke
parents:
diff changeset
82 public void setBase(Address newBase) {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 addr = newBase;
a61af66fc99e Initial load
duke
parents:
diff changeset
84 if (filename == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // ELFFile was created by address. we have to re-parse it.
a61af66fc99e Initial load
duke
parents:
diff changeset
86 file = new ELFFileByAddress();
a61af66fc99e Initial load
duke
parents:
diff changeset
87 dso = new IsDSO();
a61af66fc99e Initial load
duke
parents:
diff changeset
88 }
a61af66fc99e Initial load
duke
parents:
diff changeset
89 }
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 public long getSize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 return size;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 public CDebugInfoDataBase getDebugInfoDataBase() throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // FIXME: after stabs parser
a61af66fc99e Initial load
duke
parents:
diff changeset
97 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 public BlockSym debugInfoForPC(Address pc) throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // FIXME: after stabs parser
a61af66fc99e Initial load
duke
parents:
diff changeset
102 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 public ClosestSymbol closestSymbolToPC(Address pcAsAddr) throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 boolean dso = isDSO();
a61af66fc99e Initial load
duke
parents:
diff changeset
107 long offset = dso? pcAsAddr.minus(addr) : getAddressValue(pcAsAddr);
a61af66fc99e Initial load
duke
parents:
diff changeset
108 ELFSymbol sym = getFile().getHeader().getELFSymbol(offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
109 return (sym != null)? createClosestSymbol(sym.getName(), offset - sym.getValue()) : null;
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 public LineNumberInfo lineNumberForPC(Address pc) throws DebuggerException {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 // FIXME: after stabs parser
a61af66fc99e Initial load
duke
parents:
diff changeset
114 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 /** return true if file is a .so */
a61af66fc99e Initial load
duke
parents:
diff changeset
118 public boolean isDSO() {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 return dso.getValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 /** Look up a symbol; returns absolute address or null if symbol was
a61af66fc99e Initial load
duke
parents:
diff changeset
123 not found. */
a61af66fc99e Initial load
duke
parents:
diff changeset
124 public Address lookupSymbol(String symbol) throws ELFException {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 ELFSymbol sym = getFile().getHeader().getELFSymbol(symbol);
a61af66fc99e Initial load
duke
parents:
diff changeset
126 if (sym == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 long value = sym.getValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
131 if (isDSO()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 return addr.addOffsetTo(value);
a61af66fc99e Initial load
duke
parents:
diff changeset
133 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
134 return newAddress(value);
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 public boolean equals(Object o) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 if (o == null || !(o instanceof DSO)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142 DSO other = (DSO)o;
a61af66fc99e Initial load
duke
parents:
diff changeset
143 return getBase().equals(other.getBase());
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
145
a61af66fc99e Initial load
duke
parents:
diff changeset
146 public int hashCode() {
a61af66fc99e Initial load
duke
parents:
diff changeset
147 return getBase().hashCode();
a61af66fc99e Initial load
duke
parents:
diff changeset
148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 protected ELFFile getFile() {
a61af66fc99e Initial load
duke
parents:
diff changeset
151 return (ELFFile) file.getValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 protected abstract Address newAddress(long addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
155 protected abstract long getAddressValue(Address addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
156
a61af66fc99e Initial load
duke
parents:
diff changeset
157 protected ClosestSymbol createClosestSymbol(String name, long diff) {
a61af66fc99e Initial load
duke
parents:
diff changeset
158 return new ClosestSymbol(name, diff);
a61af66fc99e Initial load
duke
parents:
diff changeset
159 }
a61af66fc99e Initial load
duke
parents:
diff changeset
160 }