147 }
148 }
149
150 /** Memory operations */
151 public void oopsDo(AddressVisitor oopVisitor) {
152 // FIXME: add more of VM functionality
153 for (JavaThread thread = first(); thread != null; thread = thread.next()) {
154 thread.oopsDo(oopVisitor);
155 }
156 }
157
158 // refer to Threads::owning_thread_from_monitor_owner
159 public JavaThread owningThreadFromMonitor(Address o) {
160 if (o == null) return null;
161 for (JavaThread thread = first(); thread != null; thread = thread.next()) {
162 if (o.equals(thread.threadObjectAddress())) {
163 return thread;
164 }
165 }
166
167 long leastDiff = 0;
168 boolean leastDiffInitialized = false;
169 JavaThread theOwner = null;
170 for (JavaThread thread = first(); thread != null; thread = thread.next()) {
171 Address addr = thread.highestLock();
172 if (addr == null || addr.lessThan(o)) continue;
173 long diff = addr.minus(o);
174 if (!leastDiffInitialized || diff < leastDiff) {
175 leastDiffInitialized = true;
176 leastDiff = diff;
177 theOwner = thread;
178 }
179 }
180 return theOwner;
181 }
182
183 public JavaThread owningThreadFromMonitor(ObjectMonitor monitor) {
184 return owningThreadFromMonitor(monitor.owner());
185 }
186
187 // refer to Threads::get_pending_threads
188 // Get list of Java threads that are waiting to enter the specified monitor.
189 public List getPendingThreads(ObjectMonitor monitor) {
190 List pendingThreads = new ArrayList();
191 for (JavaThread thread = first(); thread != null; thread = thread.next()) {
192 if (thread.isCompilerThread()) {
193 continue;
194 }
195 ObjectMonitor pending = thread.getCurrentPendingMonitor();
196 if (monitor.equals(pending)) {
197 pendingThreads.add(thread);
198 }
199 }
200 return pendingThreads;
|
147 }
148 }
149
150 /** Memory operations */
151 public void oopsDo(AddressVisitor oopVisitor) {
152 // FIXME: add more of VM functionality
153 for (JavaThread thread = first(); thread != null; thread = thread.next()) {
154 thread.oopsDo(oopVisitor);
155 }
156 }
157
158 // refer to Threads::owning_thread_from_monitor_owner
159 public JavaThread owningThreadFromMonitor(Address o) {
160 if (o == null) return null;
161 for (JavaThread thread = first(); thread != null; thread = thread.next()) {
162 if (o.equals(thread.threadObjectAddress())) {
163 return thread;
164 }
165 }
166
167 for (JavaThread thread = first(); thread != null; thread = thread.next()) {
168 if (thread.isLockOwned(o))
169 return thread;
170 }
171 return null;
172 }
173
174 public JavaThread owningThreadFromMonitor(ObjectMonitor monitor) {
175 return owningThreadFromMonitor(monitor.owner());
176 }
177
178 // refer to Threads::get_pending_threads
179 // Get list of Java threads that are waiting to enter the specified monitor.
180 public List getPendingThreads(ObjectMonitor monitor) {
181 List pendingThreads = new ArrayList();
182 for (JavaThread thread = first(); thread != null; thread = thread.next()) {
183 if (thread.isCompilerThread()) {
184 continue;
185 }
186 ObjectMonitor pending = thread.getCurrentPendingMonitor();
187 if (monitor.equals(pending)) {
188 pendingThreads.add(thread);
189 }
190 }
191 return pendingThreads;
|