annotate agent/src/share/classes/sun/jvm/hotspot/utilities/soql/JSJavaThread.java @ 818:b109e761e927

6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14 Summary: Disable escape analysis when jvmti/debugger is used. Add support for EA ibto SA. Reviewed-by: never
author kvn
date Tue, 09 Jun 2009 16:19:10 -0700
parents a61af66fc99e
children bd02caa94611
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 2004-2007 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.utilities.soql;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.oops.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
33 * Wraps a JavaThread instance in the target VM.
a61af66fc99e Initial load
duke
parents:
diff changeset
34 */
a61af66fc99e Initial load
duke
parents:
diff changeset
35 public class JSJavaThread extends JSJavaInstance {
a61af66fc99e Initial load
duke
parents:
diff changeset
36 public JSJavaThread(Instance threadOop, JSJavaFactory fac) {
a61af66fc99e Initial load
duke
parents:
diff changeset
37 super(threadOop, fac);
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // JavaThread retrieved from java.lang.Thread instance may be null.
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // This is the case for threads not-started and for zombies. Wherever
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // appropriate, check for null instead of resulting in NullPointerException.
a61af66fc99e Initial load
duke
parents:
diff changeset
41 this.jthread = OopUtilities.threadOopGetJavaThread(threadOop);
a61af66fc99e Initial load
duke
parents:
diff changeset
42 }
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44 public JSJavaThread(JavaThread jt, JSJavaFactory fac) {
a61af66fc99e Initial load
duke
parents:
diff changeset
45 super((Instance) jt.getThreadObj(), fac);
a61af66fc99e Initial load
duke
parents:
diff changeset
46 this.jthread = jt;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 }
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 public String toString() {
a61af66fc99e Initial load
duke
parents:
diff changeset
50 String name = getName();
a61af66fc99e Initial load
duke
parents:
diff changeset
51 StringBuffer buf = new StringBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
52 buf.append("Thread (address=");
a61af66fc99e Initial load
duke
parents:
diff changeset
53 buf.append(getOop().getHandle());
a61af66fc99e Initial load
duke
parents:
diff changeset
54 buf.append(", name=");
a61af66fc99e Initial load
duke
parents:
diff changeset
55 if (name != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
56 buf.append(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
57 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 buf.append("<unnamed>");
a61af66fc99e Initial load
duke
parents:
diff changeset
59 }
a61af66fc99e Initial load
duke
parents:
diff changeset
60 buf.append(')');
a61af66fc99e Initial load
duke
parents:
diff changeset
61 return buf.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
62 }
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 protected Object getFieldValue(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 if (name.equals("name")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 return getName();
a61af66fc99e Initial load
duke
parents:
diff changeset
67 } else if (name.equals("frames")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 return getFrames();
a61af66fc99e Initial load
duke
parents:
diff changeset
69 } else if (name.equals("monitors")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 return getOwnedMonitors();
a61af66fc99e Initial load
duke
parents:
diff changeset
71 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 return super.getFieldValue(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
73 }
a61af66fc99e Initial load
duke
parents:
diff changeset
74 }
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 protected String[] getFieldNames() {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 String[] flds = super.getFieldNames();
a61af66fc99e Initial load
duke
parents:
diff changeset
78 String[] res = new String[flds.length + 2];
a61af66fc99e Initial load
duke
parents:
diff changeset
79 System.arraycopy(flds, 0, res, 0, flds.length);
a61af66fc99e Initial load
duke
parents:
diff changeset
80 res[flds.length] = "frames";
a61af66fc99e Initial load
duke
parents:
diff changeset
81 res[flds.length + 1] = "monitors";
a61af66fc99e Initial load
duke
parents:
diff changeset
82 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
83 }
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 protected boolean hasField(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 if (name.equals("frames") || name.equals("monitors")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 return super.hasField(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 //-- Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
94 private String getName() {
a61af66fc99e Initial load
duke
parents:
diff changeset
95 return OopUtilities.threadOopGetName(getOop());
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97
a61af66fc99e Initial load
duke
parents:
diff changeset
98 private synchronized JSList getFrames() {
a61af66fc99e Initial load
duke
parents:
diff changeset
99 if (framesCache == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 final List list = new ArrayList(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
101 if (jthread != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 JavaVFrame jvf = jthread.getLastJavaVFrameDbg();
a61af66fc99e Initial load
duke
parents:
diff changeset
103 while (jvf != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 list.add(jvf);
a61af66fc99e Initial load
duke
parents:
diff changeset
105 jvf = jvf.javaSender();
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108 framesCache = factory.newJSList(list);
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110 return framesCache;
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 private synchronized JSList getOwnedMonitors() {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 if (monitorsCache == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 final List ownedMonitors = new ArrayList(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
116 if (jthread != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 List lockedObjects = new ArrayList(); // List<OopHandle>
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 ObjectMonitor waitingMonitor = jthread.getCurrentWaitingMonitor();
a61af66fc99e Initial load
duke
parents:
diff changeset
120 OopHandle waitingObj = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
121 if (waitingMonitor != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 // save object of current wait() call (if any) for later comparison
a61af66fc99e Initial load
duke
parents:
diff changeset
123 waitingObj = waitingMonitor.object();
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 ObjectMonitor pendingMonitor = jthread.getCurrentPendingMonitor();
a61af66fc99e Initial load
duke
parents:
diff changeset
127 OopHandle pendingObj = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 if (pendingMonitor != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 // save object of current enter() call (if any) for later comparison
a61af66fc99e Initial load
duke
parents:
diff changeset
130 pendingObj = pendingMonitor.object();
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 JavaVFrame frame = jthread.getLastJavaVFrameDbg();
a61af66fc99e Initial load
duke
parents:
diff changeset
134 while (frame != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 List frameMonitors = frame.getMonitors(); // List<MonitorInfo>
a61af66fc99e Initial load
duke
parents:
diff changeset
136 for (Iterator miItr = frameMonitors.iterator(); miItr.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 MonitorInfo mi = (MonitorInfo) miItr.next();
818
b109e761e927 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 0
diff changeset
138
b109e761e927 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 0
diff changeset
139 if (mi.eliminated() && frame.isCompiledFrame()) {
b109e761e927 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 0
diff changeset
140 continue; // skip eliminated monitor
b109e761e927 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 0
diff changeset
141 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
142 OopHandle obj = mi.owner();
a61af66fc99e Initial load
duke
parents:
diff changeset
143 if (obj == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 // this monitor doesn't have an owning object so skip it
a61af66fc99e Initial load
duke
parents:
diff changeset
145 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 if (obj.equals(waitingObj)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
149 // the thread is waiting on this monitor so it isn't really owned
a61af66fc99e Initial load
duke
parents:
diff changeset
150 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
151 }
a61af66fc99e Initial load
duke
parents:
diff changeset
152
a61af66fc99e Initial load
duke
parents:
diff changeset
153 if (obj.equals(pendingObj)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
154 // the thread is pending on this monitor so it isn't really owned
a61af66fc99e Initial load
duke
parents:
diff changeset
155 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 boolean found = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
159 for (Iterator loItr = lockedObjects.iterator(); loItr.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // check for recursive locks
a61af66fc99e Initial load
duke
parents:
diff changeset
161 if (obj.equals(loItr.next())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 found = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
163 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
164 }
a61af66fc99e Initial load
duke
parents:
diff changeset
165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
166 if (found) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 // already have this object so don't include it
a61af66fc99e Initial load
duke
parents:
diff changeset
168 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
169 }
a61af66fc99e Initial load
duke
parents:
diff changeset
170 // add the owning object to our list
a61af66fc99e Initial load
duke
parents:
diff changeset
171 lockedObjects.add(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
172 }
a61af66fc99e Initial load
duke
parents:
diff changeset
173 frame = (JavaVFrame) frame.javaSender();
a61af66fc99e Initial load
duke
parents:
diff changeset
174 }
a61af66fc99e Initial load
duke
parents:
diff changeset
175
a61af66fc99e Initial load
duke
parents:
diff changeset
176 // now convert List<OopHandle> to List<Oop>
a61af66fc99e Initial load
duke
parents:
diff changeset
177 ObjectHeap heap = VM.getVM().getObjectHeap();
a61af66fc99e Initial load
duke
parents:
diff changeset
178 for (Iterator loItr = lockedObjects.iterator(); loItr.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 ownedMonitors.add(heap.newOop((OopHandle)loItr.next()));
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181 }
a61af66fc99e Initial load
duke
parents:
diff changeset
182 monitorsCache = factory.newJSList(ownedMonitors);
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184 return monitorsCache;
a61af66fc99e Initial load
duke
parents:
diff changeset
185 }
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 private JavaThread jthread;
a61af66fc99e Initial load
duke
parents:
diff changeset
188 private JSList framesCache;
a61af66fc99e Initial load
duke
parents:
diff changeset
189 private JSList monitorsCache;
a61af66fc99e Initial load
duke
parents:
diff changeset
190 }