annotate agent/src/share/classes/sun/jvm/hotspot/jdi/LocationImpl.java @ 6972:bd7a7ce2e264

6830717: replay of compilations would help with debugging Summary: When java process crashed in compiler thread, repeat the compilation process will help finding root cause. This is done with using SA dump application class data and replay data from core dump, then use debug version of jvm to recompile the problematic java method. Reviewed-by: kvn, twisti, sspitsyn Contributed-by: yumin.qi@oracle.com
author minqi
date Mon, 12 Nov 2012 14:03:53 -0800
parents 37be97a58393
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
2471
37be97a58393 7010849: 5/5 Extraneous javac source/target options when building sa-jdi
andrew
parents: 1552
diff changeset
2 * Copyright (c) 2002, 2011, 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
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.jdi;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import com.sun.jdi.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 public class LocationImpl extends MirrorImpl implements Location {
a61af66fc99e Initial load
duke
parents:
diff changeset
32 private final ReferenceTypeImpl declaringType;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 private Method method;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 private sun.jvm.hotspot.oops.Method methodRef;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 private long codeIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 private LineInfo baseLineInfo = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 private LineInfo otherLineInfo = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 LocationImpl(VirtualMachine vm,
a61af66fc99e Initial load
duke
parents:
diff changeset
40 Method method, long codeIndex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
41 super(vm);
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 this.method = method;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 this.codeIndex = method.isNative()? -1 : codeIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 this.declaringType = (ReferenceTypeImpl)method.declaringType();
a61af66fc99e Initial load
duke
parents:
diff changeset
46 }
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
49 * This constructor allows lazy creation of the method mirror. This
a61af66fc99e Initial load
duke
parents:
diff changeset
50 * can be a performance savings if the method mirror does not yet
a61af66fc99e Initial load
duke
parents:
diff changeset
51 * exist.
a61af66fc99e Initial load
duke
parents:
diff changeset
52 */
a61af66fc99e Initial load
duke
parents:
diff changeset
53 LocationImpl(VirtualMachine vm, ReferenceType declaringType,
a61af66fc99e Initial load
duke
parents:
diff changeset
54 sun.jvm.hotspot.oops.Method methodRef, long codeIndex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 super(vm);
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 this.method = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 this.codeIndex = codeIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 this.declaringType = (ReferenceTypeImpl)declaringType;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 this.methodRef = methodRef;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 public boolean equals(Object obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 if ((obj != null) && (obj instanceof Location)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 Location other = (Location)obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 return (method().equals(other.method())) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
67 (codeIndex() == other.codeIndex()) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
68 super.equals(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
69 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72 }
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 public int hashCode() {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
76 * TO DO: better hash code?
a61af66fc99e Initial load
duke
parents:
diff changeset
77 */
a61af66fc99e Initial load
duke
parents:
diff changeset
78 return method().hashCode() + (int)codeIndex();
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80
2471
37be97a58393 7010849: 5/5 Extraneous javac source/target options when building sa-jdi
andrew
parents: 1552
diff changeset
81 public int compareTo(Location other) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
82 int rc = method().compareTo(other.method());
a61af66fc99e Initial load
duke
parents:
diff changeset
83 if (rc == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 long diff = codeIndex() - other.codeIndex();
a61af66fc99e Initial load
duke
parents:
diff changeset
85 if (diff < 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
86 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
87 else if (diff > 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
88 return 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 else
a61af66fc99e Initial load
duke
parents:
diff changeset
90 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92 return rc;
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 ReferenceType declaringType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 return declaringType;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 public Method method() {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 if (method == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 method = declaringType.getMethodMirror(methodRef);
a61af66fc99e Initial load
duke
parents:
diff changeset
102 if (method.isNative()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
103 codeIndex = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 }
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106 return method;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 public long codeIndex() {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 method(); // be sure information is up-to-date
a61af66fc99e Initial load
duke
parents:
diff changeset
111 return codeIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 LineInfo getBaseLineInfo(SDE.Stratum stratum) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 LineInfo lineInfo;
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 /* check if there is cached info to use */
a61af66fc99e Initial load
duke
parents:
diff changeset
118 if (baseLineInfo != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 return baseLineInfo;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 /* compute the line info */
a61af66fc99e Initial load
duke
parents:
diff changeset
123 MethodImpl methodImpl = (MethodImpl)method();
a61af66fc99e Initial load
duke
parents:
diff changeset
124 lineInfo = methodImpl.codeIndexToLineInfo(stratum,
a61af66fc99e Initial load
duke
parents:
diff changeset
125 codeIndex());
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 /* cache it */
a61af66fc99e Initial load
duke
parents:
diff changeset
128 addBaseLineInfo(lineInfo);
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 return lineInfo;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 LineInfo getLineInfo(SDE.Stratum stratum) {
a61af66fc99e Initial load
duke
parents:
diff changeset
134 LineInfo lineInfo;
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 /* base stratum is done slighly differently */
a61af66fc99e Initial load
duke
parents:
diff changeset
137 if (stratum.isJava()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 return getBaseLineInfo(stratum);
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140
a61af66fc99e Initial load
duke
parents:
diff changeset
141 /* check if there is cached info to use */
a61af66fc99e Initial load
duke
parents:
diff changeset
142 lineInfo = otherLineInfo; // copy because of concurrency
a61af66fc99e Initial load
duke
parents:
diff changeset
143 if (lineInfo != null &&
a61af66fc99e Initial load
duke
parents:
diff changeset
144 stratum.id().equals(lineInfo.liStratum())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 return lineInfo;
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147 int baseLineNumber = lineNumber(SDE.BASE_STRATUM_NAME);
a61af66fc99e Initial load
duke
parents:
diff changeset
148 SDE.LineStratum lineStratum =
a61af66fc99e Initial load
duke
parents:
diff changeset
149 stratum.lineStratum(declaringType, baseLineNumber);
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 if (lineStratum != null && lineStratum.lineNumber() != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 lineInfo = new StratumLineInfo(stratum.id(),
a61af66fc99e Initial load
duke
parents:
diff changeset
153 lineStratum.lineNumber(),
a61af66fc99e Initial load
duke
parents:
diff changeset
154 lineStratum.sourceName(),
a61af66fc99e Initial load
duke
parents:
diff changeset
155 lineStratum.sourcePath());
a61af66fc99e Initial load
duke
parents:
diff changeset
156 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 /* find best match */
a61af66fc99e Initial load
duke
parents:
diff changeset
158 MethodImpl methodImpl = (MethodImpl)method();
a61af66fc99e Initial load
duke
parents:
diff changeset
159 lineInfo = methodImpl.codeIndexToLineInfo(stratum,
a61af66fc99e Initial load
duke
parents:
diff changeset
160 codeIndex());
a61af66fc99e Initial load
duke
parents:
diff changeset
161 }
a61af66fc99e Initial load
duke
parents:
diff changeset
162
a61af66fc99e Initial load
duke
parents:
diff changeset
163 /* cache it */
a61af66fc99e Initial load
duke
parents:
diff changeset
164 addStratumLineInfo(lineInfo);
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 return lineInfo;
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 void addStratumLineInfo(LineInfo lineInfo) {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 otherLineInfo = lineInfo;
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 void addBaseLineInfo(LineInfo lineInfo) {
a61af66fc99e Initial load
duke
parents:
diff changeset
174 baseLineInfo = lineInfo;
a61af66fc99e Initial load
duke
parents:
diff changeset
175 }
a61af66fc99e Initial load
duke
parents:
diff changeset
176
a61af66fc99e Initial load
duke
parents:
diff changeset
177 public String sourceName() throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
178 return sourceName(vm.getDefaultStratum());
a61af66fc99e Initial load
duke
parents:
diff changeset
179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
180
a61af66fc99e Initial load
duke
parents:
diff changeset
181 public String sourceName(String stratumID)
a61af66fc99e Initial load
duke
parents:
diff changeset
182 throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 return sourceName(declaringType.stratum(stratumID));
a61af66fc99e Initial load
duke
parents:
diff changeset
184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
185
a61af66fc99e Initial load
duke
parents:
diff changeset
186 String sourceName(SDE.Stratum stratum)
a61af66fc99e Initial load
duke
parents:
diff changeset
187 throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
188 return getLineInfo(stratum).liSourceName();
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190
a61af66fc99e Initial load
duke
parents:
diff changeset
191 public String sourcePath() throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
192 return sourcePath(vm.getDefaultStratum());
a61af66fc99e Initial load
duke
parents:
diff changeset
193 }
a61af66fc99e Initial load
duke
parents:
diff changeset
194
a61af66fc99e Initial load
duke
parents:
diff changeset
195 public String sourcePath(String stratumID)
a61af66fc99e Initial load
duke
parents:
diff changeset
196 throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
197 return sourcePath(declaringType.stratum(stratumID));
a61af66fc99e Initial load
duke
parents:
diff changeset
198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
199
a61af66fc99e Initial load
duke
parents:
diff changeset
200 String sourcePath(SDE.Stratum stratum)
a61af66fc99e Initial load
duke
parents:
diff changeset
201 throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
202 return getLineInfo(stratum).liSourcePath();
a61af66fc99e Initial load
duke
parents:
diff changeset
203 }
a61af66fc99e Initial load
duke
parents:
diff changeset
204
a61af66fc99e Initial load
duke
parents:
diff changeset
205 public int lineNumber() {
a61af66fc99e Initial load
duke
parents:
diff changeset
206 return lineNumber(vm.getDefaultStratum());
a61af66fc99e Initial load
duke
parents:
diff changeset
207 }
a61af66fc99e Initial load
duke
parents:
diff changeset
208
a61af66fc99e Initial load
duke
parents:
diff changeset
209 public int lineNumber(String stratumID) {
a61af66fc99e Initial load
duke
parents:
diff changeset
210 return lineNumber(declaringType.stratum(stratumID));
a61af66fc99e Initial load
duke
parents:
diff changeset
211 }
a61af66fc99e Initial load
duke
parents:
diff changeset
212
a61af66fc99e Initial load
duke
parents:
diff changeset
213 int lineNumber(SDE.Stratum stratum) {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 return getLineInfo(stratum).liLineNumber();
a61af66fc99e Initial load
duke
parents:
diff changeset
215 }
a61af66fc99e Initial load
duke
parents:
diff changeset
216
a61af66fc99e Initial load
duke
parents:
diff changeset
217 public String toString() {
a61af66fc99e Initial load
duke
parents:
diff changeset
218 if (lineNumber() == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
219 return method().toString() + "+" + codeIndex();
a61af66fc99e Initial load
duke
parents:
diff changeset
220 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
221 return declaringType().name() + ":" + lineNumber();
a61af66fc99e Initial load
duke
parents:
diff changeset
222 }
a61af66fc99e Initial load
duke
parents:
diff changeset
223 }
a61af66fc99e Initial load
duke
parents:
diff changeset
224 }