annotate agent/src/share/classes/sun/jvm/hotspot/jdi/ObjectReferenceImpl.java @ 844:bd02caa94611

6862919: Update copyright year Summary: Update copyright for files that have been modified in 2009, up to 07/09 Reviewed-by: tbell, ohair
author xdono
date Tue, 28 Jul 2009 12:12:40 -0700
parents b109e761e927
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
844
bd02caa94611 6862919: Update copyright year
xdono
parents: 818
diff changeset
2 * Copyright 2002-2009 Sun Microsystems, Inc. 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 *
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.jdi;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.io.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import com.sun.jdi.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.debugger.Address;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.debugger.OopHandle;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.oops.Oop;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import sun.jvm.hotspot.oops.Mark;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import sun.jvm.hotspot.oops.Instance;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 import sun.jvm.hotspot.oops.Array;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 import sun.jvm.hotspot.oops.OopUtilities;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 import sun.jvm.hotspot.oops.Klass;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 import sun.jvm.hotspot.oops.DefaultHeapVisitor;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 import sun.jvm.hotspot.runtime.JavaThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 import sun.jvm.hotspot.runtime.JavaVFrame;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 import sun.jvm.hotspot.runtime.MonitorInfo;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 import sun.jvm.hotspot.runtime.ObjectMonitor;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 import sun.jvm.hotspot.runtime.Threads;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 import sun.jvm.hotspot.utilities.Assert;
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 public class ObjectReferenceImpl extends ValueImpl implements ObjectReference {
a61af66fc99e Initial load
duke
parents:
diff changeset
49 private Oop saObject;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 private long myID;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 private boolean monitorInfoCached = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 private ThreadReferenceImpl owningThread = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 private List waitingThreads = null; // List<ThreadReferenceImpl>
a61af66fc99e Initial load
duke
parents:
diff changeset
54 private int entryCount = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 private static long nextID = 0L;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 private static synchronized long nextID() {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 return nextID++;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 }
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 ObjectReferenceImpl(VirtualMachine aVm, sun.jvm.hotspot.oops.Oop oRef) {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 super(aVm);
a61af66fc99e Initial load
duke
parents:
diff changeset
63 saObject = oRef;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 myID = nextID();
a61af66fc99e Initial load
duke
parents:
diff changeset
65 }
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 protected Oop ref() {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 return saObject;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 }
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 public Type type() {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 return referenceType();
a61af66fc99e Initial load
duke
parents:
diff changeset
73 }
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 public ReferenceType referenceType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
76 Klass myKlass = ref().getKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
77 return vm.referenceType(myKlass);
a61af66fc99e Initial load
duke
parents:
diff changeset
78 }
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 public Value getValue(Field sig) {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 List list = new ArrayList(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
82 list.add(sig);
a61af66fc99e Initial load
duke
parents:
diff changeset
83 Map map = getValues(list);
a61af66fc99e Initial load
duke
parents:
diff changeset
84 return(Value)map.get(sig);
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 public Map getValues(List theFields) {
a61af66fc99e Initial load
duke
parents:
diff changeset
88 //validateMirrors(theFields);
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 List staticFields = new ArrayList(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
91 int size = theFields.size();
a61af66fc99e Initial load
duke
parents:
diff changeset
92 List instanceFields = new ArrayList(size);
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 for (int i=0; i<size; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
95 sun.jvm.hotspot.jdi.FieldImpl field =
a61af66fc99e Initial load
duke
parents:
diff changeset
96 (sun.jvm.hotspot.jdi.FieldImpl)theFields.get(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
97
a61af66fc99e Initial load
duke
parents:
diff changeset
98 // Make sure the field is valid
a61af66fc99e Initial load
duke
parents:
diff changeset
99 ((ReferenceTypeImpl)referenceType()).validateFieldAccess(field);
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // FIX ME! We need to do some sanity checking
a61af66fc99e Initial load
duke
parents:
diff changeset
102 // here; make sure the field belongs to this
a61af66fc99e Initial load
duke
parents:
diff changeset
103 // object.
a61af66fc99e Initial load
duke
parents:
diff changeset
104 if (field.isStatic()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 staticFields.add(field);
a61af66fc99e Initial load
duke
parents:
diff changeset
106 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 instanceFields.add(field);
a61af66fc99e Initial load
duke
parents:
diff changeset
108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 // Look up static field(s) first to mimic the JDI implementation
a61af66fc99e Initial load
duke
parents:
diff changeset
112 Map map;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 if (staticFields.size() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 map = referenceType().getValues(staticFields);
a61af66fc99e Initial load
duke
parents:
diff changeset
115 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 map = new HashMap(size);
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // Then get instance field(s)
a61af66fc99e Initial load
duke
parents:
diff changeset
120 size = instanceFields.size();
a61af66fc99e Initial load
duke
parents:
diff changeset
121 for (int ii=0; ii<size; ii++){
a61af66fc99e Initial load
duke
parents:
diff changeset
122 FieldImpl fieldImpl = (FieldImpl)instanceFields.get(ii);
a61af66fc99e Initial load
duke
parents:
diff changeset
123 map.put(fieldImpl, fieldImpl.getValue(saObject));
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 return map;
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 public void setValue(Field field, Value value)
a61af66fc99e Initial load
duke
parents:
diff changeset
130 throws InvalidTypeException, ClassNotLoadedException {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 vm.throwNotReadOnlyException("ObjectReference.setValue(...)");
a61af66fc99e Initial load
duke
parents:
diff changeset
132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 public Value invokeMethod(ThreadReference threadIntf, Method methodIntf,
a61af66fc99e Initial load
duke
parents:
diff changeset
135 List arguments, int options)
a61af66fc99e Initial load
duke
parents:
diff changeset
136 throws InvalidTypeException,
a61af66fc99e Initial load
duke
parents:
diff changeset
137 IncompatibleThreadStateException,
a61af66fc99e Initial load
duke
parents:
diff changeset
138 InvocationException,
a61af66fc99e Initial load
duke
parents:
diff changeset
139 ClassNotLoadedException {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 vm.throwNotReadOnlyException("ObjectReference.invokeMethod(...)");
a61af66fc99e Initial load
duke
parents:
diff changeset
141 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
143
a61af66fc99e Initial load
duke
parents:
diff changeset
144 public void disableCollection() {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 vm.throwNotReadOnlyException("ObjectReference.disableCollection()");
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 public void enableCollection() {
a61af66fc99e Initial load
duke
parents:
diff changeset
149 vm.throwNotReadOnlyException("ObjectReference.enableCollection()");
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 public boolean isCollected() {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 vm.throwNotReadOnlyException("ObjectReference.isCollected()");
a61af66fc99e Initial load
duke
parents:
diff changeset
154 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
155 }
a61af66fc99e Initial load
duke
parents:
diff changeset
156
a61af66fc99e Initial load
duke
parents:
diff changeset
157 public long uniqueID() {
a61af66fc99e Initial load
duke
parents:
diff changeset
158 return myID;
a61af66fc99e Initial load
duke
parents:
diff changeset
159 }
a61af66fc99e Initial load
duke
parents:
diff changeset
160
a61af66fc99e Initial load
duke
parents:
diff changeset
161 public List waitingThreads() throws IncompatibleThreadStateException {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 if (vm.canGetMonitorInfo() == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 throw new UnsupportedOperationException();
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 (! monitorInfoCached) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 computeMonitorInfo();
a61af66fc99e Initial load
duke
parents:
diff changeset
168 }
a61af66fc99e Initial load
duke
parents:
diff changeset
169 return waitingThreads;
a61af66fc99e Initial load
duke
parents:
diff changeset
170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
171
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 public ThreadReference owningThread() throws IncompatibleThreadStateException {
a61af66fc99e Initial load
duke
parents:
diff changeset
174 if (vm.canGetMonitorInfo() == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 throw new UnsupportedOperationException();
a61af66fc99e Initial load
duke
parents:
diff changeset
176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 if (! monitorInfoCached) {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 computeMonitorInfo();
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181 return owningThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
183
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185 public int entryCount() throws IncompatibleThreadStateException {
a61af66fc99e Initial load
duke
parents:
diff changeset
186 if (vm.canGetMonitorInfo() == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
187 throw new UnsupportedOperationException();
a61af66fc99e Initial load
duke
parents:
diff changeset
188 }
a61af66fc99e Initial load
duke
parents:
diff changeset
189
a61af66fc99e Initial load
duke
parents:
diff changeset
190 if (! monitorInfoCached) {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 computeMonitorInfo();
a61af66fc99e Initial load
duke
parents:
diff changeset
192 }
a61af66fc99e Initial load
duke
parents:
diff changeset
193 return entryCount;
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }
a61af66fc99e Initial load
duke
parents:
diff changeset
195
a61af66fc99e Initial load
duke
parents:
diff changeset
196 // new method since 1.6.
a61af66fc99e Initial load
duke
parents:
diff changeset
197 // Real body will be supplied later.
a61af66fc99e Initial load
duke
parents:
diff changeset
198 public List referringObjects(long maxReferrers) {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 if (!vm.canGetInstanceInfo()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
200 throw new UnsupportedOperationException(
a61af66fc99e Initial load
duke
parents:
diff changeset
201 "target does not support getting instances");
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203 if (maxReferrers < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
204 throw new IllegalArgumentException("maxReferrers is less than zero: "
a61af66fc99e Initial load
duke
parents:
diff changeset
205 + maxReferrers);
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
207 final ObjectReference obj = this;
a61af66fc99e Initial load
duke
parents:
diff changeset
208 final List objects = new ArrayList(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
209 final long max = maxReferrers;
a61af66fc99e Initial load
duke
parents:
diff changeset
210 vm.saObjectHeap().iterate(new DefaultHeapVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
211 private long refCount = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
212 public boolean doObj(Oop oop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
213 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 ObjectReference objref = vm.objectMirror(oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
215 List fields = objref.referenceType().allFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
216 for (int i=0; i < fields.size(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
217 Field fld = (Field)fields.get(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
218 if (objref.getValue(fld).equals(obj) && !objects.contains(objref)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
219 objects.add(objref);
a61af66fc99e Initial load
duke
parents:
diff changeset
220 refCount++;
a61af66fc99e Initial load
duke
parents:
diff changeset
221 }
a61af66fc99e Initial load
duke
parents:
diff changeset
222 }
a61af66fc99e Initial load
duke
parents:
diff changeset
223 if (max > 0 && refCount >= max) {
a61af66fc99e Initial load
duke
parents:
diff changeset
224 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
225 }
a61af66fc99e Initial load
duke
parents:
diff changeset
226 } catch (RuntimeException x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
227 // Ignore RuntimeException thrown from vm.objectMirror(oop)
a61af66fc99e Initial load
duke
parents:
diff changeset
228 // for bad oop. It is possible to see some bad oop
a61af66fc99e Initial load
duke
parents:
diff changeset
229 // because heap might be iterating at no safepoint.
a61af66fc99e Initial load
duke
parents:
diff changeset
230 }
a61af66fc99e Initial load
duke
parents:
diff changeset
231 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
232
a61af66fc99e Initial load
duke
parents:
diff changeset
233 }
a61af66fc99e Initial load
duke
parents:
diff changeset
234 });
a61af66fc99e Initial load
duke
parents:
diff changeset
235 return objects;
a61af66fc99e Initial load
duke
parents:
diff changeset
236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
237
a61af66fc99e Initial load
duke
parents:
diff changeset
238 // refer to JvmtiEnvBase::count_locked_objects.
a61af66fc99e Initial load
duke
parents:
diff changeset
239 // Count the number of objects for a lightweight monitor. The obj
a61af66fc99e Initial load
duke
parents:
diff changeset
240 // parameter is object that owns the monitor so this routine will
a61af66fc99e Initial load
duke
parents:
diff changeset
241 // count the number of times the same object was locked by frames
a61af66fc99e Initial load
duke
parents:
diff changeset
242 // in JavaThread. i.e., we count total number of times the same
a61af66fc99e Initial load
duke
parents:
diff changeset
243 // object is (lightweight) locked by given thread.
a61af66fc99e Initial load
duke
parents:
diff changeset
244 private int countLockedObjects(JavaThread jt, Oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
245 int res = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
246 JavaVFrame frame = jt.getLastJavaVFrameDbg();
a61af66fc99e Initial load
duke
parents:
diff changeset
247 while (frame != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
248 List monitors = frame.getMonitors();
a61af66fc99e Initial load
duke
parents:
diff changeset
249 OopHandle givenHandle = obj.getHandle();
a61af66fc99e Initial load
duke
parents:
diff changeset
250 for (Iterator itr = monitors.iterator(); itr.hasNext();) {
a61af66fc99e Initial load
duke
parents:
diff changeset
251 MonitorInfo mi = (MonitorInfo) itr.next();
818
b109e761e927 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 0
diff changeset
252 if (mi.eliminated() && frame.isCompiledFrame()) continue; // skip eliminated monitor
0
a61af66fc99e Initial load
duke
parents:
diff changeset
253 if (givenHandle.equals(mi.owner())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
254 res++;
a61af66fc99e Initial load
duke
parents:
diff changeset
255 }
a61af66fc99e Initial load
duke
parents:
diff changeset
256 }
a61af66fc99e Initial load
duke
parents:
diff changeset
257 frame = (JavaVFrame) frame.javaSender();
a61af66fc99e Initial load
duke
parents:
diff changeset
258 }
a61af66fc99e Initial load
duke
parents:
diff changeset
259 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
260 }
a61af66fc99e Initial load
duke
parents:
diff changeset
261
a61af66fc99e Initial load
duke
parents:
diff changeset
262 // wrappers on same named method of Threads class
a61af66fc99e Initial load
duke
parents:
diff changeset
263 // returns List<JavaThread>
a61af66fc99e Initial load
duke
parents:
diff changeset
264 private List getPendingThreads(ObjectMonitor mon) {
a61af66fc99e Initial load
duke
parents:
diff changeset
265 return vm.saVM().getThreads().getPendingThreads(mon);
a61af66fc99e Initial load
duke
parents:
diff changeset
266 }
a61af66fc99e Initial load
duke
parents:
diff changeset
267
a61af66fc99e Initial load
duke
parents:
diff changeset
268 // returns List<JavaThread>
a61af66fc99e Initial load
duke
parents:
diff changeset
269 private List getWaitingThreads(ObjectMonitor mon) {
a61af66fc99e Initial load
duke
parents:
diff changeset
270 return vm.saVM().getThreads().getWaitingThreads(mon);
a61af66fc99e Initial load
duke
parents:
diff changeset
271 }
a61af66fc99e Initial load
duke
parents:
diff changeset
272
a61af66fc99e Initial load
duke
parents:
diff changeset
273 private JavaThread owningThreadFromMonitor(Address addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
274 return vm.saVM().getThreads().owningThreadFromMonitor(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
275 }
a61af66fc99e Initial load
duke
parents:
diff changeset
276
a61af66fc99e Initial load
duke
parents:
diff changeset
277 // refer to JvmtiEnv::GetObjectMonitorUsage
a61af66fc99e Initial load
duke
parents:
diff changeset
278 private void computeMonitorInfo() {
a61af66fc99e Initial load
duke
parents:
diff changeset
279 monitorInfoCached = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
280 Mark mark = saObject.getMark();
a61af66fc99e Initial load
duke
parents:
diff changeset
281 ObjectMonitor mon = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
282 Address owner = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
283 // check for heavyweight monitor
a61af66fc99e Initial load
duke
parents:
diff changeset
284 if (! mark.hasMonitor()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
285 // check for lightweight monitor
a61af66fc99e Initial load
duke
parents:
diff changeset
286 if (mark.hasLocker()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
287 owner = mark.locker().getAddress(); // save the address of the Lock word
a61af66fc99e Initial load
duke
parents:
diff changeset
288 }
a61af66fc99e Initial load
duke
parents:
diff changeset
289 // implied else: no owner
a61af66fc99e Initial load
duke
parents:
diff changeset
290 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
291 // this object has a heavyweight monitor
a61af66fc99e Initial load
duke
parents:
diff changeset
292 mon = mark.monitor();
a61af66fc99e Initial load
duke
parents:
diff changeset
293
a61af66fc99e Initial load
duke
parents:
diff changeset
294 // The owner field of a heavyweight monitor may be NULL for no
a61af66fc99e Initial load
duke
parents:
diff changeset
295 // owner, a JavaThread * or it may still be the address of the
a61af66fc99e Initial load
duke
parents:
diff changeset
296 // Lock word in a JavaThread's stack. A monitor can be inflated
a61af66fc99e Initial load
duke
parents:
diff changeset
297 // by a non-owning JavaThread, but only the owning JavaThread
a61af66fc99e Initial load
duke
parents:
diff changeset
298 // can change the owner field from the Lock word to the
a61af66fc99e Initial load
duke
parents:
diff changeset
299 // JavaThread * and it may not have done that yet.
a61af66fc99e Initial load
duke
parents:
diff changeset
300 owner = mon.owner();
a61af66fc99e Initial load
duke
parents:
diff changeset
301 }
a61af66fc99e Initial load
duke
parents:
diff changeset
302
a61af66fc99e Initial load
duke
parents:
diff changeset
303 // find the owning thread
a61af66fc99e Initial load
duke
parents:
diff changeset
304 if (owner != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
305 owningThread = vm.threadMirror(owningThreadFromMonitor(owner));
a61af66fc99e Initial load
duke
parents:
diff changeset
306 }
a61af66fc99e Initial load
duke
parents:
diff changeset
307
a61af66fc99e Initial load
duke
parents:
diff changeset
308 // compute entryCount
a61af66fc99e Initial load
duke
parents:
diff changeset
309 if (owningThread != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
310 if (owningThread.getJavaThread().getAddress().equals(owner)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
311 // the owner field is the JavaThread *
a61af66fc99e Initial load
duke
parents:
diff changeset
312 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
313 Assert.that(false, "must have heavyweight monitor with JavaThread * owner");
a61af66fc99e Initial load
duke
parents:
diff changeset
314 }
a61af66fc99e Initial load
duke
parents:
diff changeset
315 entryCount = (int) mark.monitor().recursions() + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
316 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
317 // The owner field is the Lock word on the JavaThread's stack
a61af66fc99e Initial load
duke
parents:
diff changeset
318 // so the recursions field is not valid. We have to count the
a61af66fc99e Initial load
duke
parents:
diff changeset
319 // number of recursive monitor entries the hard way.
a61af66fc99e Initial load
duke
parents:
diff changeset
320 entryCount = countLockedObjects(owningThread.getJavaThread(), saObject);
a61af66fc99e Initial load
duke
parents:
diff changeset
321 }
a61af66fc99e Initial load
duke
parents:
diff changeset
322 }
a61af66fc99e Initial load
duke
parents:
diff changeset
323
a61af66fc99e Initial load
duke
parents:
diff changeset
324 // find the contenders & waiters
a61af66fc99e Initial load
duke
parents:
diff changeset
325 waitingThreads = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
326 if (mon != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
327 // this object has a heavyweight monitor. threads could
a61af66fc99e Initial load
duke
parents:
diff changeset
328 // be contenders or waiters
a61af66fc99e Initial load
duke
parents:
diff changeset
329 // add all contenders
a61af66fc99e Initial load
duke
parents:
diff changeset
330 List pendingThreads = getPendingThreads(mon);
a61af66fc99e Initial load
duke
parents:
diff changeset
331 // convert the JavaThreads to ThreadReferenceImpls
a61af66fc99e Initial load
duke
parents:
diff changeset
332 for (Iterator itrPend = pendingThreads.iterator(); itrPend.hasNext();) {
a61af66fc99e Initial load
duke
parents:
diff changeset
333 waitingThreads.add(vm.threadMirror((JavaThread) itrPend.next()));
a61af66fc99e Initial load
duke
parents:
diff changeset
334 }
a61af66fc99e Initial load
duke
parents:
diff changeset
335
a61af66fc99e Initial load
duke
parents:
diff changeset
336 // add all waiters (threads in Object.wait())
a61af66fc99e Initial load
duke
parents:
diff changeset
337 // note that we don't do this JVMTI way. To do it JVMTI way,
a61af66fc99e Initial load
duke
parents:
diff changeset
338 // we would need to access ObjectWaiter list maintained in
a61af66fc99e Initial load
duke
parents:
diff changeset
339 // ObjectMonitor::_queue. But we don't have this struct exposed
a61af66fc99e Initial load
duke
parents:
diff changeset
340 // in vmStructs. We do waiters list in a way similar to getting
a61af66fc99e Initial load
duke
parents:
diff changeset
341 // pending threads list
a61af66fc99e Initial load
duke
parents:
diff changeset
342 List objWaitingThreads = getWaitingThreads(mon);
a61af66fc99e Initial load
duke
parents:
diff changeset
343 // convert the JavaThreads to ThreadReferenceImpls
a61af66fc99e Initial load
duke
parents:
diff changeset
344 for (Iterator itrWait = objWaitingThreads.iterator(); itrWait.hasNext();) {
a61af66fc99e Initial load
duke
parents:
diff changeset
345 waitingThreads.add(vm.threadMirror((JavaThread) itrWait.next()));
a61af66fc99e Initial load
duke
parents:
diff changeset
346 }
a61af66fc99e Initial load
duke
parents:
diff changeset
347 }
a61af66fc99e Initial load
duke
parents:
diff changeset
348 }
a61af66fc99e Initial load
duke
parents:
diff changeset
349
a61af66fc99e Initial load
duke
parents:
diff changeset
350 public boolean equals(Object obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
351 if ((obj != null) && (obj instanceof ObjectReferenceImpl)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
352 ObjectReferenceImpl other = (ObjectReferenceImpl)obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
353 return (ref().equals(other.ref())) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
354 super.equals(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
355 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
356 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
357 }
a61af66fc99e Initial load
duke
parents:
diff changeset
358 }
a61af66fc99e Initial load
duke
parents:
diff changeset
359
a61af66fc99e Initial load
duke
parents:
diff changeset
360 public int hashCode() {
a61af66fc99e Initial load
duke
parents:
diff changeset
361 return saObject.hashCode();
a61af66fc99e Initial load
duke
parents:
diff changeset
362 }
a61af66fc99e Initial load
duke
parents:
diff changeset
363
a61af66fc99e Initial load
duke
parents:
diff changeset
364 public String toString() {
a61af66fc99e Initial load
duke
parents:
diff changeset
365 return "instance of " + referenceType().name() + "(id=" + uniqueID() + ")";
a61af66fc99e Initial load
duke
parents:
diff changeset
366 }
a61af66fc99e Initial load
duke
parents:
diff changeset
367 }